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
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* This file contains the low level primitives for operating on tree nodes,
23 including allocation, list operations, interning of identifiers,
24 construction of data type nodes and statement nodes,
25 and construction of type conversion nodes. It also contains
26 tables index by tree code that describe how to take apart
29 It is intended to be language-independent, but occasionally
30 calls language-dependent routines defined (for C) in typecheck.c. */
34 #include "coretypes.h"
47 #include "langhooks.h"
48 #include "tree-iterator.h"
49 #include "basic-block.h"
50 #include "tree-flow.h"
52 #include "pointer-set.h"
53 #include "fixed-value.h"
55 /* Each tree code class has an associated string representation.
56 These must correspond to the tree_code_class entries. */
58 const char *const tree_code_class_strings[] =
74 /* obstack.[ch] explicitly declined to prototype this. */
75 extern int _obstack_allocated_p (struct obstack *h, void *obj);
77 #ifdef GATHER_STATISTICS
78 /* Statistics-gathering stuff. */
80 int tree_node_counts[(int) all_kinds];
81 int tree_node_sizes[(int) all_kinds];
83 /* Keep in sync with tree.h:enum tree_node_kind. */
84 static const char * const tree_node_kind_names[] = {
106 #endif /* GATHER_STATISTICS */
108 /* Unique id for next decl created. */
109 static GTY(()) int next_decl_uid;
110 /* Unique id for next type created. */
111 static GTY(()) int next_type_uid = 1;
113 /* Since we cannot rehash a type after it is in the table, we have to
114 keep the hash code. */
116 struct type_hash GTY(())
122 /* Initial size of the hash table (rounded to next prime). */
123 #define TYPE_HASH_INITIAL_SIZE 1000
125 /* Now here is the hash table. When recording a type, it is added to
126 the slot whose index is the hash code. Note that the hash table is
127 used for several kinds of types (function types, array types and
128 array index range types, for now). While all these live in the
129 same table, they are completely independent, and the hash code is
130 computed differently for each of these. */
132 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
133 htab_t type_hash_table;
135 /* Hash table and temporary node for larger integer const values. */
136 static GTY (()) tree int_cst_node;
137 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node)))
138 htab_t int_cst_hash_table;
140 /* General tree->tree mapping structure for use in hash tables. */
143 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
144 htab_t debug_expr_for_decl;
146 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
147 htab_t value_expr_for_decl;
149 static GTY ((if_marked ("tree_priority_map_marked_p"),
150 param_is (struct tree_priority_map)))
151 htab_t init_priority_for_decl;
153 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
154 htab_t restrict_base_for_decl;
156 static void set_type_quals (tree, int);
157 static int type_hash_eq (const void *, const void *);
158 static hashval_t type_hash_hash (const void *);
159 static hashval_t int_cst_hash_hash (const void *);
160 static int int_cst_hash_eq (const void *, const void *);
161 static void print_type_hash_statistics (void);
162 static void print_debug_expr_statistics (void);
163 static void print_value_expr_statistics (void);
164 static int type_hash_marked_p (const void *);
165 static unsigned int type_hash_list (const_tree, hashval_t);
166 static unsigned int attribute_hash_list (const_tree, hashval_t);
168 tree global_trees[TI_MAX];
169 tree integer_types[itk_none];
171 unsigned char tree_contains_struct[MAX_TREE_CODES][64];
173 /* Number of operands for each OpenMP clause. */
174 unsigned const char omp_clause_num_ops[] =
176 0, /* OMP_CLAUSE_ERROR */
177 1, /* OMP_CLAUSE_PRIVATE */
178 1, /* OMP_CLAUSE_SHARED */
179 1, /* OMP_CLAUSE_FIRSTPRIVATE */
180 1, /* OMP_CLAUSE_LASTPRIVATE */
181 4, /* OMP_CLAUSE_REDUCTION */
182 1, /* OMP_CLAUSE_COPYIN */
183 1, /* OMP_CLAUSE_COPYPRIVATE */
184 1, /* OMP_CLAUSE_IF */
185 1, /* OMP_CLAUSE_NUM_THREADS */
186 1, /* OMP_CLAUSE_SCHEDULE */
187 0, /* OMP_CLAUSE_NOWAIT */
188 0, /* OMP_CLAUSE_ORDERED */
189 0 /* OMP_CLAUSE_DEFAULT */
192 const char * const omp_clause_code_name[] =
215 /* Initialize the hash table of types. */
216 type_hash_table = htab_create_ggc (TYPE_HASH_INITIAL_SIZE, type_hash_hash,
219 debug_expr_for_decl = htab_create_ggc (512, tree_map_hash,
222 value_expr_for_decl = htab_create_ggc (512, tree_map_hash,
224 init_priority_for_decl = htab_create_ggc (512, tree_priority_map_hash,
225 tree_priority_map_eq, 0);
226 restrict_base_for_decl = htab_create_ggc (256, tree_map_hash,
229 int_cst_hash_table = htab_create_ggc (1024, int_cst_hash_hash,
230 int_cst_hash_eq, NULL);
232 int_cst_node = make_node (INTEGER_CST);
234 tree_contains_struct[FUNCTION_DECL][TS_DECL_NON_COMMON] = 1;
235 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_NON_COMMON] = 1;
236 tree_contains_struct[TYPE_DECL][TS_DECL_NON_COMMON] = 1;
239 tree_contains_struct[CONST_DECL][TS_DECL_COMMON] = 1;
240 tree_contains_struct[VAR_DECL][TS_DECL_COMMON] = 1;
241 tree_contains_struct[PARM_DECL][TS_DECL_COMMON] = 1;
242 tree_contains_struct[RESULT_DECL][TS_DECL_COMMON] = 1;
243 tree_contains_struct[FUNCTION_DECL][TS_DECL_COMMON] = 1;
244 tree_contains_struct[TYPE_DECL][TS_DECL_COMMON] = 1;
245 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_COMMON] = 1;
246 tree_contains_struct[LABEL_DECL][TS_DECL_COMMON] = 1;
247 tree_contains_struct[FIELD_DECL][TS_DECL_COMMON] = 1;
250 tree_contains_struct[CONST_DECL][TS_DECL_WRTL] = 1;
251 tree_contains_struct[VAR_DECL][TS_DECL_WRTL] = 1;
252 tree_contains_struct[PARM_DECL][TS_DECL_WRTL] = 1;
253 tree_contains_struct[RESULT_DECL][TS_DECL_WRTL] = 1;
254 tree_contains_struct[FUNCTION_DECL][TS_DECL_WRTL] = 1;
255 tree_contains_struct[LABEL_DECL][TS_DECL_WRTL] = 1;
257 tree_contains_struct[CONST_DECL][TS_DECL_MINIMAL] = 1;
258 tree_contains_struct[VAR_DECL][TS_DECL_MINIMAL] = 1;
259 tree_contains_struct[PARM_DECL][TS_DECL_MINIMAL] = 1;
260 tree_contains_struct[RESULT_DECL][TS_DECL_MINIMAL] = 1;
261 tree_contains_struct[FUNCTION_DECL][TS_DECL_MINIMAL] = 1;
262 tree_contains_struct[TYPE_DECL][TS_DECL_MINIMAL] = 1;
263 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_MINIMAL] = 1;
264 tree_contains_struct[LABEL_DECL][TS_DECL_MINIMAL] = 1;
265 tree_contains_struct[FIELD_DECL][TS_DECL_MINIMAL] = 1;
266 tree_contains_struct[STRUCT_FIELD_TAG][TS_DECL_MINIMAL] = 1;
267 tree_contains_struct[NAME_MEMORY_TAG][TS_DECL_MINIMAL] = 1;
268 tree_contains_struct[SYMBOL_MEMORY_TAG][TS_DECL_MINIMAL] = 1;
269 tree_contains_struct[MEMORY_PARTITION_TAG][TS_DECL_MINIMAL] = 1;
271 tree_contains_struct[STRUCT_FIELD_TAG][TS_MEMORY_TAG] = 1;
272 tree_contains_struct[NAME_MEMORY_TAG][TS_MEMORY_TAG] = 1;
273 tree_contains_struct[SYMBOL_MEMORY_TAG][TS_MEMORY_TAG] = 1;
274 tree_contains_struct[MEMORY_PARTITION_TAG][TS_MEMORY_TAG] = 1;
276 tree_contains_struct[STRUCT_FIELD_TAG][TS_STRUCT_FIELD_TAG] = 1;
277 tree_contains_struct[MEMORY_PARTITION_TAG][TS_MEMORY_PARTITION_TAG] = 1;
279 tree_contains_struct[VAR_DECL][TS_DECL_WITH_VIS] = 1;
280 tree_contains_struct[FUNCTION_DECL][TS_DECL_WITH_VIS] = 1;
281 tree_contains_struct[TYPE_DECL][TS_DECL_WITH_VIS] = 1;
282 tree_contains_struct[TRANSLATION_UNIT_DECL][TS_DECL_WITH_VIS] = 1;
284 tree_contains_struct[VAR_DECL][TS_VAR_DECL] = 1;
285 tree_contains_struct[FIELD_DECL][TS_FIELD_DECL] = 1;
286 tree_contains_struct[PARM_DECL][TS_PARM_DECL] = 1;
287 tree_contains_struct[LABEL_DECL][TS_LABEL_DECL] = 1;
288 tree_contains_struct[RESULT_DECL][TS_RESULT_DECL] = 1;
289 tree_contains_struct[CONST_DECL][TS_CONST_DECL] = 1;
290 tree_contains_struct[TYPE_DECL][TS_TYPE_DECL] = 1;
291 tree_contains_struct[FUNCTION_DECL][TS_FUNCTION_DECL] = 1;
293 lang_hooks.init_ts ();
297 /* The name of the object as the assembler will see it (but before any
298 translations made by ASM_OUTPUT_LABELREF). Often this is the same
299 as DECL_NAME. It is an IDENTIFIER_NODE. */
301 decl_assembler_name (tree decl)
303 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
304 lang_hooks.set_decl_assembler_name (decl);
305 return DECL_WITH_VIS_CHECK (decl)->decl_with_vis.assembler_name;
308 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
311 decl_assembler_name_equal (tree decl, tree asmname)
313 tree decl_asmname = DECL_ASSEMBLER_NAME (decl);
315 if (decl_asmname == asmname)
318 /* If the target assembler name was set by the user, things are trickier.
319 We have a leading '*' to begin with. After that, it's arguable what
320 is the correct thing to do with -fleading-underscore. Arguably, we've
321 historically been doing the wrong thing in assemble_alias by always
322 printing the leading underscore. Since we're not changing that, make
323 sure user_label_prefix follows the '*' before matching. */
324 if (IDENTIFIER_POINTER (decl_asmname)[0] == '*')
326 const char *decl_str = IDENTIFIER_POINTER (decl_asmname) + 1;
327 size_t ulp_len = strlen (user_label_prefix);
331 else if (strncmp (decl_str, user_label_prefix, ulp_len) == 0)
336 return strcmp (decl_str, IDENTIFIER_POINTER (asmname)) == 0;
342 /* Compute the number of bytes occupied by a tree with code CODE.
343 This function cannot be used for nodes that have variable sizes,
344 including TREE_VEC, PHI_NODE, STRING_CST, and CALL_EXPR. */
346 tree_code_size (enum tree_code code)
348 switch (TREE_CODE_CLASS (code))
350 case tcc_declaration: /* A decl node */
355 return sizeof (struct tree_field_decl);
357 return sizeof (struct tree_parm_decl);
359 return sizeof (struct tree_var_decl);
361 return sizeof (struct tree_label_decl);
363 return sizeof (struct tree_result_decl);
365 return sizeof (struct tree_const_decl);
367 return sizeof (struct tree_type_decl);
369 return sizeof (struct tree_function_decl);
370 case NAME_MEMORY_TAG:
371 case SYMBOL_MEMORY_TAG:
372 return sizeof (struct tree_memory_tag);
373 case STRUCT_FIELD_TAG:
374 return sizeof (struct tree_struct_field_tag);
375 case MEMORY_PARTITION_TAG:
376 return sizeof (struct tree_memory_partition_tag);
378 return sizeof (struct tree_decl_non_common);
382 case tcc_type: /* a type node */
383 return sizeof (struct tree_type);
385 case tcc_reference: /* a reference */
386 case tcc_expression: /* an expression */
387 case tcc_statement: /* an expression with side effects */
388 case tcc_comparison: /* a comparison expression */
389 case tcc_unary: /* a unary arithmetic expression */
390 case tcc_binary: /* a binary arithmetic expression */
391 return (sizeof (struct tree_exp)
392 + (TREE_CODE_LENGTH (code) - 1) * sizeof (tree));
394 case tcc_gimple_stmt:
395 return (sizeof (struct gimple_stmt)
396 + (TREE_CODE_LENGTH (code) - 1) * sizeof (char *));
398 case tcc_constant: /* a constant */
401 case INTEGER_CST: return sizeof (struct tree_int_cst);
402 case REAL_CST: return sizeof (struct tree_real_cst);
403 case FIXED_CST: return sizeof (struct tree_fixed_cst);
404 case COMPLEX_CST: return sizeof (struct tree_complex);
405 case VECTOR_CST: return sizeof (struct tree_vector);
406 case STRING_CST: gcc_unreachable ();
408 return lang_hooks.tree_size (code);
411 case tcc_exceptional: /* something random, like an identifier. */
414 case IDENTIFIER_NODE: return lang_hooks.identifier_size;
415 case TREE_LIST: return sizeof (struct tree_list);
418 case PLACEHOLDER_EXPR: return sizeof (struct tree_common);
422 case PHI_NODE: gcc_unreachable ();
424 case SSA_NAME: return sizeof (struct tree_ssa_name);
426 case STATEMENT_LIST: return sizeof (struct tree_statement_list);
427 case BLOCK: return sizeof (struct tree_block);
428 case VALUE_HANDLE: return sizeof (struct tree_value_handle);
429 case CONSTRUCTOR: return sizeof (struct tree_constructor);
432 return lang_hooks.tree_size (code);
440 /* Compute the number of bytes occupied by NODE. This routine only
441 looks at TREE_CODE, except for those nodes that have variable sizes. */
443 tree_size (const_tree node)
445 const enum tree_code code = TREE_CODE (node);
449 return (sizeof (struct tree_phi_node)
450 + (PHI_ARG_CAPACITY (node) - 1) * sizeof (struct phi_arg_d));
453 return (offsetof (struct tree_binfo, base_binfos)
454 + VEC_embedded_size (tree, BINFO_N_BASE_BINFOS (node)));
457 return (sizeof (struct tree_vec)
458 + (TREE_VEC_LENGTH (node) - 1) * sizeof (tree));
461 return TREE_STRING_LENGTH (node) + offsetof (struct tree_string, str) + 1;
464 return (sizeof (struct tree_omp_clause)
465 + (omp_clause_num_ops[OMP_CLAUSE_CODE (node)] - 1)
469 if (TREE_CODE_CLASS (code) == tcc_vl_exp)
470 return (sizeof (struct tree_exp)
471 + (VL_EXP_OPERAND_LENGTH (node) - 1) * sizeof (tree));
473 return tree_code_size (code);
477 /* Return a newly allocated node of code CODE. For decl and type
478 nodes, some other fields are initialized. The rest of the node is
479 initialized to zero. This function cannot be used for PHI_NODE,
480 TREE_VEC or OMP_CLAUSE nodes, which is enforced by asserts in
483 Achoo! I got a code in the node. */
486 make_node_stat (enum tree_code code MEM_STAT_DECL)
489 enum tree_code_class type = TREE_CODE_CLASS (code);
490 size_t length = tree_code_size (code);
491 #ifdef GATHER_STATISTICS
496 case tcc_declaration: /* A decl node */
500 case tcc_type: /* a type node */
504 case tcc_statement: /* an expression with side effects */
508 case tcc_reference: /* a reference */
512 case tcc_expression: /* an expression */
513 case tcc_comparison: /* a comparison expression */
514 case tcc_unary: /* a unary arithmetic expression */
515 case tcc_binary: /* a binary arithmetic expression */
519 case tcc_constant: /* a constant */
523 case tcc_gimple_stmt:
524 kind = gimple_stmt_kind;
527 case tcc_exceptional: /* something random, like an identifier. */
530 case IDENTIFIER_NODE:
547 kind = ssa_name_kind;
568 tree_node_counts[(int) kind]++;
569 tree_node_sizes[(int) kind] += length;
572 if (code == IDENTIFIER_NODE)
573 t = ggc_alloc_zone_pass_stat (length, &tree_id_zone);
575 t = ggc_alloc_zone_pass_stat (length, &tree_zone);
577 memset (t, 0, length);
579 TREE_SET_CODE (t, code);
584 TREE_SIDE_EFFECTS (t) = 1;
587 case tcc_declaration:
588 if (CODE_CONTAINS_STRUCT (code, TS_DECL_WITH_VIS))
589 DECL_IN_SYSTEM_HEADER (t) = in_system_header;
590 if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
592 if (code == FUNCTION_DECL)
594 DECL_ALIGN (t) = FUNCTION_BOUNDARY;
595 DECL_MODE (t) = FUNCTION_MODE;
599 /* We have not yet computed the alias set for this declaration. */
600 DECL_POINTER_ALIAS_SET (t) = -1;
602 DECL_SOURCE_LOCATION (t) = input_location;
603 DECL_UID (t) = next_decl_uid++;
608 TYPE_UID (t) = next_type_uid++;
609 TYPE_ALIGN (t) = BITS_PER_UNIT;
610 TYPE_USER_ALIGN (t) = 0;
611 TYPE_MAIN_VARIANT (t) = t;
612 TYPE_CANONICAL (t) = t;
614 /* Default to no attributes for type, but let target change that. */
615 TYPE_ATTRIBUTES (t) = NULL_TREE;
616 targetm.set_default_type_attributes (t);
618 /* We have not yet computed the alias set for this type. */
619 TYPE_ALIAS_SET (t) = -1;
623 TREE_CONSTANT (t) = 1;
624 TREE_INVARIANT (t) = 1;
633 case PREDECREMENT_EXPR:
634 case PREINCREMENT_EXPR:
635 case POSTDECREMENT_EXPR:
636 case POSTINCREMENT_EXPR:
637 /* All of these have side-effects, no matter what their
639 TREE_SIDE_EFFECTS (t) = 1;
647 case tcc_gimple_stmt:
650 case GIMPLE_MODIFY_STMT:
651 TREE_SIDE_EFFECTS (t) = 1;
659 /* Other classes need no special treatment. */
666 /* Return a new node with the same contents as NODE except that its
667 TREE_CHAIN is zero and it has a fresh uid. */
670 copy_node_stat (tree node MEM_STAT_DECL)
673 enum tree_code code = TREE_CODE (node);
676 gcc_assert (code != STATEMENT_LIST);
678 length = tree_size (node);
679 t = ggc_alloc_zone_pass_stat (length, &tree_zone);
680 memcpy (t, node, length);
682 if (!GIMPLE_TUPLE_P (node))
684 TREE_ASM_WRITTEN (t) = 0;
685 TREE_VISITED (t) = 0;
688 if (TREE_CODE_CLASS (code) == tcc_declaration)
690 DECL_UID (t) = next_decl_uid++;
691 if ((TREE_CODE (node) == PARM_DECL || TREE_CODE (node) == VAR_DECL)
692 && DECL_HAS_VALUE_EXPR_P (node))
694 SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (node));
695 DECL_HAS_VALUE_EXPR_P (t) = 1;
697 if (TREE_CODE (node) == VAR_DECL && DECL_HAS_INIT_PRIORITY_P (node))
699 SET_DECL_INIT_PRIORITY (t, DECL_INIT_PRIORITY (node));
700 DECL_HAS_INIT_PRIORITY_P (t) = 1;
702 if (TREE_CODE (node) == VAR_DECL && DECL_BASED_ON_RESTRICT_P (node))
704 SET_DECL_RESTRICT_BASE (t, DECL_GET_RESTRICT_BASE (node));
705 DECL_BASED_ON_RESTRICT_P (t) = 1;
708 else if (TREE_CODE_CLASS (code) == tcc_type)
710 TYPE_UID (t) = next_type_uid++;
711 /* The following is so that the debug code for
712 the copy is different from the original type.
713 The two statements usually duplicate each other
714 (because they clear fields of the same union),
715 but the optimizer should catch that. */
716 TYPE_SYMTAB_POINTER (t) = 0;
717 TYPE_SYMTAB_ADDRESS (t) = 0;
719 /* Do not copy the values cache. */
720 if (TYPE_CACHED_VALUES_P(t))
722 TYPE_CACHED_VALUES_P (t) = 0;
723 TYPE_CACHED_VALUES (t) = NULL_TREE;
730 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
731 For example, this can copy a list made of TREE_LIST nodes. */
734 copy_list (tree list)
742 head = prev = copy_node (list);
743 next = TREE_CHAIN (list);
746 TREE_CHAIN (prev) = copy_node (next);
747 prev = TREE_CHAIN (prev);
748 next = TREE_CHAIN (next);
754 /* Create an INT_CST node with a LOW value sign extended. */
757 build_int_cst (tree type, HOST_WIDE_INT low)
759 /* Support legacy code. */
761 type = integer_type_node;
763 return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
766 /* Create an INT_CST node with a LOW value zero extended. */
769 build_int_cstu (tree type, unsigned HOST_WIDE_INT low)
771 return build_int_cst_wide (type, low, 0);
774 /* Create an INT_CST node with a LOW value in TYPE. The value is sign extended
775 if it is negative. This function is similar to build_int_cst, but
776 the extra bits outside of the type precision are cleared. Constants
777 with these extra bits may confuse the fold so that it detects overflows
778 even in cases when they do not occur, and in general should be avoided.
779 We cannot however make this a default behavior of build_int_cst without
780 more intrusive changes, since there are parts of gcc that rely on the extra
781 precision of the integer constants. */
784 build_int_cst_type (tree type, HOST_WIDE_INT low)
786 unsigned HOST_WIDE_INT low1;
791 fit_double_type (low, low < 0 ? -1 : 0, &low1, &hi, type);
793 return build_int_cst_wide (type, low1, hi);
796 /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated
797 and sign extended according to the value range of TYPE. */
800 build_int_cst_wide_type (tree type,
801 unsigned HOST_WIDE_INT low, HOST_WIDE_INT high)
803 fit_double_type (low, high, &low, &high, type);
804 return build_int_cst_wide (type, low, high);
807 /* These are the hash table functions for the hash table of INTEGER_CST
808 nodes of a sizetype. */
810 /* Return the hash code code X, an INTEGER_CST. */
813 int_cst_hash_hash (const void *x)
815 const_tree const t = (const_tree) x;
817 return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
818 ^ htab_hash_pointer (TREE_TYPE (t)));
821 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
822 is the same as that given by *Y, which is the same. */
825 int_cst_hash_eq (const void *x, const void *y)
827 const_tree const xt = (const_tree) x;
828 const_tree const yt = (const_tree) y;
830 return (TREE_TYPE (xt) == TREE_TYPE (yt)
831 && TREE_INT_CST_HIGH (xt) == TREE_INT_CST_HIGH (yt)
832 && TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
835 /* Create an INT_CST node of TYPE and value HI:LOW.
836 The returned node is always shared. For small integers we use a
837 per-type vector cache, for larger ones we use a single hash table. */
840 build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
848 switch (TREE_CODE (type))
852 /* Cache NULL pointer. */
861 /* Cache false or true. */
869 if (TYPE_UNSIGNED (type))
872 limit = INTEGER_SHARE_LIMIT;
873 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
879 limit = INTEGER_SHARE_LIMIT + 1;
880 if (!hi && low < (unsigned HOST_WIDE_INT)INTEGER_SHARE_LIMIT)
882 else if (hi == -1 && low == -(unsigned HOST_WIDE_INT)1)
896 /* Look for it in the type's vector of small shared ints. */
897 if (!TYPE_CACHED_VALUES_P (type))
899 TYPE_CACHED_VALUES_P (type) = 1;
900 TYPE_CACHED_VALUES (type) = make_tree_vec (limit);
903 t = TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix);
906 /* Make sure no one is clobbering the shared constant. */
907 gcc_assert (TREE_TYPE (t) == type);
908 gcc_assert (TREE_INT_CST_LOW (t) == low);
909 gcc_assert (TREE_INT_CST_HIGH (t) == hi);
913 /* Create a new shared int. */
914 t = make_node (INTEGER_CST);
916 TREE_INT_CST_LOW (t) = low;
917 TREE_INT_CST_HIGH (t) = hi;
918 TREE_TYPE (t) = type;
920 TREE_VEC_ELT (TYPE_CACHED_VALUES (type), ix) = t;
925 /* Use the cache of larger shared ints. */
928 TREE_INT_CST_LOW (int_cst_node) = low;
929 TREE_INT_CST_HIGH (int_cst_node) = hi;
930 TREE_TYPE (int_cst_node) = type;
932 slot = htab_find_slot (int_cst_hash_table, int_cst_node, INSERT);
936 /* Insert this one into the hash table. */
939 /* Make a new node for next time round. */
940 int_cst_node = make_node (INTEGER_CST);
947 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
948 and the rest are zeros. */
951 build_low_bits_mask (tree type, unsigned bits)
953 unsigned HOST_WIDE_INT low;
955 unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0;
957 gcc_assert (bits <= TYPE_PRECISION (type));
959 if (bits == TYPE_PRECISION (type)
960 && !TYPE_UNSIGNED (type))
962 /* Sign extended all-ones mask. */
966 else if (bits <= HOST_BITS_PER_WIDE_INT)
968 low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
973 bits -= HOST_BITS_PER_WIDE_INT;
975 high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
978 return build_int_cst_wide (type, low, high);
981 /* Checks that X is integer constant that can be expressed in (unsigned)
982 HOST_WIDE_INT without loss of precision. */
985 cst_and_fits_in_hwi (const_tree x)
987 if (TREE_CODE (x) != INTEGER_CST)
990 if (TYPE_PRECISION (TREE_TYPE (x)) > HOST_BITS_PER_WIDE_INT)
993 return (TREE_INT_CST_HIGH (x) == 0
994 || TREE_INT_CST_HIGH (x) == -1);
997 /* Return a new VECTOR_CST node whose type is TYPE and whose values
998 are in a list pointed to by VALS. */
1001 build_vector (tree type, tree vals)
1003 tree v = make_node (VECTOR_CST);
1007 TREE_VECTOR_CST_ELTS (v) = vals;
1008 TREE_TYPE (v) = type;
1010 /* Iterate through elements and check for overflow. */
1011 for (link = vals; link; link = TREE_CHAIN (link))
1013 tree value = TREE_VALUE (link);
1015 /* Don't crash if we get an address constant. */
1016 if (!CONSTANT_CLASS_P (value))
1019 over |= TREE_OVERFLOW (value);
1022 TREE_OVERFLOW (v) = over;
1026 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1027 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1030 build_vector_from_ctor (tree type, VEC(constructor_elt,gc) *v)
1032 tree list = NULL_TREE;
1033 unsigned HOST_WIDE_INT idx;
1036 FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value)
1037 list = tree_cons (NULL_TREE, value, list);
1038 return build_vector (type, nreverse (list));
1041 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1042 are in the VEC pointed to by VALS. */
1044 build_constructor (tree type, VEC(constructor_elt,gc) *vals)
1046 tree c = make_node (CONSTRUCTOR);
1047 TREE_TYPE (c) = type;
1048 CONSTRUCTOR_ELTS (c) = vals;
1052 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1055 build_constructor_single (tree type, tree index, tree value)
1057 VEC(constructor_elt,gc) *v;
1058 constructor_elt *elt;
1061 v = VEC_alloc (constructor_elt, gc, 1);
1062 elt = VEC_quick_push (constructor_elt, v, NULL);
1066 t = build_constructor (type, v);
1067 TREE_CONSTANT (t) = TREE_CONSTANT (value);
1072 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1073 are in a list pointed to by VALS. */
1075 build_constructor_from_list (tree type, tree vals)
1078 VEC(constructor_elt,gc) *v = NULL;
1079 bool constant_p = true;
1083 v = VEC_alloc (constructor_elt, gc, list_length (vals));
1084 for (t = vals; t; t = TREE_CHAIN (t))
1086 constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL);
1087 val = TREE_VALUE (t);
1088 elt->index = TREE_PURPOSE (t);
1090 if (!TREE_CONSTANT (val))
1095 t = build_constructor (type, v);
1096 TREE_CONSTANT (t) = constant_p;
1100 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1103 build_fixed (tree type, FIXED_VALUE_TYPE f)
1106 FIXED_VALUE_TYPE *fp;
1108 v = make_node (FIXED_CST);
1109 fp = ggc_alloc (sizeof (FIXED_VALUE_TYPE));
1110 memcpy (fp, &f, sizeof (FIXED_VALUE_TYPE));
1112 TREE_TYPE (v) = type;
1113 TREE_FIXED_CST_PTR (v) = fp;
1117 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1120 build_real (tree type, REAL_VALUE_TYPE d)
1123 REAL_VALUE_TYPE *dp;
1126 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1127 Consider doing it via real_convert now. */
1129 v = make_node (REAL_CST);
1130 dp = ggc_alloc (sizeof (REAL_VALUE_TYPE));
1131 memcpy (dp, &d, sizeof (REAL_VALUE_TYPE));
1133 TREE_TYPE (v) = type;
1134 TREE_REAL_CST_PTR (v) = dp;
1135 TREE_OVERFLOW (v) = overflow;
1139 /* Return a new REAL_CST node whose type is TYPE
1140 and whose value is the integer value of the INTEGER_CST node I. */
1143 real_value_from_int_cst (const_tree type, const_tree i)
1147 /* Clear all bits of the real value type so that we can later do
1148 bitwise comparisons to see if two values are the same. */
1149 memset (&d, 0, sizeof d);
1151 real_from_integer (&d, type ? TYPE_MODE (type) : VOIDmode,
1152 TREE_INT_CST_LOW (i), TREE_INT_CST_HIGH (i),
1153 TYPE_UNSIGNED (TREE_TYPE (i)));
1157 /* Given a tree representing an integer constant I, return a tree
1158 representing the same value as a floating-point constant of type TYPE. */
1161 build_real_from_int_cst (tree type, const_tree i)
1164 int overflow = TREE_OVERFLOW (i);
1166 v = build_real (type, real_value_from_int_cst (type, i));
1168 TREE_OVERFLOW (v) |= overflow;
1172 /* Return a newly constructed STRING_CST node whose value is
1173 the LEN characters at STR.
1174 The TREE_TYPE is not initialized. */
1177 build_string (int len, const char *str)
1182 /* Do not waste bytes provided by padding of struct tree_string. */
1183 length = len + offsetof (struct tree_string, str) + 1;
1185 #ifdef GATHER_STATISTICS
1186 tree_node_counts[(int) c_kind]++;
1187 tree_node_sizes[(int) c_kind] += length;
1190 s = ggc_alloc_tree (length);
1192 memset (s, 0, sizeof (struct tree_common));
1193 TREE_SET_CODE (s, STRING_CST);
1194 TREE_CONSTANT (s) = 1;
1195 TREE_INVARIANT (s) = 1;
1196 TREE_STRING_LENGTH (s) = len;
1197 memcpy (s->string.str, str, len);
1198 s->string.str[len] = '\0';
1203 /* Return a newly constructed COMPLEX_CST node whose value is
1204 specified by the real and imaginary parts REAL and IMAG.
1205 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1206 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1209 build_complex (tree type, tree real, tree imag)
1211 tree t = make_node (COMPLEX_CST);
1213 TREE_REALPART (t) = real;
1214 TREE_IMAGPART (t) = imag;
1215 TREE_TYPE (t) = type ? type : build_complex_type (TREE_TYPE (real));
1216 TREE_OVERFLOW (t) = TREE_OVERFLOW (real) | TREE_OVERFLOW (imag);
1220 /* Return a constant of arithmetic type TYPE which is the
1221 multiplicative identity of the set TYPE. */
1224 build_one_cst (tree type)
1226 switch (TREE_CODE (type))
1228 case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
1229 case POINTER_TYPE: case REFERENCE_TYPE:
1231 return build_int_cst (type, 1);
1234 return build_real (type, dconst1);
1236 case FIXED_POINT_TYPE:
1237 /* We can only generate 1 for accum types. */
1238 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)));
1239 return build_fixed (type, FCONST1(TYPE_MODE (type)));
1246 scalar = build_one_cst (TREE_TYPE (type));
1248 /* Create 'vect_cst_ = {cst,cst,...,cst}' */
1250 for (i = TYPE_VECTOR_SUBPARTS (type); --i >= 0; )
1251 cst = tree_cons (NULL_TREE, scalar, cst);
1253 return build_vector (type, cst);
1257 return build_complex (type,
1258 build_one_cst (TREE_TYPE (type)),
1259 fold_convert (TREE_TYPE (type), integer_zero_node));
1266 /* Build a BINFO with LEN language slots. */
1269 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL)
1272 size_t length = (offsetof (struct tree_binfo, base_binfos)
1273 + VEC_embedded_size (tree, base_binfos));
1275 #ifdef GATHER_STATISTICS
1276 tree_node_counts[(int) binfo_kind]++;
1277 tree_node_sizes[(int) binfo_kind] += length;
1280 t = ggc_alloc_zone_pass_stat (length, &tree_zone);
1282 memset (t, 0, offsetof (struct tree_binfo, base_binfos));
1284 TREE_SET_CODE (t, TREE_BINFO);
1286 VEC_embedded_init (tree, BINFO_BASE_BINFOS (t), base_binfos);
1292 /* Build a newly constructed TREE_VEC node of length LEN. */
1295 make_tree_vec_stat (int len MEM_STAT_DECL)
1298 int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
1300 #ifdef GATHER_STATISTICS
1301 tree_node_counts[(int) vec_kind]++;
1302 tree_node_sizes[(int) vec_kind] += length;
1305 t = ggc_alloc_zone_pass_stat (length, &tree_zone);
1307 memset (t, 0, length);
1309 TREE_SET_CODE (t, TREE_VEC);
1310 TREE_VEC_LENGTH (t) = len;
1315 /* Return 1 if EXPR is the integer constant zero or a complex constant
1319 integer_zerop (const_tree expr)
1323 return ((TREE_CODE (expr) == INTEGER_CST
1324 && TREE_INT_CST_LOW (expr) == 0
1325 && TREE_INT_CST_HIGH (expr) == 0)
1326 || (TREE_CODE (expr) == COMPLEX_CST
1327 && integer_zerop (TREE_REALPART (expr))
1328 && integer_zerop (TREE_IMAGPART (expr))));
1331 /* Return 1 if EXPR is the integer constant one or the corresponding
1332 complex constant. */
1335 integer_onep (const_tree expr)
1339 return ((TREE_CODE (expr) == INTEGER_CST
1340 && TREE_INT_CST_LOW (expr) == 1
1341 && TREE_INT_CST_HIGH (expr) == 0)
1342 || (TREE_CODE (expr) == COMPLEX_CST
1343 && integer_onep (TREE_REALPART (expr))
1344 && integer_zerop (TREE_IMAGPART (expr))));
1347 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1348 it contains. Likewise for the corresponding complex constant. */
1351 integer_all_onesp (const_tree expr)
1358 if (TREE_CODE (expr) == COMPLEX_CST
1359 && integer_all_onesp (TREE_REALPART (expr))
1360 && integer_zerop (TREE_IMAGPART (expr)))
1363 else if (TREE_CODE (expr) != INTEGER_CST)
1366 uns = TYPE_UNSIGNED (TREE_TYPE (expr));
1367 if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1368 && TREE_INT_CST_HIGH (expr) == -1)
1373 /* Note that using TYPE_PRECISION here is wrong. We care about the
1374 actual bits, not the (arbitrary) range of the type. */
1375 prec = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)));
1376 if (prec >= HOST_BITS_PER_WIDE_INT)
1378 HOST_WIDE_INT high_value;
1381 shift_amount = prec - HOST_BITS_PER_WIDE_INT;
1383 /* Can not handle precisions greater than twice the host int size. */
1384 gcc_assert (shift_amount <= HOST_BITS_PER_WIDE_INT);
1385 if (shift_amount == HOST_BITS_PER_WIDE_INT)
1386 /* Shifting by the host word size is undefined according to the ANSI
1387 standard, so we must handle this as a special case. */
1390 high_value = ((HOST_WIDE_INT) 1 << shift_amount) - 1;
1392 return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
1393 && TREE_INT_CST_HIGH (expr) == high_value);
1396 return TREE_INT_CST_LOW (expr) == ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
1399 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1403 integer_pow2p (const_tree expr)
1406 HOST_WIDE_INT high, low;
1410 if (TREE_CODE (expr) == COMPLEX_CST
1411 && integer_pow2p (TREE_REALPART (expr))
1412 && integer_zerop (TREE_IMAGPART (expr)))
1415 if (TREE_CODE (expr) != INTEGER_CST)
1418 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1419 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1420 high = TREE_INT_CST_HIGH (expr);
1421 low = TREE_INT_CST_LOW (expr);
1423 /* First clear all bits that are beyond the type's precision in case
1424 we've been sign extended. */
1426 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1428 else if (prec > HOST_BITS_PER_WIDE_INT)
1429 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1433 if (prec < HOST_BITS_PER_WIDE_INT)
1434 low &= ~((HOST_WIDE_INT) (-1) << prec);
1437 if (high == 0 && low == 0)
1440 return ((high == 0 && (low & (low - 1)) == 0)
1441 || (low == 0 && (high & (high - 1)) == 0));
1444 /* Return 1 if EXPR is an integer constant other than zero or a
1445 complex constant other than zero. */
1448 integer_nonzerop (const_tree expr)
1452 return ((TREE_CODE (expr) == INTEGER_CST
1453 && (TREE_INT_CST_LOW (expr) != 0
1454 || TREE_INT_CST_HIGH (expr) != 0))
1455 || (TREE_CODE (expr) == COMPLEX_CST
1456 && (integer_nonzerop (TREE_REALPART (expr))
1457 || integer_nonzerop (TREE_IMAGPART (expr)))));
1460 /* Return 1 if EXPR is the fixed-point constant zero. */
1463 fixed_zerop (const_tree expr)
1465 return (TREE_CODE (expr) == FIXED_CST
1466 && double_int_zero_p (TREE_FIXED_CST (expr).data));
1469 /* Return the power of two represented by a tree node known to be a
1473 tree_log2 (const_tree expr)
1476 HOST_WIDE_INT high, low;
1480 if (TREE_CODE (expr) == COMPLEX_CST)
1481 return tree_log2 (TREE_REALPART (expr));
1483 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1484 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1486 high = TREE_INT_CST_HIGH (expr);
1487 low = TREE_INT_CST_LOW (expr);
1489 /* First clear all bits that are beyond the type's precision in case
1490 we've been sign extended. */
1492 if (prec == 2 * HOST_BITS_PER_WIDE_INT)
1494 else if (prec > HOST_BITS_PER_WIDE_INT)
1495 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1499 if (prec < HOST_BITS_PER_WIDE_INT)
1500 low &= ~((HOST_WIDE_INT) (-1) << prec);
1503 return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high)
1504 : exact_log2 (low));
1507 /* Similar, but return the largest integer Y such that 2 ** Y is less
1508 than or equal to EXPR. */
1511 tree_floor_log2 (const_tree expr)
1514 HOST_WIDE_INT high, low;
1518 if (TREE_CODE (expr) == COMPLEX_CST)
1519 return tree_log2 (TREE_REALPART (expr));
1521 prec = (POINTER_TYPE_P (TREE_TYPE (expr))
1522 ? POINTER_SIZE : TYPE_PRECISION (TREE_TYPE (expr)));
1524 high = TREE_INT_CST_HIGH (expr);
1525 low = TREE_INT_CST_LOW (expr);
1527 /* First clear all bits that are beyond the type's precision in case
1528 we've been sign extended. Ignore if type's precision hasn't been set
1529 since what we are doing is setting it. */
1531 if (prec == 2 * HOST_BITS_PER_WIDE_INT || prec == 0)
1533 else if (prec > HOST_BITS_PER_WIDE_INT)
1534 high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT));
1538 if (prec < HOST_BITS_PER_WIDE_INT)
1539 low &= ~((HOST_WIDE_INT) (-1) << prec);
1542 return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high)
1543 : floor_log2 (low));
1546 /* Return 1 if EXPR is the real constant zero. */
1549 real_zerop (const_tree expr)
1553 return ((TREE_CODE (expr) == REAL_CST
1554 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0))
1555 || (TREE_CODE (expr) == COMPLEX_CST
1556 && real_zerop (TREE_REALPART (expr))
1557 && real_zerop (TREE_IMAGPART (expr))));
1560 /* Return 1 if EXPR is the real constant one in real or complex form. */
1563 real_onep (const_tree expr)
1567 return ((TREE_CODE (expr) == REAL_CST
1568 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1))
1569 || (TREE_CODE (expr) == COMPLEX_CST
1570 && real_onep (TREE_REALPART (expr))
1571 && real_zerop (TREE_IMAGPART (expr))));
1574 /* Return 1 if EXPR is the real constant two. */
1577 real_twop (const_tree expr)
1581 return ((TREE_CODE (expr) == REAL_CST
1582 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2))
1583 || (TREE_CODE (expr) == COMPLEX_CST
1584 && real_twop (TREE_REALPART (expr))
1585 && real_zerop (TREE_IMAGPART (expr))));
1588 /* Return 1 if EXPR is the real constant minus one. */
1591 real_minus_onep (const_tree expr)
1595 return ((TREE_CODE (expr) == REAL_CST
1596 && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1))
1597 || (TREE_CODE (expr) == COMPLEX_CST
1598 && real_minus_onep (TREE_REALPART (expr))
1599 && real_zerop (TREE_IMAGPART (expr))));
1602 /* Nonzero if EXP is a constant or a cast of a constant. */
1605 really_constant_p (const_tree exp)
1607 /* This is not quite the same as STRIP_NOPS. It does more. */
1608 while (TREE_CODE (exp) == NOP_EXPR
1609 || TREE_CODE (exp) == CONVERT_EXPR
1610 || TREE_CODE (exp) == NON_LVALUE_EXPR)
1611 exp = TREE_OPERAND (exp, 0);
1612 return TREE_CONSTANT (exp);
1615 /* Return first list element whose TREE_VALUE is ELEM.
1616 Return 0 if ELEM is not in LIST. */
1619 value_member (tree elem, tree list)
1623 if (elem == TREE_VALUE (list))
1625 list = TREE_CHAIN (list);
1630 /* Return first list element whose TREE_PURPOSE is ELEM.
1631 Return 0 if ELEM is not in LIST. */
1634 purpose_member (const_tree elem, tree list)
1638 if (elem == TREE_PURPOSE (list))
1640 list = TREE_CHAIN (list);
1645 /* Return nonzero if ELEM is part of the chain CHAIN. */
1648 chain_member (const_tree elem, const_tree chain)
1654 chain = TREE_CHAIN (chain);
1660 /* Return the length of a chain of nodes chained through TREE_CHAIN.
1661 We expect a null pointer to mark the end of the chain.
1662 This is the Lisp primitive `length'. */
1665 list_length (const_tree t)
1668 #ifdef ENABLE_TREE_CHECKING
1676 #ifdef ENABLE_TREE_CHECKING
1679 gcc_assert (p != q);
1687 /* Returns the number of FIELD_DECLs in TYPE. */
1690 fields_length (const_tree type)
1692 tree t = TYPE_FIELDS (type);
1695 for (; t; t = TREE_CHAIN (t))
1696 if (TREE_CODE (t) == FIELD_DECL)
1702 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
1703 by modifying the last node in chain 1 to point to chain 2.
1704 This is the Lisp primitive `nconc'. */
1707 chainon (tree op1, tree op2)
1716 for (t1 = op1; TREE_CHAIN (t1); t1 = TREE_CHAIN (t1))
1718 TREE_CHAIN (t1) = op2;
1720 #ifdef ENABLE_TREE_CHECKING
1723 for (t2 = op2; t2; t2 = TREE_CHAIN (t2))
1724 gcc_assert (t2 != t1);
1731 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
1734 tree_last (tree chain)
1738 while ((next = TREE_CHAIN (chain)))
1743 /* Reverse the order of elements in the chain T,
1744 and return the new head of the chain (old last element). */
1749 tree prev = 0, decl, next;
1750 for (decl = t; decl; decl = next)
1752 next = TREE_CHAIN (decl);
1753 TREE_CHAIN (decl) = prev;
1759 /* Return a newly created TREE_LIST node whose
1760 purpose and value fields are PARM and VALUE. */
1763 build_tree_list_stat (tree parm, tree value MEM_STAT_DECL)
1765 tree t = make_node_stat (TREE_LIST PASS_MEM_STAT);
1766 TREE_PURPOSE (t) = parm;
1767 TREE_VALUE (t) = value;
1771 /* Return a newly created TREE_LIST node whose
1772 purpose and value fields are PURPOSE and VALUE
1773 and whose TREE_CHAIN is CHAIN. */
1776 tree_cons_stat (tree purpose, tree value, tree chain MEM_STAT_DECL)
1780 node = ggc_alloc_zone_pass_stat (sizeof (struct tree_list), &tree_zone);
1782 memset (node, 0, sizeof (struct tree_common));
1784 #ifdef GATHER_STATISTICS
1785 tree_node_counts[(int) x_kind]++;
1786 tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
1789 TREE_SET_CODE (node, TREE_LIST);
1790 TREE_CHAIN (node) = chain;
1791 TREE_PURPOSE (node) = purpose;
1792 TREE_VALUE (node) = value;
1797 /* Return the size nominally occupied by an object of type TYPE
1798 when it resides in memory. The value is measured in units of bytes,
1799 and its data type is that normally used for type sizes
1800 (which is the first type created by make_signed_type or
1801 make_unsigned_type). */
1804 size_in_bytes (const_tree type)
1808 if (type == error_mark_node)
1809 return integer_zero_node;
1811 type = TYPE_MAIN_VARIANT (type);
1812 t = TYPE_SIZE_UNIT (type);
1816 lang_hooks.types.incomplete_type_error (NULL_TREE, type);
1817 return size_zero_node;
1823 /* Return the size of TYPE (in bytes) as a wide integer
1824 or return -1 if the size can vary or is larger than an integer. */
1827 int_size_in_bytes (const_tree type)
1831 if (type == error_mark_node)
1834 type = TYPE_MAIN_VARIANT (type);
1835 t = TYPE_SIZE_UNIT (type);
1837 || TREE_CODE (t) != INTEGER_CST
1838 || TREE_INT_CST_HIGH (t) != 0
1839 /* If the result would appear negative, it's too big to represent. */
1840 || (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0)
1843 return TREE_INT_CST_LOW (t);
1846 /* Return the maximum size of TYPE (in bytes) as a wide integer
1847 or return -1 if the size can vary or is larger than an integer. */
1850 max_int_size_in_bytes (const_tree type)
1852 HOST_WIDE_INT size = -1;
1855 /* If this is an array type, check for a possible MAX_SIZE attached. */
1857 if (TREE_CODE (type) == ARRAY_TYPE)
1859 size_tree = TYPE_ARRAY_MAX_SIZE (type);
1861 if (size_tree && host_integerp (size_tree, 1))
1862 size = tree_low_cst (size_tree, 1);
1865 /* If we still haven't been able to get a size, see if the language
1866 can compute a maximum size. */
1870 size_tree = lang_hooks.types.max_size (type);
1872 if (size_tree && host_integerp (size_tree, 1))
1873 size = tree_low_cst (size_tree, 1);
1879 /* Return the bit position of FIELD, in bits from the start of the record.
1880 This is a tree of type bitsizetype. */
1883 bit_position (const_tree field)
1885 return bit_from_pos (DECL_FIELD_OFFSET (field),
1886 DECL_FIELD_BIT_OFFSET (field));
1889 /* Likewise, but return as an integer. It must be representable in
1890 that way (since it could be a signed value, we don't have the
1891 option of returning -1 like int_size_in_byte can. */
1894 int_bit_position (const_tree field)
1896 return tree_low_cst (bit_position (field), 0);
1899 /* Return the byte position of FIELD, in bytes from the start of the record.
1900 This is a tree of type sizetype. */
1903 byte_position (const_tree field)
1905 return byte_from_pos (DECL_FIELD_OFFSET (field),
1906 DECL_FIELD_BIT_OFFSET (field));
1909 /* Likewise, but return as an integer. It must be representable in
1910 that way (since it could be a signed value, we don't have the
1911 option of returning -1 like int_size_in_byte can. */
1914 int_byte_position (const_tree field)
1916 return tree_low_cst (byte_position (field), 0);
1919 /* Return the strictest alignment, in bits, that T is known to have. */
1922 expr_align (const_tree t)
1924 unsigned int align0, align1;
1926 switch (TREE_CODE (t))
1928 case NOP_EXPR: case CONVERT_EXPR: case NON_LVALUE_EXPR:
1929 /* If we have conversions, we know that the alignment of the
1930 object must meet each of the alignments of the types. */
1931 align0 = expr_align (TREE_OPERAND (t, 0));
1932 align1 = TYPE_ALIGN (TREE_TYPE (t));
1933 return MAX (align0, align1);
1935 case GIMPLE_MODIFY_STMT:
1936 /* We should never ask for the alignment of a gimple statement. */
1939 case SAVE_EXPR: case COMPOUND_EXPR: case MODIFY_EXPR:
1940 case INIT_EXPR: case TARGET_EXPR: case WITH_CLEANUP_EXPR:
1941 case CLEANUP_POINT_EXPR:
1942 /* These don't change the alignment of an object. */
1943 return expr_align (TREE_OPERAND (t, 0));
1946 /* The best we can do is say that the alignment is the least aligned
1948 align0 = expr_align (TREE_OPERAND (t, 1));
1949 align1 = expr_align (TREE_OPERAND (t, 2));
1950 return MIN (align0, align1);
1952 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
1953 meaningfully, it's always 1. */
1954 case LABEL_DECL: case CONST_DECL:
1955 case VAR_DECL: case PARM_DECL: case RESULT_DECL:
1957 gcc_assert (DECL_ALIGN (t) != 0);
1958 return DECL_ALIGN (t);
1964 /* Otherwise take the alignment from that of the type. */
1965 return TYPE_ALIGN (TREE_TYPE (t));
1968 /* Return, as a tree node, the number of elements for TYPE (which is an
1969 ARRAY_TYPE) minus one. This counts only elements of the top array. */
1972 array_type_nelts (const_tree type)
1974 tree index_type, min, max;
1976 /* If they did it with unspecified bounds, then we should have already
1977 given an error about it before we got here. */
1978 if (! TYPE_DOMAIN (type))
1979 return error_mark_node;
1981 index_type = TYPE_DOMAIN (type);
1982 min = TYPE_MIN_VALUE (index_type);
1983 max = TYPE_MAX_VALUE (index_type);
1985 return (integer_zerop (min)
1987 : fold_build2 (MINUS_EXPR, TREE_TYPE (max), max, min));
1990 /* If arg is static -- a reference to an object in static storage -- then
1991 return the object. This is not the same as the C meaning of `static'.
1992 If arg isn't static, return NULL. */
1997 switch (TREE_CODE (arg))
2000 /* Nested functions are static, even though taking their address will
2001 involve a trampoline as we unnest the nested function and create
2002 the trampoline on the tree level. */
2006 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2007 && ! DECL_THREAD_LOCAL_P (arg)
2008 && ! DECL_DLLIMPORT_P (arg)
2012 return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
2016 return TREE_STATIC (arg) ? arg : NULL;
2023 /* If the thing being referenced is not a field, then it is
2024 something language specific. */
2025 if (TREE_CODE (TREE_OPERAND (arg, 1)) != FIELD_DECL)
2026 return (*lang_hooks.staticp) (arg);
2028 /* If we are referencing a bitfield, we can't evaluate an
2029 ADDR_EXPR at compile time and so it isn't a constant. */
2030 if (DECL_BIT_FIELD (TREE_OPERAND (arg, 1)))
2033 return staticp (TREE_OPERAND (arg, 0));
2038 case MISALIGNED_INDIRECT_REF:
2039 case ALIGN_INDIRECT_REF:
2041 return TREE_CONSTANT (TREE_OPERAND (arg, 0)) ? arg : NULL;
2044 case ARRAY_RANGE_REF:
2045 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
2046 && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
2047 return staticp (TREE_OPERAND (arg, 0));
2052 if ((unsigned int) TREE_CODE (arg)
2053 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
2054 return lang_hooks.staticp (arg);
2060 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2061 Do this to any expression which may be used in more than one place,
2062 but must be evaluated only once.
2064 Normally, expand_expr would reevaluate the expression each time.
2065 Calling save_expr produces something that is evaluated and recorded
2066 the first time expand_expr is called on it. Subsequent calls to
2067 expand_expr just reuse the recorded value.
2069 The call to expand_expr that generates code that actually computes
2070 the value is the first call *at compile time*. Subsequent calls
2071 *at compile time* generate code to use the saved value.
2072 This produces correct result provided that *at run time* control
2073 always flows through the insns made by the first expand_expr
2074 before reaching the other places where the save_expr was evaluated.
2075 You, the caller of save_expr, must make sure this is so.
2077 Constants, and certain read-only nodes, are returned with no
2078 SAVE_EXPR because that is safe. Expressions containing placeholders
2079 are not touched; see tree.def for an explanation of what these
2083 save_expr (tree expr)
2085 tree t = fold (expr);
2088 /* If the tree evaluates to a constant, then we don't want to hide that
2089 fact (i.e. this allows further folding, and direct checks for constants).
2090 However, a read-only object that has side effects cannot be bypassed.
2091 Since it is no problem to reevaluate literals, we just return the
2093 inner = skip_simple_arithmetic (t);
2095 if (TREE_INVARIANT (inner)
2096 || (TREE_READONLY (inner) && ! TREE_SIDE_EFFECTS (inner))
2097 || TREE_CODE (inner) == SAVE_EXPR
2098 || TREE_CODE (inner) == ERROR_MARK)
2101 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2102 it means that the size or offset of some field of an object depends on
2103 the value within another field.
2105 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2106 and some variable since it would then need to be both evaluated once and
2107 evaluated more than once. Front-ends must assure this case cannot
2108 happen by surrounding any such subexpressions in their own SAVE_EXPR
2109 and forcing evaluation at the proper time. */
2110 if (contains_placeholder_p (inner))
2113 t = build1 (SAVE_EXPR, TREE_TYPE (expr), t);
2115 /* This expression might be placed ahead of a jump to ensure that the
2116 value was computed on both sides of the jump. So make sure it isn't
2117 eliminated as dead. */
2118 TREE_SIDE_EFFECTS (t) = 1;
2119 TREE_INVARIANT (t) = 1;
2123 /* Look inside EXPR and into any simple arithmetic operations. Return
2124 the innermost non-arithmetic node. */
2127 skip_simple_arithmetic (tree expr)
2131 /* We don't care about whether this can be used as an lvalue in this
2133 while (TREE_CODE (expr) == NON_LVALUE_EXPR)
2134 expr = TREE_OPERAND (expr, 0);
2136 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2137 a constant, it will be more efficient to not make another SAVE_EXPR since
2138 it will allow better simplification and GCSE will be able to merge the
2139 computations if they actually occur. */
2143 if (UNARY_CLASS_P (inner))
2144 inner = TREE_OPERAND (inner, 0);
2145 else if (BINARY_CLASS_P (inner))
2147 if (TREE_INVARIANT (TREE_OPERAND (inner, 1)))
2148 inner = TREE_OPERAND (inner, 0);
2149 else if (TREE_INVARIANT (TREE_OPERAND (inner, 0)))
2150 inner = TREE_OPERAND (inner, 1);
2161 /* Return which tree structure is used by T. */
2163 enum tree_node_structure_enum
2164 tree_node_structure (const_tree t)
2166 const enum tree_code code = TREE_CODE (t);
2168 switch (TREE_CODE_CLASS (code))
2170 case tcc_declaration:
2175 return TS_FIELD_DECL;
2177 return TS_PARM_DECL;
2181 return TS_LABEL_DECL;
2183 return TS_RESULT_DECL;
2185 return TS_CONST_DECL;
2187 return TS_TYPE_DECL;
2189 return TS_FUNCTION_DECL;
2190 case SYMBOL_MEMORY_TAG:
2191 case NAME_MEMORY_TAG:
2192 case STRUCT_FIELD_TAG:
2193 case MEMORY_PARTITION_TAG:
2194 return TS_MEMORY_TAG;
2196 return TS_DECL_NON_COMMON;
2202 case tcc_comparison:
2205 case tcc_expression:
2209 case tcc_gimple_stmt:
2210 return TS_GIMPLE_STATEMENT;
2211 default: /* tcc_constant and tcc_exceptional */
2216 /* tcc_constant cases. */
2217 case INTEGER_CST: return TS_INT_CST;
2218 case REAL_CST: return TS_REAL_CST;
2219 case FIXED_CST: return TS_FIXED_CST;
2220 case COMPLEX_CST: return TS_COMPLEX;
2221 case VECTOR_CST: return TS_VECTOR;
2222 case STRING_CST: return TS_STRING;
2223 /* tcc_exceptional cases. */
2224 /* FIXME tuples: eventually this should be TS_BASE. For now, nothing
2226 case ERROR_MARK: return TS_COMMON;
2227 case IDENTIFIER_NODE: return TS_IDENTIFIER;
2228 case TREE_LIST: return TS_LIST;
2229 case TREE_VEC: return TS_VEC;
2230 case PHI_NODE: return TS_PHI_NODE;
2231 case SSA_NAME: return TS_SSA_NAME;
2232 case PLACEHOLDER_EXPR: return TS_COMMON;
2233 case STATEMENT_LIST: return TS_STATEMENT_LIST;
2234 case BLOCK: return TS_BLOCK;
2235 case CONSTRUCTOR: return TS_CONSTRUCTOR;
2236 case TREE_BINFO: return TS_BINFO;
2237 case VALUE_HANDLE: return TS_VALUE_HANDLE;
2238 case OMP_CLAUSE: return TS_OMP_CLAUSE;
2245 /* Return 1 if EXP contains a PLACEHOLDER_EXPR; i.e., if it represents a size
2246 or offset that depends on a field within a record. */
2249 contains_placeholder_p (const_tree exp)
2251 enum tree_code code;
2256 code = TREE_CODE (exp);
2257 if (code == PLACEHOLDER_EXPR)
2260 switch (TREE_CODE_CLASS (code))
2263 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
2264 position computations since they will be converted into a
2265 WITH_RECORD_EXPR involving the reference, which will assume
2266 here will be valid. */
2267 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
2269 case tcc_exceptional:
2270 if (code == TREE_LIST)
2271 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp))
2272 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp)));
2277 case tcc_comparison:
2278 case tcc_expression:
2282 /* Ignoring the first operand isn't quite right, but works best. */
2283 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1));
2286 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
2287 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1))
2288 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 2)));
2294 switch (TREE_CODE_LENGTH (code))
2297 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0));
2299 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 0))
2300 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp, 1)));
2311 const_call_expr_arg_iterator iter;
2312 FOR_EACH_CONST_CALL_EXPR_ARG (arg, iter, exp)
2313 if (CONTAINS_PLACEHOLDER_P (arg))
2327 /* Return true if any part of the computation of TYPE involves a
2328 PLACEHOLDER_EXPR. This includes size, bounds, qualifiers
2329 (for QUAL_UNION_TYPE) and field positions. */
2332 type_contains_placeholder_1 (const_tree type)
2334 /* If the size contains a placeholder or the parent type (component type in
2335 the case of arrays) type involves a placeholder, this type does. */
2336 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type))
2337 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type))
2338 || (TREE_TYPE (type) != 0
2339 && type_contains_placeholder_p (TREE_TYPE (type))))
2342 /* Now do type-specific checks. Note that the last part of the check above
2343 greatly limits what we have to do below. */
2344 switch (TREE_CODE (type))
2352 case REFERENCE_TYPE:
2360 case FIXED_POINT_TYPE:
2361 /* Here we just check the bounds. */
2362 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type))
2363 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type)));
2366 /* We're already checked the component type (TREE_TYPE), so just check
2368 return type_contains_placeholder_p (TYPE_DOMAIN (type));
2372 case QUAL_UNION_TYPE:
2376 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
2377 if (TREE_CODE (field) == FIELD_DECL
2378 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field))
2379 || (TREE_CODE (type) == QUAL_UNION_TYPE
2380 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field)))
2381 || type_contains_placeholder_p (TREE_TYPE (field))))
2393 type_contains_placeholder_p (tree type)
2397 /* If the contains_placeholder_bits field has been initialized,
2398 then we know the answer. */
2399 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) > 0)
2400 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) - 1;
2402 /* Indicate that we've seen this type node, and the answer is false.
2403 This is what we want to return if we run into recursion via fields. */
2404 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = 1;
2406 /* Compute the real value. */
2407 result = type_contains_placeholder_1 (type);
2409 /* Store the real value. */
2410 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type) = result + 1;
2415 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
2416 return a tree with all occurrences of references to F in a
2417 PLACEHOLDER_EXPR replaced by R. Note that we assume here that EXP
2418 contains only arithmetic expressions or a CALL_EXPR with a
2419 PLACEHOLDER_EXPR occurring only in its arglist. */
2422 substitute_in_expr (tree exp, tree f, tree r)
2424 enum tree_code code = TREE_CODE (exp);
2425 tree op0, op1, op2, op3;
2429 /* We handle TREE_LIST and COMPONENT_REF separately. */
2430 if (code == TREE_LIST)
2432 op0 = SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp), f, r);
2433 op1 = SUBSTITUTE_IN_EXPR (TREE_VALUE (exp), f, r);
2434 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2437 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2439 else if (code == COMPONENT_REF)
2441 /* If this expression is getting a value from a PLACEHOLDER_EXPR
2442 and it is the right field, replace it with R. */
2443 for (inner = TREE_OPERAND (exp, 0);
2444 REFERENCE_CLASS_P (inner);
2445 inner = TREE_OPERAND (inner, 0))
2447 if (TREE_CODE (inner) == PLACEHOLDER_EXPR
2448 && TREE_OPERAND (exp, 1) == f)
2451 /* If this expression hasn't been completed let, leave it alone. */
2452 if (TREE_CODE (inner) == PLACEHOLDER_EXPR && TREE_TYPE (inner) == 0)
2455 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2456 if (op0 == TREE_OPERAND (exp, 0))
2459 new = fold_build3 (COMPONENT_REF, TREE_TYPE (exp),
2460 op0, TREE_OPERAND (exp, 1), NULL_TREE);
2463 switch (TREE_CODE_CLASS (code))
2466 case tcc_declaration:
2469 case tcc_exceptional:
2472 case tcc_comparison:
2473 case tcc_expression:
2475 switch (TREE_CODE_LENGTH (code))
2481 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2482 if (op0 == TREE_OPERAND (exp, 0))
2485 new = fold_build1 (code, TREE_TYPE (exp), op0);
2489 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2490 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2492 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2495 new = fold_build2 (code, TREE_TYPE (exp), op0, op1);
2499 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2500 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2501 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
2503 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2504 && op2 == TREE_OPERAND (exp, 2))
2507 new = fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
2511 op0 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 0), f, r);
2512 op1 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 1), f, r);
2513 op2 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 2), f, r);
2514 op3 = SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp, 3), f, r);
2516 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2517 && op2 == TREE_OPERAND (exp, 2)
2518 && op3 == TREE_OPERAND (exp, 3))
2521 new = fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2531 tree copy = NULL_TREE;
2533 int n = TREE_OPERAND_LENGTH (exp);
2534 for (i = 1; i < n; i++)
2536 tree op = TREE_OPERAND (exp, i);
2537 tree newop = SUBSTITUTE_IN_EXPR (op, f, r);
2540 copy = copy_node (exp);
2541 TREE_OPERAND (copy, i) = newop;
2554 TREE_READONLY (new) = TREE_READONLY (exp);
2558 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
2559 for it within OBJ, a tree that is an object or a chain of references. */
2562 substitute_placeholder_in_expr (tree exp, tree obj)
2564 enum tree_code code = TREE_CODE (exp);
2565 tree op0, op1, op2, op3;
2567 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
2568 in the chain of OBJ. */
2569 if (code == PLACEHOLDER_EXPR)
2571 tree need_type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
2574 for (elt = obj; elt != 0;
2575 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
2576 || TREE_CODE (elt) == COND_EXPR)
2577 ? TREE_OPERAND (elt, 1)
2578 : (REFERENCE_CLASS_P (elt)
2579 || UNARY_CLASS_P (elt)
2580 || BINARY_CLASS_P (elt)
2581 || VL_EXP_CLASS_P (elt)
2582 || EXPRESSION_CLASS_P (elt))
2583 ? TREE_OPERAND (elt, 0) : 0))
2584 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt)) == need_type)
2587 for (elt = obj; elt != 0;
2588 elt = ((TREE_CODE (elt) == COMPOUND_EXPR
2589 || TREE_CODE (elt) == COND_EXPR)
2590 ? TREE_OPERAND (elt, 1)
2591 : (REFERENCE_CLASS_P (elt)
2592 || UNARY_CLASS_P (elt)
2593 || BINARY_CLASS_P (elt)
2594 || VL_EXP_CLASS_P (elt)
2595 || EXPRESSION_CLASS_P (elt))
2596 ? TREE_OPERAND (elt, 0) : 0))
2597 if (POINTER_TYPE_P (TREE_TYPE (elt))
2598 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt)))
2600 return fold_build1 (INDIRECT_REF, need_type, elt);
2602 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
2603 survives until RTL generation, there will be an error. */
2607 /* TREE_LIST is special because we need to look at TREE_VALUE
2608 and TREE_CHAIN, not TREE_OPERANDS. */
2609 else if (code == TREE_LIST)
2611 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp), obj);
2612 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp), obj);
2613 if (op0 == TREE_CHAIN (exp) && op1 == TREE_VALUE (exp))
2616 return tree_cons (TREE_PURPOSE (exp), op1, op0);
2619 switch (TREE_CODE_CLASS (code))
2622 case tcc_declaration:
2625 case tcc_exceptional:
2628 case tcc_comparison:
2629 case tcc_expression:
2632 switch (TREE_CODE_LENGTH (code))
2638 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2639 if (op0 == TREE_OPERAND (exp, 0))
2642 return fold_build1 (code, TREE_TYPE (exp), op0);
2645 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2646 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2648 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1))
2651 return fold_build2 (code, TREE_TYPE (exp), op0, op1);
2654 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2655 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2656 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2658 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2659 && op2 == TREE_OPERAND (exp, 2))
2662 return fold_build3 (code, TREE_TYPE (exp), op0, op1, op2);
2665 op0 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 0), obj);
2666 op1 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 1), obj);
2667 op2 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 2), obj);
2668 op3 = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp, 3), obj);
2670 if (op0 == TREE_OPERAND (exp, 0) && op1 == TREE_OPERAND (exp, 1)
2671 && op2 == TREE_OPERAND (exp, 2)
2672 && op3 == TREE_OPERAND (exp, 3))
2675 return fold (build4 (code, TREE_TYPE (exp), op0, op1, op2, op3));
2684 tree copy = NULL_TREE;
2686 int n = TREE_OPERAND_LENGTH (exp);
2687 for (i = 1; i < n; i++)
2689 tree op = TREE_OPERAND (exp, i);
2690 tree newop = SUBSTITUTE_PLACEHOLDER_IN_EXPR (op, obj);
2694 copy = copy_node (exp);
2695 TREE_OPERAND (copy, i) = newop;
2709 /* Stabilize a reference so that we can use it any number of times
2710 without causing its operands to be evaluated more than once.
2711 Returns the stabilized reference. This works by means of save_expr,
2712 so see the caveats in the comments about save_expr.
2714 Also allows conversion expressions whose operands are references.
2715 Any other kind of expression is returned unchanged. */
2718 stabilize_reference (tree ref)
2721 enum tree_code code = TREE_CODE (ref);
2728 /* No action is needed in this case. */
2734 case FIX_TRUNC_EXPR:
2735 result = build_nt (code, stabilize_reference (TREE_OPERAND (ref, 0)));
2739 result = build_nt (INDIRECT_REF,
2740 stabilize_reference_1 (TREE_OPERAND (ref, 0)));
2744 result = build_nt (COMPONENT_REF,
2745 stabilize_reference (TREE_OPERAND (ref, 0)),
2746 TREE_OPERAND (ref, 1), NULL_TREE);
2750 result = build_nt (BIT_FIELD_REF,
2751 stabilize_reference (TREE_OPERAND (ref, 0)),
2752 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2753 stabilize_reference_1 (TREE_OPERAND (ref, 2)));
2757 result = build_nt (ARRAY_REF,
2758 stabilize_reference (TREE_OPERAND (ref, 0)),
2759 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2760 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2763 case ARRAY_RANGE_REF:
2764 result = build_nt (ARRAY_RANGE_REF,
2765 stabilize_reference (TREE_OPERAND (ref, 0)),
2766 stabilize_reference_1 (TREE_OPERAND (ref, 1)),
2767 TREE_OPERAND (ref, 2), TREE_OPERAND (ref, 3));
2771 /* We cannot wrap the first expression in a SAVE_EXPR, as then
2772 it wouldn't be ignored. This matters when dealing with
2774 return stabilize_reference_1 (ref);
2776 /* If arg isn't a kind of lvalue we recognize, make no change.
2777 Caller should recognize the error for an invalid lvalue. */
2782 return error_mark_node;
2785 TREE_TYPE (result) = TREE_TYPE (ref);
2786 TREE_READONLY (result) = TREE_READONLY (ref);
2787 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (ref);
2788 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (ref);
2793 /* Subroutine of stabilize_reference; this is called for subtrees of
2794 references. Any expression with side-effects must be put in a SAVE_EXPR
2795 to ensure that it is only evaluated once.
2797 We don't put SAVE_EXPR nodes around everything, because assigning very
2798 simple expressions to temporaries causes us to miss good opportunities
2799 for optimizations. Among other things, the opportunity to fold in the
2800 addition of a constant into an addressing mode often gets lost, e.g.
2801 "y[i+1] += x;". In general, we take the approach that we should not make
2802 an assignment unless we are forced into it - i.e., that any non-side effect
2803 operator should be allowed, and that cse should take care of coalescing
2804 multiple utterances of the same expression should that prove fruitful. */
2807 stabilize_reference_1 (tree e)
2810 enum tree_code code = TREE_CODE (e);
2812 /* We cannot ignore const expressions because it might be a reference
2813 to a const array but whose index contains side-effects. But we can
2814 ignore things that are actual constant or that already have been
2815 handled by this function. */
2817 if (TREE_INVARIANT (e))
2820 switch (TREE_CODE_CLASS (code))
2822 case tcc_exceptional:
2824 case tcc_declaration:
2825 case tcc_comparison:
2827 case tcc_expression:
2830 /* If the expression has side-effects, then encase it in a SAVE_EXPR
2831 so that it will only be evaluated once. */
2832 /* The reference (r) and comparison (<) classes could be handled as
2833 below, but it is generally faster to only evaluate them once. */
2834 if (TREE_SIDE_EFFECTS (e))
2835 return save_expr (e);
2839 /* Constants need no processing. In fact, we should never reach
2844 /* Division is slow and tends to be compiled with jumps,
2845 especially the division by powers of 2 that is often
2846 found inside of an array reference. So do it just once. */
2847 if (code == TRUNC_DIV_EXPR || code == TRUNC_MOD_EXPR
2848 || code == FLOOR_DIV_EXPR || code == FLOOR_MOD_EXPR
2849 || code == CEIL_DIV_EXPR || code == CEIL_MOD_EXPR
2850 || code == ROUND_DIV_EXPR || code == ROUND_MOD_EXPR)
2851 return save_expr (e);
2852 /* Recursively stabilize each operand. */
2853 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)),
2854 stabilize_reference_1 (TREE_OPERAND (e, 1)));
2858 /* Recursively stabilize each operand. */
2859 result = build_nt (code, stabilize_reference_1 (TREE_OPERAND (e, 0)));
2866 TREE_TYPE (result) = TREE_TYPE (e);
2867 TREE_READONLY (result) = TREE_READONLY (e);
2868 TREE_SIDE_EFFECTS (result) = TREE_SIDE_EFFECTS (e);
2869 TREE_THIS_VOLATILE (result) = TREE_THIS_VOLATILE (e);
2870 TREE_INVARIANT (result) = 1;
2875 /* Low-level constructors for expressions. */
2877 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
2878 TREE_INVARIANT, and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
2881 recompute_tree_invariant_for_addr_expr (tree t)
2884 bool tc = true, ti = true, se = false;
2886 /* We started out assuming this address is both invariant and constant, but
2887 does not have side effects. Now go down any handled components and see if
2888 any of them involve offsets that are either non-constant or non-invariant.
2889 Also check for side-effects.
2891 ??? Note that this code makes no attempt to deal with the case where
2892 taking the address of something causes a copy due to misalignment. */
2894 #define UPDATE_TITCSE(NODE) \
2895 do { tree _node = (NODE); \
2896 if (_node && !TREE_INVARIANT (_node)) ti = false; \
2897 if (_node && !TREE_CONSTANT (_node)) tc = false; \
2898 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
2900 for (node = TREE_OPERAND (t, 0); handled_component_p (node);
2901 node = TREE_OPERAND (node, 0))
2903 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
2904 array reference (probably made temporarily by the G++ front end),
2905 so ignore all the operands. */
2906 if ((TREE_CODE (node) == ARRAY_REF
2907 || TREE_CODE (node) == ARRAY_RANGE_REF)
2908 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node, 0))) == ARRAY_TYPE)
2910 UPDATE_TITCSE (TREE_OPERAND (node, 1));
2911 if (TREE_OPERAND (node, 2))
2912 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2913 if (TREE_OPERAND (node, 3))
2914 UPDATE_TITCSE (TREE_OPERAND (node, 3));
2916 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
2917 FIELD_DECL, apparently. The G++ front end can put something else
2918 there, at least temporarily. */
2919 else if (TREE_CODE (node) == COMPONENT_REF
2920 && TREE_CODE (TREE_OPERAND (node, 1)) == FIELD_DECL)
2922 if (TREE_OPERAND (node, 2))
2923 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2925 else if (TREE_CODE (node) == BIT_FIELD_REF)
2926 UPDATE_TITCSE (TREE_OPERAND (node, 2));
2929 node = lang_hooks.expr_to_decl (node, &tc, &ti, &se);
2931 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
2932 the address, since &(*a)->b is a form of addition. If it's a decl, it's
2933 invariant and constant if the decl is static. It's also invariant if it's
2934 a decl in the current function. Taking the address of a volatile variable
2935 is not volatile. If it's a constant, the address is both invariant and
2936 constant. Otherwise it's neither. */
2937 if (TREE_CODE (node) == INDIRECT_REF)
2938 UPDATE_TITCSE (TREE_OPERAND (node, 0));
2939 else if (DECL_P (node))
2943 else if (decl_function_context (node) == current_function_decl
2944 /* Addresses of thread-local variables are invariant. */
2945 || (TREE_CODE (node) == VAR_DECL
2946 && DECL_THREAD_LOCAL_P (node)))
2951 else if (CONSTANT_CLASS_P (node))
2956 se |= TREE_SIDE_EFFECTS (node);
2959 TREE_CONSTANT (t) = tc;
2960 TREE_INVARIANT (t) = ti;
2961 TREE_SIDE_EFFECTS (t) = se;
2962 #undef UPDATE_TITCSE
2965 /* Build an expression of code CODE, data type TYPE, and operands as
2966 specified. Expressions and reference nodes can be created this way.
2967 Constants, decls, types and misc nodes cannot be.
2969 We define 5 non-variadic functions, from 0 to 4 arguments. This is
2970 enough for all extant tree codes. */
2973 build0_stat (enum tree_code code, tree tt MEM_STAT_DECL)
2977 gcc_assert (TREE_CODE_LENGTH (code) == 0);
2979 t = make_node_stat (code PASS_MEM_STAT);
2986 build1_stat (enum tree_code code, tree type, tree node MEM_STAT_DECL)
2988 int length = sizeof (struct tree_exp);
2989 #ifdef GATHER_STATISTICS
2990 tree_node_kind kind;
2994 #ifdef GATHER_STATISTICS
2995 switch (TREE_CODE_CLASS (code))
2997 case tcc_statement: /* an expression with side effects */
3000 case tcc_reference: /* a reference */
3008 tree_node_counts[(int) kind]++;
3009 tree_node_sizes[(int) kind] += length;
3012 gcc_assert (TREE_CODE_LENGTH (code) == 1);
3014 t = ggc_alloc_zone_pass_stat (length, &tree_zone);
3016 memset (t, 0, sizeof (struct tree_common));
3018 TREE_SET_CODE (t, code);
3020 TREE_TYPE (t) = type;
3021 #ifdef USE_MAPPED_LOCATION
3022 SET_EXPR_LOCATION (t, UNKNOWN_LOCATION);
3024 SET_EXPR_LOCUS (t, NULL);
3026 TREE_OPERAND (t, 0) = node;
3027 TREE_BLOCK (t) = NULL_TREE;
3028 if (node && !TYPE_P (node))
3030 TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
3031 TREE_READONLY (t) = TREE_READONLY (node);
3034 if (TREE_CODE_CLASS (code) == tcc_statement)
3035 TREE_SIDE_EFFECTS (t) = 1;
3039 /* All of these have side-effects, no matter what their
3041 TREE_SIDE_EFFECTS (t) = 1;
3042 TREE_READONLY (t) = 0;
3045 case MISALIGNED_INDIRECT_REF:
3046 case ALIGN_INDIRECT_REF:
3048 /* Whether a dereference is readonly has nothing to do with whether
3049 its operand is readonly. */
3050 TREE_READONLY (t) = 0;
3055 recompute_tree_invariant_for_addr_expr (t);
3059 if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
3060 && node && !TYPE_P (node)
3061 && TREE_CONSTANT (node))
3062 TREE_CONSTANT (t) = 1;
3063 if ((TREE_CODE_CLASS (code) == tcc_unary || code == VIEW_CONVERT_EXPR)
3064 && node && TREE_INVARIANT (node))
3065 TREE_INVARIANT (t) = 1;
3066 if (TREE_CODE_CLASS (code) == tcc_reference
3067 && node && TREE_THIS_VOLATILE (node))
3068 TREE_THIS_VOLATILE (t) = 1;
3075 #define PROCESS_ARG(N) \
3077 TREE_OPERAND (t, N) = arg##N; \
3078 if (arg##N &&!TYPE_P (arg##N)) \
3080 if (TREE_SIDE_EFFECTS (arg##N)) \
3082 if (!TREE_READONLY (arg##N)) \
3084 if (!TREE_CONSTANT (arg##N)) \
3086 if (!TREE_INVARIANT (arg##N)) \
3092 build2_stat (enum tree_code code, tree tt, tree arg0, tree arg1 MEM_STAT_DECL)
3094 bool constant, read_only, side_effects, invariant;
3097 gcc_assert (TREE_CODE_LENGTH (code) == 2);
3100 /* FIXME tuples: Statement's aren't expressions! */
3101 if (code == GIMPLE_MODIFY_STMT)
3102 return build_gimple_modify_stmt_stat (arg0, arg1 PASS_MEM_STAT);
3104 /* Must use build_gimple_modify_stmt to construct GIMPLE_MODIFY_STMTs. */
3105 gcc_assert (code != GIMPLE_MODIFY_STMT);
3108 if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
3109 && arg0 && arg1 && tt && POINTER_TYPE_P (tt))
3110 gcc_assert (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST);
3112 if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
3113 gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
3114 && INTEGRAL_TYPE_P (TREE_TYPE (arg1))
3115 && useless_type_conversion_p (sizetype, TREE_TYPE (arg1)));
3117 t = make_node_stat (code PASS_MEM_STAT);
3120 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
3121 result based on those same flags for the arguments. But if the
3122 arguments aren't really even `tree' expressions, we shouldn't be trying
3125 /* Expressions without side effects may be constant if their
3126 arguments are as well. */
3127 constant = (TREE_CODE_CLASS (code) == tcc_comparison
3128 || TREE_CODE_CLASS (code) == tcc_binary);
3130 side_effects = TREE_SIDE_EFFECTS (t);
3131 invariant = constant;
3136 TREE_READONLY (t) = read_only;
3137 TREE_CONSTANT (t) = constant;
3138 TREE_INVARIANT (t) = invariant;
3139 TREE_SIDE_EFFECTS (t) = side_effects;
3140 TREE_THIS_VOLATILE (t)
3141 = (TREE_CODE_CLASS (code) == tcc_reference
3142 && arg0 && TREE_THIS_VOLATILE (arg0));
3148 /* Build a GIMPLE_MODIFY_STMT node. This tree code doesn't have a
3149 type, so we can't use build2 (a.k.a. build2_stat). */
3152 build_gimple_modify_stmt_stat (tree arg0, tree arg1 MEM_STAT_DECL)
3156 t = make_node_stat (GIMPLE_MODIFY_STMT PASS_MEM_STAT);
3157 /* ?? We don't care about setting flags for tuples... */
3158 GIMPLE_STMT_OPERAND (t, 0) = arg0;
3159 GIMPLE_STMT_OPERAND (t, 1) = arg1;
3164 build3_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3165 tree arg2 MEM_STAT_DECL)
3167 bool constant, read_only, side_effects, invariant;
3170 gcc_assert (TREE_CODE_LENGTH (code) == 3);
3171 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3173 t = make_node_stat (code PASS_MEM_STAT);
3176 /* As a special exception, if COND_EXPR has NULL branches, we
3177 assume that it is a gimple statement and always consider
3178 it to have side effects. */
3179 if (code == COND_EXPR
3180 && tt == void_type_node
3181 && arg1 == NULL_TREE
3182 && arg2 == NULL_TREE)
3183 side_effects = true;
3185 side_effects = TREE_SIDE_EFFECTS (t);
3191 TREE_SIDE_EFFECTS (t) = side_effects;
3192 TREE_THIS_VOLATILE (t)
3193 = (TREE_CODE_CLASS (code) == tcc_reference
3194 && arg0 && TREE_THIS_VOLATILE (arg0));
3200 build4_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3201 tree arg2, tree arg3 MEM_STAT_DECL)
3203 bool constant, read_only, side_effects, invariant;
3206 gcc_assert (TREE_CODE_LENGTH (code) == 4);
3208 t = make_node_stat (code PASS_MEM_STAT);
3211 side_effects = TREE_SIDE_EFFECTS (t);
3218 TREE_SIDE_EFFECTS (t) = side_effects;
3219 TREE_THIS_VOLATILE (t)
3220 = (TREE_CODE_CLASS (code) == tcc_reference
3221 && arg0 && TREE_THIS_VOLATILE (arg0));
3227 build5_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3228 tree arg2, tree arg3, tree arg4 MEM_STAT_DECL)
3230 bool constant, read_only, side_effects, invariant;
3233 gcc_assert (TREE_CODE_LENGTH (code) == 5);
3235 t = make_node_stat (code PASS_MEM_STAT);
3238 side_effects = TREE_SIDE_EFFECTS (t);
3246 TREE_SIDE_EFFECTS (t) = side_effects;
3247 TREE_THIS_VOLATILE (t)
3248 = (TREE_CODE_CLASS (code) == tcc_reference
3249 && arg0 && TREE_THIS_VOLATILE (arg0));
3255 build7_stat (enum tree_code code, tree tt, tree arg0, tree arg1,
3256 tree arg2, tree arg3, tree arg4, tree arg5,
3257 tree arg6 MEM_STAT_DECL)
3259 bool constant, read_only, side_effects, invariant;
3262 gcc_assert (code == TARGET_MEM_REF);
3264 t = make_node_stat (code PASS_MEM_STAT);
3267 side_effects = TREE_SIDE_EFFECTS (t);
3277 TREE_SIDE_EFFECTS (t) = side_effects;
3278 TREE_THIS_VOLATILE (t) = 0;
3283 /* Similar except don't specify the TREE_TYPE
3284 and leave the TREE_SIDE_EFFECTS as 0.
3285 It is permissible for arguments to be null,
3286 or even garbage if their values do not matter. */
3289 build_nt (enum tree_code code, ...)
3296 gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
3300 t = make_node (code);
3301 length = TREE_CODE_LENGTH (code);
3303 for (i = 0; i < length; i++)
3304 TREE_OPERAND (t, i) = va_arg (p, tree);
3310 /* Similar to build_nt, but for creating a CALL_EXPR object with
3311 ARGLIST passed as a list. */
3314 build_nt_call_list (tree fn, tree arglist)
3319 t = build_vl_exp (CALL_EXPR, list_length (arglist) + 3);
3320 CALL_EXPR_FN (t) = fn;
3321 CALL_EXPR_STATIC_CHAIN (t) = NULL_TREE;
3322 for (i = 0; arglist; arglist = TREE_CHAIN (arglist), i++)
3323 CALL_EXPR_ARG (t, i) = TREE_VALUE (arglist);
3327 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
3328 We do NOT enter this node in any sort of symbol table.
3330 layout_decl is used to set up the decl's storage layout.
3331 Other slots are initialized to 0 or null pointers. */
3334 build_decl_stat (enum tree_code code, tree name, tree type MEM_STAT_DECL)
3338 t = make_node_stat (code PASS_MEM_STAT);
3340 /* if (type == error_mark_node)
3341 type = integer_type_node; */
3342 /* That is not done, deliberately, so that having error_mark_node
3343 as the type can suppress useless errors in the use of this variable. */
3345 DECL_NAME (t) = name;
3346 TREE_TYPE (t) = type;
3348 if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
3354 /* Builds and returns function declaration with NAME and TYPE. */
3357 build_fn_decl (const char *name, tree type)
3359 tree id = get_identifier (name);
3360 tree decl = build_decl (FUNCTION_DECL, id, type);
3362 DECL_EXTERNAL (decl) = 1;
3363 TREE_PUBLIC (decl) = 1;
3364 DECL_ARTIFICIAL (decl) = 1;
3365 TREE_NOTHROW (decl) = 1;
3371 /* BLOCK nodes are used to represent the structure of binding contours
3372 and declarations, once those contours have been exited and their contents
3373 compiled. This information is used for outputting debugging info. */
3376 build_block (tree vars, tree subblocks, tree supercontext, tree chain)
3378 tree block = make_node (BLOCK);
3380 BLOCK_VARS (block) = vars;
3381 BLOCK_SUBBLOCKS (block) = subblocks;
3382 BLOCK_SUPERCONTEXT (block) = supercontext;
3383 BLOCK_CHAIN (block) = chain;
3387 #if 1 /* ! defined(USE_MAPPED_LOCATION) */
3388 /* ??? gengtype doesn't handle conditionals */
3389 static GTY(()) source_locus last_annotated_node;
3392 #ifdef USE_MAPPED_LOCATION
3395 expand_location (source_location loc)
3397 expanded_location xloc;
3406 const struct line_map *map = linemap_lookup (line_table, loc);
3407 xloc.file = map->to_file;
3408 xloc.line = SOURCE_LINE (map, loc);
3409 xloc.column = SOURCE_COLUMN (map, loc);
3416 /* Record the exact location where an expression or an identifier were
3420 annotate_with_file_line (tree node, const char *file, int line)
3422 location_t *new_loc;
3424 /* Roughly one percent of the calls to this function are to annotate
3425 a node with the same information already attached to that node!
3426 Just return instead of wasting memory. */
3427 if (EXPR_LOCUS (node)
3428 && EXPR_LINENO (node) == line
3429 && (EXPR_FILENAME (node) == file
3430 || !strcmp (EXPR_FILENAME (node), file)))
3432 last_annotated_node = EXPR_LOCUS (node);
3436 /* In heavily macroized code (such as GCC itself) this single
3437 entry cache can reduce the number of allocations by more
3439 if (last_annotated_node
3440 && last_annotated_node->line == line
3441 && (last_annotated_node->file == file
3442 || !strcmp (last_annotated_node->file, file)))
3444 SET_EXPR_LOCUS (node, last_annotated_node);
3448 new_loc = GGC_NEW (location_t);
3449 new_loc->file = file;
3450 new_loc->line = line;
3451 SET_EXPR_LOCUS (node, new_loc);
3452 last_annotated_node = new_loc;
3456 annotate_with_locus (tree node, location_t locus)
3458 annotate_with_file_line (node, locus.file, locus.line);
3462 /* Source location accessor functions. */
3465 /* The source location of this expression. Non-tree_exp nodes such as
3466 decls and constants can be shared among multiple locations, so
3469 expr_location (const_tree node)
3471 #ifdef USE_MAPPED_LOCATION
3472 if (GIMPLE_STMT_P (node))
3473 return GIMPLE_STMT_LOCUS (node);
3474 return EXPR_P (node) ? node->exp.locus : UNKNOWN_LOCATION;
3476 if (GIMPLE_STMT_P (node))
3477 return EXPR_HAS_LOCATION (node)
3478 ? *GIMPLE_STMT_LOCUS (node) : UNKNOWN_LOCATION;
3479 return EXPR_HAS_LOCATION (node) ? *node->exp.locus : UNKNOWN_LOCATION;
3484 set_expr_location (tree node, location_t locus)
3486 #ifdef USE_MAPPED_LOCATION
3487 if (GIMPLE_STMT_P (node))
3488 GIMPLE_STMT_LOCUS (node) = locus;
3490 EXPR_CHECK (node)->exp.locus = locus;
3492 annotate_with_locus (node, locus);
3497 expr_has_location (const_tree node)
3499 #ifdef USE_MAPPED_LOCATION
3500 return expr_location (node) != UNKNOWN_LOCATION;
3502 return expr_locus (node) != NULL;
3506 #ifdef USE_MAPPED_LOCATION
3511 expr_locus (const_tree node)
3513 #ifdef USE_MAPPED_LOCATION
3514 if (GIMPLE_STMT_P (node))
3515 return CONST_CAST (source_location *, &GIMPLE_STMT_LOCUS (node));
3516 return (EXPR_P (node)
3517 ? CONST_CAST (source_location *, &node->exp.locus)
3518 : (source_location *) NULL);
3520 if (GIMPLE_STMT_P (node))
3521 return GIMPLE_STMT_LOCUS (node);
3522 return EXPR_P (node) ? node->exp.locus : (source_locus) NULL;
3527 set_expr_locus (tree node,
3528 #ifdef USE_MAPPED_LOCATION
3529 source_location *loc
3535 #ifdef USE_MAPPED_LOCATION
3538 if (GIMPLE_STMT_P (node))
3539 GIMPLE_STMT_LOCUS (node) = UNKNOWN_LOCATION;
3541 EXPR_CHECK (node)->exp.locus = UNKNOWN_LOCATION;
3545 if (GIMPLE_STMT_P (node))
3546 GIMPLE_STMT_LOCUS (node) = *loc;
3548 EXPR_CHECK (node)->exp.locus = *loc;
3551 if (GIMPLE_STMT_P (node))
3552 GIMPLE_STMT_LOCUS (node) = loc;
3554 EXPR_CHECK (node)->exp.locus = loc;
3558 /* Return the file name of the location of NODE. */
3560 expr_filename (const_tree node)
3562 if (GIMPLE_STMT_P (node))
3563 return LOCATION_FILE (location_from_locus (GIMPLE_STMT_LOCUS (node)));
3564 return LOCATION_FILE (location_from_locus (EXPR_CHECK (node)->exp.locus));
3567 /* Return the line number of the location of NODE. */
3569 expr_lineno (const_tree node)
3571 if (GIMPLE_STMT_P (node))
3572 return LOCATION_LINE (location_from_locus (GIMPLE_STMT_LOCUS (node)));
3573 return LOCATION_LINE (location_from_locus (EXPR_CHECK (node)->exp.locus));
3577 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
3581 build_decl_attribute_variant (tree ddecl, tree attribute)
3583 DECL_ATTRIBUTES (ddecl) = attribute;
3587 /* Borrowed from hashtab.c iterative_hash implementation. */
3588 #define mix(a,b,c) \
3590 a -= b; a -= c; a ^= (c>>13); \
3591 b -= c; b -= a; b ^= (a<< 8); \
3592 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
3593 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
3594 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
3595 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
3596 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
3597 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
3598 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
3602 /* Produce good hash value combining VAL and VAL2. */
3603 static inline hashval_t
3604 iterative_hash_hashval_t (hashval_t val, hashval_t val2)
3606 /* the golden ratio; an arbitrary value. */
3607 hashval_t a = 0x9e3779b9;
3613 /* Produce good hash value combining PTR and VAL2. */
3614 static inline hashval_t
3615 iterative_hash_pointer (const void *ptr, hashval_t val2)
3617 if (sizeof (ptr) == sizeof (hashval_t))
3618 return iterative_hash_hashval_t ((size_t) ptr, val2);
3621 hashval_t a = (hashval_t) (size_t) ptr;
3622 /* Avoid warnings about shifting of more than the width of the type on
3623 hosts that won't execute this path. */
3625 hashval_t b = (hashval_t) ((size_t) ptr >> (sizeof (hashval_t) * 8 + zero));
3631 /* Produce good hash value combining VAL and VAL2. */
3632 static inline hashval_t
3633 iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2)
3635 if (sizeof (HOST_WIDE_INT) == sizeof (hashval_t))
3636 return iterative_hash_hashval_t (val, val2);
3639 hashval_t a = (hashval_t) val;
3640 /* Avoid warnings about shifting of more than the width of the type on
3641 hosts that won't execute this path. */
3643 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 8 + zero));
3645 if (sizeof (HOST_WIDE_INT) > 2 * sizeof (hashval_t))
3647 hashval_t a = (hashval_t) (val >> (sizeof (hashval_t) * 16 + zero));
3648 hashval_t b = (hashval_t) (val >> (sizeof (hashval_t) * 24 + zero));
3655 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3656 is ATTRIBUTE and its qualifiers are QUALS.
3658 Record such modified types already made so we don't make duplicates. */
3661 build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
3663 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
3665 hashval_t hashcode = 0;
3667 enum tree_code code = TREE_CODE (ttype);
3669 /* Building a distinct copy of a tagged type is inappropriate; it
3670 causes breakage in code that expects there to be a one-to-one
3671 relationship between a struct and its fields.
3672 build_duplicate_type is another solution (as used in
3673 handle_transparent_union_attribute), but that doesn't play well
3674 with the stronger C++ type identity model. */
3675 if (TREE_CODE (ttype) == RECORD_TYPE
3676 || TREE_CODE (ttype) == UNION_TYPE
3677 || TREE_CODE (ttype) == QUAL_UNION_TYPE
3678 || TREE_CODE (ttype) == ENUMERAL_TYPE)
3680 warning (OPT_Wattributes,
3681 "ignoring attributes applied to %qT after definition",
3682 TYPE_MAIN_VARIANT (ttype));
3683 return build_qualified_type (ttype, quals);
3686 ntype = build_distinct_type_copy (ttype);
3688 TYPE_ATTRIBUTES (ntype) = attribute;
3689 set_type_quals (ntype, TYPE_UNQUALIFIED);
3691 hashcode = iterative_hash_object (code, hashcode);
3692 if (TREE_TYPE (ntype))
3693 hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype)),
3695 hashcode = attribute_hash_list (attribute, hashcode);
3697 switch (TREE_CODE (ntype))
3700 hashcode = type_hash_list (TYPE_ARG_TYPES (ntype), hashcode);
3703 hashcode = iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype)),
3707 hashcode = iterative_hash_object
3708 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype)), hashcode);
3709 hashcode = iterative_hash_object
3710 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype)), hashcode);
3713 case FIXED_POINT_TYPE:
3715 unsigned int precision = TYPE_PRECISION (ntype);
3716 hashcode = iterative_hash_object (precision, hashcode);
3723 ntype = type_hash_canon (hashcode, ntype);
3725 /* If the target-dependent attributes make NTYPE different from
3726 its canonical type, we will need to use structural equality
3727 checks for this qualified type. */
3728 ttype = build_qualified_type (ttype, TYPE_UNQUALIFIED);
3729 if (TYPE_STRUCTURAL_EQUALITY_P (ttype)
3730 || !targetm.comp_type_attributes (ntype, ttype))
3731 SET_TYPE_STRUCTURAL_EQUALITY (ntype);
3733 TYPE_CANONICAL (ntype) = TYPE_CANONICAL (ttype);
3735 ttype = build_qualified_type (ntype, quals);
3742 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
3745 Record such modified types already made so we don't make duplicates. */
3748 build_type_attribute_variant (tree ttype, tree attribute)
3750 return build_type_attribute_qual_variant (ttype, attribute,
3751 TYPE_QUALS (ttype));
3754 /* Return nonzero if IDENT is a valid name for attribute ATTR,
3757 We try both `text' and `__text__', ATTR may be either one. */
3758 /* ??? It might be a reasonable simplification to require ATTR to be only
3759 `text'. One might then also require attribute lists to be stored in
3760 their canonicalized form. */
3763 is_attribute_with_length_p (const char *attr, int attr_len, const_tree ident)