1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This file contains the low level primitives for operating on tree nodes,
23 including allocation, list operations, interning of identifiers,
24 construction of data type nodes and statement nodes,
25 and construction of type conversion nodes. It also contains
26 tables index by tree code that describe how to take apart
29 It is intended to be language-independent, but occasionally
30 calls language-dependent routines defined (for C) in typecheck.c. */
34 #include "coretypes.h"
47 #include "langhooks.h"
48 #include "tree-iterator.h"
49 #include "basic-block.h"
50 #include "tree-flow.h"
52 #include "pointer-set.h"
53 #include "fixed-value.h"
55 /* Tree code classes. */
57 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
58 #define END_OF_BASE_TREE_CODES tcc_exceptional,
60 const enum tree_code_class tree_code_type[] = {
61 #include "all-tree.def"
65 #undef END_OF_BASE_TREE_CODES
67 /* Table indexed by tree code giving number of expression
68 operands beyond the fixed part of the node structure.
69 Not used for types or decls. */
71 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
72 #define END_OF_BASE_TREE_CODES 0,
74 const unsigned char tree_code_length[] = {
75 #include "all-tree.def"
79 #undef END_OF_BASE_TREE_CODES
81 /* Names of tree components.
82 Used for printing out the tree and error messages. */
83 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
84 #define END_OF_BASE_TREE_CODES "@dummy",
86 const char *const tree_code_name[] = {
87 #include "all-tree.def"
91 #undef END_OF_BASE_TREE_CODES
93 /* Each tree code class has an associated string representation.
94 These must correspond to the tree_code_class entries. */
96 const char *const tree_code_class_strings[] =
112 /* obstack.[ch] explicitly declined to prototype this. */
113 extern int _obstack_allocated_p (struct obstack *h, void *obj);
115 #ifdef GATHER_STATISTICS
116 /* Statistics-gathering stuff. */
118 int tree_node_counts[(int) all_kinds];
119 int tree_node_sizes[(int) all_kinds];
121 /* Keep in sync with tree.h:enum tree_node_kind. */
122 static const char * const tree_node_kind_names[] = {
144 #endif /* GATHER_STATISTICS */
146 /* Unique id for next decl created. */
147 static GTY(()) int next_decl_uid;
148 /* Unique id for next type created. */
149 static GTY(()) int next_type_uid = 1;
151 /* Since we cannot rehash a type after it is in the table, we have to
152 keep the hash code. */
154 struct type_hash GTY(())
160 /* Initial size of the hash table (rounded to next prime). */
161 #define TYPE_HASH_INITIAL_SIZE 1000
163 /* Now here is the hash table. When recording a type, it is added to
164 the slot whose index is the hash code. Note that the hash table is
165 used for several kinds of types (function types, array types and
166 array index range types, for now). While all these live in the
167 same table, they are completely independent, and the hash code is
168 computed differently for each of these. */
170 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
171 htab_t type_hash_table;
173 /* Hash table and temporary node for larger integer const values. */
174 static GTY (()) tree int_cst_node;
175 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
176 htab_t int_cst_hash_table;
178 /* General tree->tree mapping structure for use in hash tables. */
181 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
182 htab_t debug_expr_for_decl;
184 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
185 htab_t value_expr_for_decl;
187 static GTY ((if_marked ("tree_priority_map_marked_p"),
188 param_is (struct tree_priority_map)))
189 htab_t init_priority_for_decl;
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
192 htab_t restrict_base_for_decl;
194 static void set_type_quals (tree, int);
195 static int type_hash_eq (const void *, const void *);
196 static hashval_t type_hash_hash (const void *);
197 static hashval_t int_cst_hash_hash (const void *);
198 static int int_cst_hash_eq (const void *, const void *);
199 static void print_type_hash_statistics (void);
200 static void print_debug_expr_statistics (void);
201 static void print_value_expr_statistics (void);
202 static int type_hash_marked_p (const void *);
203 static unsigned int type_hash_list (const_tree, hashval_t);
204 static unsigned int attribute_hash_list (const_tree, hashval_t);
206 tree global_trees[TI_MAX];
207 tree integer_types[itk_none];
209 unsigned char tree_contains_struct[MAX_TREE_CODES][64];
211 /* Number of operands for each OpenMP clause. */
212 unsigned const char omp_clause_num_ops[] =
214 0, /* OMP_CLAUSE_ERROR */
215 1, /* OMP_CLAUSE_PRIVATE */
216 1, /* OMP_CLAUSE_SHARED */
217 1, /* OMP_CLAUSE_FIRSTPRIVATE */
218 2, /* OMP_CLAUSE_LASTPRIVATE */
219 4, /* OMP_CLAUSE_REDUCTION */
220 1, /* OMP_CLAUSE_COPYIN */
221 1, /* OMP_CLAUSE_COPYPRIVATE */
222 1, /* OMP_CLAUSE_IF */
223 1, /* OMP_CLAUSE_NUM_THREADS */
224 1, /* OMP_CLAUSE_SCHEDULE */
225 0, /* OMP_CLAUSE_NOWAIT */
226 0, /* OMP_CLAUSE_ORDERED */
227 0, /* OMP_CLAUSE_DEFAULT */
228 3, /* OMP_CLAUSE_COLLAPSE */
229 0 /* OMP_CLAUSE_UNTIED */
232 const char * const omp_clause_code_name[] =
257 /* Initialize the hash table of types. */
258 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
261 debug_expr_for_decl = htab_create_ggc (512, tree_map_hash,
264 value_expr_for_decl = htab_create_ggc (512, tree_map_hash,
266 init_priority_for_decl = htab_create_ggc (512, tree_priority_map_hash,
267 tree_priority_map_eq, 0);
268 restrict_base_for_decl = htab_create_ggc (256, tree_map_hash,
271 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash,
272 int_cst_hash_eq, NULL);
274 int_cst_node = make_node (INTEGER_CST);
276 tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON] = 1;
277 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON] = 1;
278 tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON] = 1;
281 tree_contains_struct[CONST_DECL][TS_DECL_COMMON] = 1;
282 tree_contains_struct[VAR_DECL][TS_DECL_COMMON] = 1;
283 tree_contains_struct[PARM_DECL][TS_DECL_COMMON] = 1;
284 tree_contains_struct[RESULT_DECL][TS_DECL_COMMON] = 1;
285 tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON] = 1;
286 tree_contains_struct[TYPE_DECL][TS_DECL_COMMON] = 1;
287 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON] = 1;
288 tree_contains_struct[LABEL_DECL][TS_DECL_COMMON] = 1;
289 tree_contains_struct[FIELD_DECL][TS_DECL_COMMON] = 1;
292 tree_contains_struct[CONST_DECL][TS_DECL_WRTL] = 1;
293 tree_contains_struct[VAR_DECL][TS_DECL_WRTL] = 1;
294 tree_contains_struct[PARM_DECL][TS_DECL_WRTL] = 1;
295 tree_contains_struct[RESULT_DECL][TS_DECL_WRTL] = 1;
296 tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL] = 1;
297 tree_contains_struct[LABEL_DECL][TS_DECL_WRTL] = 1;
299 tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL] = 1;
300 tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL] = 1;
301 tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL] = 1;
302 tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL] = 1;
303 tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL] = 1;
304 tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL] = 1;
305 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL] = 1;
306 tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL] = 1;
307 tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL] = 1;
308 tree_contains_struct[NAME_MEMORY_TAG][TS_DECL_MINIMAL] = 1;
309 tree_contains_struct[SYMBOL_MEMORY_TAG][TS_DECL_MINIMAL] = 1;
310 tree_contains_struct[MEMORY_PARTITION_TAG][TS_DECL_MINIMAL] = 1;
312 tree_contains_struct[NAME_MEMORY_TAG][TS_MEMORY_TAG] = 1;
313 tree_contains_struct[SYMBOL_MEMORY_TAG][TS_MEMORY_TAG] = 1;
314 tree_contains_struct[MEMORY_PARTITION_TAG][TS_MEMORY_TAG] = 1;
316 tree_contains_struct[MEMORY_PARTITION_TAG][TS_MEMORY_PARTITION_TAG] = 1;
318 tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS] = 1;
319 tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS] = 1;
320 tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS] = 1;
321 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_WITH_VIS] = 1;
323 tree_contains_struct[VAR_DECL][TS_VAR_DECL] = 1;
324 tree_contains_struct[FIELD_DECL][TS_FIELD_DECL] = 1;
325 tree_contains_struct[PARM_DECL][TS_PARM_DECL] = 1;
326 tree_contains_struct[LABEL_DECL][TS_LABEL_DECL] = 1;
327 tree_contains_struct[RESULT_DECL][TS_RESULT_DECL] = 1;
328 tree_contains_struct[CONST_DECL][TS_CONST_DECL] = 1;
329 tree_contains_struct[TYPE_DECL][TS_TYPE_DECL] = 1;
330 tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL] = 1;
332 lang_hooks.init_ts ();
336 /* The name of the object as the assembler will see it (but before any
337 translations made by ASM_OUTPUT_LABELREF). Often this is the same
338 as DECL_NAME. It is an IDENTIFIER_NODE. */
340 decl_assembler_name (tree decl)
342 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
343 lang_hooks.set_decl_assembler_name (decl);
344 return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name;
347 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
350 decl_assembler_name_equal (tree decl, const_tree asmname)
352 tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
353 const char *decl_str;
354 const char *asmname_str;
357 if (decl_asmname == asmname)
360 decl_str = IDENTIFIER_POINTER (decl_asmname);
361 asmname_str = IDENTIFIER_POINTER (asmname);
364 /* If the target assembler name was set by the user, things are trickier.
365 We have a leading '*' to begin with. After that, it's arguable what
366 is the correct thing to do with -fleading-underscore. Arguably, we've
367 historically been doing the wrong thing in assemble_alias by always
368 printing the leading underscore. Since we're not changing that, make
369 sure user_label_prefix follows the '*' before matching. */
370 if (decl_str[0] == '*')
372 size_t ulp_len = strlen (user_label_prefix);
378 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
379 decl_str += ulp_len, test=true;
383 if (asmname_str[0] == '*')
385 size_t ulp_len = strlen (user_label_prefix);
391 else if (strncmp (asmname_str, user_label_prefix, ulp_len) == 0)
392 asmname_str += ulp_len, test=true;
399 return strcmp (decl_str, asmname_str) == 0;
402 /* Hash asmnames ignoring the user specified marks. */
405 decl_assembler_name_hash (const_tree asmname)
407 if (IDENTIFIER_POINTER (asmname)[0] == '*')
409 const char *decl_str = IDENTIFIER_POINTER (asmname) + 1;
410 size_t ulp_len = strlen (user_label_prefix);
414 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
417 return htab_hash_string (decl_str);
420 return htab_hash_string (IDENTIFIER_POINTER (asmname));
423 /* Compute the number of bytes occupied by a tree with code CODE.
424 This function cannot be used for nodes that have variable sizes,
425 including TREE_VEC, PHI_NODE, STRING_CST, and CALL_EXPR. */
427 tree_code_size (enum tree_code code)
429 switch (TREE_CODE_CLASS (code))
431 case tcc_declaration: /* A decl node */
436 return sizeof (struct tree_field_decl);
438 return sizeof (struct tree_parm_decl);
440 return sizeof (struct tree_var_decl);
442 return sizeof (struct tree_label_decl);
444 return sizeof (struct tree_result_decl);
446 return sizeof (struct tree_const_decl);
448 return sizeof (struct tree_type_decl);
450 return sizeof (struct tree_function_decl);
451 case NAME_MEMORY_TAG:
452 case SYMBOL_MEMORY_TAG:
453 return sizeof (struct tree_memory_tag);
454 case MEMORY_PARTITION_TAG:
455 return sizeof (struct tree_memory_partition_tag);
457 return sizeof (struct tree_decl_non_common);
461 case tcc_type: /* a type node */
462 return sizeof (struct tree_type);
464 case tcc_reference: /* a reference */
465 case tcc_expression: /* an expression */
466 case tcc_statement: /* an expression with side effects */
467 case tcc_comparison: /* a comparison expression */
468 case tcc_unary: /* a unary arithmetic expression */
469 case tcc_binary: /* a binary arithmetic expression */
470 return (sizeof (struct tree_exp)
471 + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
473 case tcc_gimple_stmt:
474 return (sizeof (struct gimple_stmt)
475 + (TREE_CODE_LENGTH (code) - 1) * sizeof (char *));
477 case tcc_constant: /* a constant */
480 case INTEGER_CST: return sizeof (struct tree_int_cst);
481 case REAL_CST: return sizeof (struct tree_real_cst);
482 case FIXED_CST: return sizeof (struct tree_fixed_cst);
483 case COMPLEX_CST: return sizeof (struct tree_complex);
484 case VECTOR_CST: return sizeof (struct tree_vector);
485 case STRING_CST: gcc_unreachable ();
487 return lang_hooks.tree_size (code);
490 case tcc_exceptional: /* something random, like an identifier. */
493 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
494 case TREE_LIST: return sizeof (struct tree_list);
497 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
501 case PHI_NODE: gcc_unreachable ();
503 case SSA_NAME: return sizeof (struct tree_ssa_name);
505 case STATEMENT_LIST: return sizeof (struct tree_statement_list);
506 case BLOCK: return sizeof (struct tree_block);
507 case CONSTRUCTOR: return sizeof (struct tree_constructor);
510 return lang_hooks.tree_size (code);
518 /* Compute the number of bytes occupied by NODE. This routine only
519 looks at TREE_CODE, except for those nodes that have variable sizes. */
521 tree_size (const_tree node)
523 const enum tree_code code = TREE_CODE (node);
527 return (sizeof (struct tree_phi_node)
528 + (PHI_ARG_CAPACITY (node) - 1) * sizeof (struct phi_arg_d));
531 return (offsetof (struct tree_binfo, base_binfos)
532 + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node)));
535 return (sizeof (struct tree_vec)
536 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
539 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
542 return (sizeof (struct tree_omp_clause)
543 + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
547 if (TREE_CODE_CLASS (code) == tcc_vl_exp)
548 return (sizeof (struct tree_exp)
549 + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
551 return tree_code_size (code);
555 /* Return a newly allocated node of code CODE. For decl and type
556 nodes, some other fields are initialized. The rest of the node is
557 initialized to zero. This function cannot be used for PHI_NODE,
558 TREE_VEC or OMP_CLAUSE nodes, which is enforced by asserts in
561 Achoo! I got a code in the node. */
564 make_node_stat (enum tree_code code MEM_STAT_DECL)
567 enum tree_code_class type = TREE_CODE_CLASS (code);
568 size_t length = tree_code_size (code);
569 #ifdef GATHER_STATISTICS
574 case tcc_declaration: /* A decl node */
578 case tcc_type: /* a type node */
582 case tcc_statement: /* an expression with side effects */
586 case tcc_reference: /* a reference */
590 case tcc_expression: /* an expression */
591 case tcc_comparison: /* a comparison expression */
592 case tcc_unary: /* a unary arithmetic expression */
593 case tcc_binary: /* a binary arithmetic expression */
597 case tcc_constant: /* a constant */
601 case tcc_gimple_stmt:
602 kind = gimple_stmt_kind;
605 case tcc_exceptional: /* something random, like an identifier. */
608 case IDENTIFIER_NODE:
625 kind = ssa_name_kind;
646 tree_node_counts[(int) kind]++;
647 tree_node_sizes[(int) kind] += length;
650 if (code == IDENTIFIER_NODE)
651 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_id_zone);
653 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
655 memset (t, 0, length);
657 TREE_SET_CODE (t, code);
662 TREE_SIDE_EFFECTS (t) = 1;
665 case tcc_declaration:
666 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
667 DECL_IN_SYSTEM_HEADER (t) = in_system_header;
668 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
670 if (code == FUNCTION_DECL)
672 DECL_ALIGN (t) = FUNCTION_BOUNDARY;
673 DECL_MODE (t) = FUNCTION_MODE;
677 /* We have not yet computed the alias set for this declaration. */
678 DECL_POINTER_ALIAS_SET (t) = -1;
680 DECL_SOURCE_LOCATION (t) = input_location;
681 DECL_UID (t) = next_decl_uid++;
686 TYPE_UID (t) = next_type_uid++;
687 TYPE_ALIGN (t) = BITS_PER_UNIT;
688 TYPE_USER_ALIGN (t) = 0;
689 TYPE_MAIN_VARIANT (t) = t;
690 TYPE_CANONICAL (t) = t;
692 /* Default to no attributes for type, but let target change that. */
693 TYPE_ATTRIBUTES (t) = NULL_TREE;
694 targetm.set_default_type_attributes (t);
696 /* We have not yet computed the alias set for this type. */
697 TYPE_ALIAS_SET (t) = -1;
701 TREE_CONSTANT (t) = 1;
710 case PREDECREMENT_EXPR:
711 case PREINCREMENT_EXPR:
712 case POSTDECREMENT_EXPR:
713 case POSTINCREMENT_EXPR:
714 /* All of these have side-effects, no matter what their
716 TREE_SIDE_EFFECTS (t) = 1;
724 case tcc_gimple_stmt:
727 case GIMPLE_MODIFY_STMT:
728 TREE_SIDE_EFFECTS (t) = 1;
736 /* Other classes need no special treatment. */
743 /* Return a new node with the same contents as NODE except that its
744 TREE_CHAIN is zero and it has a fresh uid. */
747 copy_node_stat (tree node MEM_STAT_DECL)
750 enum tree_code code = TREE_CODE (node);
753 gcc_assert (code != STATEMENT_LIST);
755 length = tree_size (node);
756 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
757 memcpy (t, node, length);
759 if (!GIMPLE_TUPLE_P (node))
761 TREE_ASM_WRITTEN (t) = 0;
762 TREE_VISITED (t) = 0;
765 if (TREE_CODE_CLASS (code) == tcc_declaration)
767 DECL_UID (t) = next_decl_uid++;
768 if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL)
769 && DECL_HAS_VALUE_EXPR_P (node))
771 SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
772 DECL_HAS_VALUE_EXPR_P (t) = 1;
774 if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node))
776 SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
777 DECL_HAS_INIT_PRIORITY_P (t) = 1;
779 if (TREE_CODE (node) == VAR_DECL && DECL_BASED_ON_RESTRICT_P (node))
781 SET_DECL_RESTRICT_BASE (t, DECL_GET_RESTRICT_BASE (node));
782 DECL_BASED_ON_RESTRICT_P (t) = 1;
785 else if (TREE_CODE_CLASS (code) == tcc_type)
787 TYPE_UID (t) = next_type_uid++;
788 /* The following is so that the debug code for
789 the copy is different from the original type.
790 The two statements usually duplicate each other
791 (because they clear fields of the same union),
792 but the optimizer should catch that. */
793 TYPE_SYMTAB_POINTER (t) = 0;
794 TYPE_SYMTAB_ADDRESS (t) = 0;
796 /* Do not copy the values cache. */
797 if (TYPE_CACHED_VALUES_P(t))
799 TYPE_CACHED_VALUES_P (t) = 0;
800 TYPE_CACHED_VALUES (t) = NULL_TREE;
807 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
808 For example, this can copy a list made of TREE_LIST nodes. */
811 copy_list (tree list)
819 head = prev = copy_node (list);
820 next = TREE_CHAIN (list);
823 TREE_CHAIN (prev) = copy_node (next);
824 prev = TREE_CHAIN (prev);
825 next = TREE_CHAIN (next);
831 /* Create an INT_CST node with a LOW value sign extended. */
834 build_int_cst (tree type, HOST_WIDE_INT low)
836 /* Support legacy code. */
838 type = integer_type_node;
840 return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
843 /* Create an INT_CST node with a LOW value zero extended. */
846 build_int_cstu (tree type, unsigned HOST_WIDE_INT low)
848 return build_int_cst_wide (type, low, 0);
851 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
852 if it is negative. This function is similar to build_int_cst, but
853 the extra bits outside of the type precision are cleared. Constants
854 with these extra bits may confuse the fold so that it detects overflows
855 even in cases when they do not occur, and in general should be avoided.
856 We cannot however make this a default behavior of build_int_cst without
857 more intrusive changes, since there are parts of gcc that rely on the extra
858 precision of the integer constants. */
861 build_int_cst_type (tree type, HOST_WIDE_INT low)
863 unsigned HOST_WIDE_INT low1;
868 fit_double_type (low, low < 0 ? -1 : 0, &low1, &hi, type);
870 return build_int_cst_wide (type, low1, hi);
873 /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated
874 and sign extended according to the value range of TYPE. */
877 build_int_cst_wide_type (tree type,
878 unsigned HOST_WIDE_INT low, HOST_WIDE_INT high)
880 fit_double_type (low, high, &low, &high, type);
881 return build_int_cst_wide (type, low, high);
884 /* These are the hash table functions for the hash table of INTEGER_CST
885 nodes of a sizetype. */
887 /* Return the hash code code X, an INTEGER_CST. */
890 int_cst_hash_hash (const void *x)
892 const_tree const t = (const_tree) x;
894 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
895 ^ htab_hash_pointer (TREE_TYPE (t)));
898 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
899 is the same as that given by *Y, which is the same. */
902 int_cst_hash_eq (const void *x, const void *y)
904 const_tree const xt = (const_tree) x;
905 const_tree const yt = (const_tree) y;
907 return (TREE_TYPE (xt) == TREE_TYPE (yt)
908 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt)
909 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
912 /* Create an INT_CST node of TYPE and value HI:LOW.
913 The returned node is always shared. For small integers we use a
914 per-type vector cache, for larger ones we use a single hash table. */
917 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
925 switch (TREE_CODE (type))
929 /* Cache NULL pointer. */
938 /* Cache false or true. */
946 if (TYPE_UNSIGNED (type))
949 limit = INTEGER_SHARE_LIMIT;
950 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
956 limit = INTEGER_SHARE_LIMIT + 1;
957 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
959 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
973 /* Look for it in the type's vector of small shared ints. */
974 if (!TYPE_CACHED_VALUES_P (type))
976 TYPE_CACHED_VALUES_P (type) = 1;
977 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
980 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
983 /* Make sure no one is clobbering the shared constant. */
984 gcc_assert (TREE_TYPE (t) == type);
985 gcc_assert (TREE_INT_CST_LOW (t) == low);
986 gcc_assert (TREE_INT_CST_HIGH (t) == hi);
990 /* Create a new shared int. */
991 t = make_node (INTEGER_CST);
993 TREE_INT_CST_LOW (t) = low;
994 TREE_INT_CST_HIGH (t) = hi;
995 TREE_TYPE (t) = type;
997 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
1002 /* Use the cache of larger shared ints. */
1005 TREE_INT_CST_LOW (int_cst_node) = low;
1006 TREE_INT_CST_HIGH (int_cst_node) = hi;
1007 TREE_TYPE (int_cst_node) = type;
1009 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT);
1013 /* Insert this one into the hash table. */
1016 /* Make a new node for next time round. */
1017 int_cst_node = make_node (INTEGER_CST);
1024 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1025 and the rest are zeros. */
1028 build_low_bits_mask (tree type, unsigned bits)
1030 unsigned HOST_WIDE_INT low;
1032 unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0;
1034 gcc_assert (bits <= TYPE_PRECISION (type));
1036 if (bits == TYPE_PRECISION (type)
1037 && !TYPE_UNSIGNED (type))
1039 /* Sign extended all-ones mask. */
1043 else if (bits <= HOST_BITS_PER_WIDE_INT)
1045 low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
1050 bits -= HOST_BITS_PER_WIDE_INT;
1052 high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
1055 return build_int_cst_wide (type, low, high);
1058 /* Checks that X is integer constant that can be expressed in (unsigned)
1059 HOST_WIDE_INT without loss of precision. */
1062 cst_and_fits_in_hwi (const_tree x)
1064 if (TREE_CODE (x) != INTEGER_CST)
1067 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
1070 return (TREE_INT_CST_HIGH (x) == 0
1071 || TREE_INT_CST_HIGH (x) == -1);
1074 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1075 are in a list pointed to by VALS. */
1078 build_vector (tree type, tree vals)
1080 tree v = make_node (VECTOR_CST);
1084 TREE_VECTOR_CST_ELTS (v) = vals;
1085 TREE_TYPE (v) = type;
1087 /* Iterate through elements and check for overflow. */
1088 for (link = vals; link; link = TREE_CHAIN (link))
1090 tree value = TREE_VALUE (link);
1092 /* Don't crash if we get an address constant. */
1093 if (!CONSTANT_CLASS_P (value))
1096 over |= TREE_OVERFLOW (value);
1099 TREE_OVERFLOW (v) = over;
1103 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1104 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1107 build_vector_from_ctor (tree type, VEC(constructor_elt,gc) *v)
1109 tree list = NULL_TREE;
1110 unsigned HOST_WIDE_INT idx;
1113 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
1114 list = tree_cons (NULL_TREE, value, list);
1115 return build_vector (type, nreverse (list));
1118 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1119 are in the VEC pointed to by VALS. */
1121 build_constructor (tree type, VEC(constructor_elt,gc) *vals)
1123 tree c = make_node (CONSTRUCTOR);
1124 TREE_TYPE (c) = type;
1125 CONSTRUCTOR_ELTS (c) = vals;
1129 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1132 build_constructor_single (tree type, tree index, tree value)
1134 VEC(constructor_elt,gc) *v;
1135 constructor_elt *elt;
1138 v = VEC_alloc (constructor_elt, gc, 1);
1139 elt = VEC_quick_push (constructor_elt, v, NULL);
1143 t = build_constructor (type, v);
1144 TREE_CONSTANT (t) = TREE_CONSTANT (value);
1149 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1150 are in a list pointed to by VALS. */
1152 build_constructor_from_list (tree type, tree vals)
1155 VEC(constructor_elt,gc) *v = NULL;
1156 bool constant_p = true;
1160 v = VEC_alloc (constructor_elt, gc, list_length (vals));
1161 for (t = vals; t; t = TREE_CHAIN (t))
1163 constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL);
1164 val = TREE_VALUE (t);
1165 elt->index = TREE_PURPOSE (t);
1167 if (!TREE_CONSTANT (val))
1172 t = build_constructor (type, v);
1173 TREE_CONSTANT (t) = constant_p;
1177 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1180 build_fixed (tree type, FIXED_VALUE_TYPE f)
1183 FIXED_VALUE_TYPE *fp;
1185 v = make_node (FIXED_CST);
1186 fp = GGC_NEW (FIXED_VALUE_TYPE);
1187 memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
1189 TREE_TYPE (v) = type;
1190 TREE_FIXED_CST_PTR (v) = fp;
1194 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1197 build_real (tree type, REAL_VALUE_TYPE d)
1200 REAL_VALUE_TYPE *dp;
1203 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1204 Consider doing it via real_convert now. */
1206 v = make_node (REAL_CST);
1207 dp = GGC_NEW (REAL_VALUE_TYPE);
1208 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
1210 TREE_TYPE (v) = type;
1211 TREE_REAL_CST_PTR (v) = dp;
1212 TREE_OVERFLOW (v) = overflow;
1216 /* Return a new REAL_CST node whose type is TYPE
1217 and whose value is the integer value of the INTEGER_CST node I. */
1220 real_value_from_int_cst (const_tree type, const_tree i)
1224 /* Clear all bits of the real value type so that we can later do
1225 bitwise comparisons to see if two values are the same. */
1226 memset (&d, 0, sizeof d);
1228 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
1229 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
1230 TYPE_UNSIGNED (TREE_TYPE (i)));
1234 /* Given a tree representing an integer constant I, return a tree
1235 representing the same value as a floating-point constant of type TYPE. */
1238 build_real_from_int_cst (tree type, const_tree i)
1241 int overflow = TREE_OVERFLOW (i);
1243 v = build_real (type, real_value_from_int_cst (type, i));
1245 TREE_OVERFLOW (v) |= overflow;
1249 /* Return a newly constructed STRING_CST node whose value is
1250 the LEN characters at STR.
1251 The TREE_TYPE is not initialized. */
1254 build_string (int len, const char *str)
1259 /* Do not waste bytes provided by padding of struct tree_string. */
1260 length = len + offsetof (struct tree_string, str) + 1;
1262 #ifdef GATHER_STATISTICS
1263 tree_node_counts[(int) c_kind]++;
1264 tree_node_sizes[(int) c_kind] += length;
1267 s = ggc_alloc_tree (length);
1269 memset (s, 0, sizeof (struct tree_common));
1270 TREE_SET_CODE (s, STRING_CST);
1271 TREE_CONSTANT (s) = 1;
1272 TREE_STRING_LENGTH (s) = len;
1273 memcpy (s->string.str, str, len);
1274 s->string.str[len] = '\0';
1279 /* Return a newly constructed COMPLEX_CST node whose value is
1280 specified by the real and imaginary parts REAL and IMAG.
1281 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1282 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1285 build_complex (tree type, tree real, tree imag)
1287 tree t = make_node (COMPLEX_CST);
1289 TREE_REALPART (t) = real;
1290 TREE_IMAGPART (t) = imag;
1291 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
1292 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
1296 /* Return a constant of arithmetic type TYPE which is the
1297 multiplicative identity of the set TYPE. */
1300 build_one_cst (tree type)
1302 switch (TREE_CODE (type))
1304 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
1305 case POINTER_TYPE: case REFERENCE_TYPE:
1307 return build_int_cst (type, 1);
1310 return build_real (type, dconst1);
1312 case FIXED_POINT_TYPE:
1313 /* We can only generate 1 for accum types. */
1314 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
1315 return build_fixed (type, FCONST1(TYPE_MODE (type)));
1322 scalar = build_one_cst (TREE_TYPE (type));
1324 /* Create 'vect_cst_ = {cst,cst,...,cst}' */
1326 for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; )
1327 cst = tree_cons (NULL_TREE, scalar, cst);
1329 return build_vector (type, cst);
1333 return build_complex (type,
1334 build_one_cst (TREE_TYPE (type)),
1335 fold_convert (TREE_TYPE (type), integer_zero_node));
1342 /* Build a BINFO with LEN language slots. */
1345 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
1348 size_t length = (offsetof (struct tree_binfo, base_binfos)
1349 + VEC_embedded_size (tree, base_binfos));
1351 #ifdef GATHER_STATISTICS
1352 tree_node_counts[(int) binfo_kind]++;
1353 tree_node_sizes[(int) binfo_kind] += length;
1356 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
1358 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
1360 TREE_SET_CODE (t, TREE_BINFO);
1362 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
1368 /* Build a newly constructed TREE_VEC node of length LEN. */
1371 make_tree_vec_stat (int len MEM_STAT_DECL)
1374 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
1376 #ifdef GATHER_STATISTICS
1377 tree_node_counts[(int) vec_kind]++;
1378 tree_node_sizes[(int) vec_kind] += length;
1381 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
1383 memset (t, 0, length);
1385 TREE_SET_CODE (t, TREE_VEC);
1386 TREE_VEC_LENGTH (t) = len;
1391 /* Return 1 if EXPR is the integer constant zero or a complex constant
1395 integer_zerop (const_tree expr)
1399 return ((TREE_CODE (expr) == INTEGER_CST
1400 && TREE_INT_CST_LOW (expr) == 0
1401 && TREE_INT_CST_HIGH (expr) == 0)
1402 || (TREE_CODE (expr) == COMPLEX_CST
1403 && integer_zerop (TREE_REALPART (expr))
1404 && integer_zerop (TREE_IMAGPART (expr))));
1407 /* Return 1 if EXPR is the integer constant one or the corresponding
1408 complex constant. */
1411 integer_onep (const_tree expr)
1415 return ((TREE_CODE (expr) == INTEGER_CST
1416 && TREE_INT_CST_LOW (expr) == 1
1417 && TREE_INT_CST_HIGH (expr) == 0)
1418 || (TREE_CODE (expr) == COMPLEX_CST
1419 && integer_onep (TREE_REALPART (expr))
1420 && integer_zerop (TREE_IMAGPART (expr))));
1423 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1424 it contains. Likewise for the corresponding complex constant. */
1427 integer_all_onesp (const_tree expr)
1434 if (TREE_CODE (expr) == COMPLEX_CST
1435 && integer_all_onesp (TREE_REALPART (expr))
1436 && integer_zerop (TREE_IMAGPART (expr)))
1439 else if (TREE_CODE (expr) != INTEGER_CST)
1442 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
1443 if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1444 && TREE_INT_CST_HIGH (expr) == -1)
1449 /* Note that using TYPE_PRECISION here is wrong. We care about the
1450 actual bits, not the (arbitrary) range of the type. */
1451 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
1452 if (prec >= HOST_BITS_PER_WIDE_INT)
1454 HOST_WIDE_INT high_value;
1457 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1459 /* Can not handle precisions greater than twice the host int size. */
1460 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
1461 if (shift_amount == HOST_BITS_PER_WIDE_INT)
1462 /* Shifting by the host word size is undefined according to the ANSI
1463 standard, so we must handle this as a special case. */
1466 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1468 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1469 && TREE_INT_CST_HIGH (expr) == high_value);
1472 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
1475 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1479 integer_pow2p (const_tree expr)
1482 HOST_WIDE_INT high, low;
1486 if (TREE_CODE (expr) == COMPLEX_CST
1487 && integer_pow2p (TREE_REALPART (expr))
1488 && integer_zerop (TREE_IMAGPART (expr)))
1491 if (TREE_CODE (expr) != INTEGER_CST)
1494 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1495 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1496 high = TREE_INT_CST_HIGH (expr);
1497 low = TREE_INT_CST_LOW (expr);
1499 /* First clear all bits that are beyond the type's precision in case
1500 we've been sign extended. */
1502 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1504 else if (prec > HOST_BITS_PER_WIDE_INT)
1505 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1509 if (prec < HOST_BITS_PER_WIDE_INT)
1510 low &= ~((HOST_WIDE_INT) (-1) << prec);
1513 if (high == 0 && low == 0)
1516 return ((high == 0 && (low & (low - 1)) == 0)
1517 || (low == 0 && (high & (high - 1)) == 0));
1520 /* Return 1 if EXPR is an integer constant other than zero or a
1521 complex constant other than zero. */
1524 integer_nonzerop (const_tree expr)
1528 return ((TREE_CODE (expr) == INTEGER_CST
1529 && (TREE_INT_CST_LOW (expr) != 0
1530 || TREE_INT_CST_HIGH (expr) != 0))
1531 || (TREE_CODE (expr) == COMPLEX_CST
1532 && (integer_nonzerop (TREE_REALPART (expr))
1533 || integer_nonzerop (TREE_IMAGPART (expr)))));
1536 /* Return 1 if EXPR is the fixed-point constant zero. */
1539 fixed_zerop (const_tree expr)
1541 return (TREE_CODE (expr) == FIXED_CST
1542 && double_int_zero_p (TREE_FIXED_CST (expr).data));
1545 /* Return the power of two represented by a tree node known to be a
1549 tree_log2 (const_tree expr)
1552 HOST_WIDE_INT high, low;
1556 if (TREE_CODE (expr) == COMPLEX_CST)
1557 return tree_log2 (TREE_REALPART (expr));
1559 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1560 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1562 high = TREE_INT_CST_HIGH (expr);
1563 low = TREE_INT_CST_LOW (expr);
1565 /* First clear all bits that are beyond the type's precision in case
1566 we've been sign extended. */
1568 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1570 else if (prec > HOST_BITS_PER_WIDE_INT)
1571 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1575 if (prec < HOST_BITS_PER_WIDE_INT)
1576 low &= ~((HOST_WIDE_INT) (-1) << prec);
1579 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
1580 : exact_log2 (low));
1583 /* Similar, but return the largest integer Y such that 2 ** Y is less
1584 than or equal to EXPR. */
1587 tree_floor_log2 (const_tree expr)
1590 HOST_WIDE_INT high, low;
1594 if (TREE_CODE (expr) == COMPLEX_CST)
1595 return tree_log2 (TREE_REALPART (expr));
1597 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1598 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1600 high = TREE_INT_CST_HIGH (expr);
1601 low = TREE_INT_CST_LOW (expr);
1603 /* First clear all bits that are beyond the type's precision in case
1604 we've been sign extended. Ignore if type's precision hasn't been set
1605 since what we are doing is setting it. */
1607 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
1609 else if (prec > HOST_BITS_PER_WIDE_INT)
1610 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1614 if (prec < HOST_BITS_PER_WIDE_INT)
1615 low &= ~((HOST_WIDE_INT) (-1) << prec);
1618 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
1619 : floor_log2 (low));
1622 /* Return 1 if EXPR is the real constant zero. */
1625 real_zerop (const_tree expr)
1629 return ((TREE_CODE (expr) == REAL_CST
1630 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
1631 || (TREE_CODE (expr) == COMPLEX_CST
1632 && real_zerop (TREE_REALPART (expr))
1633 && real_zerop (TREE_IMAGPART (expr))));
1636 /* Return 1 if EXPR is the real constant one in real or complex form. */
1639 real_onep (const_tree expr)
1643 return ((TREE_CODE (expr) == REAL_CST
1644 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
1645 || (TREE_CODE (expr) == COMPLEX_CST
1646 && real_onep (TREE_REALPART (expr))
1647 && real_zerop (TREE_IMAGPART (expr))));
1650 /* Return 1 if EXPR is the real constant two. */
1653 real_twop (const_tree expr)
1657 return ((TREE_CODE (expr) == REAL_CST
1658 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
1659 || (TREE_CODE (expr) == COMPLEX_CST
1660 && real_twop (TREE_REALPART (expr))
1661 && real_zerop (TREE_IMAGPART (expr))));
1664 /* Return 1 if EXPR is the real constant minus one. */
1667 real_minus_onep (const_tree expr)
1671 return ((TREE_CODE (expr) == REAL_CST
1672 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1))
1673 || (TREE_CODE (expr) == COMPLEX_CST
1674 && real_minus_onep (TREE_REALPART (expr))
1675 && real_zerop (TREE_IMAGPART (expr))));
1678 /* Nonzero if EXP is a constant or a cast of a constant. */
1681 really_constant_p (const_tree exp)
1683 /* This is not quite the same as STRIP_NOPS. It does more. */
1684 while (CONVERT_EXPR_P (exp)
1685 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1686 exp = TREE_OPERAND (exp, 0);
1687 return TREE_CONSTANT (exp);
1690 /* Return first list element whose TREE_VALUE is ELEM.
1691 Return 0 if ELEM is not in LIST. */
1694 value_member (tree elem, tree list)
1698 if (elem == TREE_VALUE (list))
1700 list = TREE_CHAIN (list);
1705 /* Return first list element whose TREE_PURPOSE is ELEM.
1706 Return 0 if ELEM is not in LIST. */
1709 purpose_member (const_tree elem, tree list)
1713 if (elem == TREE_PURPOSE (list))
1715 list = TREE_CHAIN (list);
1720 /* Return nonzero if ELEM is part of the chain CHAIN. */
1723 chain_member (const_tree elem, const_tree chain)
1729 chain = TREE_CHAIN (chain);
1735 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1736 We expect a null pointer to mark the end of the chain.
1737 This is the Lisp primitive `length'. */
1740 list_length (const_tree t)
1743 #ifdef ENABLE_TREE_CHECKING
1751 #ifdef ENABLE_TREE_CHECKING
1754 gcc_assert (p != q);
1762 /* Returns the number of FIELD_DECLs in TYPE. */
1765 fields_length (const_tree type)
1767 tree t = TYPE_FIELDS (type);
1770 for (; t; t = TREE_CHAIN (t))
1771 if (TREE_CODE (t) == FIELD_DECL)
1777 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1778 by modifying the last node in chain 1 to point to chain 2.
1779 This is the Lisp primitive `nconc'. */
1782 chainon (tree op1, tree op2)
1791 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1793 TREE_CHAIN (t1) = op2;
1795 #ifdef ENABLE_TREE_CHECKING
1798 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1799 gcc_assert (t2 != t1);
1806 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1809 tree_last (tree chain)
1813 while ((next = TREE_CHAIN (chain)))
1818 /* Reverse the order of elements in the chain T,
1819 and return the new head of the chain (old last element). */
1824 tree prev = 0, decl, next;
1825 for (decl = t; decl; decl = next)
1827 next = TREE_CHAIN (decl);
1828 TREE_CHAIN (decl) = prev;
1834 /* Return a newly created TREE_LIST node whose
1835 purpose and value fields are PARM and VALUE. */
1838 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
1840 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
1841 TREE_PURPOSE (t) = parm;
1842 TREE_VALUE (t) = value;
1846 /* Return a newly created TREE_LIST node whose
1847 purpose and value fields are PURPOSE and VALUE
1848 and whose TREE_CHAIN is CHAIN. */
1851 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
1855 node = (tree) ggc_alloc_zone_pass_stat (sizeof (struct tree_list), &tree_zone);
1857 memset (node, 0, sizeof (struct tree_common));
1859 #ifdef GATHER_STATISTICS
1860 tree_node_counts[(int) x_kind]++;
1861 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1864 TREE_SET_CODE (node, TREE_LIST);
1865 TREE_CHAIN (node) = chain;
1866 TREE_PURPOSE (node) = purpose;
1867 TREE_VALUE (node) = value;
1871 /* Return the elements of a CONSTRUCTOR as a TREE_LIST. */
1874 ctor_to_list (tree ctor)
1876 tree list = NULL_TREE;
1881 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), ix, purpose, val)
1883 *p = build_tree_list (purpose, val);
1884 p = &TREE_CHAIN (*p);
1890 /* Return the size nominally occupied by an object of type TYPE
1891 when it resides in memory. The value is measured in units of bytes,
1892 and its data type is that normally used for type sizes
1893 (which is the first type created by make_signed_type or
1894 make_unsigned_type). */
1897 size_in_bytes (const_tree type)
1901 if (type == error_mark_node)
1902 return integer_zero_node;
1904 type = TYPE_MAIN_VARIANT (type);
1905 t = TYPE_SIZE_UNIT (type);
1909 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
1910 return size_zero_node;
1916 /* Return the size of TYPE (in bytes) as a wide integer
1917 or return -1 if the size can vary or is larger than an integer. */
1920 int_size_in_bytes (const_tree type)
1924 if (type == error_mark_node)
1927 type = TYPE_MAIN_VARIANT (type);
1928 t = TYPE_SIZE_UNIT (type);
1930 || TREE_CODE (t) != INTEGER_CST
1931 || TREE_INT_CST_HIGH (t) != 0
1932 /* If the result would appear negative, it's too big to represent. */
1933 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
1936 return TREE_INT_CST_LOW (t);
1939 /* Return the maximum size of TYPE (in bytes) as a wide integer
1940 or return -1 if the size can vary or is larger than an integer. */
1943 max_int_size_in_bytes (const_tree type)
1945 HOST_WIDE_INT size = -1;
1948 /* If this is an array type, check for a possible MAX_SIZE attached. */
1950 if (TREE_CODE (type) == ARRAY_TYPE)
1952 size_tree = TYPE_ARRAY_MAX_SIZE (type);
1954 if (size_tree && host_integerp (size_tree, 1))
1955 size = tree_low_cst (size_tree, 1);
1958 /* If we still haven't been able to get a size, see if the language
1959 can compute a maximum size. */
1963 size_tree = lang_hooks.types.max_size (type);
1965 if (size_tree && host_integerp (size_tree, 1))
1966 size = tree_low_cst (size_tree, 1);
1972 /* Return the bit position of FIELD, in bits from the start of the record.
1973 This is a tree of type bitsizetype. */
1976 bit_position (const_tree field)
1978 return bit_from_pos (DECL_FIELD_OFFSET (field),
1979 DECL_FIELD_BIT_OFFSET (field));
1982 /* Likewise, but return as an integer. It must be representable in
1983 that way (since it could be a signed value, we don't have the
1984 option of returning -1 like int_size_in_byte can. */
1987 int_bit_position (const_tree field)
1989 return tree_low_cst (bit_position (field), 0);
1992 /* Return the byte position of FIELD, in bytes from the start of the record.
1993 This is a tree of type sizetype. */
1996 byte_position (const_tree field)
1998 return byte_from_pos (DECL_FIELD_OFFSET (field),
1999 DECL_FIELD_BIT_OFFSET (field));
2002 /* Likewise, but return as an integer. It must be representable in
2003 that way (since it could be a signed value, we don't have the
2004 option of returning -1 like int_size_in_byte can. */
2007 int_byte_position (const_tree field)
2009 return tree_low_cst (byte_position (field), 0);
2012 /* Return the strictest alignment, in bits, that T is known to have. */
2015 expr_align (const_tree t)
2017 unsigned int align0, align1;
2019 switch (TREE_CODE (t))
2021 CASE_CONVERT: case NON_LVALUE_EXPR:
2022 /* If we have conversions, we know that the alignment of the
2023 object must meet each of the alignments of the types. */
2024 align0 = expr_align (TREE_OPERAND (t, 0));
2025 align1 = TYPE_ALIGN (TREE_TYPE (t));
2026 return MAX (align0, align1);
2028 case GIMPLE_MODIFY_STMT:
2029 /* We should never ask for the alignment of a gimple statement. */
2032 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
2033 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
2034 case CLEANUP_POINT_EXPR:
2035 /* These don't change the alignment of an object. */
2036 return expr_align (TREE_OPERAND (t, 0));
2039 /* The best we can do is say that the alignment is the least aligned
2041 align0 = expr_align (TREE_OPERAND (t, 1));
2042 align1 = expr_align (TREE_OPERAND (t, 2));
2043 return MIN (align0, align1);
2045 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2046 meaningfully, it's always 1. */
2047 case LABEL_DECL: case CONST_DECL:
2048 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
2050 gcc_assert (DECL_ALIGN (t) != 0);
2051 return DECL_ALIGN (t);
2057 /* Otherwise take the alignment from that of the type. */
2058 return TYPE_ALIGN (TREE_TYPE (t));
2061 /* Return, as a tree node, the number of elements for TYPE (which is an
2062 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2065 array_type_nelts (const_tree type)
2067 tree index_type, min, max;
2069 /* If they did it with unspecified bounds, then we should have already
2070 given an error about it before we got here. */
2071 if (! TYPE_DOMAIN (type))
2072 return error_mark_node;
2074 index_type = TYPE_DOMAIN (type);
2075 min = TYPE_MIN_VALUE (index_type);
2076 max = TYPE_MAX_VALUE (index_type);
2078 return (integer_zerop (min)
2080 : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
2083 /* If arg is static -- a reference to an object in static storage -- then
2084 return the object. This is not the same as the C meaning of `static'.
2085 If arg isn't static, return NULL. */
2090 switch (TREE_CODE (arg))
2093 /* Nested functions are static, even though taking their address will
2094 involve a trampoline as we unnest the nested function and create
2095 the trampoline on the tree level. */
2099 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2100 && ! DECL_THREAD_LOCAL_P (arg)
2101 && ! DECL_DLLIMPORT_P (arg)
2105 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2109 return TREE_STATIC (arg) ? arg : NULL;
2116 /* If the thing being referenced is not a field, then it is
2117 something language specific. */
2118 if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL)
2119 return (*lang_hooks.staticp) (arg);
2121 /* If we are referencing a bitfield, we can't evaluate an
2122 ADDR_EXPR at compile time and so it isn't a constant. */
2123 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
2126 return staticp (TREE_OPERAND (arg, 0));
2131 case MISALIGNED_INDIRECT_REF:
2132 case ALIGN_INDIRECT_REF:
2134 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
2137 case ARRAY_RANGE_REF:
2138 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
2139 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
2140 return staticp (TREE_OPERAND (arg, 0));
2145 if ((unsigned int) TREE_CODE (arg)
2146 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
2147 return lang_hooks.staticp (arg);
2156 /* Return whether OP is a DECL whose address is function-invariant. */
2159 decl_address_invariant_p (const_tree op)
2161 /* The conditions below are slightly less strict than the one in
2164 switch (TREE_CODE (op))
2173 if (((TREE_STATIC (op) || DECL_EXTERNAL (op))
2174 && !DECL_DLLIMPORT_P (op))
2175 || DECL_THREAD_LOCAL_P (op)
2176 || DECL_CONTEXT (op) == current_function_decl
2177 || decl_function_context (op) == current_function_decl)
2182 if ((TREE_STATIC (op) || DECL_EXTERNAL (op))
2183 || decl_function_context (op) == current_function_decl)
2195 /* Return true if T is function-invariant (internal function, does
2196 not handle arithmetic; that's handled in skip_simple_arithmetic and
2197 tree_invariant_p). */
2199 static bool tree_invariant_p (tree t);
2202 tree_invariant_p_1 (tree t)
2206 if (TREE_CONSTANT (t)
2207 || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
2210 switch (TREE_CODE (t))
2216 op = TREE_OPERAND (t, 0);
2217 while (handled_component_p (op))
2219 switch (TREE_CODE (op))
2222 case ARRAY_RANGE_REF:
2223 if (!tree_invariant_p (TREE_OPERAND (op, 1))
2224 || TREE_OPERAND (op, 2) != NULL_TREE
2225 || TREE_OPERAND (op, 3) != NULL_TREE)
2230 if (TREE_OPERAND (op, 2) != NULL_TREE)
2236 op = TREE_OPERAND (op, 0);
2239 return CONSTANT_CLASS_P (op) || decl_address_invariant_p (op);
2248 /* Return true if T is function-invariant. */
2251 tree_invariant_p (tree t)
2253 tree inner = skip_simple_arithmetic (t);
2254 return tree_invariant_p_1 (inner);
2257 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2258 Do this to any expression which may be used in more than one place,
2259 but must be evaluated only once.
2261 Normally, expand_expr would reevaluate the expression each time.
2262 Calling save_expr produces something that is evaluated and recorded
2263 the first time expand_expr is called on it. Subsequent calls to
2264 expand_expr just reuse the recorded value.
2266 The call to expand_expr that generates code that actually computes
2267 the value is the first call *at compile time*. Subsequent calls
2268 *at compile time* generate code to use the saved value.
2269 This produces correct result provided that *at run time* control
2270 always flows through the insns made by the first expand_expr
2271 before reaching the other places where the save_expr was evaluated.
2272 You, the caller of save_expr, must make sure this is so.
2274 Constants, and certain read-only nodes, are returned with no
2275 SAVE_EXPR because that is safe. Expressions containing placeholders
2276 are not touched; see tree.def for an explanation of what these
2280 save_expr (tree expr)
2282 tree t = fold (expr);
2285 /* If the tree evaluates to a constant, then we don't want to hide that
2286 fact (i.e. this allows further folding, and direct checks for constants).
2287 However, a read-only object that has side effects cannot be bypassed.
2288 Since it is no problem to reevaluate literals, we just return the
2290 inner = skip_simple_arithmetic (t);
2291 if (TREE_CODE (inner) == ERROR_MARK)
2294 if (tree_invariant_p_1 (inner))
2297 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2298 it means that the size or offset of some field of an object depends on
2299 the value within another field.
2301 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2302 and some variable since it would then need to be both evaluated once and
2303 evaluated more than once. Front-ends must assure this case cannot
2304 happen by surrounding any such subexpressions in their own SAVE_EXPR
2305 and forcing evaluation at the proper time. */
2306 if (contains_placeholder_p (inner))
2309 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
2311 /* This expression might be placed ahead of a jump to ensure that the
2312 value was computed on both sides of the jump. So make sure it isn't
2313 eliminated as dead. */
2314 TREE_SIDE_EFFECTS (t) = 1;
2318 /* Look inside EXPR and into any simple arithmetic operations. Return
2319 the innermost non-arithmetic node. */
2322 skip_simple_arithmetic (tree expr)
2326 /* We don't care about whether this can be used as an lvalue in this
2328 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
2329 expr = TREE_OPERAND (expr, 0);
2331 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2332 a constant, it will be more efficient to not make another SAVE_EXPR since
2333 it will allow better simplification and GCSE will be able to merge the
2334 computations if they actually occur. */
2338 if (UNARY_CLASS_P (inner))
2339 inner = TREE_OPERAND (inner, 0);
2340 else if (BINARY_CLASS_P (inner))
2342 if (tree_invariant_p (TREE_OPERAND (inner, 1)))
2343 inner = TREE_OPERAND (inner, 0);
2344 else if (tree_invariant_p (TREE_OPERAND (inner, 0)))
2345 inner = TREE_OPERAND (inner, 1);
2356 /* Return which tree structure is used by T. */
2358 enum tree_node_structure_enum
2359 tree_node_structure (const_tree t)
2361 const enum tree_code code = TREE_CODE (t);
2363 switch (TREE_CODE_CLASS (code))
2365 case tcc_declaration:
2370 return TS_FIELD_DECL;
2372 return TS_PARM_DECL;
2376 return TS_LABEL_DECL;
2378 return TS_RESULT_DECL;
2380 return TS_CONST_DECL;
2382 return TS_TYPE_DECL;
2384 return TS_FUNCTION_DECL;
2385 case SYMBOL_MEMORY_TAG:
2386 case NAME_MEMORY_TAG:
2387 case MEMORY_PARTITION_TAG:
2388 return TS_MEMORY_TAG;
2390 return TS_DECL_NON_COMMON;
2396 case tcc_comparison:
2399 case tcc_expression:
2403 case tcc_gimple_stmt:
2404 return TS_GIMPLE_STATEMENT;
2405 default: /* tcc_constant and tcc_exceptional */
2410 /* tcc_constant cases. */
2411 case INTEGER_CST: return TS_INT_CST;
2412 case REAL_CST: return TS_REAL_CST;
2413 case FIXED_CST: return TS_FIXED_CST;
2414 case COMPLEX_CST: return TS_COMPLEX;
2415 case VECTOR_CST: return TS_VECTOR;
2416 case STRING_CST: return TS_STRING;
2417 /* tcc_exceptional cases. */
2418 /* FIXME tuples: eventually this should be TS_BASE. For now, nothing
2420 case ERROR_MARK: return TS_COMMON;
2421 case IDENTIFIER_NODE: return TS_IDENTIFIER;
2422 case TREE_LIST: return TS_LIST;
2423 case TREE_VEC: return TS_VEC;
2424 case PHI_NODE: return TS_PHI_NODE;
2425 case SSA_NAME: return TS_SSA_NAME;
2426 case PLACEHOLDER_EXPR: return TS_COMMON;
2427 case STATEMENT_LIST: return TS_STATEMENT_LIST;
2428 case BLOCK: return TS_BLOCK;
2429 case CONSTRUCTOR: return TS_CONSTRUCTOR;
2430 case TREE_BINFO: return TS_BINFO;
2431 case OMP_CLAUSE: return TS_OMP_CLAUSE;
2438 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2439 or offset that depends on a field within a record. */
2442 contains_placeholder_p (const_tree exp)
2444 enum tree_code code;
2449 code = TREE_CODE (exp);
2450 if (code == PLACEHOLDER_EXPR)
2453 switch (TREE_CODE_CLASS (code))
2456 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2457 position computations since they will be converted into a
2458 WITH_RECORD_EXPR involving the reference, which will assume
2459 here will be valid. */
2460 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
2462 case tcc_exceptional:
2463 if (code == TREE_LIST)
2464 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
2465 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
2470 case tcc_comparison:
2471 case tcc_expression:
2475 /* Ignoring the first operand isn't quite right, but works best. */
2476 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
2479 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
2480 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
2481 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
2487 switch (TREE_CODE_LENGTH (code))
2490 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
2492 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
2493 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
2504 const_call_expr_arg_iterator iter;
2505 FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
2506 if (CONTAINS_PLACEHOLDER_P (arg))
2520 /* Return true if any part of the computation of TYPE involves a
2521 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
2522 (for QUAL_UNION_TYPE) and field positions. */
2525 type_contains_placeholder_1 (const_tree type)
2527 /* If the size contains a placeholder or the parent type (component type in
2528 the case of arrays) type involves a placeholder, this type does. */
2529 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
2530 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
2531 || (TREE_TYPE (type) != 0
2532 && type_contains_placeholder_p (TREE_TYPE (type))))
2535 /* Now do type-specific checks. Note that the last part of the check above
2536 greatly limits what we have to do below. */
2537 switch (TREE_CODE (type))
2545 case REFERENCE_TYPE:
2553 case FIXED_POINT_TYPE:
2554 /* Here we just check the bounds. */
2555 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
2556 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
2559 /* We're already checked the component type (TREE_TYPE), so just check
2561 return type_contains_placeholder_p (TYPE_DOMAIN (type));
2565 case QUAL_UNION_TYPE:
2569 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
2570 if (TREE_CODE (field) == FIELD_DECL
2571 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
2572 || (TREE_CODE (type) == QUAL_UNION_TYPE
2573 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
2574 || type_contains_placeholder_p (TREE_TYPE (field))))
2586 type_contains_placeholder_p (tree type)
2590 /* If the contains_placeholder_bits field has been initialized,
2591 then we know the answer. */
2592 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
2593 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
2595 /* Indicate that we've seen this type node, and the answer is false.
2596 This is what we want to return if we run into recursion via fields. */
2597 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
2599 /* Compute the real value. */
2600 result = type_contains_placeholder_1 (type);
2602 /* Store the real value. */
2603 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
2608 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2609 return a tree with all occurrences of references to F in a
2610 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2611 contains only arithmetic expressions or a CALL_EXPR with a
2612 PLACEHOLDER_EXPR occurring only in its arglist. */
2615 substitute_in_expr (tree exp, tree f, tree r)
2617 enum tree_code code = TREE_CODE (exp);
2618 tree op0, op1, op2, op3;
2621 /* We handle TREE_LIST and COMPONENT_REF separately. */
2622 if (code == TREE_LIST)
2624 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
2625 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
2626 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2629 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2631 else if (code == COMPONENT_REF)
2633 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2634 and it is the right field, replace it with R. */
2635 for (inner = TREE_OPERAND (exp, 0);
2636 REFERENCE_CLASS_P (inner);
2637 inner = TREE_OPERAND (inner, 0))
2639 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2640 && TREE_OPERAND (exp, 1) == f)
2643 /* If this expression hasn't been completed let, leave it alone. */
2644 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0)
2647 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2648 if (op0 == TREE_OPERAND (exp, 0))
2651 new = fold_build3 (COMPONENT_REF, TREE_TYPE (exp),
2652 op0, TREE_OPERAND (exp, 1), NULL_TREE);
2655 switch (TREE_CODE_CLASS (code))
2658 case tcc_declaration:
2661 case tcc_exceptional:
2664 case tcc_comparison:
2665 case tcc_expression:
2667 switch (TREE_CODE_LENGTH (code))
2673 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2674 if (op0 == TREE_OPERAND (exp, 0))
2677 new = fold_build1 (code, TREE_TYPE (exp), op0);
2681 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2682 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2684 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2687 new = fold_build2 (code, TREE_TYPE (exp), op0, op1);
2691 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2692 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2693 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
2695 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2696 && op2 == TREE_OPERAND (exp, 2))
2699 new = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
2703 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2704 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2705 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
2706 op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
2708 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2709 && op2 == TREE_OPERAND (exp, 2)
2710 && op3 == TREE_OPERAND (exp, 3))
2713 new = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2723 tree copy = NULL_TREE;
2726 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
2728 tree op = TREE_OPERAND (exp, i);
2729 tree new_op = SUBSTITUTE_IN_EXPR (op, f, r);
2733 copy = copy_node (exp);
2734 TREE_OPERAND (copy, i) = new_op;
2749 TREE_READONLY (new) = TREE_READONLY (exp);
2753 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2754 for it within OBJ, a tree that is an object or a chain of references. */
2757 substitute_placeholder_in_expr (tree exp, tree obj)
2759 enum tree_code code = TREE_CODE (exp);
2760 tree op0, op1, op2, op3;
2762 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2763 in the chain of OBJ. */
2764 if (code == PLACEHOLDER_EXPR)
2766 tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
2769 for (elt = obj; elt != 0;
2770 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
2771 || TREE_CODE (elt) == COND_EXPR)
2772 ? TREE_OPERAND (elt, 1)
2773 : (REFERENCE_CLASS_P (elt)
2774 || UNARY_CLASS_P (elt)
2775 || BINARY_CLASS_P (elt)
2776 || VL_EXP_CLASS_P (elt)
2777 || EXPRESSION_CLASS_P (elt))
2778 ? TREE_OPERAND (elt, 0) : 0))
2779 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
2782 for (elt = obj; elt != 0;
2783 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
2784 || TREE_CODE (elt) == COND_EXPR)
2785 ? TREE_OPERAND (elt, 1)
2786 : (REFERENCE_CLASS_P (elt)
2787 || UNARY_CLASS_P (elt)
2788 || BINARY_CLASS_P (elt)
2789 || VL_EXP_CLASS_P (elt)
2790 || EXPRESSION_CLASS_P (elt))
2791 ? TREE_OPERAND (elt, 0) : 0))
2792 if (POINTER_TYPE_P (TREE_TYPE (elt))
2793 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
2795 return fold_build1 (INDIRECT_REF, need_type, elt);
2797 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2798 survives until RTL generation, there will be an error. */
2802 /* TREE_LIST is special because we need to look at TREE_VALUE
2803 and TREE_CHAIN, not TREE_OPERANDS. */
2804 else if (code == TREE_LIST)
2806 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
2807 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
2808 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2811 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2814 switch (TREE_CODE_CLASS (code))
2817 case tcc_declaration:
2820 case tcc_exceptional:
2823 case tcc_comparison:
2824 case tcc_expression:
2827 switch (TREE_CODE_LENGTH (code))
2833 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2834 if (op0 == TREE_OPERAND (exp, 0))
2837 return fold_build1 (code, TREE_TYPE (exp), op0);
2840 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2841 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2843 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2846 return fold_build2 (code, TREE_TYPE (exp), op0, op1);
2849 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2850 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2851 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2853 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2854 && op2 == TREE_OPERAND (exp, 2))
2857 return fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
2860 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2861 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2862 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2863 op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
2865 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2866 && op2 == TREE_OPERAND (exp, 2)
2867 && op3 == TREE_OPERAND (exp, 3))
2870 return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2879 tree copy = NULL_TREE;
2882 for (i = 1; i < TREE_OPERAND_LENGTH (exp); i++)
2884 tree op = TREE_OPERAND (exp, i);
2885 tree new_op = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
2889 copy = copy_node (exp);
2890 TREE_OPERAND (copy, i) = new_op;
2905 /* Stabilize a reference so that we can use it any number of times
2906 without causing its operands to be evaluated more than once.
2907 Returns the stabilized reference. This works by means of save_expr,
2908 so see the caveats in the comments about save_expr.
2910 Also allows conversion expressions whose operands are references.
2911 Any other kind of expression is returned unchanged. */
2914 stabilize_reference (tree ref)
2917 enum tree_code code = TREE_CODE (ref);
2924 /* No action is needed in this case. */
2929 case FIX_TRUNC_EXPR:
2930 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2934 result = build_nt (INDIRECT_REF,
2935 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2939 result = build_nt (COMPONENT_REF,
2940 stabilize_reference (TREE_OPERAND (ref, 0)),
2941 TREE_OPERAND (ref, 1), NULL_TREE);
2945 result = build_nt (BIT_FIELD_REF,
2946 stabilize_reference (TREE_OPERAND (ref, 0)),
2947 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2948 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2952 result = build_nt (ARRAY_REF,
2953 stabilize_reference (TREE_OPERAND (ref, 0)),
2954 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2955 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2958 case ARRAY_RANGE_REF:
2959 result = build_nt (ARRAY_RANGE_REF,
2960 stabilize_reference (TREE_OPERAND (ref, 0)),
2961 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2962 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2966 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2967 it wouldn't be ignored. This matters when dealing with
2969 return stabilize_reference_1 (ref);
2971 /* If arg isn't a kind of lvalue we recognize, make no change.
2972 Caller should recognize the error for an invalid lvalue. */
2977 return error_mark_node;
2980 TREE_TYPE (result) = TREE_TYPE (ref);
2981 TREE_READONLY (result) = TREE_READONLY (ref);
2982 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2983 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2988 /* Subroutine of stabilize_reference; this is called for subtrees of
2989 references. Any expression with side-effects must be put in a SAVE_EXPR
2990 to ensure that it is only evaluated once.
2992 We don't put SAVE_EXPR nodes around everything, because assigning very
2993 simple expressions to temporaries causes us to miss good opportunities
2994 for optimizations. Among other things, the opportunity to fold in the
2995 addition of a constant into an addressing mode often gets lost, e.g.
2996 "y[i+1] += x;". In general, we take the approach that we should not make
2997 an assignment unless we are forced into it - i.e., that any non-side effect
2998 operator should be allowed, and that cse should take care of coalescing
2999 multiple utterances of the same expression should that prove fruitful. */
3002 stabilize_reference_1 (tree e)
3005 enum tree_code code = TREE_CODE (e);
3007 /* We cannot ignore const expressions because it might be a reference
3008 to a const array but whose index contains side-effects. But we can
3009 ignore things that are actual constant or that already have been
3010 handled by this function. */
3012 if (tree_invariant_p (e))
3015 switch (TREE_CODE_CLASS (code))
3017 case tcc_exceptional:
3019 case tcc_declaration:
3020 case tcc_comparison:
3022 case tcc_expression:
3025 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3026 so that it will only be evaluated once. */
3027 /* The reference (r) and comparison (<) classes could be handled as
3028 below, but it is generally faster to only evaluate them once. */
3029 if (TREE_SIDE_EFFECTS (e))
3030 return save_expr (e);
3034 /* Constants need no processing. In fact, we should never reach
3039 /* Division is slow and tends to be compiled with jumps,
3040 especially the division by powers of 2 that is often
3041 found inside of an array reference. So do it just once. */
3042 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
3043 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
3044 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
3045 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
3046 return save_expr (e);
3047 /* Recursively stabilize each operand. */
3048 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
3049 stabilize_reference_1 (TREE_OPERAND (e, 1)));
3053 /* Recursively stabilize each operand. */
3054 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
3061 TREE_TYPE (result) = TREE_TYPE (e);
3062 TREE_READONLY (result) = TREE_READONLY (e);
3063 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
3064 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
3069 /* Low-level constructors for expressions. */
3071 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
3072 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
3075 recompute_tree_invariant_for_addr_expr (tree t)
3078 bool tc = true, se = false;
3080 /* We started out assuming this address is both invariant and constant, but
3081 does not have side effects. Now go down any handled components and see if
3082 any of them involve offsets that are either non-constant or non-invariant.
3083 Also check for side-effects.
3085 ??? Note that this code makes no attempt to deal with the case where
3086 taking the address of something causes a copy due to misalignment. */
3088 #define UPDATE_FLAGS(NODE) \
3089 do { tree _node = (NODE); \
3090 if (_node && !TREE_CONSTANT (_node)) tc = false; \
3091 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
3093 for (node = TREE_OPERAND (t, 0); handled_component_p (node);
3094 node = TREE_OPERAND (node, 0))
3096 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
3097 array reference (probably made temporarily by the G++ front end),
3098 so ignore all the operands. */
3099 if ((TREE_CODE (node) == ARRAY_REF
3100 || TREE_CODE (node) == ARRAY_RANGE_REF)
3101 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
3103 UPDATE_FLAGS (TREE_OPERAND (node, 1));
3104 if (TREE_OPERAND (node, 2))
3105 UPDATE_FLAGS (TREE_OPERAND (node, 2));
3106 if (TREE_OPERAND (node, 3))
3107 UPDATE_FLAGS (TREE_OPERAND (node, 3));
3109 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
3110 FIELD_DECL, apparently. The G++ front end can put something else
3111 there, at least temporarily. */
3112 else if (TREE_CODE (node) == COMPONENT_REF
3113 && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
3115 if (TREE_OPERAND (node, 2))
3116 UPDATE_FLAGS (TREE_OPERAND (node, 2));
3118 else if (TREE_CODE (node) == BIT_FIELD_REF)
3119 UPDATE_FLAGS (TREE_OPERAND (node, 2));
3122 node = lang_hooks.expr_to_decl (node, &tc, &se);
3124 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
3125 the address, since &(*a)->b is a form of addition. If it's a constant, the
3126 address is constant too. If it's a decl, its address is constant if the
3127 decl is static. Everything else is not constant and, furthermore,
3128 taking the address of a volatile variable is not volatile. */
3129 if (TREE_CODE (node) == INDIRECT_REF)
3130 UPDATE_FLAGS (TREE_OPERAND (node, 0));
3131 else if (CONSTANT_CLASS_P (node))
3133 else if (DECL_P (node))
3134 tc &= (staticp (node) != NULL_TREE);
3138 se |= TREE_SIDE_EFFECTS (node);
3142 TREE_CONSTANT (t) = tc;
3143 TREE_SIDE_EFFECTS (t) = se;
3147 /* Build an expression of code CODE, data type TYPE, and operands as
3148 specified. Expressions and reference nodes can be created this way.
3149 Constants, decls, types and misc nodes cannot be.
3151 We define 5 non-variadic functions, from 0 to 4 arguments. This is
3152 enough for all extant tree codes. */
3155 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
3159 gcc_assert (TREE_CODE_LENGTH (code) == 0);
3161 t = make_node_stat (code PASS_MEM_STAT);
3168 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
3170 int length = sizeof (struct tree_exp);
3171 #ifdef GATHER_STATISTICS
3172 tree_node_kind kind;
3176 #ifdef GATHER_STATISTICS
3177 switch (TREE_CODE_CLASS (code))
3179 case tcc_statement: /* an expression with side effects */
3182 case tcc_reference: /* a reference */
3190 tree_node_counts[(int) kind]++;
3191 tree_node_sizes[(int) kind] += length;
3194 gcc_assert (TREE_CODE_LENGTH (code) == 1);
3196 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
3198 memset (t, 0, sizeof (struct tree_common));
3200 TREE_SET_CODE (t, code);
3202 TREE_TYPE (t) = type;
3203 SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
3204 TREE_OPERAND (t, 0) = node;
3205 TREE_BLOCK (t) = NULL_TREE;
3206 if (node && !TYPE_P (node))
3208 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
3209 TREE_READONLY (t) = TREE_READONLY (node);
3212 if (TREE_CODE_CLASS (code) == tcc_statement)
3213 TREE_SIDE_EFFECTS (t) = 1;
3217 /* All of these have side-effects, no matter what their
3219 TREE_SIDE_EFFECTS (t) = 1;
3220 TREE_READONLY (t) = 0;
3223 case MISALIGNED_INDIRECT_REF:
3224 case ALIGN_INDIRECT_REF:
3226 /* Whether a dereference is readonly has nothing to do with whether
3227 its operand is readonly. */
3228 TREE_READONLY (t) = 0;
3233 recompute_tree_invariant_for_addr_expr (t);
3237 if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
3238 && node && !TYPE_P (node)
3239 && TREE_CONSTANT (node))
3240 TREE_CONSTANT (t) = 1;
3241 if (TREE_CODE_CLASS (code) == tcc_reference
3242 && node && TREE_THIS_VOLATILE (node))
3243 TREE_THIS_VOLATILE (t) = 1;
3250 #define PROCESS_ARG(N) \
3252 TREE_OPERAND (t, N) = arg##N; \
3253 if (arg##N &&!TYPE_P (arg##N)) \
3255 if (TREE_SIDE_EFFECTS (arg##N)) \
3257 if (!TREE_READONLY (arg##N)) \
3259 if (!TREE_CONSTANT (arg##N)) \
3265 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
3267 bool constant, read_only, side_effects;
3270 gcc_assert (TREE_CODE_LENGTH (code) == 2);
3273 /* FIXME tuples: Statement's aren't expressions! */
3274 if (code == GIMPLE_MODIFY_STMT)
3275 return build_gimple_modify_stmt_stat (arg0, arg1 PASS_MEM_STAT);
3277 /* Must use build_gimple_modify_stmt to construct GIMPLE_MODIFY_STMTs. */
3278 gcc_assert (code != GIMPLE_MODIFY_STMT);
3281 if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
3282 && arg0 && arg1 && tt && POINTER_TYPE_P (tt))
3283 gcc_assert (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST);
3285 if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
3286 gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
3287 && INTEGRAL_TYPE_P (TREE_TYPE (arg1))
3288 && useless_type_conversion_p (sizetype, TREE_TYPE (arg1)));
3290 t = make_node_stat (code PASS_MEM_STAT);
3293 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
3294 result based on those same flags for the arguments. But if the
3295 arguments aren't really even `tree' expressions, we shouldn't be trying
3298 /* Expressions without side effects may be constant if their
3299 arguments are as well. */
3300 constant = (TREE_CODE_CLASS (code) == tcc_comparison
3301 || TREE_CODE_CLASS (code) == tcc_binary);
3303 side_effects = TREE_SIDE_EFFECTS (t);
3308 TREE_READONLY (t) = read_only;
3309 TREE_CONSTANT (t) = constant;
3310 TREE_SIDE_EFFECTS (t) = side_effects;
3311 TREE_THIS_VOLATILE (t)
3312 = (TREE_CODE_CLASS (code) == tcc_reference
3313 && arg0 && TREE_THIS_VOLATILE (arg0));
3319 /* Build a GIMPLE_MODIFY_STMT node. This tree code doesn't have a
3320 type, so we can't use build2 (a.k.a. build2_stat). */
3323 build_gimple_modify_stmt_stat (tree arg0, tree arg1 MEM_STAT_DECL)
3327 t = make_node_stat (GIMPLE_MODIFY_STMT PASS_MEM_STAT);
3328 /* ?? We don't care about setting flags for tuples... */
3329 GIMPLE_STMT_OPERAND (t, 0) = arg0;
3330 GIMPLE_STMT_OPERAND (t, 1) = arg1;
3335 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3336 tree arg2 MEM_STAT_DECL)
3338 bool constant, read_only, side_effects;
3341 gcc_assert (TREE_CODE_LENGTH (code) == 3);
3342 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3344 t = make_node_stat (code PASS_MEM_STAT);
3347 /* As a special exception, if COND_EXPR has NULL branches, we
3348 assume that it is a gimple statement and always consider
3349 it to have side effects. */
3350 if (code == COND_EXPR
3351 && tt == void_type_node
3352 && arg1 == NULL_TREE
3353 && arg2 == NULL_TREE)
3354 side_effects = true;
3356 side_effects = TREE_SIDE_EFFECTS (t);
3362 TREE_SIDE_EFFECTS (t) = side_effects;
3363 TREE_THIS_VOLATILE (t)
3364 = (TREE_CODE_CLASS (code) == tcc_reference
3365 && arg0 && TREE_THIS_VOLATILE (arg0));
3371 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3372 tree arg2, tree arg3 MEM_STAT_DECL)
3374 bool constant, read_only, side_effects;
3377 gcc_assert (TREE_CODE_LENGTH (code) == 4);
3379 t = make_node_stat (code PASS_MEM_STAT);
3382 side_effects = TREE_SIDE_EFFECTS (t);
3389 TREE_SIDE_EFFECTS (t) = side_effects;
3390 TREE_THIS_VOLATILE (t)
3391 = (TREE_CODE_CLASS (code) == tcc_reference
3392 && arg0 && TREE_THIS_VOLATILE (arg0));
3398 build5_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3399 tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
3401 bool constant, read_only, side_effects;
3404 gcc_assert (TREE_CODE_LENGTH (code) == 5);
3406 t = make_node_stat (code PASS_MEM_STAT);
3409 side_effects = TREE_SIDE_EFFECTS (t);
3417 TREE_SIDE_EFFECTS (t) = side_effects;
3418 TREE_THIS_VOLATILE (t)
3419 = (TREE_CODE_CLASS (code) == tcc_reference
3420 && arg0 && TREE_THIS_VOLATILE (arg0));
3426 build7_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3427 tree arg2, tree arg3, tree arg4, tree arg5,
3428 tree arg6 MEM_STAT_DECL)
3430 bool constant, read_only, side_effects;
3433 gcc_assert (code == TARGET_MEM_REF);
3435 t = make_node_stat (code PASS_MEM_STAT);
3438 side_effects = TREE_SIDE_EFFECTS (t);
3448 TREE_SIDE_EFFECTS (t) = side_effects;
3449 TREE_THIS_VOLATILE (t) = 0;
3454 /* Similar except don't specify the TREE_TYPE
3455 and leave the TREE_SIDE_EFFECTS as 0.
3456 It is permissible for arguments to be null,
3457 or even garbage if their values do not matter. */
3460 build_nt (enum tree_code code, ...)
3467 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3471 t = make_node (code);
3472 length = TREE_CODE_LENGTH (code);
3474 for (i = 0; i < length; i++)
3475 TREE_OPERAND (t, i) = va_arg (p, tree);
3481 /* Similar to build_nt, but for creating a CALL_EXPR object with
3482 ARGLIST passed as a list. */
3485 build_nt_call_list (tree fn, tree arglist)
3490 t = build_vl_exp (CALL_EXPR, list_length (arglist) + 3);
3491 CALL_EXPR_FN (t) = fn;
3492 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
3493 for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++)
3494 CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist);
3498 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
3499 We do NOT enter this node in any sort of symbol table.
3501 layout_decl is used to set up the decl's storage layout.
3502 Other slots are initialized to 0 or null pointers. */
3505 build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL)
3509 t = make_node_stat (code PASS_MEM_STAT);
3511 /* if (type == error_mark_node)
3512 type = integer_type_node; */
3513 /* That is not done, deliberately, so that having error_mark_node
3514 as the type can suppress useless errors in the use of this variable. */
3516 DECL_NAME (t) = name;
3517 TREE_TYPE (t) = type;
3519 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
3525 /* Builds and returns function declaration with NAME and TYPE. */
3528 build_fn_decl (const char *name, tree type)
3530 tree id = get_identifier (name);
3531 tree decl = build_decl (FUNCTION_DECL, id, type);
3533 DECL_EXTERNAL (decl) = 1;
3534 TREE_PUBLIC (decl) = 1;
3535 DECL_ARTIFICIAL (decl) = 1;
3536 TREE_NOTHROW (decl) = 1;
3542 /* BLOCK nodes are used to represent the structure of binding contours
3543 and declarations, once those contours have been exited and their contents
3544 compiled. This information is used for outputting debugging info. */
3547 build_block (tree vars, tree subblocks, tree supercontext, tree chain)
3549 tree block = make_node (BLOCK);
3551 BLOCK_VARS (block) = vars;
3552 BLOCK_SUBBLOCKS (block) = subblocks;
3553 BLOCK_SUPERCONTEXT (block) = supercontext;
3554 BLOCK_CHAIN (block) = chain;
3559 expand_location (source_location loc)
3561 expanded_location xloc;
3570 const struct line_map *map = linemap_lookup (line_table, loc);
3571 xloc.file = map->to_file;
3572 xloc.line = SOURCE_LINE (map, loc);
3573 xloc.column = SOURCE_COLUMN (map, loc);
3579 /* Source location accessor functions. */
3582 /* The source location of this expression. Non-tree_exp nodes such as
3583 decls and constants can be shared among multiple locations, so
3586 expr_location (const_tree node)
3588 if (GIMPLE_STMT_P (node))
3589 return GIMPLE_STMT_LOCUS (node);
3590 return EXPR_P (node) ? node->exp.locus : UNKNOWN_LOCATION;
3594 set_expr_location (tree node, location_t locus)
3596 if (GIMPLE_STMT_P (node))
3597 GIMPLE_STMT_LOCUS (node) = locus;
3599 EXPR_CHECK (node)->exp.locus = locus;
3603 expr_has_location (const_tree node)
3605 return expr_location (node) != UNKNOWN_LOCATION;
3609 expr_locus (const_tree node)
3611 if (GIMPLE_STMT_P (node))
3612 return CONST_CAST (source_location *, &GIMPLE_STMT_LOCUS (node));
3613 return (EXPR_P (node)
3614 ? CONST_CAST (source_location *, &node->exp.locus)
3615 : (source_location *) NULL);
3619 set_expr_locus (tree node, source_location *loc)
3623 if (GIMPLE_STMT_P (node))
3624 GIMPLE_STMT_LOCUS (node) = UNKNOWN_LOCATION;
3626 EXPR_CHECK (node)->exp.locus = UNKNOWN_LOCATION;
3630 if (GIMPLE_STMT_P (node))
3631 GIMPLE_STMT_LOCUS (node) = *loc;
3633 EXPR_CHECK (node)->exp.locus = *loc;
3637 /* Return the file name of the location of NODE. */
3639 expr_filename (const_tree node)
3641 if (GIMPLE_STMT_P (node))
3642 return LOCATION_FILE (GIMPLE_STMT_LOCUS (node));
3643 return LOCATION_FILE (EXPR_CHECK (node)->exp.locus);
3646 /* Return the line number of the location of NODE. */
3648 expr_lineno (const_tree node)
3650 if (GIMPLE_STMT_P (node))
3651 return LOCATION_LINE (GIMPLE_STMT_LOCUS (node));
3652 return LOCATION_LINE (EXPR_CHECK (node)->exp.locus);
3656 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
3660 build_decl_attribute_variant (tree ddecl, tree attribute)
3662 DECL_ATTRIBUTES (ddecl) = attribute;
3666 /* Borrowed from hashtab.c iterative_hash implementation. */
3667 #define mix(a,b,c) \
3669 a -= b; a -= c; a ^= (c>>13); \
3670 b -= c; b -= a; b ^= (a<< 8); \
3671 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
3672 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
3673 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
3674 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
3675 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
3676 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
3677 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
3681 /* Produce good hash value combining VAL and VAL2. */
3683 iterative_hash_hashval_t (hashval_t val, hashval_t val2)
3685 /* the golden ratio; an arbitrary value. */
3686 hashval_t a = 0x9e3779b9;
3692 /* Produce good hash value combining PTR and VAL2. */
3693 static inline hashval_t
3694 iterative_hash_pointer (const void *ptr, hashval_t val2)
3696 if (sizeof (ptr) == sizeof (hashval_t))
3697 return iterative_hash_hashval_t ((size_t) ptr, val2);
3700 hashval_t a = (hashval_t) (size_t) ptr;
3701 /* Avoid warnings about shifting of more than the width of the type on
3702 hosts that won't execute this path. */
3704 hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero));
3710 /* Produce good hash value combining VAL and VAL2. */
3711 static inline hashval_t
3712 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
3714 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t))
3715 return iterative_hash_hashval_t (val, val2);
3718 hashval_t a = (hashval_t) val;
3719 /* Avoid warnings about shifting of more than the width of the type on
3720 hosts that won't execute this path. */
3722 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero));
3724 if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t))
3726 hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero));
3727 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero));
3734 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3735 is ATTRIBUTE and its qualifiers are QUALS.
3737 Record such modified types already made so we don't make duplicates. */
3740 build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
3742 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
3744 hashval_t hashcode = 0;
3746 enum tree_code code = TREE_CODE (ttype);
3748 /* Building a distinct copy of a tagged type is inappropriate; it
3749 causes breakage in code that expects there to be a one-to-one
3750 relationship between a struct and its fields.
3751 build_duplicate_type is another solution (as used in
3752 handle_transparent_union_attribute), but that doesn't play well
3753 with the stronger C++ type identity model. */
3754 if (TREE_CODE (ttype) == RECORD_TYPE
3755 || TREE_CODE (ttype) == UNION_TYPE
3756 || TREE_CODE (ttype) == QUAL_UNION_TYPE
3757 || TREE_CODE (ttype) == ENUMERAL_TYPE)
3759 warning (OPT_Wattributes,
3760 "ignoring attributes applied to %qT after definition",
3761 TYPE_MAIN_VARIANT (ttype));
3762 return build_qualified_type (ttype, quals);
3765 ntype = build_distinct_type_copy (ttype);
3767 TYPE_ATTRIBUTES (ntype) = attribute;
3768 set_type_quals (ntype, TYPE_UNQUALIFIED);
3770 hashcode = iterative_hash_object (code, hashcode);
3771 if (TREE_TYPE (ntype))
3772 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)),
3774 hashcode = attribute_hash_list (attribute, hashcode);
3776 switch (TREE_CODE (ntype))
3779 hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode);
3782 if (TYPE_DOMAIN (ntype))
3783 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)),
3787 hashcode = iterative_hash_object
3788 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode);
3789 hashcode = iterative_hash_object
3790 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode);
3793 case FIXED_POINT_TYPE:
3795 unsigned int precision = TYPE_PRECISION (ntype);
3796 hashcode = iterative_hash_object (precision, hashcode);
3803 ntype = type_hash_canon (hashcode, ntype);
3805 /* If the target-dependent attributes make NTYPE different from
3806 its canonical type, we will need to use structural equality
3807 checks for this qualified type. */
3808 ttype = build_qualified_type (ttype, TYPE_UNQUALIFIED);
3809 if (TYPE_STRUCTURAL_EQUALITY_P (ttype)
3810 || !targetm.comp_type_attributes (ntype, ttype))
3811 SET_TYPE_STRUCTURAL_EQUALITY (ntype);
3813 TYPE_CANONICAL (ntype) = TYPE_CANONICAL (ttype);
3815 ttype = build_qualified_type (ntype, quals);
3817 else if (TYPE_QUALS (ttype) != quals)
3818 ttype = build_qualified_type (ttype, quals);
3824 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3827 Record such modified types already made so we don't make duplicates. */
3830 build_type_attribute_variant (tree ttype, tree attribute)
3832 return build_type_attribute_qual_variant (ttype, attribute,
3833 TYPE_QUALS (ttype));
3836 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3839 We try both `text' and `__text__', ATTR may be either one. */
3840 /* ??? It might be a reasonable simplification to require ATTR to be only
3841 `text'. One might then also require attribute lists to be stored in
3842 their canonicalized form. */
3845 is_attribute_with_length_p (const char *attr, int attr_len, const_tree ident)
3850 if (TREE_CODE (ident) != IDENTIFIER_NODE)
3853 p = IDENTIFIER_POINTER (ident);
3854 ident_len = IDENTIFIER_LENGTH (ident);
3856 if (ident_len == attr_len
3857 && strcmp (attr, p) == 0)
3860 /* If ATTR is `__text__', IDENT must be `text'; and vice versa. */
3863 gcc_assert (attr[1] == '_');
3864 gcc_assert (attr[attr_len - 2] == '_');
3865 gcc_assert (attr[attr_len - 1] == '_');
3866 if (ident_len == attr_len - 4
3867 && strncmp (attr + 2, p, attr_len - 4) == 0)
3872 if (ident_len == attr_len + 4
3873 && p[0] == '_' && p[1] == '_'
3874 && p[ident_len - 2] == '_' && p[ident_len - 1] == '_'
3875 && strncmp (attr, p + 2, attr_len) == 0)
3882 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3885 We try both `text' and `__text__', ATTR may be either one. */
3888 is_attribute_p (const char *attr, const_tree ident)
3890 return is_attribute_with_length_p (attr, strlen (attr), ident);
3893 /* Given an attribute name and a list of attributes, return a pointer to the
3894 attribute's list element if the attribute is part of the list, or NULL_TREE
3895 if not found. If the attribute appears more than once, this only
3896 returns the first occurrence; the TREE_CHAIN of the return value should
3897 be passed back in if further occurrences are wanted. */
3900 lookup_attribute (const char *attr_name, tree list)
3903 size_t attr_len = strlen (attr_name);
3905 for (l = list; l; l = TREE_CHAIN (l))
3907 gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
3908 if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l)))
3914 /* Remove any instances of attribute ATTR_NAME in LIST and return the
3918 remove_attribute (const char *attr_name, tree list)
3921 size_t attr_len = strlen (attr_name);
3923 for (p = &list; *p; )
3926 gcc_assert (TREE_CODE (TREE_PURPOSE (l)) == IDENTIFIER_NODE);
3927 if (is_attribute_with_length_p (attr_name, attr_len, TREE_PURPOSE (l)))
3928 *p = TREE_CHAIN (l);
3930 p = &TREE_CHAIN (l);
3936 /* Return an attribute list that is the union of a1 and a2. */
3939 merge_attributes (tree a1, tree a2)
3943 /* Either one unset? Take the set one. */
3945 if ((attributes = a1) == 0)
3948 /* One that completely contains the other? Take it. */
3950 else if (a2 != 0 && ! attribute_list_contained (a1, a2))
3952 if (attribute_list_contained (a2, a1))
3956 /* Pick the longest list, and hang on the other list. */
3958 if (list_length (a1) < list_length (a2))
3959 attributes = a2, a2 = a1;
3961 for (; a2 != 0; a2 = TREE_CHAIN (a2))
3964 for (a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3967 a = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
3970 if (TREE_VALUE (a) != NULL
3971 && TREE_CODE (TREE_VALUE (a)) == TREE_LIST
3972 && TREE_VALUE (a2) != NULL
3973 && TREE_CODE (TREE_VALUE (a2)) == TREE_LIST)
3975 if (simple_cst_list_equal (TREE_VALUE (a),
3976 TREE_VALUE (a2)) == 1)
3979 else if (simple_cst_equal (TREE_VALUE (a),
3980 TREE_VALUE (a2)) == 1)
3985 a1 = copy_node (a2);
3986 TREE_CHAIN (a1) = attributes;
3995 /* Given types T1 and T2, merge their attributes and return
3999 merge_type_attributes (tree t1, tree t2)
4001 return merge_attributes (TYPE_ATTRIBUTES (t1),
4002 TYPE_ATTRIBUTES (t2));
4005 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
4009 merge_decl_attributes (tree olddecl, tree newdecl)
4011 return merge_attributes (DECL_ATTRIBUTES (olddecl),
4012 DECL_ATTRIBUTES (newdecl));
4015 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
4017 /* Specialization of merge_decl_attributes for various Windows targets.
4019 This handles the following situation:
4021 __declspec (dllimport) int foo;
4024 The second instance of `foo' nullifies the dllimport. */
4027 merge_dllimport_decl_attributes (tree old, tree new)
4030 int delete_dllimport_p = 1;
4032 /* What we need to do here is remove from `old' dllimport if it doesn't
4033 appear in `new'. dllimport behaves like extern: if a declaration is
4034 marked dllimport and a definition appears later, then the object
4035 is not dllimport'd. We also remove a `new' dllimport if the old list
4036 contains dllexport: dllexport always overrides dllimport, regardless
4037 of the order of declaration. */
4038 if (!VAR_OR_FUNCTION_DECL_P (new))
4039 delete_dllimport_p = 0;
4040 else if (DECL_DLLIMPORT_P (new)
4041 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old)))
4043 DECL_DLLIMPORT_P (new) = 0;
4044 warning (OPT_Wattributes, "%q+D already declared with dllexport attribute: "
4045 "dllimport ignored", new);
4047 else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new))
4049 /* Warn about overriding a symbol that has already been used, e.g.:
4050 extern int __attribute__ ((dllimport)) foo;
4051 int* bar () {return &foo;}
4054 if (TREE_USED (old))
4056 warning (0, "%q+D redeclared without dllimport attribute "
4057 "after being referenced with dll linkage", new);
4058 /* If we have used a variable's address with dllimport linkage,
4059 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
4060 decl may already have had TREE_CONSTANT computed.
4061 We still remove the attribute so that assembler code refers
4062 to '&foo rather than '_imp__foo'. */
4063 if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old))
4064 DECL_DLLIMPORT_P (new) = 1;
4067 /* Let an inline definition silently override the external reference,
4068 but otherwise warn about attribute inconsistency. */
4069 else if (TREE_CODE (new) == VAR_DECL
4070 || !DECL_DECLARED_INLINE_P (new))
4071 warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: "
4072 "previous dllimport ignored", new);
4075 delete_dllimport_p = 0;
4077 a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new));
4079 if (delete_dllimport_p)
4082 const size_t attr_len = strlen ("dllimport");
4084 /* Scan the list for dllimport and delete it. */
4085 for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
4087 if (is_attribute_with_length_p ("dllimport", attr_len,
4090 if (prev == NULL_TREE)
4093 TREE_CHAIN (prev) = TREE_CHAIN (t);
4102 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
4103 struct attribute_spec.handler. */
4106 handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
4111 /* These attributes may apply to structure and union types being created,
4112 but otherwise should pass to the declaration involved. */
4115 if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
4116 | (int) ATTR_FLAG_ARRAY_NEXT))
4118 *no_add_attrs = true;
4119 return tree_cons (name, args, NULL_TREE);
4121 if (TREE_CODE (node) == RECORD_TYPE
4122 || TREE_CODE (node) == UNION_TYPE)
4124 node = TYPE_NAME (node);
4130 warning (OPT_Wattributes, "%qs attribute ignored",
4131 IDENTIFIER_POINTER (name));
4132 *no_add_attrs = true;
4137 if (TREE_CODE (node) != FUNCTION_DECL
4138 && TREE_CODE (node) != VAR_DECL
4139 && TREE_CODE (node) != TYPE_DECL)
4141 *no_add_attrs = true;
4142 warning (OPT_Wattributes, "%qs attribute ignored",
4143 IDENTIFIER_POINTER (name));
4147 if (TREE_CODE (node) == TYPE_DECL
4148 && TREE_CODE (TREE_TYPE (node)) != RECORD_TYPE
4149 && TREE_CODE (TREE_TYPE (node)) != UNION_TYPE)
4151 *no_add_attrs = true;
4152 warning (OPT_Wattributes, "%qs attribute ignored",
4153 IDENTIFIER_POINTER (name));
4157 /* Report error on dllimport ambiguities seen now before they cause
4159 else if (is_attribute_p ("dllimport", name))
4161 /* Honor any target-specific overrides. */
4162 if (!targetm.valid_dllimport_attribute_p (node))
4163 *no_add_attrs = true;
4165 else if (TREE_CODE (node) == FUNCTION_DECL
4166 && DECL_DECLARED_INLINE_P (node))
4168 warning (OPT_Wattributes, "inline function %q+D declared as "
4169 " dllimport: attribute ignored", node);
4170 *no_add_attrs = true;
4172 /* Like MS, treat definition of dllimported variables and
4173 non-inlined functions on declaration as syntax errors. */
4174 else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node))
4176 error ("function %q+D definition is marked dllimport", node);
4177 *no_add_attrs = true;
4180 else if (TREE_CODE (node) == VAR_DECL)
4182 if (DECL_INITIAL (node))
4184 error ("variable %q+D definition is marked dllimport",
4186 *no_add_attrs = true;
4189 /* `extern' needn't be specified with dllimport.
4190 Specify `extern' now and hope for the best. Sigh. */
4191 DECL_EXTERNAL (node) = 1;
4192 /* Also, implicitly give dllimport'd variables declared within
4193 a function global scope, unless declared static. */
4194 if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
4195 TREE_PUBLIC (node) = 1;
4198 if (*no_add_attrs == false)
4199 DECL_DLLIMPORT_P (node) = 1;
4202 /* Report error if symbol is not accessible at global scope. */
4203 if (!TREE_PUBLIC (node)
4204 && (TREE_CODE (node) == VAR_DECL
4205 || TREE_CODE (node) == FUNCTION_DECL))
4207 error ("external linkage required for symbol %q+D because of "
4208 "%qs attribute", node, IDENTIFIER_POINTER (name));
4209 *no_add_attrs = true;
4212 /* A dllexport'd entity must have default visibility so that other
4213 program units (shared libraries or the main executable) can see
4214 it. A dllimport'd entity must have default visibility so that
4215 the linker knows that undefined references within this program
4216 unit can be resolved by the dynamic linker. */
4219 if (DECL_VISIBILITY_SPECIFIED (node)
4220 && DECL_VISIBILITY (node) != VISIBILITY_DEFAULT)
4221 error ("%qs implies default visibility, but %qD has already "
4222 "been declared with a different visibility",
4223 IDENTIFIER_POINTER (name), node);
4224 DECL_VISIBILITY (node) = VISIBILITY_DEFAULT;
4225 DECL_VISIBILITY_SPECIFIED (node) = 1;
4231 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
4233 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
4234 of the various TYPE_QUAL values. */
4237 set_type_quals (tree type, int type_quals)
4239 TYPE_READONLY (type) = (type_quals & TYPE_QUAL_CONST) != 0;
4240 TYPE_VOLATILE (type) = (type_quals & TYPE_QUAL_VOLATILE) != 0;
4241 TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
4244 /* Returns true iff CAND is equivalent to BASE with TYPE_QUALS. */
4247 check_qualified_type (const_tree cand, const_tree base, int type_quals)
4249 return (TYPE_QUALS (cand) == type_quals
4250 && TYPE_NAME (cand) == TYPE_NAME (base)
4251 /* Apparently this is needed for Objective-C. */
4252 && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
4253 && attribute_list_equal (TYPE_ATTRIBUTES (cand),
4254 TYPE_ATTRIBUTES (base)));
4257 /* Return a version of the TYPE, qualified as indicated by the
4258 TYPE_QUALS, if one exists. If no qualified version exists yet,
4259 return NULL_TREE. */
4262 get_qualified_type (tree type, int type_quals)
4266 if (TYPE_QUALS (type) == type_quals)
4269 /* Search the chain of variants to see if there is already one there just
4270 like the one we need to have. If so, use that existing one. We must
4271 preserve the TYPE_NAME, since there is code that depends on this. */
4272 for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
4273 if (check_qualified_type (t, type, type_quals))
4279 /* Like get_qualified_type, but creates the type if it does not
4280 exist. This function never returns NULL_TREE. */
4283 build_qualified_type (tree type, int type_quals)
4287 /* See if we already have the appropriate qualified variant. */
4288 t = get_qualified_type (type, type_quals);
4290 /* If not, build it. */
4293 t = build_variant_type_copy (type);
4294 set_type_quals (t, type_quals);
4296 if (TYPE_STRUCTURAL_EQUALITY_P (type))
4297 /* Propagate structural equality. */
4298 SET_TYPE_STRUCTURAL_EQUALITY (t);
4299 else if (TYPE_CANONICAL (type) != type)
4300 /* Build the underlying canonical type, since it is different
4302 TYPE_CANONICAL (t) = build_qualified_type (TYPE_CANONICAL (type),
4305 /* T is its own canonical type. */
4306 TYPE_CANONICAL (t) = t;
4313 /* Create a new distinct copy of TYPE. The new type is made its own
4314 MAIN_VARIANT. If TYPE requires structural equality checks, the
4315 resulting type requires structural equality checks; otherwise, its
4316 TYPE_CANONICAL points to itself. */
4319 build_distinct_type_copy (tree type)
4321 tree t = copy_node (type);
4323 TYPE_POINTER_TO (t) = 0;
4324 TYPE_REFERENCE_TO (t) = 0;
4326 /* Set the canonical type either to a new equivalence class, or
4327 propagate the need for structural equality checks. */
4328 if (TYPE_STRUCTURAL_EQUALITY_P (type))
4329 SET_TYPE_STRUCTURAL_EQUALITY (t);
4331 TYPE_CANONICAL (t) = t;
4333 /* Make it its own variant. */
4334 TYPE_MAIN_VARIANT (t) = t;
4335 TYPE_NEXT_VARIANT (t) = 0;
4337 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
4338 whose TREE_TYPE is not t. This can also happen in the Ada
4339 frontend when using subtypes. */
4344 /* Create a new variant of TYPE, equivalent but distinct. This is so
4345 the caller can modify it. TYPE_CANONICAL for the return type will
4346 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
4347 are considered equal by the language itself (or that both types
4348 require structural equality checks). */
4351 build_variant_type_copy (tree type)
4353 tree t, m = TYPE_MAIN_VARIANT (type);
4355 t = build_distinct_type_copy (type);
4357 /* Since we're building a variant, assume that it is a non-semantic
4358 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
4359 TYPE_CANONICAL (t) = TYPE_CANONICAL (type);
4361 /* Add the new type to the chain of variants of TYPE. */
4362 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
4363 TYPE_NEXT_VARIANT (m) = t;
4364 TYPE_MAIN_VARIANT (t) = m;
4369 /* Return true if the from tree in both tree maps are equal. */
4372 tree_map_base_eq (const void *va, const void *vb)
4374 const struct tree_map_base *const a = (const struct tree_map_base *) va,
4375 *const b = (const struct tree_map_base *) vb;
4376 return (a->from == b->from);
4379 /* Hash a from tree in a tree_map. */
4382 tree_map_base_hash (const void *item)
4384 return htab_hash_pointer (((const struct tree_map_base *)item)->from);
4387 /* Return true if this tree map structure is marked for garbage collection
4388 purposes. We simply return true if the from tree is marked, so that this
4389 structure goes away when the from tree goes away. */
4392 tree_map_base_marked_p (const void *p)
4394 return ggc_marked_p (((const struct tree_map_base *) p)->from);
4398 tree_map_hash (const void *item)
4400 return (((const struct tree_map *) item)->hash);
4403 /* Return the initialization priority for DECL. */
4406 decl_init_priority_lookup (tree decl)
4408 struct tree_priority_map *h;
4409 struct tree_map_base in;
4411 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
4413 h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in);
4414 return h ? h->init : DEFAULT_INIT_PRIORITY;
4417 /* Return the finalization priority for DECL. */
4420 decl_fini_priority_lookup (tree decl)
4422 struct tree_priority_map *h;
4423 struct tree_map_base in;
4425 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
4427 h = (struct tree_priority_map *) htab_find (init_priority_for_decl, &in);
4428 return h ? h->fini : DEFAULT_INIT_PRIORITY;
4431 /* Return the initialization and finalization priority information for
4432 DECL. If there is no previous priority information, a freshly
4433 allocated structure is returned. */
4435 static struct tree_priority_map *
4436 decl_priority_info (tree decl)
4438 struct tree_priority_map in;
4439 struct tree_priority_map *h;
4442 in.base.from = decl;
4443 loc = htab_find_slot (init_priority_for_decl, &in, INSERT);
4444 h = (struct tree_priority_map *) *loc;
4447 h = GGC_CNEW (struct tree_priority_map);
4449 h->base.from = decl;
4450 h->init = DEFAULT_INIT_PRIORITY;
4451 h->fini = DEFAULT_INIT_PRIORITY;
4457 /* Set the initialization priority for DECL to PRIORITY. */
4460 decl_init_priority_insert (tree decl, priority_type priority)
4462 struct tree_priority_map *h;
4464 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
4465 h = decl_priority_info (decl);
4469 /* Set the finalization priority for DECL to PRIORITY. */
4472 decl_fini_priority_insert (tree decl, priority_type priority)
4474 struct tree_priority_map *h;
4476 gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
4477 h = decl_priority_info (decl);
4481 /* Look up a restrict qualified base decl for FROM. */
4484 decl_restrict_base_lookup (tree from)
4489 in.base.from = from;
4490 h = (struct tree_map *) htab_find_with_hash (restrict_base_for_decl, &in,
4491 htab_hash_pointer (from));
4492 return h ? h->to : NULL_TREE;
4495 /* Record the restrict qualified base TO for FROM. */
4498 decl_restrict_base_insert (tree from, tree to)
4503 h = GGC_NEW (struct tree_map);
4504 h->hash = htab_hash_pointer (from);
4505 h->base.from = from;
4507 loc = htab_find_slot_with_hash (restrict_base_for_decl, h, h->hash, INSERT);
4508 *(struct tree_map **) loc = h;
4511 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
4514 print_debug_expr_statistics (void)
4516 fprintf (stderr, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
4517 (long) htab_size (debug_expr_for_decl),
4518 (long) htab_elements (debug_expr_for_decl),
4519 htab_collisions (debug_expr_for_decl));
4522 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
4525 print_value_expr_statistics (void)
4527 fprintf (stderr, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
4528 (long) htab_size (value_expr_for_decl),
4529 (long) htab_elements (value_expr_for_decl),
4530 htab_collisions (value_expr_for_decl));
4533 /* Print out statistics for the RESTRICT_BASE_FOR_DECL hash table, but
4534 don't print anything if the table is empty. */
4537 print_restrict_base_statistics (void)
4539 if (htab_elements (restrict_base_for_decl) != 0)
4541 "RESTRICT_BASE hash: size %ld, %ld elements, %f collisions\n",
4542 (long) htab_size (restrict_base_for_decl),
4543 (long) htab_elements (restrict_base_for_decl),
4544 htab_collisions (restrict_base_for_decl));
4547 /* Lookup a debug expression for FROM, and return it if we find one. */
4550 decl_debug_expr_lookup (tree from)
4552 struct tree_map *h, in;
4553 in.base.from = from;
4555 h = (struct tree_map *) htab_find_with_hash (debug_expr_for_decl, &in,
4556 htab_hash_pointer (from));
4562 /* Insert a mapping FROM->TO in the debug expression hashtable. */
4565 decl_debug_expr_insert (tree from, tree to)
4570 h = GGC_NEW (struct tree_map);
4571 h->hash = htab_hash_pointer (from);
4572 h->base.from = from;
4574 loc = htab_find_slot_with_hash (debug_expr_for_decl, h, h->hash, INSERT);
4575 *(struct tree_map **) loc = h;
4578 /* Lookup a value expression for FROM, and return it if we find one. */
4581 decl_value_expr_lookup (tree from)
4583 struct tree_map *h, in;
4584 in.base.from = from;
4586 h = (struct tree_map *) htab_find_with_hash (value_expr_for_decl, &in,
4587 htab_hash_pointer (from));
4593 /* Insert a mapping FROM->TO in the value expression hashtable. */
4596 decl_value_expr_insert (tree from, tree to)
4601 h = GGC_NEW (struct tree_map);
4602 h->hash = htab_hash_pointer (from);
4603 h->base.from = from;
4605 loc = htab_find_slot_with_hash (value_expr_for_decl, h, h->hash, INSERT);
4606 *(struct tree_map **) loc = h;
4609 /* Hashing of types so that we don't make duplicates.
4610 The entry point is `type_hash_canon'. */
4612 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
4613 with types in the TREE_VALUE slots), by adding the hash codes
4614 of the individual types. */
4617 type_hash_list (const_tree list, hashval_t hashcode)
4621 for (tail = list; tail; tail = TREE_CHAIN (tail))
4622 if (TREE_VALUE (tail) != error_mark_node)
4623 hashcode = iterative_hash_object (TYPE_HASH (TREE_VALUE (tail)),
4629 /* These are the Hashtable callback functions. */
4631 /* Returns true iff the types are equivalent. */
4634 type_hash_eq (const void *va, const void *vb)
4636 const struct type_hash *const a = (const struct type_hash *) va,
4637 *const b = (const struct type_hash *) vb;
4639 /* First test the things that are the same for all types. */
4640 if (a->hash != b->hash
4641 || TREE_CODE (a->type) != TREE_CODE (b->type)
4642 || TREE_TYPE (a->type) != TREE_TYPE (b->type)
4643 || !attribute_list_equal (TYPE_ATTRIBUTES (a->type),
4644 TYPE_ATTRIBUTES (b->type))
4645 || TYPE_ALIGN (a->type) != TYPE_ALIGN (b->type)
4646 || TYPE_MODE (a->type) != TYPE_MODE (b->type))
4649 switch (TREE_CODE (a->type))
4654 case REFERENCE_TYPE:
4658 return TYPE_VECTOR_SUBPARTS (a->type) == TYPE_VECTOR_SUBPARTS (b->type);
4661 if (TYPE_VALUES (a->type) != TYPE_VALUES (b->type)
4662 && !(TYPE_VALUES (a->type)
4663 && TREE_CODE (TYPE_VALUES (a->type)) == TREE_LIST
4664 && TYPE_VALUES (b->type)
4665 && TREE_CODE (TYPE_VALUES (b->type)) == TREE_LIST
4666 && type_list_equal (TYPE_VALUES (a->type),
4667 TYPE_VALUES (b->type))))
4670 /* ... fall through ... */
4675 return ((TYPE_MAX_VALUE (a->type) == TYPE_MAX_VALUE (b->type)
4676 || tree_int_cst_equal (TYPE_MAX_VALUE (a->type),
4677 TYPE_MAX_VALUE (b->type)))
4678 && (TYPE_MIN_VALUE (a->type) == TYPE_MIN_VALUE (b->type)
4679 || tree_int_cst_equal (TYPE_MIN_VALUE (a->type),
4680 TYPE_MIN_VALUE (b->type))));
4682 case FIXED_POINT_TYPE:
4683 return TYPE_SATURATING (a->type) == TYPE_SATURATING (b->type);
4686 return TYPE_OFFSET_BASETYPE (a->type) == TYPE_OFFSET_BASETYPE (b->type);
4689 return (TYPE_METHOD_BASETYPE (a->type) == TYPE_METHOD_BASETYPE (b->type)
4690 && (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
4691 || (TYPE_ARG_TYPES (a->type)
4692 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
4693 && TYPE_ARG_TYPES (b->type)
4694 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
4695 && type_list_equal (TYPE_ARG_TYPES (a->type),
4696 TYPE_ARG_TYPES (b->type)))));
4699 return TYPE_DOMAIN (a->type) == TYPE_DOMAIN (b->type);
4703 case QUAL_UNION_TYPE:
4704 return (TYPE_FIELDS (a->type) == TYPE_FIELDS (b->type)
4705 || (TYPE_FIELDS (a->type)
4706 && TREE_CODE (TYPE_FIELDS (a->type)) == TREE_LIST
4707 && TYPE_FIELDS (b->type)
4708 && TREE_CODE (TYPE_FIELDS (b->type)) == TREE_LIST
4709 && type_list_equal (TYPE_FIELDS (a->type),
4710 TYPE_FIELDS (b->type))));
4713 if (TYPE_ARG_TYPES (a->type) == TYPE_ARG_TYPES (b->type)
4714 || (TYPE_ARG_TYPES (a->type)
4715 && TREE_CODE (TYPE_ARG_TYPES (a->type)) == TREE_LIST
4716 && TYPE_ARG_TYPES (b->type)
4717 && TREE_CODE (TYPE_ARG_TYPES (b->type)) == TREE_LIST
4718 && type_list_equal (TYPE_ARG_TYPES (a->type),
4719 TYPE_ARG_TYPES (b->type))))
4727 if (lang_hooks.types.type_hash_eq != NULL)
4728 return lang_hooks.types.type_hash_eq (a->type, b->type);
4733 /* Return the cached hash value. */
4736 type_hash_hash (const void *item)
4738 return ((const struct type_hash *) item)->hash;
4741 /* Look in the type hash table for a type isomorphic to TYPE.
4742 If one is found, return it. Otherwise return 0. */
4745 type_hash_lookup (hashval_t hashcode, tree type)
4747 struct type_hash *h, in;
4749 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
4750 must call that routine before comparing TYPE_ALIGNs. */
4756 h = (struct type_hash *) htab_find_with_hash (type_hash_table, &in,
4763 /* Add an entry to the type-hash-table
4764 for a type TYPE whose hash code is HASHCODE. */
4767 type_hash_add (hashval_t hashcode, tree type)
4769 struct type_hash *h;
4772 h = GGC_NEW (struct type_hash);
4775 loc = htab_find_slot_with_hash (type_hash_table, h, hashcode, INSERT);
4779 /* Given TYPE, and HASHCODE its hash code, return the canonical
4780 object for an identical type if one already exists.
4781 Otherwise, return TYPE, and record it as the canonical object.
4783 To use this function, first create a type of the sort you want.
4784 Then compute its hash code from the fields of the type that
4785 make it different from other similar types.
4786 Then call this function and use the value. */
4789 type_hash_canon (unsigned int hashcode, tree type)
4793 /* The hash table only contains main variants, so ensure that's what we're
4795 gcc_assert (TYPE_MAIN_VARIANT (type) == type);
4797 if (!lang_hooks.types.hash_types)
4800 /* See if the type is in the hash table already. If so, return it.
4801 Otherwise, add the type. */
4802 t1 = type_hash_lookup (hashcode, type);
4805 #ifdef GATHER_STATISTICS
4806 tree_node_counts[(int) t_kind]--;
4807 tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
4813 type_hash_add (hashcode, type);
4818 /* See if the data pointed to by the type hash table is marked. We consider
4819 it marked if the type is marked or if a debug type number or symbol
4820 table entry has been made for the type. This reduces the amount of
4821 debugging output and eliminates that dependency of the debug output on
4822 the number of garbage collections. */
4825 type_hash_marked_p (const void *p)
4827 const_tree const type = ((const struct type_hash *) p)->type;
4829 return ggc_marked_p (type) || TYPE_SYMTAB_POINTER (type);
4833 print_type_hash_statistics (void)
4835 fprintf (stderr, "Type hash: size %ld, %ld elements, %f collisions\n",
4836 (long) htab_size (type_hash_table),
4837 (long) htab_elements (type_hash_table),
4838 htab_collisions (type_hash_table));
4841 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
4842 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
4843 by adding the hash codes of the individual attributes. */
4846 attribute_hash_list (const_tree list, hashval_t hashcode)
4850 for (tail = list; tail; tail = TREE_CHAIN (tail))
4851 /* ??? Do we want to add in TREE_VALUE too? */
4852 hashcode = iterative_hash_object
4853 (IDENTIFIER_HASH_VALUE (TREE_PURPOSE (tail)), hashcode);
4857 /* Given two lists of attributes, return true if list l2 is
4858 equivalent to l1. */
4861 attribute_list_equal (const_tree l1, const_tree l2)
4863 return attribute_list_contained (l1, l2)
4864 && attribute_list_contained (l2, l1);
4867 /* Given two lists of attributes, return true if list L2 is
4868 completely contained within L1. */
4869 /* ??? This would be faster if attribute names were stored in a canonicalized
4870 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
4871 must be used to show these elements are equivalent (which they are). */
4872 /* ??? It's not clear that attributes with arguments will always be handled
4876 attribute_list_contained (const_tree l1, const_tree l2)
4880 /* First check the obvious, maybe the lists are identical. */
4884 /* Maybe the lists are similar. */
4885 for (t1 = l1, t2 = l2;
4887 && TREE_PURPOSE (t1) == TREE_PURPOSE (t2)
4888 && TREE_VALUE (t1) == TREE_VALUE (t2);
4889 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2));
4891 /* Maybe the lists are equal. */
4892 if (t1 == 0 && t2 == 0)
4895 for (; t2 != 0; t2 = TREE_CHAIN (t2))
4898 /* This CONST_CAST is okay because lookup_attribute does not
4899 modify its argument and the return value is assigned to a
4901 for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
4902 CONST_CAST_TREE(l1));
4904 attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
4907 if (TREE_VALUE (t2) != NULL
4908 && TREE_CODE (TREE_VALUE (t2)) == TREE_LIST
4909 && TREE_VALUE (attr) != NULL
4910 && TREE_CODE (TREE_VALUE (attr)) == TREE_LIST)
4912 if (simple_cst_list_equal (TREE_VALUE (t2),
4913 TREE_VALUE (attr)) == 1)
4916 else if (simple_cst_equal (TREE_VALUE (t2), TREE_VALUE (attr)) == 1)
4927 /* Given two lists of types
4928 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
4929 return 1 if the lists contain the same types in the same order.
4930 Also, the TREE_PURPOSEs must match. */
4933 type_list_equal (const_tree l1, const_tree l2)
4937 for (t1 = l1, t2 = l2; t1 && t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
4938 if (TREE_VALUE (t1) != TREE_VALUE (t2)
4939 || (TREE_PURPOSE (t1) != TREE_PURPOSE (t2)
4940 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))
4941 && (TREE_TYPE (TREE_PURPOSE (t1))
4942 == TREE_TYPE (TREE_PURPOSE (t2))))))
4948 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
4949 given by TYPE. If the argument list accepts variable arguments,
4950 then this function counts only the ordinary arguments. */
4953 type_num_arguments (const_tree type)
4958 for (t = TYPE_ARG_TYPES (type); t; t = TREE_CHAIN (t))
4959 /* If the function does not take a variable number of arguments,
4960 the last element in the list will have type `void'. */
4961 if (VOID_TYPE_P (TREE_VALUE (t)))
4969 /* Nonzero if integer constants T1 and T2
4970 represent the same constant value. */
4973 tree_int_cst_equal (const_tree t1, const_tree t2)
4978 if (t1 == 0 || t2 == 0)
4981 if (TREE_CODE (t1) == INTEGER_CST
4982 && TREE_CODE (t2) == INTEGER_CST
4983 && TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
4984 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2))
4990 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
4991 The precise way of comparison depends on their data type. */
4994 tree_int_cst_lt (const_tree t1, const_tree t2)
4999 if (TYPE_UNSIGNED (TREE_TYPE (t1)) != TYPE_UNSIGNED (TREE_TYPE (t2)))
5001 int t1_sgn = tree_int_cst_sgn (t1);
5002 int t2_sgn = tree_int_cst_sgn (t2);
5004 if (t1_sgn < t2_sgn)
5006 else if (t1_sgn > t2_sgn)
5008 /* Otherwise, both are non-negative, so we compare them as
5009 unsigned just in case one of them would overflow a signed
5012 else if (!TYPE_UNSIGNED (TREE_TYPE (t1)))
5013 return INT_CST_LT (t1, t2);
5015 return INT_CST_LT_UNSIGNED (t1, t2);
5018 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
5021 tree_int_cst_compare (const_tree t1, const_tree t2)
5023 if (tree_int_cst_lt (t1, t2))
5025 else if (tree_int_cst_lt (t2, t1))
5031 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
5032 the host. If POS is zero, the value can be represented in a single
5033 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
5034 be represented in a single unsigned HOST_WIDE_INT. */
5037 host_integerp (const_tree t, int pos)
5039 return (TREE_CODE (t) == INTEGER_CST
5040 && ((TREE_INT_CST_HIGH (t) == 0
5041 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
5042 || (! pos && TREE_INT_CST_HIGH (t) == -1
5043 && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
5044 && (!TYPE_UNSIGNED (TREE_TYPE (t))
5045 || (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
5046 && TYPE_IS_SIZETYPE (TREE_TYPE (t)))))
5047 || (pos && TREE_INT_CST_HIGH (t) == 0)));
5050 /* Return the HOST_WIDE_INT least significant bits of T if it is an
5051 INTEGER_CST and there is no overflow. POS is nonzero if the result must
5052 be non-negative. We must be able to satisfy the above conditions. */
5055 tree_low_cst (const_tree t, int pos)
5057 gcc_assert (host_integerp (t, pos));
5058 return TREE_INT_CST_LOW (t);
5061 /* Return the most significant bit of the integer constant T. */
5064 tree_int_cst_msb (const_tree t)
5068 unsigned HOST_WIDE_INT l;
5070 /* Note that using TYPE_PRECISION here is wrong. We care about the
5071 actual bits, not the (arbitrary) range of the type. */
5072 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (t))) - 1;
5073 rshift_double (TREE_INT_CST_LOW (t), TREE_INT_CST_HIGH (t), prec,
5074 2 * HOST_BITS_PER_WIDE_INT, &l, &h, 0);
5075 return (l & 1) == 1;
5078 /* Return an indication of the sign of the integer constant T.
5079 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
5080 Note that -1 will never be returned if T's type is unsigned. */
5083 tree_int_cst_sgn (const_tree t)
5085 if (TREE_INT_CST_LOW (t) == 0 && TREE_INT_CST_HIGH (t) == 0)
5087 else if (TYPE_UNSIGNED (TREE_TYPE (t)))
5089 else if (TREE_INT_CST_HIGH (t) < 0)
5095 /* Compare two constructor-element-type constants. Return 1 if the lists
5096 are known to be equal; otherwise return 0. */
5099 simple_cst_list_equal (const_tree l1, const_tree l2)
5101 while (l1 != NULL_TREE && l2 != NULL_TREE)
5103 if (simple_cst_equal (TREE_VALUE (l1), TREE_VALUE (l2)) != 1)
5106 l1 = TREE_CHAIN (l1);
5107 l2 = TREE_CHAIN (l2);
5113 /* Return truthvalue of whether T1 is the same tree structure as T2.
5114 Return 1 if they are the same.
5115 Return 0 if they are understandably different.
5116 Return -1 if either contains tree structure not understood by
5120 simple_cst_equal (const_tree t1, const_tree t2)
5122 enum tree_code code1, code2;
5128 if (t1 == 0 || t2 == 0)
5131 code1 = TREE_CODE (t1);
5132 code2 = TREE_CODE (t2);
5134 if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
5136 if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
5137 || code2 == NON_LVALUE_EXPR)
5138 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
5140 return simple_cst_equal (TREE_OPERAND (t1, 0), t2);
5143 else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
5144 || code2 == NON_LVALUE_EXPR)
5145 return simple_cst_equal (t1, TREE_OPERAND (t2, 0));
5153 return (TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2)
5154 && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2));
5157 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
5160 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
5163 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
5164 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
5165 TREE_STRING_LENGTH (t1)));
5169 unsigned HOST_WIDE_INT idx;
5170 VEC(constructor_elt, gc) *v1 = CONSTRUCTOR_ELTS (t1);
5171 VEC(constructor_elt, gc) *v2 = CONSTRUCTOR_ELTS (t2);
5173 if (VEC_length (constructor_elt, v1) != VEC_length (constructor_elt, v2))
5176 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
5177 /* ??? Should we handle also fields here? */
5178 if (!simple_cst_equal (VEC_index (constructor_elt, v1, idx)->value,
5179 VEC_index (constructor_elt, v2, idx)->value))
5185 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
5188 cmp = simple_cst_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2));
5191 if (call_expr_nargs (t1) != call_expr_nargs (t2))
5194 const_tree arg1, arg2;
5195 const_call_expr_arg_iterator iter1, iter2;
5196 for (arg1 = first_const_call_expr_arg (t1, &iter1),
5197 arg2 = first_const_call_expr_arg (t2, &iter2);
5199 arg1 = next_const_call_expr_arg (&iter1),
5200 arg2 = next_const_call_expr_arg (&iter2))
5202 cmp = simple_cst_equal (arg1, arg2);
5206 return arg1 == arg2;
5210 /* Special case: if either target is an unallocated VAR_DECL,
5211 it means that it's going to be unified with whatever the
5212 TARGET_EXPR is really supposed to initialize, so treat it
5213 as being equivalent to anything. */
5214 if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
5215 && DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
5216 && !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
5217 || (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
5218 && DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
5219 && !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
5222 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
5227 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
5229 case WITH_CLEANUP_EXPR:
5230 cmp = simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
5234 return simple_cst_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
5237 if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
5238 return simple_cst_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
5252 /* This general rule works for most tree codes. All exceptions should be
5253 handled above. If this is a language-specific tree code, we can't
5254 trust what might be in the operand, so say we don't know
5256 if ((int) code1 >= (int) LAST_AND_UNUSED_TREE_CODE)
5259 switch (TREE_CODE_CLASS (code1))
5263 case tcc_comparison:
5264 case tcc_expression:
5268 for (i = 0; i < TREE_CODE_LENGTH (code1); i++)
5270 cmp = simple_cst_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
5282 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
5283 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
5284 than U, respectively. */
5287 compare_tree_int (const_tree t, unsigned HOST_WIDE_INT u)
5289 if (tree_int_cst_sgn (t) < 0)
5291 else if (TREE_INT_CST_HIGH (t) != 0)
5293 else if (TREE_INT_CST_LOW (t) == u)
5295 else if (TREE_INT_CST_LOW (t) < u)
5301 /* Return true if CODE represents an associative tree code. Otherwise
5304 associative_tree_code (enum tree_code code)
5323 /* Return true if CODE represents a commutative tree code. Otherwise
5326 commutative_tree_code (enum tree_code code)
5339 case UNORDERED_EXPR:
5343 case TRUTH_AND_EXPR:
5344 case TRUTH_XOR_EXPR:
5354 /* Generate a hash value for an expression. This can be used iteratively
5355 by passing a previous result as the "val" argument.
5357 This function is intended to produce the same hash for expressions which
5358 would compare equal using operand_equal_p. */
5361 iterative_hash_expr (const_tree t, hashval_t val)
5364 enum tree_code code;
5368 return iterative_hash_pointer (t, val);
5370 code = TREE_CODE (t);
5374 /* Alas, constants aren't shared, so we can't rely on pointer
5377 val = iterative_hash_host_wide_int (TREE_INT_CST_LOW (t), val);
5378 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t), val);
5381 unsigned int val2 = real_hash (TREE_REAL_CST_PTR (t));
5383 return iterative_hash_hashval_t (val2, val);
5387 unsigned int val2 = fixed_hash (TREE_FIXED_CST_PTR (t));
5389 return iterative_hash_hashval_t (val2, val);
5392 return iterative_hash (TREE_STRING_POINTER (t),
5393 TREE_STRING_LENGTH (t), val);
5395 val = iterative_hash_expr (TREE_REALPART (t), val);
5396 return iterative_hash_expr (TREE_IMAGPART (t), val);
5398 return iterative_hash_expr (TREE_VECTOR_CST_ELTS (t), val);
5401 /* we can just compare by pointer. */
5402 return iterative_hash_pointer (t, val);
5405 /* A list of expressions, for a CALL_EXPR or as the elements of a
5407 for (; t; t = TREE_CHAIN (t))
5408 val = iterative_hash_expr (TREE_VALUE (t), val);
5412 unsigned HOST_WIDE_INT idx;
5414 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), idx, field, value)
5416 val = iterative_hash_expr (field, val);
5417 val = iterative_hash_expr (value, val);
5422 /* When referring to a built-in FUNCTION_DECL, use the
5423 __builtin__ form. Otherwise nodes that compare equal
5424 according to operand_equal_p might get different
5426 if (DECL_BUILT_IN (t))
5428 val = iterative_hash_pointer (built_in_decls[DECL_FUNCTION_CODE (t)],
5432 /* else FALL THROUGH */
5434 class = TREE_CODE_CLASS (code);
5436 if (class == tcc_declaration)
5438 /* DECL's have a unique ID */
5439 val = iterative_hash_host_wide_int (DECL_UID (t), val);
5443 gcc_assert (IS_EXPR_CODE_CLASS (class));
5445 val = iterative_hash_object (code, val);
5447 /* Don't hash the type, that can lead to having nodes which
5448 compare equal according to operand_equal_p, but which
5449 have different hash codes. */
5450 if (code == NOP_EXPR
5451 || code == CONVERT_EXPR
5452 || code == NON_LVALUE_EXPR)
5454 /* Make sure to include signness in the hash computation. */
5455 val += TYPE_UNSIGNED (TREE_TYPE (t));
5456 val = iterative_hash_expr (TREE_OPERAND (t, 0), val);
5459 else if (commutative_tree_code (code))
5461 /* It's a commutative expression. We want to hash it the same
5462 however it appears. We do this by first hashing both operands
5463 and then rehashing based on the order of their independent
5465 hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
5466 hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
5470 t = one, one = two, two = t;
5472 val = iterative_hash_hashval_t (one, val);
5473 val = iterative_hash_hashval_t (two, val);
5476 for (i = TREE_OPERAND_LENGTH (t) - 1; i >= 0; --i)
5477 val = iterative_hash_expr (TREE_OPERAND (t, i), val);
5484 /* Constructors for pointer, array and function types.
5485 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
5486 constructed by language-dependent code, not here.) */
5488 /* Construct, lay out and return the type of pointers to TO_TYPE with
5489 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
5490 reference all of memory. If such a type has already been
5491 constructed, reuse it. */
5494 build_pointer_type_for_mode (tree to_type, enum machine_mode mode,
5499 if (to_type == error_mark_node)
5500 return error_mark_node;
5502 /* If the pointed-to type has the may_alias attribute set, force
5503 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
5504 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
5505 can_alias_all = true;
5507 /* In some cases, languages will have things that aren't a POINTER_TYPE
5508 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
5509 In that case, return that type without regard to the rest of our
5512 ??? This is a kludge, but consistent with the way this function has
5513 always operated and there doesn't seem to be a good way to avoid this
5515 if (TYPE_POINTER_TO (to_type) != 0
5516 && TREE_CODE (TYPE_POINTER_TO (to_type)) != POINTER_TYPE)
5517 return TYPE_POINTER_TO (to_type);
5519 /* First, if we already have a type for pointers to TO_TYPE and it's
5520 the proper mode, use it. */
5521 for (t = TYPE_POINTER_TO (to_type); t; t = TYPE_NEXT_PTR_TO (t))
5522 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
5525 t = make_node (POINTER_TYPE);
5527 TREE_TYPE (t) = to_type;
5528 TYPE_MODE (t) = mode;
5529 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
5530 TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (to_type);
5531 TYPE_POINTER_TO (to_type) = t;
5533 if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
5534 SET_TYPE_STRUCTURAL_EQUALITY (t);
5535 else if (TYPE_CANONICAL (to_type) != to_type)
5537 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type),
5538 mode, can_alias_all);
5540 /* Lay out the type. This function has many callers that are concerned
5541 with expression-construction, and this simplifies them all. */
5547 /* By default build pointers in ptr_mode. */
5550 build_pointer_type (tree to_type)
5552 return build_pointer_type_for_mode (to_type, ptr_mode, false);
5555 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
5558 build_reference_type_for_mode (tree to_type, enum machine_mode mode,
5563 if (to_type == error_mark_node)
5564 return error_mark_node;
5566 /* If the pointed-to type has the may_alias attribute set, force
5567 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
5568 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type)))
5569 can_alias_all = true;
5571 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
5572 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
5573 In that case, return that type without regard to the rest of our
5576 ??? This is a kludge, but consistent with the way this function has
5577 always operated and there doesn't seem to be a good way to avoid this
5579 if (TYPE_REFERENCE_TO (to_type) != 0
5580 && TREE_CODE (TYPE_REFERENCE_TO (to_type)) != REFERENCE_TYPE)
5581 return TYPE_REFERENCE_TO (to_type);
5583 /* First, if we already have a type for pointers to TO_TYPE and it's
5584 the proper mode, use it. */
5585 for (t = TYPE_REFERENCE_TO (to_type); t; t = TYPE_NEXT_REF_TO (t))
5586 if (TYPE_MODE (t) == mode && TYPE_REF_CAN_ALIAS_ALL (t) == can_alias_all)
5589 t = make_node (REFERENCE_TYPE);
5591 TREE_TYPE (t) = to_type;
5592 TYPE_MODE (t) = mode;
5593 TYPE_REF_CAN_ALIAS_ALL (t) = can_alias_all;
5594 TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (to_type);
5595 TYPE_REFERENCE_TO (to_type) = t;
5597 if (TYPE_STRUCTURAL_EQUALITY_P (to_type))
5598 SET_TYPE_STRUCTURAL_EQUALITY (t);
5599 else if (TYPE_CANONICAL (to_type) != to_type)
5601 = build_reference_type_for_mode (TYPE_CANONICAL (to_type),
5602 mode, can_alias_all);
5610 /* Build the node for the type of references-to-TO_TYPE by default
5614 build_reference_type (tree to_type)
5616 return build_reference_type_for_mode (to_type, ptr_mode, false);
5619 /* Build a type that is compatible with t but has no cv quals anywhere
5622 const char *const *const * -> char ***. */
5625 build_type_no_quals (tree t)
5627 switch (TREE_CODE (t))
5630 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
5632 TYPE_REF_CAN_ALIAS_ALL (t));
5633 case REFERENCE_TYPE:
5635 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t)),
5637 TYPE_REF_CAN_ALIAS_ALL (t));
5639 return TYPE_MAIN_VARIANT (t);
5643 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
5644 MAXVAL should be the maximum value in the domain
5645 (one less than the length of the array).
5647 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
5648 We don't enforce this limit, that is up to caller (e.g. language front end).
5649 The limit exists because the result is a signed type and we don't handle
5650 sizes that use more than one HOST_WIDE_INT. */
5653 build_index_type (tree maxval)
5655 tree itype = make_node (INTEGER_TYPE);
5657 TREE_TYPE (itype) = sizetype;
5658 TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
5659 TYPE_MIN_VALUE (itype) = size_zero_node;
5660 TYPE_MAX_VALUE (itype) = fold_convert (sizetype, maxval);
5661 TYPE_MODE (itype) = TYPE_MODE (sizetype);
5662 TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
5663 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
5664 TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
5665 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
5667 if (host_integerp (maxval, 1))
5668 return type_hash_canon (tree_low_cst (maxval, 1), itype);
5671 /* Since we cannot hash this type, we need to compare it using
5672 structural equality checks. */
5673 SET_TYPE_STRUCTURAL_EQUALITY (itype);
5678 /* Builds a signed or unsigned integer type of precision PRECISION.
5679 Used for C bitfields whose precision does not match that of
5680 built-in target types. */
5682 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision,
5685 tree itype = make_node (INTEGER_TYPE);
5687 TYPE_PRECISION (itype) = precision;
5690 fixup_unsigned_type (itype);
5692 fixup_signed_type (itype);
5694 if (host_integerp (TYPE_MAX_VALUE (itype), 1))
5695 return type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype), 1), itype);
5700 /* Create a range of some discrete type TYPE (an INTEGER_TYPE,
5701 ENUMERAL_TYPE or BOOLEAN_TYPE), with low bound LOWVAL and
5702 high bound HIGHVAL. If TYPE is NULL, sizetype is used. */
5705 build_range_type (tree type, tree lowval, tree highval)
5707 tree itype = make_node (INTEGER_TYPE);
5709 TREE_TYPE (itype) = type;
5710 if (type == NULL_TREE)
5713 TYPE_MIN_VALUE (itype) = fold_convert (type, lowval);
5714 TYPE_MAX_VALUE (itype) = highval ? fold_convert (type, highval) : NULL;
5716 TYPE_PRECISION (itype) = TYPE_PRECISION (type);
5717 TYPE_MODE (itype) = TYPE_MODE (type);
5718 TYPE_SIZE (itype) = TYPE_SIZE (type);
5719 TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (type);
5720 TYPE_ALIGN (itype) = TYPE_ALIGN (type);
5721 TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (type);
5723 if (host_integerp (lowval, 0) && highval != 0 && host_integerp (highval, 0))
5724 return type_hash_canon (tree_low_cst (highval, 0)
5725 - tree_low_cst (lowval, 0),
5731 /* Just like build_index_type, but takes lowval and highval instead
5732 of just highval (maxval). */
5735 build_index_2_type (tree lowval, tree highval)
5737 return build_range_type (sizetype, lowval, highval);
5740 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
5741 and number of elements specified by the range of values of INDEX_TYPE.
5742 If such a type has already been constructed, reuse it. */
5745 build_array_type (tree elt_type, tree index_type)
5748 hashval_t hashcode = 0;
5750 if (TREE_CODE (elt_type) == FUNCTION_TYPE)
5752 error ("arrays of functions are not meaningful");
5753 elt_type = integer_type_node;
5756 t = make_node (ARRAY_TYPE);
5757 TREE_TYPE (t) = elt_type;
5758 TYPE_DOMAIN (t) = index_type;
5760 if (index_type == 0)
5763 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
5764 t = type_hash_canon (hashcode, t);
5768 if (TYPE_CANONICAL (t) == t)
5770 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type))
5771 SET_TYPE_STRUCTURAL_EQUALITY (t);
5772 else if (TYPE_CANONICAL (elt_type) != elt_type)
5774 = build_array_type (TYPE_CANONICAL (elt_type), index_type);
5780 hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
5781 hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
5782 t = type_hash_canon (hashcode, t);
5784 if (!COMPLETE_TYPE_P (t))
5787 if (TYPE_CANONICAL (t) == t)
5789 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
5790 || TYPE_STRUCTURAL_EQUALITY_P (index_type))
5791 SET_TYPE_STRUCTURAL_EQUALITY (t);
5792 else if (TYPE_CANONICAL (elt_type) != elt_type
5793 || TYPE_CANONICAL (index_type) != index_type)
5795 = build_array_type (TYPE_CANONICAL (elt_type),
5796 TYPE_CANONICAL (index_type));
5802 /* Recursively examines the array elements of TYPE, until a non-array
5803 element type is found. */
5806 strip_array_types (tree type)
5808 while (TREE_CODE (type) == ARRAY_TYPE)
5809 type = TREE_TYPE (type);
5814 /* Computes the canonical argument types from the argument type list
5817 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
5818 on entry to this function, or if any of the ARGTYPES are
5821 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
5822 true on entry to this function, or if any of the ARGTYPES are
5825 Returns a canonical argument list, which may be ARGTYPES when the
5826 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
5827 true) or would not differ from ARGTYPES. */
5830 maybe_canonicalize_argtypes(tree argtypes,
5831 bool *any_structural_p,
5832 bool *any_noncanonical_p)
5835 bool any_noncanonical_argtypes_p = false;
5837 for (arg = argtypes; arg && !(*any_structural_p); arg = TREE_CHAIN (arg))
5839 if (!TREE_VALUE (arg) || TREE_VALUE (arg) == error_mark_node)
5840 /* Fail gracefully by stating that the type is structural. */
5841 *any_structural_p = true;
5842 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg)))
5843 *any_structural_p = true;
5844 else if (TYPE_CANONICAL (TREE_VALUE (arg)) != TREE_VALUE (arg)
5845 || TREE_PURPOSE (arg))
5846 /* If the argument has a default argument, we consider it
5847 non-canonical even though the type itself is canonical.
5848 That way, different variants of function and method types
5849 with default arguments will all point to the variant with
5850 no defaults as their canonical type. */
5851 any_noncanonical_argtypes_p = true;
5854 if (*any_structural_p)
5857 if (any_noncanonical_argtypes_p)
5859 /* Build the canonical list of argument types. */
5860 tree canon_argtypes = NULL_TREE;
5861 bool is_void = false;
5863 for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
5865 if (arg == void_list_node)
5868 canon_argtypes = tree_cons (NULL_TREE,
5869 TYPE_CANONICAL (TREE_VALUE (arg)),
5873 canon_argtypes = nreverse (canon_argtypes);
5875 canon_argtypes = chainon (canon_argtypes, void_list_node);
5877 /* There is a non-canonical type. */
5878 *any_noncanonical_p = true;
5879 return canon_argtypes;
5882 /* The canonical argument types are the same as ARGTYPES. */
5886 /* Construct, lay out and return
5887 the type of functions returning type VALUE_TYPE
5888 given arguments of types ARG_TYPES.
5889 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
5890 are data type nodes for the arguments of the function.
5891 If such a type has already been constructed, reuse it. */
5894 build_function_type (tree value_type, tree arg_types)
5897 hashval_t hashcode = 0;
5898 bool any_structural_p, any_noncanonical_p;
5899 tree canon_argtypes;
5901 if (TREE_CODE (value_type) == FUNCTION_TYPE)
5903 error ("function return type cannot be function");
5904 value_type = integer_type_node;
5907 /* Make a node of the sort we want. */
5908 t = make_node (FUNCTION_TYPE);
5909 TREE_TYPE (t) = value_type;
5910 TYPE_ARG_TYPES (t) = arg_types;
5912 /* If we already have such a type, use the old one. */
5913 hashcode = iterative_hash_object (TYPE_HASH (value_type), hashcode);
5914 hashcode = type_hash_list (arg_types, hashcode);
5915 t = type_hash_canon (hashcode, t);
5917 /* Set up the canonical type. */
5918 any_structural_p = TYPE_STRUCTURAL_EQUALITY_P (value_type);
5919 any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
5920 canon_argtypes = maybe_canonicalize_argtypes (arg_types,
5922 &any_noncanonical_p);
5923 if (any_structural_p)
5924 SET_TYPE_STRUCTURAL_EQUALITY (t);
5925 else if (any_noncanonical_p)
5926 TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
5929 if (!COMPLETE_TYPE_P (t))
5934 /* Build a function type. The RETURN_TYPE is the type returned by the
5935 function. If VAARGS is set, no void_type_node is appended to the
5936 the list. ARGP muse be alway be terminated be a NULL_TREE. */
5939 build_function_type_list_1 (bool vaargs, tree return_type, va_list argp)
5943 t = va_arg (argp, tree);
5944 for (args = NULL_TREE; t != NULL_TREE; t = va_arg (argp, tree))
5945 args = tree_cons (NULL_TREE, t, args);
5950 if (args != NULL_TREE)
5951 args = nreverse (args);
5952 gcc_assert (args != NULL_TREE && last != void_list_node);
5954 else if (args == NULL_TREE)
5955 args = void_list_node;
5959 args = nreverse (args);
5960 TREE_CHAIN (last) = void_list_node;
5962 args = build_function_type (return_type, args);
5967 /* Build a function type. The RETURN_TYPE is the type returned by the
5968 function. If additional arguments are provided, they are
5969 additional argument types. The list of argument types must always
5970 be terminated by NULL_TREE. */
5973 build_function_type_list (tree return_type, ...)
5978 va_start (p, return_type);
5979 args = build_function_type_list_1 (false, return_type, p);
5984 /* Build a variable argument function type. The RETURN_TYPE is the
5985 type returned by the function. If additional arguments are provided,
5986 they are additional argument types. The list of argument types must
5987 always be terminated by NULL_TREE. */
5990 build_varargs_function_type_list (tree return_type, ...)
5995 va_start (p, return_type);
5996 args = build_function_type_list_1 (true, return_type, p);
6002 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
6003 and ARGTYPES (a TREE_LIST) are the return type and arguments types
6004 for the method. An implicit additional parameter (of type
6005 pointer-to-BASETYPE) is added to the ARGTYPES. */
6008 build_method_type_directly (tree basetype,
6015 bool any_structural_p, any_noncanonical_p;
6016 tree canon_argtypes;
6018 /* Make a node of the sort we want. */
6019 t = make_node (METHOD_TYPE);
6021 TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
6022 TREE_TYPE (t) = rettype;
6023 ptype = build_pointer_type (basetype);
6025 /* The actual arglist for this function includes a "hidden" argument
6026 which is "this". Put it into the list of argument types. */
6027 argtypes = tree_cons (NULL_TREE, ptype, argtypes);
6028 TYPE_ARG_TYPES (t) = argtypes;
6030 /* If we already have such a type, use the old one. */
6031 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
6032 hashcode = iterative_hash_object (TYPE_HASH (rettype), hashcode);
6033 hashcode = type_hash_list (argtypes, hashcode);
6034 t = type_hash_canon (hashcode, t);
6036 /* Set up the canonical type. */
6038 = (TYPE_STRUCTURAL_EQUALITY_P (basetype)
6039 || TYPE_STRUCTURAL_EQUALITY_P (rettype));
6041 = (TYPE_CANONICAL (basetype) != basetype
6042 || TYPE_CANONICAL (rettype) != rettype);
6043 canon_argtypes = maybe_canonicalize_argtypes (TREE_CHAIN (argtypes),
6045 &any_noncanonical_p);
6046 if (any_structural_p)
6047 SET_TYPE_STRUCTURAL_EQUALITY (t);
6048 else if (any_noncanonical_p)
6050 = build_method_type_directly (TYPE_CANONICAL (basetype),
6051 TYPE_CANONICAL (rettype),
6053 if (!COMPLETE_TYPE_P (t))
6059 /* Construct, lay out and return the type of methods belonging to class
6060 BASETYPE and whose arguments and values are described by TYPE.
6061 If that type exists already, reuse it.
6062 TYPE must be a FUNCTION_TYPE node. */
6065 build_method_type (tree basetype, tree type)
6067 gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
6069 return build_method_type_directly (basetype,
6071 TYPE_ARG_TYPES (type));
6074 /* Construct, lay out and return the type of offsets to a value
6075 of type TYPE, within an object of type BASETYPE.
6076 If a suitable offset type exists already, reuse it. */
6079 build_offset_type (tree basetype, tree type)
6082 hashval_t hashcode = 0;
6084 /* Make a node of the sort we want. */
6085 t = make_node (OFFSET_TYPE);
6087 TYPE_OFFSET_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype);
6088 TREE_TYPE (t) = type;
6090 /* If we already have such a type, use the old one. */
6091 hashcode = iterative_hash_object (TYPE_HASH (basetype), hashcode);
6092 hashcode = iterative_hash_object (TYPE_HASH (type), hashcode);
6093 t = type_hash_canon (hashcode, t);
6095 if (!COMPLETE_TYPE_P (t))
6098 if (TYPE_CANONICAL (t) == t)
6100 if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
6101 || TYPE_STRUCTURAL_EQUALITY_P (type))
6102 SET_TYPE_STRUCTURAL_EQUALITY (t);
6103 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
6104 || TYPE_CANONICAL (type) != type)
6106 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
6107 TYPE_CANONICAL (type));
6113 /* Create a complex type whose components are COMPONENT_TYPE. */
6116 build_complex_type (tree component_type)
6121 /* Make a node of the sort we want. */
6122 t = make_node (COMPLEX_TYPE);
6124 TREE_TYPE (t) = TYPE_MAIN_VARIANT (component_type);
6126 /* If we already have such a type, use the old one. */
6127 hashcode = iterative_hash_object (TYPE_HASH (component_type), 0);
6128 t = type_hash_canon (hashcode, t);
6130 if (!COMPLETE_TYPE_P (t))
6133 if (TYPE_CANONICAL (t) == t)
6135 if (TYPE_STRUCTURAL_EQUALITY_P (component_type))
6136 SET_TYPE_STRUCTURAL_EQUALITY (t);
6137 else if (TYPE_CANONICAL (component_type) != component_type)
6139 = build_complex_type (TYPE_CANONICAL (component_type));
6142 /* We need to create a name, since complex is a fundamental type. */
6143 if (! TYPE_NAME (t))
6146 if (component_type == char_type_node)
6147 name = "complex char";
6148 else if (component_type == signed_char_type_node)
6149 name = "complex signed char";
6150 else if (component_type == unsigned_char_type_node)
6151 name = "complex unsigned char";
6152 else if (component_type == short_integer_type_node)
6153 name = "complex short int";
6154 else if (component_type == short_unsigned_type_node)
6155 name = "complex short unsigned int";
6156 else if (component_type == integer_type_node)
6157 name = "complex int";
6158 else if (component_type == unsigned_type_node)
6159 name = "complex unsigned int";
6160 else if (component_type == long_integer_type_node)
6161 name = "complex long int";
6162 else if (component_type == long_unsigned_type_node)
6163 name = "complex long unsigned int";
6164 else if (component_type == long_long_integer_type_node)
6165 name = "complex long long int";
6166 else if (component_type == long_long_unsigned_type_node)
6167 name = "complex long long unsigned int";
6172 TYPE_NAME (t) = build_decl (TYPE_DECL, get_identifier (name), t);
6175 return build_qualified_type (t, TYPE_QUALS (component_type));
6178 /* Return OP, stripped of any conversions to wider types as much as is safe.
6179 Converting the value back to OP's type makes a value equivalent to OP.
6181 If FOR_TYPE is nonzero, we return a value which, if converted to
6182 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
6184 OP must have integer, real or enumeral type. Pointers are not allowed!
6186 There are some cases where the obvious value we could return
6187 would regenerate to OP if converted to OP's type,
6188 but would not extend like OP to wider types.
6189 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
6190 For example, if OP is (unsigned short)(signed char)-1,
6191 we avoid returning (signed char)-1 if FOR_TYPE is int,
6192 even though extending that to an unsigned short would regenerate OP,
6193 since the result of extending (signed char)-1 to (int)
6194 is different from (int) OP. */
6197 get_unwidened (tree op, tree for_type)
6199 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
6200 tree type = TREE_TYPE (op);
6202 = TYPE_PRECISION (for_type != 0 ? for_type : type);
6204 = (for_type != 0 && for_type != type
6205 && final_prec > TYPE_PRECISION (type)
6206 && TYPE_UNSIGNED (type));
6209 while (CONVERT_EXPR_P (op))
6213 /* TYPE_PRECISION on vector types has different meaning
6214 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
6215 so avoid them here. */
6216 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op, 0))) == VECTOR_TYPE)
6219 bitschange = TYPE_PRECISION (TREE_TYPE (op))
6220 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0)));
6222 /* Truncations are many-one so cannot be removed.
6223 Unless we are later going to truncate down even farther. */
6225 && final_prec > TYPE_PRECISION (TREE_TYPE (op)))
6228 /* See what's inside this conversion. If we decide to strip it,
6230 op = TREE_OPERAND (op, 0);
6232 /* If we have not stripped any zero-extensions (uns is 0),
6233 we can strip any kind of extension.
6234 If we have previously stripped a zero-extension,
6235 only zero-extensions can safely be stripped.
6236 Any extension can be stripped if the bits it would produce
6237 are all going to be discarded later by truncating to FOR_TYPE. */
6241 if (! uns || final_prec <= TYPE_PRECISION (TREE_TYPE (op)))
6243 /* TYPE_UNSIGNED says whether this is a zero-extension.
6244 Let's avoid computing it if it does not affect WIN
6245 and if UNS will not be needed again. */
6247 || CONVERT_EXPR_P (op))
6248 && TYPE_UNSIGNED (TREE_TYPE (op)))
6259 /* Return OP or a simpler expression for a narrower value
6260 which can be sign-extended or zero-extended to give back OP.
6261 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
6262 or 0 if the value should be sign-extended. */
6265 get_narrower (tree op, int *unsignedp_ptr)
6270 bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
6272 while (TREE_CODE (op) == NOP_EXPR)
6275 = (TYPE_PRECISION (TREE_TYPE (op))
6276 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op, 0))));
6278 /* Truncations are many-one so cannot be removed. */
6282 /* See what's inside this conversion. If we decide to strip it,
6287 op = TREE_OPERAND (op, 0);
6288 /* An extension: the outermost one can be stripped,
6289 but remember whether it is zero or sign extension. */
6291 uns = TYPE_UNSIGNED (TREE_TYPE (op));
6292 /* Otherwise, if a sign extension has been stripped,
6293 only sign extensions can now be stripped;
6294 if a zero extension has been stripped, only zero-extensions. */
6295 else if (uns != TYPE_UNSIGNED (TREE_TYPE (op)))
6299 else /* bitschange == 0 */
6301 /* A change in nominal type can always be stripped, but we must
6302 preserve the unsignedness. */
6304 uns = TYPE_UNSIGNED (TREE_TYPE (op));
6306 op = TREE_OPERAND (op, 0);
6307 /* Keep trying to narrow, but don't assign op to win if it
6308 would turn an integral type into something else. */
6309 if (INTEGRAL_TYPE_P (TREE_TYPE (op)) != integral_p)
6316 if (TREE_CODE (op) == COMPONENT_REF
6317 /* Since type_for_size always gives an integer type. */
6318 && TREE_CODE (TREE_TYPE (op)) != REAL_TYPE
6319 && TREE_CODE (TREE_TYPE (op)) != FIXED_POINT_TYPE
6320 /* Ensure field is laid out already. */
6321 && DECL_SIZE (TREE_OPERAND (op, 1)) != 0
6322 && host_integerp (DECL_SIZE (TREE_OPERAND (op, 1)), 1))
6324 unsigned HOST_WIDE_INT innerprec
6325 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op, 1)), 1);
6326 int unsignedp = (DECL_UNSIGNED (TREE_OPERAND (op, 1))
6327 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op, 1))));
6328 tree type = lang_hooks.types.type_for_size (innerprec, unsignedp);
6330 /* We can get this structure field in a narrower type that fits it,
6331 but the resulting extension to its nominal type (a fullword type)
6332 must satisfy the same conditions as for other extensions.
6334 Do this only for fields that are aligned (not bit-fields),
6335 because when bit-field insns will be used there is no
6336 advantage in doing this. */
6338 if (innerprec < TYPE_PRECISION (TREE_TYPE (op))
6339 && ! DECL_BIT_FIELD (TREE_OPERAND (op, 1))
6340 && (first || uns == DECL_UNSIGNED (TREE_OPERAND (op, 1)))
6344 uns = DECL_UNSIGNED (TREE_OPERAND (op, 1));
6345 win = fold_convert (type, op);
6349 *unsignedp_ptr = uns;
6353 /* Nonzero if integer constant C has a value that is permissible
6354 for type TYPE (an INTEGER_TYPE). */
6357 int_fits_type_p (const_tree c, const_tree type)
6359 tree type_low_bound = TYPE_MIN_VALUE (type);
6360 tree type_high_bound = TYPE_MAX_VALUE (type);
6361 bool ok_for_low_bound, ok_for_high_bound;
6362 unsigned HOST_WIDE_INT low;
6365 /* If at least one bound of the type is a constant integer, we can check
6366 ourselves and maybe make a decision. If no such decision is possible, but
6367 this type is a subtype, try checking against that. Otherwise, use
6368 fit_double_type, which checks against the precision.
6370 Compute the status for each possibly constant bound, and return if we see
6371 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
6372 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
6373 for "constant known to fit". */
6375 /* Check if C >= type_low_bound. */
6376 if (type_low_bound && TREE_CODE (type_low_bound) == INTEGER_CST)
6378 if (tree_int_cst_lt (c, type_low_bound))
6380 ok_for_low_bound = true;
6383 ok_for_low_bound = false;
6385 /* Check if c <= type_high_bound. */
6386 if (type_high_bound && TREE_CODE (type_high_bound) == INTEGER_CST)
6388 if (tree_int_cst_lt (type_high_bound, c))
6390 ok_for_high_bound = true;
6393 ok_for_high_bound = false;
6395 /* If the constant fits both bounds, the result is known. */
6396 if (ok_for_low_bound && ok_for_high_bound)
6399 /* Perform some generic filtering which may allow making a decision
6400 even if the bounds are not constant. First, negative integers
6401 never fit in unsigned types, */
6402 if (TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0)
6405 /* Second, narrower types always fit in wider ones. */
6406 if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
6409 /* Third, unsigned integers with top bit set never fit signed types. */
6410 if (! TYPE_UNSIGNED (type)
6411 && TYPE_UNSIGNED (TREE_TYPE (c))
6412 && tree_int_cst_msb (c))
6415 /* If we haven't been able to decide at this point, there nothing more we
6416 can check ourselves here. Look at the base type if we have one and it
6417 has the same precision. */
6418 if (TREE_CODE (type) == INTEGER_TYPE
6419 && TREE_TYPE (type) != 0
6420 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (type)))
6421 return int_fits_type_p (c, TREE_TYPE (type));
6423 /* Or to fit_double_type, if nothing else. */
6424 low = TREE_INT_CST_LOW (c);
6425 high = TREE_INT_CST_HIGH (c);
6426 return !fit_double_type (low, high, &low, &high, type);
6429 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
6430 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
6431 represented (assuming two's-complement arithmetic) within the bit
6432 precision of the type are returned instead. */
6435 get_type_static_bounds (const_tree type, mpz_t min, mpz_t max)
6437 if (!POINTER_TYPE_P (type) && TYPE_MIN_VALUE (type)
6438 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
6439 mpz_set_double_int (min, tree_to_double_int (TYPE_MIN_VALUE (type)),
6440 TYPE_UNSIGNED (type));
6443 if (TYPE_UNSIGNED (type))
6444 mpz_set_ui (min, 0);
6448 mn = double_int_mask (TYPE_PRECISION (type) - 1);
6449 mn = double_int_sext (double_int_add (mn, double_int_one),
6450 TYPE_PRECISION (type));
6451 mpz_set_double_int (min, mn, false);
6455 if (!POINTER_TYPE_P (type) && TYPE_MAX_VALUE (type)
6456 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
6457 mpz_set_double_int (max, tree_to_double_int (TYPE_MAX_VALUE (type)),
6458 TYPE_UNSIGNED (type));
6461 if (TYPE_UNSIGNED (type))
6462 mpz_set_double_int (max, double_int_mask (TYPE_PRECISION (type)),
6465 mpz_set_double_int (max, double_int_mask (TYPE_PRECISION (type) - 1),
6470 /* auto_var_in_fn_p is called to determine whether VAR is an automatic
6471 variable defined in function FN. */
6474 auto_var_in_fn_p (const_tree var, const_tree fn)
6476 return (DECL_P (var) && DECL_CONTEXT (var) == fn
6477 && (((TREE_CODE (var) == VAR_DECL || TREE_CODE (var) == PARM_DECL)
6478 && ! TREE_STATIC (var))
6479 || TREE_CODE (var) == LABEL_DECL
6480 || TREE_CODE (var) == RESULT_DECL));
6483 /* Subprogram of following function. Called by walk_tree.
6485 Return *TP if it is an automatic variable or parameter of the
6486 function passed in as DATA. */
6489 find_var_from_fn (tree *tp, int *walk_subtrees, void *data)
6491 tree fn = (tree) data;
6496 else if (DECL_P (*tp)
6497 && auto_var_in_fn_p (*tp, fn))
6503 /* Returns true if T is, contains, or refers to a type with variable
6504 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
6505 arguments, but not the return type. If FN is nonzero, only return
6506 true if a modifier of the type or position of FN is a variable or
6507 parameter inside FN.
6509 This concept is more general than that of C99 'variably modified types':
6510 in C99, a struct type is never variably modified because a VLA may not
6511 appear as a structure member. However, in GNU C code like:
6513 struct S { int i[f()]; };
6515 is valid, and other languages may define similar constructs. */
6518 variably_modified_type_p (tree type, tree fn)
6522 /* Test if T is either variable (if FN is zero) or an expression containing
6523 a variable in FN. */
6524 #define RETURN_TRUE_IF_VAR(T) \
6525 do { tree _t = (T); \
6526 if (_t && _t != error_mark_node && TREE_CODE (_t) != INTEGER_CST \
6527 && (!fn || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
6528 return true; } while (0)
6530 if (type == error_mark_node)
6533 /* If TYPE itself has variable size, it is variably modified. */
6534 RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
6535 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
6537 switch (TREE_CODE (type))
6540 case REFERENCE_TYPE:
6542 if (variably_modified_type_p (TREE_TYPE (type), fn))
6548 /* If TYPE is a function type, it is variably modified if the
6549 return type is variably modified. */
6550 if (variably_modified_type_p (TREE_TYPE (type), fn))
6556 case FIXED_POINT_TYPE:
6559 /* Scalar types are variably modified if their end points
6561 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type));
6562 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type));
6567 case QUAL_UNION_TYPE:
6568 /* We can't see if any of the fields are variably-modified by the
6569 definition we normally use, since that would produce infinite
6570 recursion via pointers. */
6571 /* This is variably modified if some field's type is. */
6572 for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t))
6573 if (TREE_CODE (t) == FIELD_DECL)
6575 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t));
6576 RETURN_TRUE_IF_VAR (DECL_SIZE (t));
6577 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t));
6579 if (TREE_CODE (type) == QUAL_UNION_TYPE)
6580 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t));
6585 /* Do not call ourselves to avoid infinite recursion. This is
6586 variably modified if the element type is. */
6587 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
6588 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
6595 /* The current language may have other cases to check, but in general,
6596 all other types are not variably modified. */
6597 return lang_hooks.tree_inlining.var_mod_type_p (type, fn);
6599 #undef RETURN_TRUE_IF_VAR
6602 /* Given a DECL or TYPE, return the scope in which it was declared, or
6603 NULL_TREE if there is no containing scope. */
6606 get_containing_scope (const_tree t)
6608 return (TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t));
6611 /* Return the innermost context enclosing DECL that is
6612 a FUNCTION_DECL, or zero if none. */
6615 decl_function_context (const_tree decl)
6619 if (TREE_CODE (decl) == ERROR_MARK)
6622 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
6623 where we look up the function at runtime. Such functions always take
6624 a first argument of type 'pointer to real context'.
6626 C++ should really be fixed to use DECL_CONTEXT for the real context,
6627 and use something else for the "virtual context". */
6628 else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VINDEX (decl))
6631 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
6633 context = DECL_CONTEXT (decl);
6635 while (context && TREE_CODE (context) != FUNCTION_DECL)
6637 if (TREE_CODE (context) == BLOCK)
6638 context = BLOCK_SUPERCONTEXT (context);
6640 context = get_containing_scope (context);
6646 /* Return the innermost context enclosing DECL that is
6647 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
6648 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
6651 decl_type_context (const_tree decl)
6653 tree context = DECL_CONTEXT (decl);
6656 switch (TREE_CODE (context))
6658 case NAMESPACE_DECL:
6659 case TRANSLATION_UNIT_DECL:
6664 case QUAL_UNION_TYPE:
6669 context = DECL_CONTEXT (context);
6673 context = BLOCK_SUPERCONTEXT (context);
6683 /* CALL is a CALL_EXPR. Return the declaration for the function
6684 called, or NULL_TREE if the called function cannot be
6688 get_callee_fndecl (const_tree call)
6692 if (call == error_mark_node)
6693 return error_mark_node;
6695 /* It's invalid to call this function with anything but a
6697 gcc_assert (TREE_CODE (call) == CALL_EXPR);
6699 /* The first operand to the CALL is the address of the function
6701 addr = CALL_EXPR_FN (call);
6705 /* If this is a readonly function pointer, extract its initial value. */
6706 if (DECL_P (addr) && TREE_CODE (addr) != FUNCTION_DECL
6707 && TREE_READONLY (addr) && ! TREE_THIS_VOLATILE (addr)
6708 && DECL_INITIAL (addr))
6709 addr = DECL_INITIAL (addr);
6711 /* If the address is just `&f' for some function `f', then we know
6712 that `f' is being called. */
6713 if (TREE_CODE (addr) == ADDR_EXPR
6714 && TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL)
6715 return TREE_OPERAND (addr, 0);
6717 /* We couldn't figure out what was being called. Maybe the front
6718 end has some idea. */
6719 return lang_hooks.lang_get_callee_fndecl (call);
6722 /* Print debugging information about tree nodes generated during the compile,
6723 and any language-specific information. */
6726 dump_tree_statistics (void)
6728 #ifdef GATHER_STATISTICS
6730 int total_nodes, total_bytes;
6733 fprintf (stderr, "\n??? tree nodes created\n\n");
6734 #ifdef GATHER_STATISTICS
6735 fprintf (stderr, "Kind Nodes Bytes\n");
6736 fprintf (stderr, "---------------------------------------\n");
6737 total_nodes = total_bytes = 0;
6738 for (i = 0; i < (int) all_kinds; i++)
6740 fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
6741 tree_node_counts[i], tree_node_sizes[i]);
6742 total_nodes += tree_node_counts[i];
6743 total_bytes += tree_node_sizes[i];
6745 fprintf (stderr, "---------------------------------------\n");
6746 fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
6747 fprintf (stderr, "---------------------------------------\n");
6748 ssanames_print_statistics ();
6749 phinodes_print_statistics ();
6751 fprintf (stderr, "(No per-node statistics)\n");
6753 print_type_hash_statistics ();
6754 print_debug_expr_statistics ();
6755 print_value_expr_statistics ();
6756 print_restrict_base_statistics ();
6757 lang_hooks.print_statistics ();
6760 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
6762 /* Generate a crc32 of a string. */
6765 crc32_string (unsigned chksum, const char *string)
6769 unsigned value = *string << 24;
6772 for (ix = 8; ix--; value <<= 1)
6776 feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
6785 /* P is a string that will be used in a symbol. Mask out any characters
6786 that are not valid in that context. */
6789 clean_symbol_name (char *p)
6793 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
6796 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
6803 /* Generate a name for a special-purpose function function.
6804 The generated name may need to be unique across the whole link.
6805 TYPE is some string to identify the purpose of this function to the
6806 linker or collect2; it must start with an uppercase letter,
6808 I - for constructors
6810 N - for C++ anonymous namespaces
6811 F - for DWARF unwind frame information. */
6814 get_file_function_name (const char *type)
6820 /* If we already have a name we know to be unique, just use that. */
6821 if (first_global_object_name)
6822 p = first_global_object_name;
6823 /* If the target is handling the constructors/destructors, they
6824 will be local to this file and the name is only necessary for
6825 debugging purposes. */
6826 else if ((type[0] == 'I' || type[0] == 'D') && targetm.have_ctors_dtors)
6828 const char *file = main_input_filename;
6830 file = input_filename;
6831 /* Just use the file's basename, because the full pathname
6832 might be quite long. */
6833 p = strrchr (file, '/');
6838 p = q = ASTRDUP (p);
6839 clean_symbol_name (q);
6843 /* Otherwise, the name must be unique across the entire link.
6844 We don't have anything that we know to be unique to this translation
6845 unit, so use what we do have and throw in some randomness. */
6847 const char *name = weak_global_object_name;
6848 const char *file = main_input_filename;
6853 file = input_filename;
6855 len = strlen (file);
6856 q = (char *) alloca (9 * 2 + len + 1);
6857 memcpy (q, file, len + 1);
6858 clean_symbol_name (q);
6860 sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
6861 crc32_string (0, get_random_seed (false)));
6866 buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
6869 /* Set up the name of the file-level functions we may need.
6870 Use a global object (which is already required to be unique over
6871 the program) rather than the file name (which imposes extra
6873 sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
6875 return get_identifier (buf);
6878 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
6880 /* Complain that the tree code of NODE does not match the expected 0
6881 terminated list of trailing codes. The trailing code list can be
6882 empty, for a more vague error message. FILE, LINE, and FUNCTION
6883 are of the caller. */
6886 tree_check_failed (const_tree node, const char *file,
6887 int line, const char *function, ...)
6891 unsigned length = 0;
6894 va_start (args, function);
6895 while ((code = va_arg (args, int)))
6896 length += 4 + strlen (tree_code_name[code]);
6901 va_start (args, function);
6902 length += strlen ("expected ");
6903 buffer = tmp = (char *) alloca (length);
6905 while ((code = va_arg (args, int)))
6907 const char *prefix = length ? " or " : "expected ";
6909 strcpy (tmp + length, prefix);
6910 length += strlen (prefix);
6911 strcpy (tmp + length, tree_code_name[code]);
6912 length += strlen (tree_code_name[code]);
6917 buffer = "unexpected node";
6919 internal_error ("tree check: %s, have %s in %s, at %s:%d",
6920 buffer, tree_code_name[TREE_CODE (node)],
6921 function, trim_filename (file), line);
6924 /* Complain that the tree code of NODE does match the expected 0
6925 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
6929 tree_not_check_failed (const_tree node, const char *file,
6930 int line, const char *function, ...)
6934 unsigned length = 0;
6937 va_start (args, function);
6938 while ((code = va_arg (args, int)))
6939 length += 4 + strlen (tree_code_name[code]);
6941 va_start (args, function);
6942 buffer = (char *) alloca (length);
6944 while ((code = va_arg (args, int)))
6948 strcpy (buffer + length, " or ");
6951 strcpy (buffer + length, tree_code_name[code]);
6952 length += strlen (tree_code_name[code]);
6956 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
6957 buffer, tree_code_name[TREE_CODE (node)],
6958 function, trim_filename (file), line);
6961 /* Similar to tree_check_failed, except that we check for a class of tree
6962 code, given in CL. */
6965 tree_class_check_failed (const_tree node, const enum tree_code_class cl,
6966 const char *file, int line, const char *function)
6969 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
6970 TREE_CODE_CLASS_STRING (cl),
6971 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
6972 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
6975 /* Similar to tree_check_failed, except that instead of specifying a
6976 dozen codes, use the knowledge that they're all sequential. */
6979 tree_range_check_failed (const_tree node, const char *file, int line,
6980 const char *function, enum tree_code c1,
6984 unsigned length = 0;
6987 for (c = c1; c <= c2; ++c)
6988 length += 4 + strlen (tree_code_name[c]);
6990 length += strlen ("expected ");
6991 buffer = (char *) alloca (length);
6994 for (c = c1; c <= c2; ++c)
6996 const char *prefix = length ? " or " : "expected ";
6998 strcpy (buffer + length, prefix);
6999 length += strlen (prefix);
7000 strcpy (buffer + length, tree_code_name[c]);
7001 length += strlen (tree_code_name[c]);
7004 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7005 buffer, tree_code_name[TREE_CODE (node)],
7006 function, trim_filename (file), line);
7010 /* Similar to tree_check_failed, except that we check that a tree does
7011 not have the specified code, given in CL. */
7014 tree_not_class_check_failed (const_tree node, const enum tree_code_class cl,
7015 const char *file, int line, const char *function)
7018 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
7019 TREE_CODE_CLASS_STRING (cl),
7020 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
7021 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
7025 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
7028 omp_clause_check_failed (const_tree node, const char *file, int line,
7029 const char *function, enum omp_clause_code code)
7031 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
7032 omp_clause_code_name[code], tree_code_name[TREE_CODE (node)],
7033 function, trim_filename (file), line);
7037 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
7040 omp_clause_range_check_failed (const_tree node, const char *file, int line,
7041 const char *function, enum omp_clause_code c1,
7042 enum omp_clause_code c2)
7045 unsigned length = 0;
7046 enum omp_clause_code c;
7048 for (c = c1; c <= c2; ++c)
7049 length += 4 + strlen (omp_clause_code_name[c]);
7051 length += strlen ("expected ");
7052 buffer = (char *) alloca (length);
7055 for (c = c1; c <= c2; ++c)
7057 const char *prefix = length ? " or " : "expected ";
7059 strcpy (buffer + length, prefix);
7060 length += strlen (prefix);
7061 strcpy (buffer + length, omp_clause_code_name[c]);
7062 length += strlen (omp_clause_code_name[c]);
7065 internal_error ("tree check: %s, have %s in %s, at %s:%d",
7066 buffer, omp_clause_code_name[TREE_CODE (node)],
7067 function, trim_filename (file), line);
7071 #undef DEFTREESTRUCT
7072 #define DEFTREESTRUCT(VAL, NAME) NAME,
7074 static const char *ts_enum_names[] = {
7075 #include "treestruct.def"
7077 #undef DEFTREESTRUCT
7079 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
7081 /* Similar to tree_class_check_failed, except that we check for
7082 whether CODE contains the tree structure identified by EN. */
7085 tree_contains_struct_check_failed (const_tree node,
7086 const enum tree_node_structure_enum en,
7087 const char *file, int line,
7088 const char *function)
7091 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
7093 tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
7097 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
7098 (dynamically sized) vector. */
7101 tree_vec_elt_check_failed (int idx, int len, const char *file, int line,
7102 const char *function)
7105 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
7106 idx + 1, len, function, trim_filename (file), line);
7109 /* Similar to above, except that the check is for the bounds of a PHI_NODE's
7110 (dynamically sized) vector. */
7113 phi_node_elt_check_failed (int idx, int len, const char *file, int line,
7114 const char *function)
7117 ("tree check: accessed elt %d of phi_node with %d elts in %s, at %s:%d",
7118 idx + 1, len, function, trim_filename (file), line);
7121 /* Similar to above, except that the check is for the bounds of the operand
7122 vector of an expression node EXP. */
7125 tree_operand_check_failed (int idx, const_tree exp, const char *file,
7126 int line, const char *function)
7128 int code = TREE_CODE (exp);
7130 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
7131 idx + 1, tree_code_name[code], TREE_OPERAND_LENGTH (exp),
7132 function, trim_filename (file), line);
7135 /* Similar to above, except that the check is for the number of
7136 operands of an OMP_CLAUSE node. */
7139 omp_clause_operand_check_failed (int idx, const_tree t, const char *file,
7140 int line, const char *function)
7143 ("tree check: accessed operand %d of omp_clause %s with %d operands "
7144 "in %s, at %s:%d", idx + 1, omp_clause_code_name[OMP_CLAUSE_CODE (t)],
7145 omp_clause_num_ops [OMP_CLAUSE_CODE (t)], function,
7146 trim_filename (file), line);
7148 #endif /* ENABLE_TREE_CHECKING */
7150 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
7151 and mapped to the machine mode MODE. Initialize its fields and build
7152 the information necessary for debugging output. */
7155 make_vector_type (tree innertype, int nunits, enum machine_mode mode)
7158 hashval_t hashcode = 0;
7160 /* Build a main variant, based on the main variant of the inner type, then
7161 use it to build the variant we return. */
7162 if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
7163 && TYPE_MAIN_VARIANT (innertype) != innertype)
7164 return build_type_attribute_qual_variant (
7165 make_vector_type (TYPE_MAIN_VARIANT (innertype), nunits, mode),
7166 TYPE_ATTRIBUTES (innertype),
7167 TYPE_QUALS (innertype));
7169 t = make_node (VECTOR_TYPE);
7170 TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype);
7171 SET_TYPE_VECTOR_SUBPARTS (t, nunits);
7172 TYPE_MODE (t) = mode;
7173 TYPE_READONLY (t) = TYPE_READONLY (innertype);
7174 TYPE_VOLATILE (t) = TYPE_VOLATILE (innertype);
7176 if (TYPE_STRUCTURAL_EQUALITY_P (innertype))
7177 SET_TYPE_STRUCTURAL_EQUALITY (t);
7178 else if (TYPE_CANONICAL (innertype) != innertype
7179 || mode != VOIDmode)
7181 = make_vector_type (TYPE_CANONICAL (innertype), nunits, VOIDmode);
7186 tree index = build_int_cst (NULL_TREE, nunits - 1);
7187 tree array = build_array_type (innertype, build_index_type (index));
7188 tree rt = make_node (RECORD_TYPE);
7190 TYPE_FIELDS (rt) = build_decl (FIELD_DECL, get_identifier ("f"), array);
7191 DECL_CONTEXT (TYPE_FIELDS (rt)) = rt;
7193 TYPE_DEBUG_REPRESENTATION_TYPE (t) = rt;
7194 /* In dwarfout.c, type lookup uses TYPE_UID numbers. We want to output
7195 the representation type, and we want to find that die when looking up
7196 the vector type. This is most easily achieved by making the TYPE_UID
7198 TYPE_UID (rt) = TYPE_UID (t);
7201 hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode);
7202 hashcode = iterative_hash_host_wide_int (mode, hashcode);
7203 hashcode = iterative_hash_object (TYPE_HASH (innertype), hashcode);
7204 return type_hash_canon (hashcode, t);
7208 make_or_reuse_type (unsigned size, int unsignedp)
7210 if (size == INT_TYPE_SIZE)
7211 return unsignedp ? unsigned_type_node : integer_type_node;
7212 if (size == CHAR_TYPE_SIZE)
7213 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
7214 if (size == SHORT_TYPE_SIZE)
7215 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
7216 if (size == LONG_TYPE_SIZE)
7217 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
7218 if (size == LONG_LONG_TYPE_SIZE)
7219 return (unsignedp ? long_long_unsigned_type_node
7220 : long_long_integer_type_node);
7223 return make_unsigned_type (size);
7225 return make_signed_type (size);
7228 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
7231 make_or_reuse_fract_type (unsigned size, int unsignedp, int satp)
7235 if (size == SHORT_FRACT_TYPE_SIZE)
7236 return unsignedp ? sat_unsigned_short_fract_type_node
7237 : sat_short_fract_type_node;
7238 if (size == FRACT_TYPE_SIZE)
7239 return unsignedp ? sat_unsigned_fract_type_node : sat_fract_type_node;
7240 if (size == LONG_FRACT_TYPE_SIZE)
7241 return unsignedp ? sat_unsigned_long_fract_type_node
7242 : sat_long_fract_type_node;
7243 if (size == LONG_LONG_FRACT_TYPE_SIZE)
7244 return unsignedp ? sat_unsigned_long_long_fract_type_node
7245 : sat_long_long_fract_type_node;
7249 if (size == SHORT_FRACT_TYPE_SIZE)
7250 return unsignedp ? unsigned_short_fract_type_node
7251 : short_fract_type_node;
7252 if (size == FRACT_TYPE_SIZE)
7253 return unsignedp ? unsigned_fract_type_node : fract_type_node;
7254 if (size == LONG_FRACT_TYPE_SIZE)
7255 return unsignedp ? unsigned_long_fract_type_node
7256 : long_fract_type_node;
7257 if (size == LONG_LONG_FRACT_TYPE_SIZE)
7258 return unsignedp ? unsigned_long_long_fract_type_node
7259 : long_long_fract_type_node;
7262 return make_fract_type (size, unsignedp, satp);
7265 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
7268 make_or_reuse_accum_type (unsigned size, int unsignedp, int satp)
7272 if (size == SHORT_ACCUM_TYPE_SIZE)
7273 return unsignedp ? sat_unsigned_short_accum_type_node
7274 : sat_short_accum_type_node;
7275 if (size == ACCUM_TYPE_SIZE)
7276 return unsignedp ? sat_unsigned_accum_type_node : sat_accum_type_node;
7277 if (size == LONG_ACCUM_TYPE_SIZE)
7278 return unsignedp ? sat_unsigned_long_accum_type_node
7279 : sat_long_accum_type_node;
7280 if (size == LONG_LONG_ACCUM_TYPE_SIZE)
7281 return unsignedp ? sat_unsigned_long_long_accum_type_node
7282 : sat_long_long_accum_type_node;
7286 if (size == SHORT_ACCUM_TYPE_SIZE)
7287 return unsignedp ? unsigned_short_accum_type_node
7288 : short_accum_type_node;
7289 if (size == ACCUM_TYPE_SIZE)
7290 return unsignedp ? unsigned_accum_type_node : accum_type_node;
7291 if (size == LONG_ACCUM_TYPE_SIZE)
7292 return unsignedp ? unsigned_long_accum_type_node
7293 : long_accum_type_node;
7294 if (size == LONG_LONG_ACCUM_TYPE_SIZE)
7295 return unsignedp ? unsigned_long_long_accum_type_node
7296 : long_long_accum_type_node;
7299 return make_accum_type (size, unsignedp, satp);
7302 /* Create nodes for all integer types (and error_mark_node) using the sizes
7303 of C datatypes. The caller should call set_sizetype soon after calling
7304 this function to select one of the types as sizetype. */
7307 build_common_tree_nodes (bool signed_char, bool signed_sizetype)
7309 error_mark_node = make_node (ERROR_MARK);
7310 TREE_TYPE (error_mark_node) = error_mark_node;
7312 initialize_sizetypes (signed_sizetype);
7314 /* Define both `signed char' and `unsigned char'. */
7315 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
7316 TYPE_STRING_FLAG (signed_char_type_node) = 1;
7317 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
7318 TYPE_STRING_FLAG (unsigned_char_type_node) = 1;
7320 /* Define `char', which is like either `signed char' or `unsigned char'
7321 but not the same as either. */
7324 ? make_signed_type (CHAR_TYPE_SIZE)
7325 : make_unsigned_type (CHAR_TYPE_SIZE));
7326 TYPE_STRING_FLAG (char_type_node) = 1;
7328 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
7329 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
7330 integer_type_node = make_signed_type (INT_TYPE_SIZE);
7331 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
7332 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
7333 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
7334 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
7335 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
7337 /* Define a boolean type. This type only represents boolean values but
7338 may be larger than char depending on the value of BOOL_TYPE_SIZE.
7339 Front ends which want to override this size (i.e. Java) can redefine
7340 boolean_type_node before calling build_common_tree_nodes_2. */
7341 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
7342 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
7343 TYPE_MAX_VALUE (boolean_type_node) = build_int_cst (boolean_type_node, 1);
7344 TYPE_PRECISION (boolean_type_node) = 1;
7346 /* Fill in the rest of the sized types. Reuse existing type nodes
7348 intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 0);
7349 intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 0);
7350 intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 0);
7351 intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 0);
7352 intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 0);
7354 unsigned_intQI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (QImode), 1);
7355 unsigned_intHI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (HImode), 1);
7356 unsigned_intSI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (SImode), 1);
7357 unsigned_intDI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (DImode), 1);
7358 unsigned_intTI_type_node = make_or_reuse_type (GET_MODE_BITSIZE (TImode), 1);
7360 access_public_node = get_identifier ("public");
7361 access_protected_node = get_identifier ("protected");
7362 access_private_node = get_identifier ("private");
7365 /* Call this function after calling build_common_tree_nodes and set_sizetype.
7366 It will create several other common tree nodes. */
7369 build_common_tree_nodes_2 (int short_double)
7371 /* Define these next since types below may used them. */
7372 integer_zero_node = build_int_cst (NULL_TREE, 0);
7373 integer_one_node = build_int_cst (NULL_TREE, 1);
7374 integer_minus_one_node = build_int_cst (NULL_TREE, -1);
7376 size_zero_node = size_int (0);
7377 size_one_node = size_int (1);
7378 bitsize_zero_node = bitsize_int (0);
7379 bitsize_one_node = bitsize_int (1);
7380 bitsize_unit_node = bitsize_int (BITS_PER_UNIT);
7382 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
7383 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
7385 void_type_node = make_node (VOID_TYPE);
7386 layout_type (void_type_node);
7388 /* We are not going to have real types in C with less than byte alignment,
7389 so we might as well not have any types that claim to have it. */
7390 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
7391 TYPE_USER_ALIGN (void_type_node) = 0;
7393 null_pointer_node = build_int_cst (build_pointer_type (void_type_node), 0);
7394 layout_type (TREE_TYPE (null_pointer_node));
7396 ptr_type_node = build_pointer_type (void_type_node);
7398 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
7399 fileptr_type_node = ptr_type_node;
7401 float_type_node = make_node (REAL_TYPE);
7402 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
7403 layout_type (float_type_node);
7405 double_type_node = make_node (REAL_TYPE);
7407 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
7409 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
7410 layout_type (double_type_node);
7412 long_double_type_node = make_node (REAL_TYPE);
7413 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
7414 layout_type (long_double_type_node);
7416 float_ptr_type_node = build_pointer_type (float_type_node);
7417 double_ptr_type_node = build_pointer_type (double_type_node);
7418 long_double_ptr_type_node = build_pointer_type (long_double_type_node);
7419 integer_ptr_type_node = build_pointer_type (integer_type_node);
7421 /* Fixed size integer types. */
7422 uint32_type_node = build_nonstandard_integer_type (32, true);
7423 uint64_type_node = build_nonstandard_integer_type (64, true);
7425 /* Decimal float types. */
7426 dfloat32_type_node = make_node (REAL_TYPE);
7427 TYPE_PRECISION (dfloat32_type_node) = DECIMAL32_TYPE_SIZE;
7428 layout_type (dfloat32_type_node);
7429 TYPE_MODE (dfloat32_type_node) = SDmode;
7430 dfloat32_ptr_type_node = build_pointer_type (dfloat32_type_node);
7432 dfloat64_type_node = make_node (REAL_TYPE);
7433 TYPE_PRECISION (dfloat64_type_node) = DECIMAL64_TYPE_SIZE;
7434 layout_type (dfloat64_type_node);
7435 TYPE_MODE (dfloat64_type_node) = DDmode;
7436 dfloat64_ptr_type_node = build_pointer_type (dfloat64_type_node);
7438 dfloat128_type_node = make_node (REAL_TYPE);
7439 TYPE_PRECISION (dfloat128_type_node) = DECIMAL128_TYPE_SIZE;
7440 layout_type (dfloat128_type_node);
7441 TYPE_MODE (dfloat128_type_node) = TDmode;
7442 dfloat128_ptr_type_node = build_pointer_type (dfloat128_type_node);
7444 complex_integer_type_node = build_complex_type (integer_type_node);
7445 complex_float_type_node = build_complex_type (float_type_node);
7446 complex_double_type_node = build_complex_type (double_type_node);
7447 complex_long_double_type_node = build_complex_type (long_double_type_node);
7449 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
7450 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
7451 sat_ ## KIND ## _type_node = \
7452 make_sat_signed_ ## KIND ## _type (SIZE); \
7453 sat_unsigned_ ## KIND ## _type_node = \
7454 make_sat_unsigned_ ## KIND ## _type (SIZE); \
7455 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
7456 unsigned_ ## KIND ## _type_node = \
7457 make_unsigned_ ## KIND ## _type (SIZE);
7459 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
7460 sat_ ## WIDTH ## KIND ## _type_node = \
7461 make_sat_signed_ ## KIND ## _type (SIZE); \
7462 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
7463 make_sat_unsigned_ ## KIND ## _type (SIZE); \
7464 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
7465 unsigned_ ## WIDTH ## KIND ## _type_node = \
7466 make_unsigned_ ## KIND ## _type (SIZE);
7468 /* Make fixed-point type nodes based on four different widths. */
7469 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
7470 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
7471 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
7472 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
7473 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
7475 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
7476 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
7477 NAME ## _type_node = \
7478 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
7479 u ## NAME ## _type_node = \
7480 make_or_reuse_unsigned_ ## KIND ## _type \
7481 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
7482 sat_ ## NAME ## _type_node = \
7483 make_or_reuse_sat_signed_ ## KIND ## _type \
7484 (GET_MODE_BITSIZE (MODE ## mode)); \
7485 sat_u ## NAME ## _type_node = \
7486 make_or_reuse_sat_unsigned_ ## KIND ## _type \
7487 (GET_MODE_BITSIZE (U ## MODE ## mode));
7489 /* Fixed-point type and mode nodes. */
7490 MAKE_FIXED_TYPE_NODE_FAMILY (fract, FRACT)
7491 MAKE_FIXED_TYPE_NODE_FAMILY (accum, ACCUM)
7492 MAKE_FIXED_MODE_NODE (fract, qq, QQ)
7493 MAKE_FIXED_MODE_NODE (fract, hq, HQ)
7494 MAKE_FIXED_MODE_NODE (fract, sq, SQ)
7495 MAKE_FIXED_MODE_NODE (fract, dq, DQ)
7496 MAKE_FIXED_MODE_NODE (fract, tq, TQ)
7497 MAKE_FIXED_MODE_NODE (accum, ha, HA)
7498 MAKE_FIXED_MODE_NODE (accum, sa, SA)
7499 MAKE_FIXED_MODE_NODE (accum, da, DA)
7500 MAKE_FIXED_MODE_NODE (accum, ta, TA)
7503 tree t = targetm.build_builtin_va_list ();
7505 /* Many back-ends define record types without setting TYPE_NAME.
7506 If we copied the record type here, we'd keep the original
7507 record type without a name. This breaks name mangling. So,
7508 don't copy record types and let c_common_nodes_and_builtins()
7509 declare the type to be __builtin_va_list. */
7510 if (TREE_CODE (t) != RECORD_TYPE)
7511 t = build_variant_type_copy (t);
7513 va_list_type_node = t;
7517 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
7520 local_define_builtin (const char *name, tree type, enum built_in_function code,
7521 const char *library_name, int ecf_flags)
7525 decl = add_builtin_function (name, type, code, BUILT_IN_NORMAL,
7526 library_name, NULL_TREE);
7527 if (ecf_flags & ECF_CONST)
7528 TREE_READONLY (decl) = 1;
7529 if (ecf_flags & ECF_PURE)
7530 DECL_PURE_P (decl) = 1;
7531 if (ecf_flags & ECF_LOOPING_CONST_OR_PURE)
7532 DECL_LOOPING_CONST_OR_PURE_P (decl) = 1;
7533 if (ecf_flags & ECF_NORETURN)
7534 TREE_THIS_VOLATILE (decl) = 1;
7535 if (ecf_flags & ECF_NOTHROW)
7536 TREE_NOTHROW (decl) = 1;
7537 if (ecf_flags & ECF_MALLOC)
7538 DECL_IS_MALLOC (decl) = 1;
7540 built_in_decls[code] = decl;
7541 implicit_built_in_decls[code] = decl;
7544 /* Call this function after instantiating all builtins that the language
7545 front end cares about. This will build the rest of the builtins that
7546 are relied upon by the tree optimizers and the middle-end. */
7549 build_common_builtin_nodes (void)
7553 if (built_in_decls[BUILT_IN_MEMCPY] == NULL
7554 || built_in_decls[BUILT_IN_MEMMOVE] == NULL)
7556 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
7557 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
7558 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7559 ftype = build_function_type (ptr_type_node, tmp);
7561 if (built_in_decls[BUILT_IN_MEMCPY] == NULL)
7562 local_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
7563 "memcpy", ECF_NOTHROW);
7564 if (built_in_decls[BUILT_IN_MEMMOVE] == NULL)
7565 local_define_builtin ("__builtin_memmove", ftype, BUILT_IN_MEMMOVE,
7566 "memmove", ECF_NOTHROW);
7569 if (built_in_decls[BUILT_IN_MEMCMP] == NULL)
7571 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
7572 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
7573 tmp = tree_cons (NULL_TREE, const_ptr_type_node, tmp);
7574 ftype = build_function_type (integer_type_node, tmp);
7575 local_define_builtin ("__builtin_memcmp", ftype, BUILT_IN_MEMCMP,
7576 "memcmp", ECF_PURE | ECF_NOTHROW);
7579 if (built_in_decls[BUILT_IN_MEMSET] == NULL)
7581 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
7582 tmp = tree_cons (NULL_TREE, integer_type_node, tmp);
7583 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7584 ftype = build_function_type (ptr_type_node, tmp);
7585 local_define_builtin ("__builtin_memset", ftype, BUILT_IN_MEMSET,
7586 "memset", ECF_NOTHROW);
7589 if (built_in_decls[BUILT_IN_ALLOCA] == NULL)
7591 tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
7592 ftype = build_function_type (ptr_type_node, tmp);
7593 local_define_builtin ("__builtin_alloca", ftype, BUILT_IN_ALLOCA,
7594 "alloca", ECF_NOTHROW | ECF_MALLOC);
7597 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7598 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7599 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7600 ftype = build_function_type (void_type_node, tmp);
7601 local_define_builtin ("__builtin_init_trampoline", ftype,
7602 BUILT_IN_INIT_TRAMPOLINE,
7603 "__builtin_init_trampoline", ECF_NOTHROW);
7605 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7606 ftype = build_function_type (ptr_type_node, tmp);
7607 local_define_builtin ("__builtin_adjust_trampoline", ftype,
7608 BUILT_IN_ADJUST_TRAMPOLINE,
7609 "__builtin_adjust_trampoline",
7610 ECF_CONST | ECF_NOTHROW);
7612 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7613 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7614 ftype = build_function_type (void_type_node, tmp);
7615 local_define_builtin ("__builtin_nonlocal_goto", ftype,
7616 BUILT_IN_NONLOCAL_GOTO,
7617 "__builtin_nonlocal_goto",
7618 ECF_NORETURN | ECF_NOTHROW);
7620 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7621 tmp = tree_cons (NULL_TREE, ptr_type_node, tmp);
7622 ftype = build_function_type (void_type_node, tmp);
7623 local_define_builtin ("__builtin_setjmp_setup", ftype,
7624 BUILT_IN_SETJMP_SETUP,
7625 "__builtin_setjmp_setup", ECF_NOTHROW);
7627 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7628 ftype = build_function_type (ptr_type_node, tmp);
7629 local_define_builtin ("__builtin_setjmp_dispatcher", ftype,
7630 BUILT_IN_SETJMP_DISPATCHER,
7631 "__builtin_setjmp_dispatcher",
7632 ECF_PURE | ECF_NOTHROW);
7634 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7635 ftype = build_function_type (void_type_node, tmp);
7636 local_define_builtin ("__builtin_setjmp_receiver", ftype,
7637 BUILT_IN_SETJMP_RECEIVER,
7638 "__builtin_setjmp_receiver", ECF_NOTHROW);
7640 ftype = build_function_type (ptr_type_node, void_list_node);
7641 local_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
7642 "__builtin_stack_save", ECF_NOTHROW);
7644 tmp = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
7645 ftype = build_function_type (void_type_node, tmp);
7646 local_define_builtin ("__builtin_stack_restore", ftype,
7647 BUILT_IN_STACK_RESTORE,
7648 "__builtin_stack_restore", ECF_NOTHROW);
7650 ftype = build_function_type (void_type_node, void_list_node);
7651 local_define_builtin ("__builtin_profile_func_enter", ftype,
7652 BUILT_IN_PROFILE_FUNC_ENTER, "profile_func_enter", 0);
7653 local_define_builtin ("__builtin_profile_func_exit", ftype,
7654 BUILT_IN_PROFILE_FUNC_EXIT, "profile_func_exit", 0);
7656 /* Complex multiplication and division. These are handled as builtins
7657 rather than optabs because emit_library_call_value doesn't support
7658 complex. Further, we can do slightly better with folding these
7659 beasties if the real and complex parts of the arguments are separate. */
7661 enum machine_mode mode;
7663 for (mode = MIN_MODE_COMPLEX_FLOAT; mode <= MAX_MODE_COMPLEX_FLOAT; ++mode)
7665 char mode_name_buf[4], *q;
7667 enum built_in_function mcode, dcode;
7668 tree type, inner_type;
7670 type = lang_hooks.types.type_for_mode (mode, 0);
7673 inner_type = TREE_TYPE (type);
7675 tmp = tree_cons (NULL_TREE, inner_type, void_list_node);
7676 tmp = tree_cons (NULL_TREE, inner_type, tmp);
7677 tmp = tree_cons (NULL_TREE, inner_type, tmp);
7678 tmp = tree_cons (NULL_TREE, inner_type, tmp);
7679 ftype = build_function_type (type, tmp);
7681 mcode = BUILT_IN_COMPLEX_MUL_MIN + mode - MIN_MODE_COMPLEX_FLOAT;
7682 dcode = BUILT_IN_COMPLEX_DIV_MIN + mode - MIN_MODE_COMPLEX_FLOAT;
7684 for (p = GET_MODE_NAME (mode), q = mode_name_buf; *p; p++, q++)
7688 built_in_names[mcode] = concat ("__mul", mode_name_buf, "3", NULL);
7689 local_define_builtin (built_in_names[mcode], ftype, mcode,
7690 built_in_names[mcode], ECF_CONST | ECF_NOTHROW);
7692 built_in_names[dcode] = concat ("__div", mode_name_buf, "3", NULL);
7693 local_define_builtin (built_in_names[dcode], ftype, dcode,
7694 built_in_names[dcode], ECF_CONST | ECF_NOTHROW);
7699 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
7702 If we requested a pointer to a vector, build up the pointers that
7703 we stripped off while looking for the inner type. Similarly for
7704 return values from functions.
7706 The argument TYPE is the top of the chain, and BOTTOM is the
7707 new type which we will point to. */
7710 reconstruct_complex_type (tree type, tree bottom)
7714 if (TREE_CODE (type) == POINTER_TYPE)
7716 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7717 outer = build_pointer_type_for_mode (inner, TYPE_MODE (type),
7718 TYPE_REF_CAN_ALIAS_ALL (type));
7720 else if (TREE_CODE (type) == REFERENCE_TYPE)
7722 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7723 outer = build_reference_type_for_mode (inner, TYPE_MODE (type),
7724 TYPE_REF_CAN_ALIAS_ALL (type));
7726 else if (TREE_CODE (type) == ARRAY_TYPE)
7728 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7729 outer = build_array_type (inner, TYPE_DOMAIN (type));
7731 else if (TREE_CODE (type) == FUNCTION_TYPE)
7733 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7734 outer = build_function_type (inner, TYPE_ARG_TYPES (type));
7736 else if (TREE_CODE (type) == METHOD_TYPE)
7738 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7739 /* The build_method_type_directly() routine prepends 'this' to argument list,
7740 so we must compensate by getting rid of it. */
7742 = build_method_type_directly
7743 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type))),
7745 TREE_CHAIN (TYPE_ARG_TYPES (type)));
7747 else if (TREE_CODE (type) == OFFSET_TYPE)
7749 inner = reconstruct_complex_type (TREE_TYPE (type), bottom);
7750 outer = build_offset_type (TYPE_OFFSET_BASETYPE (type), inner);
7755 return build_qualified_type (outer, TYPE_QUALS (type));
7758 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
7761 build_vector_type_for_mode (tree innertype, enum machine_mode mode)
7765 switch (GET_MODE_CLASS (mode))
7767 case MODE_VECTOR_INT:
7768 case MODE_VECTOR_FLOAT:
7769 case MODE_VECTOR_FRACT:
7770 case MODE_VECTOR_UFRACT:
7771 case MODE_VECTOR_ACCUM:
7772 case MODE_VECTOR_UACCUM:
7773 nunits = GET_MODE_NUNITS (mode);
7777 /* Check that there are no leftover bits. */
7778 gcc_assert (GET_MODE_BITSIZE (mode)
7779 % TREE_INT_CST_LOW (TYPE_SIZE (innertype)) == 0);
7781 nunits = GET_MODE_BITSIZE (mode)
7782 / TREE_INT_CST_LOW (TYPE_SIZE (innertype));
7789 return make_vector_type (innertype, nunits, mode);
7792 /* Similarly, but takes the inner type and number of units, which must be
7796 build_vector_type (tree innertype, int nunits)
7798 return make_vector_type (innertype, nunits, VOIDmode);
7802 /* Build RESX_EXPR with given REGION_NUMBER. */
7804 build_resx (int region_number)
7807 t = build1 (RESX_EXPR, void_type_node,
7808 build_int_cst (NULL_TREE, region_number));
7812 /* Given an initializer INIT, return TRUE if INIT is zero or some
7813 aggregate of zeros. Otherwise return FALSE. */
7815 initializer_zerop (const_tree init)
7821 switch (TREE_CODE (init))
7824 return integer_zerop (init);
7827 /* ??? Note that this is not correct for C4X float formats. There,
7828 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
7829 negative exponent. */
7830 return real_zerop (init)
7831 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init));
7834 return fixed_zerop (init);
7837 return integer_zerop (init)
7838 || (real_zerop (init)
7839 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init)))
7840 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init))));
7843 for (elt = TREE_VECTOR_CST_ELTS (init); elt; elt = TREE_CHAIN (elt))
7844 if (!initializer_zerop (TREE_VALUE (elt)))
7850 unsigned HOST_WIDE_INT idx;
7852 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
7853 if (!initializer_zerop (elt))
7863 /* Build an empty statement. */
7866 build_empty_stmt (void)
7868 return build1 (NOP_EXPR, void_type_node, size_zero_node);
7872 /* Build an OpenMP clause with code CODE. */
7875 build_omp_clause (enum omp_clause_code code)
7880 length = omp_clause_num_ops[code];
7881 size = (sizeof (struct tree_omp_clause) + (length - 1) * sizeof (tree));
7883 t = GGC_NEWVAR (union tree_node, size);
7884 memset (t, 0, size);
7885 TREE_SET_CODE (t, OMP_CLAUSE);
7886 OMP_CLAUSE_SET_CODE (t, code);
7888 #ifdef GATHER_STATISTICS
7889 tree_node_counts[(int) omp_clause_kind]++;
7890 tree_node_sizes[(int) omp_clause_kind] += size;
7896 /* Set various status flags when building a CALL_EXPR object T. */
7899 process_call_operands (tree t)
7903 side_effects = TREE_SIDE_EFFECTS (t);
7907 n = TREE_OPERAND_LENGTH (t);
7908 for (i = 1; i < n; i++)
7910 tree op = TREE_OPERAND (t, i);
7911 if (op && TREE_SIDE_EFFECTS (op))
7922 /* Calls have side-effects, except those to const or
7924 i = call_expr_flags (t);
7925 if ((i & ECF_LOOPING_CONST_OR_PURE) || !(i & (ECF_CONST | ECF_PURE)))
7928 TREE_SIDE_EFFECTS (t) = side_effects;
7931 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
7932 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
7933 Except for the CODE and operand count field, other storage for the
7934 object is initialized to zeros. */
7937 build_vl_exp_stat (enum tree_code code, int len MEM_STAT_DECL)
7940 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_exp);
7942 gcc_assert (TREE_CODE_CLASS (code) == tcc_vl_exp);
7943 gcc_assert (len >= 1);
7945 #ifdef GATHER_STATISTICS
7946 tree_node_counts[(int) e_kind]++;
7947 tree_node_sizes[(int) e_kind] += length;
7950 t = (tree) ggc_alloc_zone_pass_stat (length, &tree_zone);
7952 memset (t, 0, length);
7954 TREE_SET_CODE (t, code);
7956 /* Can't use TREE_OPERAND to store the length because if checking is
7957 enabled, it will try to check the length before we store it. :-P */
7958 t->exp.operands[0] = build_int_cst (sizetype, len);
7964 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE
7965 and FN and a null static chain slot. ARGLIST is a TREE_LIST of the
7969 build_call_list (tree return_type, tree fn, tree arglist)
7974 t = build_vl_exp (CALL_EXPR, list_length (arglist) + 3);
7975 TREE_TYPE (t) = return_type;
7976 CALL_EXPR_FN (t) = fn;
7977 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
7978 for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++)
7979 CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist);
7980 process_call_operands (t);
7984 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
7985 FN and a null static chain slot. NARGS is the number of call arguments
7986 which are specified as "..." arguments. */
7989 build_call_nary (tree return_type, tree fn, int nargs, ...)
7993 va_start (args, nargs);
7994 ret = build_call_valist (return_type, fn, nargs, args);
7999 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8000 FN and a null static chain slot. NARGS is the number of call arguments
8001 which are specified as a va_list ARGS. */
8004 build_call_valist (tree return_type, tree fn, int nargs, va_list args)
8009 t = build_vl_exp (CALL_EXPR, nargs + 3);
8010 TREE_TYPE (t) = return_type;
8011 CALL_EXPR_FN (t) = fn;
8012 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
8013 for (i = 0; i < nargs; i++)
8014 CALL_EXPR_ARG (t, i) = va_arg (args, tree);
8015 process_call_operands (t);
8019 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
8020 FN and a null static chain slot. NARGS is the number of call arguments
8021 which are specified as a tree array ARGS. */
8024 build_call_array (tree return_type, tree fn, int nargs, tree *args)
8029 t = build_vl_exp (CALL_EXPR, nargs + 3);
8030 TREE_TYPE (t) = return_type;
8031 CALL_EXPR_FN (t) = fn;
8032 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
8033 for (i = 0; i < nargs; i++)
8034 CALL_EXPR_ARG (t, i) = args[i];
8035 process_call_operands (t);
8040 /* Returns true if it is possible to prove that the index of
8041 an array access REF (an ARRAY_REF expression) falls into the
8045 in_array_bounds_p (tree ref)
8047 tree idx = TREE_OPERAND (ref, 1);
8050 if (TREE_CODE (idx) != INTEGER_CST)
8053 min = array_ref_low_bound (ref);
8054 max = array_ref_up_bound (ref);
8057 || TREE_CODE (min) != INTEGER_CST
8058 || TREE_CODE (max) != INTEGER_CST)
8061 if (tree_int_cst_lt (idx, min)
8062 || tree_int_cst_lt (max, idx))
8068 /* Returns true if it is possible to prove that the range of
8069 an array access REF (an ARRAY_RANGE_REF expression) falls
8070 into the array bounds. */
8073 range_in_array_bounds_p (tree ref)
8075 tree domain_type = TYPE_DOMAIN (TREE_TYPE (ref));
8076 tree range_min, range_max, min, max;
8078 range_min = TYPE_MIN_VALUE (domain_type);
8079 range_max = TYPE_MAX_VALUE (domain_type);
8082 || TREE_CODE (range_min) != INTEGER_CST
8083 || TREE_CODE (range_max) != INTEGER_CST)
8086 min = array_ref_low_bound (ref);
8087 max = array_ref_up_bound (ref);
8090 || TREE_CODE (min) != INTEGER_CST
8091 || TREE_CODE (max) != INTEGER_CST)
8094 if (tree_int_cst_lt (range_min, min)
8095 || tree_int_cst_lt (max, range_max))
8101 /* Return true if T (assumed to be a DECL) must be assigned a memory
8105 needs_to_live_in_memory (const_tree t)
8107 if (TREE_CODE (t) == SSA_NAME)
8108 t = SSA_NAME_VAR (t);
8110 return (TREE_ADDRESSABLE (t)
8111 || is_global_var (t)
8112 || (TREE_CODE (t) == RESULT_DECL
8113 && aggregate_value_p (t, current_function_decl)));
8116 /* There are situations in which a language considers record types
8117 compatible which have different field lists. Decide if two fields
8118 are compatible. It is assumed that the parent records are compatible. */
8121 fields_compatible_p (const_tree f1, const_tree f2)
8123 if (!operand_equal_p (DECL_FIELD_BIT_OFFSET (f1),
8124 DECL_FIELD_BIT_OFFSET (f2), OEP_ONLY_CONST))
8127 if (!operand_equal_p (DECL_FIELD_OFFSET (f1),
8128 DECL_FIELD_OFFSET (f2), OEP_ONLY_CONST))
8131 if (!types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2)))
8137 /* Locate within RECORD a field that is compatible with ORIG_FIELD. */
8140 find_compatible_field (tree record, tree orig_field)
8144 for (f = TYPE_FIELDS (record); f ; f = TREE_CHAIN (f))
8145 if (TREE_CODE (f) == FIELD_DECL
8146 && fields_compatible_p (f, orig_field))
8149 /* ??? Why isn't this on the main fields list? */
8150 f = TYPE_VFIELD (record);
8151 if (f && TREE_CODE (f) == FIELD_DECL
8152 && fields_compatible_p (f, orig_field))
8155 /* ??? We should abort here, but Java appears to do Bad Things
8156 with inherited fields. */
8160 /* Return value of a constant X and sign-extend it. */
8163 int_cst_value (const_tree x)
8165 unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
8166 unsigned HOST_WIDE_INT val = TREE_INT_CST_LOW (x);
8168 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
8169 gcc_assert (TREE_INT_CST_HIGH (x) == 0
8170 || TREE_INT_CST_HIGH (x) == -1);
8172 if (bits < HOST_BITS_PER_WIDE_INT)
8174 bool negative = ((val >> (bits - 1)) & 1) != 0;
8176 val |= (~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1;
8178 val &= ~((~(unsigned HOST_WIDE_INT) 0) << (bits - 1) << 1);
8184 /* If TYPE is an integral type, return an equivalent type which is
8185 unsigned iff UNSIGNEDP is true. If TYPE is not an integral type,
8186 return TYPE itself. */
8189 signed_or_unsigned_type_for (int unsignedp, tree type)
8192 if (POINTER_TYPE_P (type))
8195 if (!INTEGRAL_TYPE_P (t) || TYPE_UNSIGNED (t) == unsignedp)
8198 return lang_hooks.types.type_for_size (TYPE_PRECISION (t), unsignedp);
8201 /* Returns unsigned variant of TYPE. */
8204 unsigned_type_for (tree type)
8206 return signed_or_unsigned_type_for (1, type);
8209 /* Returns signed variant of TYPE. */
8212 signed_type_for (tree type)
8214 return signed_or_unsigned_type_for (0, type);
8217 /* Returns the largest value obtainable by casting something in INNER type to
8221 upper_bound_in_type (tree outer, tree inner)
8223 unsigned HOST_WIDE_INT lo, hi;
8224 unsigned int det = 0;
8225 unsigned oprec = TYPE_PRECISION (outer);
8226 unsigned iprec = TYPE_PRECISION (inner);
8229 /* Compute a unique number for every combination. */
8230 det |= (oprec > iprec) ? 4 : 0;
8231 det |= TYPE_UNSIGNED (outer) ? 2 : 0;
8232 det |= TYPE_UNSIGNED (inner) ? 1 : 0;
8234 /* Determine the exponent to use. */
8239 /* oprec <= iprec, outer: signed, inner: don't care. */
8244 /* oprec <= iprec, outer: unsigned, inner: don't care. */
8248 /* oprec > iprec, outer: signed, inner: signed. */
8252 /* oprec > iprec, outer: signed, inner: unsigned. */
8256 /* oprec > iprec, outer: unsigned, inner: signed. */
8260 /* oprec > iprec, outer: unsigned, inner: unsigned. */
8267 /* Compute 2^^prec - 1. */
8268 if (prec <= HOST_BITS_PER_WIDE_INT)
8271 lo = ((~(unsigned HOST_WIDE_INT) 0)
8272 >> (HOST_BITS_PER_WIDE_INT - prec));
8276 hi = ((~(unsigned HOST_WIDE_INT) 0)
8277 >> (2 * HOST_BITS_PER_WIDE_INT - prec));
8278 lo = ~(unsigned HOST_WIDE_INT) 0;
8281 return build_int_cst_wide (outer, lo, hi);
8284 /* Returns the smallest value obtainable by casting something in INNER type to
8288 lower_bound_in_type (tree outer, tree inner)
8290 unsigned HOST_WIDE_INT lo, hi;
8291 unsigned oprec = TYPE_PRECISION (outer);
8292 unsigned iprec = TYPE_PRECISION (inner);
8294 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
8296 if (TYPE_UNSIGNED (outer)
8297 /* If we are widening something of an unsigned type, OUTER type
8298 contains all values of INNER type. In particular, both INNER
8299 and OUTER types have zero in common. */
8300 || (oprec > iprec && TYPE_UNSIGNED (inner)))
8304 /* If we are widening a signed type to another signed type, we
8305 want to obtain -2^^(iprec-1). If we are keeping the
8306 precision or narrowing to a signed type, we want to obtain
8308 unsigned prec = oprec > iprec ? iprec : oprec;
8310 if (prec <= HOST_BITS_PER_WIDE_INT)
8312 hi = ~(unsigned HOST_WIDE_INT) 0;
8313 lo = (~(unsigned HOST_WIDE_INT) 0) << (prec - 1);
8317 hi = ((~(unsigned HOST_WIDE_INT) 0)
8318 << (prec - HOST_BITS_PER_WIDE_INT - 1));
8323 return build_int_cst_wide (outer, lo, hi);
8326 /* Return nonzero if two operands that are suitable for PHI nodes are
8327 necessarily equal. Specifically, both ARG0 and ARG1 must be either
8328 SSA_NAME or invariant. Note that this is strictly an optimization.
8329 That is, callers of this function can directly call operand_equal_p
8330 and get the same result, only slower. */
8333 operand_equal_for_phi_arg_p (const_tree arg0, const_tree arg1)
8337 if (TREE_CODE (arg0) == SSA_NAME || TREE_CODE (arg1) == SSA_NAME)
8339 return operand_equal_p (arg0, arg1, 0);
8342 /* Returns number of zeros at the end of binary representation of X.
8344 ??? Use ffs if available? */
8347 num_ending_zeros (const_tree x)
8349 unsigned HOST_WIDE_INT fr, nfr;
8350 unsigned num, abits;
8351 tree type = TREE_TYPE (x);
8353 if (TREE_INT_CST_LOW (x) == 0)
8355 num = HOST_BITS_PER_WIDE_INT;
8356 fr = TREE_INT_CST_HIGH (x);
8361 fr = TREE_INT_CST_LOW (x);
8364 for (abits = HOST_BITS_PER_WIDE_INT / 2; abits; abits /= 2)
8367 if (nfr << abits == fr)
8374 if (num > TYPE_PRECISION (type))
8375 num = TYPE_PRECISION (type);
8377 return build_int_cst_type (type, num);
8381 #define WALK_SUBTREE(NODE) \
8384 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
8390 /* This is a subroutine of walk_tree that walks field of TYPE that are to
8391 be walked whenever a type is seen in the tree. Rest of operands and return
8392 value are as for walk_tree. */
8395 walk_type_fields (tree type, walk_tree_fn func, void *data,
8396 struct pointer_set_t *pset, walk_tree_lh lh)
8398 tree result = NULL_TREE;
8400 switch (TREE_CODE (type))
8403 case REFERENCE_TYPE:
8404 /* We have to worry about mutually recursive pointers. These can't
8405 be written in C. They can in Ada. It's pathological, but
8406 there's an ACATS test (c38102a) that checks it. Deal with this
8407 by checking if we're pointing to another pointer, that one
8408 points to another pointer, that one does too, and we have no htab.
8409 If so, get a hash table. We check three levels deep to avoid
8410 the cost of the hash table if we don't need one. */
8411 if (POINTER_TYPE_P (TREE_TYPE (type))
8412 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type)))
8413 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type))))
8416 result = walk_tree_without_duplicates (&TREE_TYPE (type),
8424 /* ... fall through ... */
8427 WALK_SUBTREE (TREE_TYPE (type));
8431 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type));
8436 WALK_SUBTREE (TREE_TYPE (type));
8440 /* We never want to walk into default arguments. */
8441 for (arg = TYPE_ARG_TYPES (type); arg; arg = TREE_CHAIN (arg))
8442 WALK_SUBTREE (TREE_VALUE (arg));
8447 /* Don't follow this nodes's type if a pointer for fear that
8448 we'll have infinite recursion. If we have a PSET, then we
8451 || (!POINTER_TYPE_P (TREE_TYPE (type))
8452 && TREE_CODE (TREE_TYPE (type)) != OFFSET_TYPE))
8453 WALK_SUBTREE (TREE_TYPE (type));
8454 WALK_SUBTREE (TYPE_DOMAIN (type));
8458 WALK_SUBTREE (TREE_TYPE (type));
8459 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type));
8469 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
8470 called with the DATA and the address of each sub-tree. If FUNC returns a
8471 non-NULL value, the traversal is stopped, and the value returned by FUNC
8472 is returned. If PSET is non-NULL it is used to record the nodes visited,
8473 and to avoid visiting a node more than once. */
8476 walk_tree_1 (tree *tp, walk_tree_fn func, void *data,
8477 struct pointer_set_t *pset, walk_tree_lh lh)
8479 enum tree_code code;
8483 #define WALK_SUBTREE_TAIL(NODE) \
8487 goto tail_recurse; \
8492 /* Skip empty subtrees. */
8496 /* Don't walk the same tree twice, if the user has requested
8497 that we avoid doing so. */
8498 if (pset && pointer_set_insert (pset, *tp))
8501 /* Call the function. */
8503 result = (*func) (tp, &walk_subtrees, data);
8505 /* If we found something, return it. */
8509 code = TREE_CODE (*tp);
8511 /* Even if we didn't, FUNC may have decided that there was nothing
8512 interesting below this point in the tree. */
8515 /* But we still need to check our siblings. */
8516 if (code == TREE_LIST)
8517 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
8518 else if (code == OMP_CLAUSE)
8519 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
8526 result = (*lh) (tp, &walk_subtrees, func, data, pset);
8527 if (result || !walk_subtrees)
8534 case IDENTIFIER_NODE:
8541 case PLACEHOLDER_EXPR:
8545 /* None of these have subtrees other than those already walked
8550 WALK_SUBTREE (TREE_VALUE (*tp));
8551 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
8556 int len = TREE_VEC_LENGTH (*tp);
8561 /* Walk all elements but the first. */
8563 WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
8565 /* Now walk the first one as a tail call. */
8566 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0));
8570 WALK_SUBTREE (TREE_REALPART (*tp));
8571 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));
8575 unsigned HOST_WIDE_INT idx;
8576 constructor_elt *ce;
8579 VEC_iterate(constructor_elt, CONSTRUCTOR_ELTS (*tp), idx, ce);
8581 WALK_SUBTREE (ce->value);
8586 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, 0));
8591 for (decl = BIND_EXPR_VARS (*tp); decl; decl = TREE_CHAIN (decl))
8593 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
8594 into declarations that are just mentioned, rather than
8595 declared; they don't really belong to this part of the tree.
8596 And, we can see cycles: the initializer for a declaration
8597 can refer to the declaration itself. */
8598 WALK_SUBTREE (DECL_INITIAL (decl));
8599 WALK_SUBTREE (DECL_SIZE (decl));
8600 WALK_SUBTREE (DECL_SIZE_UNIT (decl));
8602 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp));
8605 case STATEMENT_LIST:
8607 tree_stmt_iterator i;
8608 for (i = tsi_start (*tp); !tsi_end_p (i); tsi_next (&i))
8609 WALK_SUBTREE (*tsi_stmt_ptr (i));
8614 switch (OMP_CLAUSE_CODE (*tp))
8616 case OMP_CLAUSE_PRIVATE:
8617 case OMP_CLAUSE_SHARED:
8618 case OMP_CLAUSE_FIRSTPRIVATE:
8619 case OMP_CLAUSE_COPYIN:
8620 case OMP_CLAUSE_COPYPRIVATE:
8622 case OMP_CLAUSE_NUM_THREADS:
8623 case OMP_CLAUSE_SCHEDULE:
8624 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, 0));
8627 case OMP_CLAUSE_NOWAIT:
8628 case OMP_CLAUSE_ORDERED:
8629 case OMP_CLAUSE_DEFAULT:
8630 case OMP_CLAUSE_UNTIED:
8631 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
8633 case OMP_CLAUSE_LASTPRIVATE:
8634 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp));
8635 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp));
8636 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
8638 case OMP_CLAUSE_COLLAPSE:
8641 for (i = 0; i < 3; i++)
8642 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i));
8643 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
8646 case OMP_CLAUSE_REDUCTION:
8649 for (i = 0; i < 4; i++)
8650 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp, i));
8651 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
8663 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
8664 But, we only want to walk once. */
8665 len = (TREE_OPERAND (*tp, 3) == TREE_OPERAND (*tp, 1)) ? 2 : 3;
8666 for (i = 0; i < len; ++i)
8667 WALK_SUBTREE (TREE_OPERAND (*tp, i));
8668 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp, len));
8672 /* If this is a TYPE_DECL, walk into the fields of the type that it's
8673 defining. We only want to walk into these fields of a type in this
8674 case and not in the general case of a mere reference to the type.
8676 The criterion is as follows: if the field can be an expression, it
8677 must be walked only here. This should be in keeping with the fields
8678 that are directly gimplified in gimplify_type_sizes in order for the
8679 mark/copy-if-shared/unmark machinery of the gimplifier to work with
8680 variable-sized types.
8682 Note that DECLs get walked as part of processing the BIND_EXPR. */
8683 if (TREE_CODE (DECL_EXPR_DECL (*tp)) == TYPE_DECL)
8685 tree *type_p = &TREE_TYPE (DECL_EXPR_DECL (*tp));
8686 if (TREE_CODE (*type_p) == ERROR_MARK)
8689 /* Call the function for the type. See if it returns anything or
8690 doesn't want us to continue. If we are to continue, walk both
8691 the normal fields and those for the declaration case. */
8692 result = (*func) (type_p, &walk_subtrees, data);
8693 if (result || !walk_subtrees)
8696 result = walk_type_fields (*type_p, func, data, pset, lh);
8700 /* If this is a record type, also walk the fields. */
8701 if (TREE_CODE (*type_p) == RECORD_TYPE
8702 || TREE_CODE (*type_p) == UNION_TYPE
8703 || TREE_CODE (*type_p) == QUAL_UNION_TYPE)
8707 for (field = TYPE_FIELDS (*type_p); field;
8708 field = TREE_CHAIN (field))
8710 /* We'd like to look at the type of the field, but we can
8711 easily get infinite recursion. So assume it's pointed
8712 to elsewhere in the tree. Also, ignore things that
8714 if (TREE_CODE (field) != FIELD_DECL)
8717 WALK_SUBTREE (DECL_FIELD_OFFSET (field));
8718 WALK_SUBTREE (DECL_SIZE (field));
8719 WALK_SUBTREE (DECL_SIZE_UNIT (field));
8720 if (TREE_CODE (*type_p) == QUAL_UNION_TYPE)
8721 WALK_SUBTREE (DECL_QUALIFIER (field));
8725 /* Same for scalar types. */
8726 else if (TREE_CODE (*type_p) == BOOLEAN_TYPE
8727 || TREE_CODE (*type_p) == ENUMERAL_TYPE
8728 || TREE_CODE (*type_p) == INTEGER_TYPE
8729 || TREE_CODE (*type_p) == FIXED_POINT_TYPE
8730 || TREE_CODE (*type_p) == REAL_TYPE)
8732 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p));
8733 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p));
8736 WALK_SUBTREE (TYPE_SIZE (*type_p));
8737 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p));
8742 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
8743 || IS_GIMPLE_STMT_CODE_CLASS (TREE_CODE_CLASS (code)))
8747 /* Walk over all the sub-trees of this operand. */
8748 len = TREE_OPERAND_LENGTH (*tp);
8750 /* Go through the subtrees. We need to do this in forward order so
8751 that the scope of a FOR_EXPR is handled properly. */
8754 for (i = 0; i < len - 1; ++i)
8755 WALK_SUBTREE (GENERIC_TREE_OPERAND (*tp, i));
8756 WALK_SUBTREE_TAIL (GENERIC_TREE_OPERAND (*tp, len - 1));
8759 /* If this is a type, walk the needed fields in the type. */
8760 else if (TYPE_P (*tp))
8761 return walk_type_fields (*tp, func, data, pset, lh);
8765 /* We didn't find what we were looking for. */
8768 #undef WALK_SUBTREE_TAIL
8772 /* Like walk_tree, but does not walk duplicate nodes more than once. */
8775 walk_tree_without_duplicates_1 (tree *tp, walk_tree_fn func, void *data,
8779 struct pointer_set_t *pset;
8781 pset = pointer_set_create ();
8782 result = walk_tree_1 (tp, func, data, pset, lh);
8783 pointer_set_destroy (pset);
8788 /* Return true if STMT is an empty statement or contains nothing but
8789 empty statements. */
8792 empty_body_p (tree stmt)
8794 tree_stmt_iterator i;
8797 if (IS_EMPTY_STMT (stmt))
8799 else if (TREE_CODE (stmt) == BIND_EXPR)
8800 body = BIND_EXPR_BODY (stmt);
8801 else if (TREE_CODE (stmt) == STATEMENT_LIST)
8806 for (i = tsi_start (body); !tsi_end_p (i); tsi_next (&i))
8807 if (!empty_body_p (tsi_stmt (i)))
8816 char const c = TREE_CODE_CLASS (TREE_CODE (t));
8818 if (IS_EXPR_CODE_CLASS (c))
8819 return &t->exp.block;
8820 else if (IS_GIMPLE_STMT_CODE_CLASS (c))
8821 return &GIMPLE_STMT_BLOCK (t);
8827 generic_tree_operand (tree node, int i)
8829 if (GIMPLE_STMT_P (node))
8830 return &GIMPLE_STMT_OPERAND (node, i);
8831 return &TREE_OPERAND (node, i);
8835 generic_tree_type (tree node)
8837 if (GIMPLE_STMT_P (node))
8838 return &void_type_node;
8839 return &TREE_TYPE (node);
8842 /* Build and return a TREE_LIST of arguments in the CALL_EXPR exp.
8843 FIXME: don't use this function. It exists for compatibility with
8844 the old representation of CALL_EXPRs where a list was used to hold the
8845 arguments. Places that currently extract the arglist from a CALL_EXPR
8846 ought to be rewritten to use the CALL_EXPR itself. */
8848 call_expr_arglist (tree exp)
8850 tree arglist = NULL_TREE;
8852 for (i = call_expr_nargs (exp) - 1; i >= 0; i--)
8853 arglist = tree_cons (NULL_TREE, CALL_EXPR_ARG (exp, i), arglist);
8857 /* Return true if TYPE has a variable argument list. */
8860 stdarg_p (tree fntype)
8862 function_args_iterator args_iter;
8863 tree n = NULL_TREE, t;
8868 FOREACH_FUNCTION_ARGS(fntype, t, args_iter)
8873 return n != NULL_TREE && n != void_type_node;
8876 /* Return true if TYPE has a prototype. */
8879 prototype_p (tree fntype)
8883 gcc_assert (fntype != NULL_TREE);
8885 t = TYPE_ARG_TYPES (fntype);
8886 return (t != NULL_TREE);
8889 /* Return the number of arguments that a function has. */
8892 function_args_count (tree fntype)
8894 function_args_iterator args_iter;
8900 FOREACH_FUNCTION_ARGS(fntype, t, args_iter)
8909 /* If BLOCK is inlined from an __attribute__((__artificial__))
8910 routine, return pointer to location from where it has been
8913 block_nonartificial_location (tree block)
8915 location_t *ret = NULL;
8917 while (block && TREE_CODE (block) == BLOCK
8918 && BLOCK_ABSTRACT_ORIGIN (block))
8920 tree ao = BLOCK_ABSTRACT_ORIGIN (block);
8922 while (TREE_CODE (ao) == BLOCK && BLOCK_ABSTRACT_ORIGIN (ao))
8923 ao = BLOCK_ABSTRACT_ORIGIN (ao);
8925 if (TREE_CODE (ao) == FUNCTION_DECL)
8927 /* If AO is an artificial inline, point RET to the
8928 call site locus at which it has been inlined and continue
8929 the loop, in case AO's caller is also an artificial
8931 if (DECL_DECLARED_INLINE_P (ao)
8932 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao)))
8933 ret = &BLOCK_SOURCE_LOCATION (block);
8937 else if (TREE_CODE (ao) != BLOCK)
8940 block = BLOCK_SUPERCONTEXT (block);
8945 #include "gt-tree.h"