1 /* Language-independent node constructors for parse phase of GNU compiler.
2 Copyright (C) 1987-2013 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This file contains the low level primitives for operating on tree nodes,
21 including allocation, list operations, interning of identifiers,
22 construction of data type nodes and statement nodes,
23 and construction of type conversion nodes. It also contains
24 tables index by tree code that describe how to take apart
27 It is intended to be language-independent, but occasionally
28 calls language-dependent routines defined (for C) in typecheck.c. */
32 #include "coretypes.h"
39 #include "toplev.h" /* get_random_seed */
42 #include "filenames.h"
45 #include "common/common-target.h"
46 #include "langhooks.h"
47 #include "tree-inline.h"
48 #include "tree-iterator.h"
49 #include "basic-block.h"
50 #include "tree-flow.h"
52 #include "pointer-set.h"
53 #include "tree-pass.h"
54 #include "langhooks-def.h"
55 #include "diagnostic.h"
56 #include "tree-diagnostic.h"
57 #include "tree-pretty-print.h"
63 /* Tree code classes. */
65 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
66 #define END_OF_BASE_TREE_CODES tcc_exceptional,
68 const enum tree_code_class tree_code_type
[] = {
69 #include "all-tree.def"
73 #undef END_OF_BASE_TREE_CODES
75 /* Table indexed by tree code giving number of expression
76 operands beyond the fixed part of the node structure.
77 Not used for types or decls. */
79 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
80 #define END_OF_BASE_TREE_CODES 0,
82 const unsigned char tree_code_length
[] = {
83 #include "all-tree.def"
87 #undef END_OF_BASE_TREE_CODES
89 /* Names of tree components.
90 Used for printing out the tree and error messages. */
91 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
92 #define END_OF_BASE_TREE_CODES "@dummy",
94 const char *const tree_code_name
[] = {
95 #include "all-tree.def"
99 #undef END_OF_BASE_TREE_CODES
101 /* Each tree code class has an associated string representation.
102 These must correspond to the tree_code_class entries. */
104 const char *const tree_code_class_strings
[] =
119 /* obstack.[ch] explicitly declined to prototype this. */
120 extern int _obstack_allocated_p (struct obstack
*h
, void *obj
);
122 /* Statistics-gathering stuff. */
124 static int tree_code_counts
[MAX_TREE_CODES
];
125 int tree_node_counts
[(int) all_kinds
];
126 int tree_node_sizes
[(int) all_kinds
];
128 /* Keep in sync with tree.h:enum tree_node_kind. */
129 static const char * const tree_node_kind_names
[] = {
148 /* Unique id for next decl created. */
149 static GTY(()) int next_decl_uid
;
150 /* Unique id for next type created. */
151 static GTY(()) int next_type_uid
= 1;
152 /* Unique id for next debug decl created. Use negative numbers,
153 to catch erroneous uses. */
154 static GTY(()) int next_debug_decl_uid
;
156 /* Since we cannot rehash a type after it is in the table, we have to
157 keep the hash code. */
159 struct GTY(()) type_hash
{
164 /* Initial size of the hash table (rounded to next prime). */
165 #define TYPE_HASH_INITIAL_SIZE 1000
167 /* Now here is the hash table. When recording a type, it is added to
168 the slot whose index is the hash code. Note that the hash table is
169 used for several kinds of types (function types, array types and
170 array index range types, for now). While all these live in the
171 same table, they are completely independent, and the hash code is
172 computed differently for each of these. */
174 static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash
)))
175 htab_t type_hash_table
;
177 /* Hash table and temporary node for larger integer const values. */
178 static GTY (()) tree int_cst_node
;
179 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
180 htab_t int_cst_hash_table
;
182 /* Hash table for optimization flags and target option flags. Use the same
183 hash table for both sets of options. Nodes for building the current
184 optimization and target option nodes. The assumption is most of the time
185 the options created will already be in the hash table, so we avoid
186 allocating and freeing up a node repeatably. */
187 static GTY (()) tree cl_optimization_node
;
188 static GTY (()) tree cl_target_option_node
;
189 static GTY ((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
190 htab_t cl_option_hash_table
;
192 /* General tree->tree mapping structure for use in hash tables. */
195 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map
)))
196 htab_t debug_expr_for_decl
;
198 static GTY ((if_marked ("tree_decl_map_marked_p"), param_is (struct tree_decl_map
)))
199 htab_t value_expr_for_decl
;
201 static GTY ((if_marked ("tree_vec_map_marked_p"), param_is (struct tree_vec_map
)))
202 htab_t debug_args_for_decl
;
204 static GTY ((if_marked ("tree_priority_map_marked_p"),
205 param_is (struct tree_priority_map
)))
206 htab_t init_priority_for_decl
;
208 static void set_type_quals (tree
, int, tree
);
209 static int type_hash_eq (const void *, const void *);
210 static hashval_t
type_hash_hash (const void *);
211 static hashval_t
int_cst_hash_hash (const void *);
212 static int int_cst_hash_eq (const void *, const void *);
213 static hashval_t
cl_option_hash_hash (const void *);
214 static int cl_option_hash_eq (const void *, const void *);
215 static void print_type_hash_statistics (void);
216 static void print_debug_expr_statistics (void);
217 static void print_value_expr_statistics (void);
218 static int type_hash_marked_p (const void *);
219 static unsigned int type_hash_list (const_tree
, hashval_t
);
220 static unsigned int attribute_hash_list (const_tree
, hashval_t
);
222 tree global_trees
[TI_MAX
];
223 tree integer_types
[itk_none
];
225 unsigned char tree_contains_struct
[MAX_TREE_CODES
][64];
227 /* Number of operands for each OpenMP clause. */
228 unsigned const char omp_clause_num_ops
[] =
230 0, /* OMP_CLAUSE_ERROR */
231 1, /* OMP_CLAUSE_PRIVATE */
232 1, /* OMP_CLAUSE_SHARED */
233 1, /* OMP_CLAUSE_FIRSTPRIVATE */
234 2, /* OMP_CLAUSE_LASTPRIVATE */
235 4, /* OMP_CLAUSE_REDUCTION */
236 1, /* OMP_CLAUSE_COPYIN */
237 1, /* OMP_CLAUSE_COPYPRIVATE */
238 1, /* OMP_CLAUSE_IF */
239 1, /* OMP_CLAUSE_NUM_THREADS */
240 1, /* OMP_CLAUSE_SCHEDULE */
241 0, /* OMP_CLAUSE_NOWAIT */
242 0, /* OMP_CLAUSE_ORDERED */
243 0, /* OMP_CLAUSE_DEFAULT */
244 3, /* OMP_CLAUSE_COLLAPSE */
245 0, /* OMP_CLAUSE_UNTIED */
246 1, /* OMP_CLAUSE_FINAL */
247 0 /* OMP_CLAUSE_MERGEABLE */
250 const char * const omp_clause_code_name
[] =
273 /* Return the tree node structure used by tree code CODE. */
275 static inline enum tree_node_structure_enum
276 tree_node_structure_for_code (enum tree_code code
)
278 switch (TREE_CODE_CLASS (code
))
280 case tcc_declaration
:
285 return TS_FIELD_DECL
;
291 return TS_LABEL_DECL
;
293 return TS_RESULT_DECL
;
294 case DEBUG_EXPR_DECL
:
297 return TS_CONST_DECL
;
301 return TS_FUNCTION_DECL
;
302 case TRANSLATION_UNIT_DECL
:
303 return TS_TRANSLATION_UNIT_DECL
;
305 return TS_DECL_NON_COMMON
;
309 return TS_TYPE_NON_COMMON
;
318 default: /* tcc_constant and tcc_exceptional */
323 /* tcc_constant cases. */
324 case INTEGER_CST
: return TS_INT_CST
;
325 case REAL_CST
: return TS_REAL_CST
;
326 case FIXED_CST
: return TS_FIXED_CST
;
327 case COMPLEX_CST
: return TS_COMPLEX
;
328 case VECTOR_CST
: return TS_VECTOR
;
329 case STRING_CST
: return TS_STRING
;
330 /* tcc_exceptional cases. */
331 case ERROR_MARK
: return TS_COMMON
;
332 case IDENTIFIER_NODE
: return TS_IDENTIFIER
;
333 case TREE_LIST
: return TS_LIST
;
334 case TREE_VEC
: return TS_VEC
;
335 case SSA_NAME
: return TS_SSA_NAME
;
336 case PLACEHOLDER_EXPR
: return TS_COMMON
;
337 case STATEMENT_LIST
: return TS_STATEMENT_LIST
;
338 case BLOCK
: return TS_BLOCK
;
339 case CONSTRUCTOR
: return TS_CONSTRUCTOR
;
340 case TREE_BINFO
: return TS_BINFO
;
341 case OMP_CLAUSE
: return TS_OMP_CLAUSE
;
342 case OPTIMIZATION_NODE
: return TS_OPTIMIZATION
;
343 case TARGET_OPTION_NODE
: return TS_TARGET_OPTION
;
351 /* Initialize tree_contains_struct to describe the hierarchy of tree
355 initialize_tree_contains_struct (void)
359 for (i
= ERROR_MARK
; i
< LAST_AND_UNUSED_TREE_CODE
; i
++)
362 enum tree_node_structure_enum ts_code
;
364 code
= (enum tree_code
) i
;
365 ts_code
= tree_node_structure_for_code (code
);
367 /* Mark the TS structure itself. */
368 tree_contains_struct
[code
][ts_code
] = 1;
370 /* Mark all the structures that TS is derived from. */
388 case TS_STATEMENT_LIST
:
389 MARK_TS_TYPED (code
);
393 case TS_DECL_MINIMAL
:
399 case TS_OPTIMIZATION
:
400 case TS_TARGET_OPTION
:
401 MARK_TS_COMMON (code
);
404 case TS_TYPE_WITH_LANG_SPECIFIC
:
405 MARK_TS_TYPE_COMMON (code
);
408 case TS_TYPE_NON_COMMON
:
409 MARK_TS_TYPE_WITH_LANG_SPECIFIC (code
);
413 MARK_TS_DECL_MINIMAL (code
);
418 MARK_TS_DECL_COMMON (code
);
421 case TS_DECL_NON_COMMON
:
422 MARK_TS_DECL_WITH_VIS (code
);
425 case TS_DECL_WITH_VIS
:
429 MARK_TS_DECL_WRTL (code
);
433 MARK_TS_DECL_COMMON (code
);
437 MARK_TS_DECL_WITH_VIS (code
);
441 case TS_FUNCTION_DECL
:
442 MARK_TS_DECL_NON_COMMON (code
);
445 case TS_TRANSLATION_UNIT_DECL
:
446 MARK_TS_DECL_COMMON (code
);
454 /* Basic consistency checks for attributes used in fold. */
455 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_NON_COMMON
]);
456 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_NON_COMMON
]);
457 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_COMMON
]);
458 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_COMMON
]);
459 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_COMMON
]);
460 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_COMMON
]);
461 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_COMMON
]);
462 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_COMMON
]);
463 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_COMMON
]);
464 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_COMMON
]);
465 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_COMMON
]);
466 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WRTL
]);
467 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_WRTL
]);
468 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_WRTL
]);
469 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WRTL
]);
470 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_WRTL
]);
471 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_DECL_MINIMAL
]);
472 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_MINIMAL
]);
473 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_DECL_MINIMAL
]);
474 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_DECL_MINIMAL
]);
475 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_MINIMAL
]);
476 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_MINIMAL
]);
477 gcc_assert (tree_contains_struct
[TRANSLATION_UNIT_DECL
][TS_DECL_MINIMAL
]);
478 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_DECL_MINIMAL
]);
479 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_DECL_MINIMAL
]);
480 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_DECL_WITH_VIS
]);
481 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_DECL_WITH_VIS
]);
482 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_DECL_WITH_VIS
]);
483 gcc_assert (tree_contains_struct
[VAR_DECL
][TS_VAR_DECL
]);
484 gcc_assert (tree_contains_struct
[FIELD_DECL
][TS_FIELD_DECL
]);
485 gcc_assert (tree_contains_struct
[PARM_DECL
][TS_PARM_DECL
]);
486 gcc_assert (tree_contains_struct
[LABEL_DECL
][TS_LABEL_DECL
]);
487 gcc_assert (tree_contains_struct
[RESULT_DECL
][TS_RESULT_DECL
]);
488 gcc_assert (tree_contains_struct
[CONST_DECL
][TS_CONST_DECL
]);
489 gcc_assert (tree_contains_struct
[TYPE_DECL
][TS_TYPE_DECL
]);
490 gcc_assert (tree_contains_struct
[FUNCTION_DECL
][TS_FUNCTION_DECL
]);
491 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_MINIMAL
]);
492 gcc_assert (tree_contains_struct
[IMPORTED_DECL
][TS_DECL_COMMON
]);
501 /* Initialize the hash table of types. */
502 type_hash_table
= htab_create_ggc (TYPE_HASH_INITIAL_SIZE
, type_hash_hash
,
505 debug_expr_for_decl
= htab_create_ggc (512, tree_decl_map_hash
,
506 tree_decl_map_eq
, 0);
508 value_expr_for_decl
= htab_create_ggc (512, tree_decl_map_hash
,
509 tree_decl_map_eq
, 0);
510 init_priority_for_decl
= htab_create_ggc (512, tree_priority_map_hash
,
511 tree_priority_map_eq
, 0);
513 int_cst_hash_table
= htab_create_ggc (1024, int_cst_hash_hash
,
514 int_cst_hash_eq
, NULL
);
516 int_cst_node
= make_node (INTEGER_CST
);
518 cl_option_hash_table
= htab_create_ggc (64, cl_option_hash_hash
,
519 cl_option_hash_eq
, NULL
);
521 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
522 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
524 /* Initialize the tree_contains_struct array. */
525 initialize_tree_contains_struct ();
526 lang_hooks
.init_ts ();
530 /* The name of the object as the assembler will see it (but before any
531 translations made by ASM_OUTPUT_LABELREF). Often this is the same
532 as DECL_NAME. It is an IDENTIFIER_NODE. */
534 decl_assembler_name (tree decl
)
536 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
537 lang_hooks
.set_decl_assembler_name (decl
);
538 return DECL_WITH_VIS_CHECK (decl
)->decl_with_vis
.assembler_name
;
541 /* Compare ASMNAME with the DECL_ASSEMBLER_NAME of DECL. */
544 decl_assembler_name_equal (tree decl
, const_tree asmname
)
546 tree decl_asmname
= DECL_ASSEMBLER_NAME (decl
);
547 const char *decl_str
;
548 const char *asmname_str
;
551 if (decl_asmname
== asmname
)
554 decl_str
= IDENTIFIER_POINTER (decl_asmname
);
555 asmname_str
= IDENTIFIER_POINTER (asmname
);
558 /* If the target assembler name was set by the user, things are trickier.
559 We have a leading '*' to begin with. After that, it's arguable what
560 is the correct thing to do with -fleading-underscore. Arguably, we've
561 historically been doing the wrong thing in assemble_alias by always
562 printing the leading underscore. Since we're not changing that, make
563 sure user_label_prefix follows the '*' before matching. */
564 if (decl_str
[0] == '*')
566 size_t ulp_len
= strlen (user_label_prefix
);
572 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
573 decl_str
+= ulp_len
, test
=true;
577 if (asmname_str
[0] == '*')
579 size_t ulp_len
= strlen (user_label_prefix
);
585 else if (strncmp (asmname_str
, user_label_prefix
, ulp_len
) == 0)
586 asmname_str
+= ulp_len
, test
=true;
593 return strcmp (decl_str
, asmname_str
) == 0;
596 /* Hash asmnames ignoring the user specified marks. */
599 decl_assembler_name_hash (const_tree asmname
)
601 if (IDENTIFIER_POINTER (asmname
)[0] == '*')
603 const char *decl_str
= IDENTIFIER_POINTER (asmname
) + 1;
604 size_t ulp_len
= strlen (user_label_prefix
);
608 else if (strncmp (decl_str
, user_label_prefix
, ulp_len
) == 0)
611 return htab_hash_string (decl_str
);
614 return htab_hash_string (IDENTIFIER_POINTER (asmname
));
617 /* Compute the number of bytes occupied by a tree with code CODE.
618 This function cannot be used for nodes that have variable sizes,
619 including TREE_VEC, STRING_CST, and CALL_EXPR. */
621 tree_code_size (enum tree_code code
)
623 switch (TREE_CODE_CLASS (code
))
625 case tcc_declaration
: /* A decl node */
630 return sizeof (struct tree_field_decl
);
632 return sizeof (struct tree_parm_decl
);
634 return sizeof (struct tree_var_decl
);
636 return sizeof (struct tree_label_decl
);
638 return sizeof (struct tree_result_decl
);
640 return sizeof (struct tree_const_decl
);
642 return sizeof (struct tree_type_decl
);
644 return sizeof (struct tree_function_decl
);
645 case DEBUG_EXPR_DECL
:
646 return sizeof (struct tree_decl_with_rtl
);
648 return sizeof (struct tree_decl_non_common
);
652 case tcc_type
: /* a type node */
653 return sizeof (struct tree_type_non_common
);
655 case tcc_reference
: /* a reference */
656 case tcc_expression
: /* an expression */
657 case tcc_statement
: /* an expression with side effects */
658 case tcc_comparison
: /* a comparison expression */
659 case tcc_unary
: /* a unary arithmetic expression */
660 case tcc_binary
: /* a binary arithmetic expression */
661 return (sizeof (struct tree_exp
)
662 + (TREE_CODE_LENGTH (code
) - 1) * sizeof (tree
));
664 case tcc_constant
: /* a constant */
667 case INTEGER_CST
: return sizeof (struct tree_int_cst
);
668 case REAL_CST
: return sizeof (struct tree_real_cst
);
669 case FIXED_CST
: return sizeof (struct tree_fixed_cst
);
670 case COMPLEX_CST
: return sizeof (struct tree_complex
);
671 case VECTOR_CST
: return sizeof (struct tree_vector
);
672 case STRING_CST
: gcc_unreachable ();
674 return lang_hooks
.tree_size (code
);
677 case tcc_exceptional
: /* something random, like an identifier. */
680 case IDENTIFIER_NODE
: return lang_hooks
.identifier_size
;
681 case TREE_LIST
: return sizeof (struct tree_list
);
684 case PLACEHOLDER_EXPR
: return sizeof (struct tree_common
);
687 case OMP_CLAUSE
: gcc_unreachable ();
689 case SSA_NAME
: return sizeof (struct tree_ssa_name
);
691 case STATEMENT_LIST
: return sizeof (struct tree_statement_list
);
692 case BLOCK
: return sizeof (struct tree_block
);
693 case CONSTRUCTOR
: return sizeof (struct tree_constructor
);
694 case OPTIMIZATION_NODE
: return sizeof (struct tree_optimization_option
);
695 case TARGET_OPTION_NODE
: return sizeof (struct tree_target_option
);
698 return lang_hooks
.tree_size (code
);
706 /* Compute the number of bytes occupied by NODE. This routine only
707 looks at TREE_CODE, except for those nodes that have variable sizes. */
709 tree_size (const_tree node
)
711 const enum tree_code code
= TREE_CODE (node
);
715 return (offsetof (struct tree_binfo
, base_binfos
)
717 ::embedded_size (BINFO_N_BASE_BINFOS (node
)));
720 return (sizeof (struct tree_vec
)
721 + (TREE_VEC_LENGTH (node
) - 1) * sizeof (tree
));
724 return (sizeof (struct tree_vector
)
725 + (TYPE_VECTOR_SUBPARTS (TREE_TYPE (node
)) - 1) * sizeof (tree
));
728 return TREE_STRING_LENGTH (node
) + offsetof (struct tree_string
, str
) + 1;
731 return (sizeof (struct tree_omp_clause
)
732 + (omp_clause_num_ops
[OMP_CLAUSE_CODE (node
)] - 1)
736 if (TREE_CODE_CLASS (code
) == tcc_vl_exp
)
737 return (sizeof (struct tree_exp
)
738 + (VL_EXP_OPERAND_LENGTH (node
) - 1) * sizeof (tree
));
740 return tree_code_size (code
);
744 /* Record interesting allocation statistics for a tree node with CODE
748 record_node_allocation_statistics (enum tree_code code ATTRIBUTE_UNUSED
,
749 size_t length ATTRIBUTE_UNUSED
)
751 enum tree_code_class type
= TREE_CODE_CLASS (code
);
754 if (!GATHER_STATISTICS
)
759 case tcc_declaration
: /* A decl node */
763 case tcc_type
: /* a type node */
767 case tcc_statement
: /* an expression with side effects */
771 case tcc_reference
: /* a reference */
775 case tcc_expression
: /* an expression */
776 case tcc_comparison
: /* a comparison expression */
777 case tcc_unary
: /* a unary arithmetic expression */
778 case tcc_binary
: /* a binary arithmetic expression */
782 case tcc_constant
: /* a constant */
786 case tcc_exceptional
: /* something random, like an identifier. */
789 case IDENTIFIER_NODE
:
802 kind
= ssa_name_kind
;
814 kind
= omp_clause_kind
;
831 tree_code_counts
[(int) code
]++;
832 tree_node_counts
[(int) kind
]++;
833 tree_node_sizes
[(int) kind
] += length
;
836 /* Allocate and return a new UID from the DECL_UID namespace. */
839 allocate_decl_uid (void)
841 return next_decl_uid
++;
844 /* Return a newly allocated node of code CODE. For decl and type
845 nodes, some other fields are initialized. The rest of the node is
846 initialized to zero. This function cannot be used for TREE_VEC or
847 OMP_CLAUSE nodes, which is enforced by asserts in tree_code_size.
849 Achoo! I got a code in the node. */
852 make_node_stat (enum tree_code code MEM_STAT_DECL
)
855 enum tree_code_class type
= TREE_CODE_CLASS (code
);
856 size_t length
= tree_code_size (code
);
858 record_node_allocation_statistics (code
, length
);
860 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
861 TREE_SET_CODE (t
, code
);
866 TREE_SIDE_EFFECTS (t
) = 1;
869 case tcc_declaration
:
870 if (CODE_CONTAINS_STRUCT (code
, TS_DECL_COMMON
))
872 if (code
== FUNCTION_DECL
)
874 DECL_ALIGN (t
) = FUNCTION_BOUNDARY
;
875 DECL_MODE (t
) = FUNCTION_MODE
;
880 DECL_SOURCE_LOCATION (t
) = input_location
;
881 if (TREE_CODE (t
) == DEBUG_EXPR_DECL
)
882 DECL_UID (t
) = --next_debug_decl_uid
;
885 DECL_UID (t
) = allocate_decl_uid ();
886 SET_DECL_PT_UID (t
, -1);
888 if (TREE_CODE (t
) == LABEL_DECL
)
889 LABEL_DECL_UID (t
) = -1;
894 TYPE_UID (t
) = next_type_uid
++;
895 TYPE_ALIGN (t
) = BITS_PER_UNIT
;
896 TYPE_USER_ALIGN (t
) = 0;
897 TYPE_MAIN_VARIANT (t
) = t
;
898 TYPE_CANONICAL (t
) = t
;
900 /* Default to no attributes for type, but let target change that. */
901 TYPE_ATTRIBUTES (t
) = NULL_TREE
;
902 targetm
.set_default_type_attributes (t
);
904 /* We have not yet computed the alias set for this type. */
905 TYPE_ALIAS_SET (t
) = -1;
909 TREE_CONSTANT (t
) = 1;
918 case PREDECREMENT_EXPR
:
919 case PREINCREMENT_EXPR
:
920 case POSTDECREMENT_EXPR
:
921 case POSTINCREMENT_EXPR
:
922 /* All of these have side-effects, no matter what their
924 TREE_SIDE_EFFECTS (t
) = 1;
933 /* Other classes need no special treatment. */
940 /* Return a new node with the same contents as NODE except that its
941 TREE_CHAIN, if it has one, is zero and it has a fresh uid. */
944 copy_node_stat (tree node MEM_STAT_DECL
)
947 enum tree_code code
= TREE_CODE (node
);
950 gcc_assert (code
!= STATEMENT_LIST
);
952 length
= tree_size (node
);
953 record_node_allocation_statistics (code
, length
);
954 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
955 memcpy (t
, node
, length
);
957 if (CODE_CONTAINS_STRUCT (code
, TS_COMMON
))
959 TREE_ASM_WRITTEN (t
) = 0;
960 TREE_VISITED (t
) = 0;
962 if (TREE_CODE_CLASS (code
) == tcc_declaration
)
964 if (code
== DEBUG_EXPR_DECL
)
965 DECL_UID (t
) = --next_debug_decl_uid
;
968 DECL_UID (t
) = allocate_decl_uid ();
969 if (DECL_PT_UID_SET_P (node
))
970 SET_DECL_PT_UID (t
, DECL_PT_UID (node
));
972 if ((TREE_CODE (node
) == PARM_DECL
|| TREE_CODE (node
) == VAR_DECL
)
973 && DECL_HAS_VALUE_EXPR_P (node
))
975 SET_DECL_VALUE_EXPR (t
, DECL_VALUE_EXPR (node
));
976 DECL_HAS_VALUE_EXPR_P (t
) = 1;
978 /* DECL_DEBUG_EXPR is copied explicitely by callers. */
979 if (TREE_CODE (node
) == VAR_DECL
)
980 DECL_HAS_DEBUG_EXPR_P (t
) = 0;
981 if (TREE_CODE (node
) == VAR_DECL
&& DECL_HAS_INIT_PRIORITY_P (node
))
983 SET_DECL_INIT_PRIORITY (t
, DECL_INIT_PRIORITY (node
));
984 DECL_HAS_INIT_PRIORITY_P (t
) = 1;
986 if (TREE_CODE (node
) == FUNCTION_DECL
)
987 DECL_STRUCT_FUNCTION (t
) = NULL
;
989 else if (TREE_CODE_CLASS (code
) == tcc_type
)
991 TYPE_UID (t
) = next_type_uid
++;
992 /* The following is so that the debug code for
993 the copy is different from the original type.
994 The two statements usually duplicate each other
995 (because they clear fields of the same union),
996 but the optimizer should catch that. */
997 TYPE_SYMTAB_POINTER (t
) = 0;
998 TYPE_SYMTAB_ADDRESS (t
) = 0;
1000 /* Do not copy the values cache. */
1001 if (TYPE_CACHED_VALUES_P(t
))
1003 TYPE_CACHED_VALUES_P (t
) = 0;
1004 TYPE_CACHED_VALUES (t
) = NULL_TREE
;
1007 if (TYPE_HAS_BLOCK_FACTOR (node
))
1008 SET_TYPE_BLOCK_FACTOR (t
, TYPE_BLOCK_FACTOR (node
));
1014 /* Return a copy of a chain of nodes, chained through the TREE_CHAIN field.
1015 For example, this can copy a list made of TREE_LIST nodes. */
1018 copy_list (tree list
)
1026 head
= prev
= copy_node (list
);
1027 next
= TREE_CHAIN (list
);
1030 TREE_CHAIN (prev
) = copy_node (next
);
1031 prev
= TREE_CHAIN (prev
);
1032 next
= TREE_CHAIN (next
);
1038 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1041 build_int_cst (tree type
, HOST_WIDE_INT low
)
1043 /* Support legacy code. */
1045 type
= integer_type_node
;
1047 return double_int_to_tree (type
, double_int::from_shwi (low
));
1050 /* Create an INT_CST node with a LOW value sign extended to TYPE. */
1053 build_int_cst_type (tree type
, HOST_WIDE_INT low
)
1057 return double_int_to_tree (type
, double_int::from_shwi (low
));
1060 /* Constructs tree in type TYPE from with value given by CST. Signedness
1061 of CST is assumed to be the same as the signedness of TYPE. */
1064 double_int_to_tree (tree type
, double_int cst
)
1066 bool sign_extended_type
= !TYPE_UNSIGNED (type
);
1068 cst
= cst
.ext (TYPE_PRECISION (type
), !sign_extended_type
);
1070 return build_int_cst_wide (type
, cst
.low
, cst
.high
);
1073 /* Returns true if CST fits into range of TYPE. Signedness of CST is assumed
1074 to be the same as the signedness of TYPE. */
1077 double_int_fits_to_tree_p (const_tree type
, double_int cst
)
1079 bool sign_extended_type
= !TYPE_UNSIGNED (type
);
1082 = cst
.ext (TYPE_PRECISION (type
), !sign_extended_type
);
1087 /* We force the double_int CST to the range of the type TYPE by sign or
1088 zero extending it. OVERFLOWABLE indicates if we are interested in
1089 overflow of the value, when >0 we are only interested in signed
1090 overflow, for <0 we are interested in any overflow. OVERFLOWED
1091 indicates whether overflow has already occurred. CONST_OVERFLOWED
1092 indicates whether constant overflow has already occurred. We force
1093 T's value to be within range of T's type (by setting to 0 or 1 all
1094 the bits outside the type's range). We set TREE_OVERFLOWED if,
1095 OVERFLOWED is nonzero,
1096 or OVERFLOWABLE is >0 and signed overflow occurs
1097 or OVERFLOWABLE is <0 and any overflow occurs
1098 We return a new tree node for the extended double_int. The node
1099 is shared if no overflow flags are set. */
1103 force_fit_type_double (tree type
, double_int cst
, int overflowable
,
1106 bool sign_extended_type
= !TYPE_UNSIGNED (type
);
1108 /* If we need to set overflow flags, return a new unshared node. */
1109 if (overflowed
|| !double_int_fits_to_tree_p(type
, cst
))
1113 || (overflowable
> 0 && sign_extended_type
))
1115 tree t
= make_node (INTEGER_CST
);
1117 = cst
.ext (TYPE_PRECISION (type
), !sign_extended_type
);
1118 TREE_TYPE (t
) = type
;
1119 TREE_OVERFLOW (t
) = 1;
1124 /* Else build a shared node. */
1125 return double_int_to_tree (type
, cst
);
1128 /* These are the hash table functions for the hash table of INTEGER_CST
1129 nodes of a sizetype. */
1131 /* Return the hash code code X, an INTEGER_CST. */
1134 int_cst_hash_hash (const void *x
)
1136 const_tree
const t
= (const_tree
) x
;
1138 return (TREE_INT_CST_HIGH (t
) ^ TREE_INT_CST_LOW (t
)
1139 ^ htab_hash_pointer (TREE_TYPE (t
)));
1142 /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
1143 is the same as that given by *Y, which is the same. */
1146 int_cst_hash_eq (const void *x
, const void *y
)
1148 const_tree
const xt
= (const_tree
) x
;
1149 const_tree
const yt
= (const_tree
) y
;
1151 return (TREE_TYPE (xt
) == TREE_TYPE (yt
)
1152 && TREE_INT_CST_HIGH (xt
) == TREE_INT_CST_HIGH (yt
)
1153 && TREE_INT_CST_LOW (xt
) == TREE_INT_CST_LOW (yt
));
1156 /* Create an INT_CST node of TYPE and value HI:LOW.
1157 The returned node is always shared. For small integers we use a
1158 per-type vector cache, for larger ones we use a single hash table. */
1161 build_int_cst_wide (tree type
, unsigned HOST_WIDE_INT low
, HOST_WIDE_INT hi
)
1169 switch (TREE_CODE (type
))
1172 gcc_assert (hi
== 0 && low
== 0);
1176 case REFERENCE_TYPE
:
1177 /* Cache NULL pointer. */
1186 /* Cache false or true. */
1194 if (TYPE_UNSIGNED (type
))
1197 limit
= INTEGER_SHARE_LIMIT
;
1198 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1204 limit
= INTEGER_SHARE_LIMIT
+ 1;
1205 if (!hi
&& low
< (unsigned HOST_WIDE_INT
)INTEGER_SHARE_LIMIT
)
1207 else if (hi
== -1 && low
== -(unsigned HOST_WIDE_INT
)1)
1221 /* Look for it in the type's vector of small shared ints. */
1222 if (!TYPE_CACHED_VALUES_P (type
))
1224 TYPE_CACHED_VALUES_P (type
) = 1;
1225 TYPE_CACHED_VALUES (type
) = make_tree_vec (limit
);
1228 t
= TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
);
1231 /* Make sure no one is clobbering the shared constant. */
1232 gcc_assert (TREE_TYPE (t
) == type
);
1233 gcc_assert (TREE_INT_CST_LOW (t
) == low
);
1234 gcc_assert (TREE_INT_CST_HIGH (t
) == hi
);
1238 /* Create a new shared int. */
1239 t
= make_node (INTEGER_CST
);
1241 TREE_INT_CST_LOW (t
) = low
;
1242 TREE_INT_CST_HIGH (t
) = hi
;
1243 TREE_TYPE (t
) = type
;
1245 TREE_VEC_ELT (TYPE_CACHED_VALUES (type
), ix
) = t
;
1250 /* Use the cache of larger shared ints. */
1253 TREE_INT_CST_LOW (int_cst_node
) = low
;
1254 TREE_INT_CST_HIGH (int_cst_node
) = hi
;
1255 TREE_TYPE (int_cst_node
) = type
;
1257 slot
= htab_find_slot (int_cst_hash_table
, int_cst_node
, INSERT
);
1261 /* Insert this one into the hash table. */
1264 /* Make a new node for next time round. */
1265 int_cst_node
= make_node (INTEGER_CST
);
1272 /* Builds an integer constant in TYPE such that lowest BITS bits are ones
1273 and the rest are zeros. */
1276 build_low_bits_mask (tree type
, unsigned bits
)
1280 gcc_assert (bits
<= TYPE_PRECISION (type
));
1282 if (bits
== TYPE_PRECISION (type
)
1283 && !TYPE_UNSIGNED (type
))
1284 /* Sign extended all-ones mask. */
1285 mask
= double_int_minus_one
;
1287 mask
= double_int::mask (bits
);
1289 return build_int_cst_wide (type
, mask
.low
, mask
.high
);
1292 /* Checks that X is integer constant that can be expressed in (unsigned)
1293 HOST_WIDE_INT without loss of precision. */
1296 cst_and_fits_in_hwi (const_tree x
)
1298 if (TREE_CODE (x
) != INTEGER_CST
)
1301 if (TYPE_PRECISION (TREE_TYPE (x
)) > HOST_BITS_PER_WIDE_INT
)
1304 return (TREE_INT_CST_HIGH (x
) == 0
1305 || TREE_INT_CST_HIGH (x
) == -1);
1308 /* Build a newly constructed TREE_VEC node of length LEN. */
1311 make_vector_stat (unsigned len MEM_STAT_DECL
)
1314 unsigned length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vector
);
1316 record_node_allocation_statistics (VECTOR_CST
, length
);
1318 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
1320 TREE_SET_CODE (t
, VECTOR_CST
);
1321 TREE_CONSTANT (t
) = 1;
1326 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1327 are in a list pointed to by VALS. */
1330 build_vector_stat (tree type
, tree
*vals MEM_STAT_DECL
)
1334 tree v
= make_vector (TYPE_VECTOR_SUBPARTS (type
));
1335 TREE_TYPE (v
) = type
;
1337 /* Iterate through elements and check for overflow. */
1338 for (cnt
= 0; cnt
< TYPE_VECTOR_SUBPARTS (type
); ++cnt
)
1340 tree value
= vals
[cnt
];
1342 VECTOR_CST_ELT (v
, cnt
) = value
;
1344 /* Don't crash if we get an address constant. */
1345 if (!CONSTANT_CLASS_P (value
))
1348 over
|= TREE_OVERFLOW (value
);
1351 TREE_OVERFLOW (v
) = over
;
1355 /* Return a new VECTOR_CST node whose type is TYPE and whose values
1356 are extracted from V, a vector of CONSTRUCTOR_ELT. */
1359 build_vector_from_ctor (tree type
, vec
<constructor_elt
, va_gc
> *v
)
1361 tree
*vec
= XALLOCAVEC (tree
, TYPE_VECTOR_SUBPARTS (type
));
1362 unsigned HOST_WIDE_INT idx
;
1365 FOR_EACH_CONSTRUCTOR_VALUE (v
, idx
, value
)
1367 for (; idx
< TYPE_VECTOR_SUBPARTS (type
); ++idx
)
1368 vec
[idx
] = build_zero_cst (TREE_TYPE (type
));
1370 return build_vector (type
, vec
);
1373 /* Build a vector of type VECTYPE where all the elements are SCs. */
1375 build_vector_from_val (tree vectype
, tree sc
)
1377 int i
, nunits
= TYPE_VECTOR_SUBPARTS (vectype
);
1379 if (sc
== error_mark_node
)
1382 /* Verify that the vector type is suitable for SC. Note that there
1383 is some inconsistency in the type-system with respect to restrict
1384 qualifications of pointers. Vector types always have a main-variant
1385 element type and the qualification is applied to the vector-type.
1386 So TREE_TYPE (vector-type) does not return a properly qualified
1387 vector element-type. */
1388 gcc_checking_assert (types_compatible_p (TYPE_MAIN_VARIANT (TREE_TYPE (sc
)),
1389 TREE_TYPE (vectype
)));
1391 if (CONSTANT_CLASS_P (sc
))
1393 tree
*v
= XALLOCAVEC (tree
, nunits
);
1394 for (i
= 0; i
< nunits
; ++i
)
1396 return build_vector (vectype
, v
);
1400 vec
<constructor_elt
, va_gc
> *v
;
1401 vec_alloc (v
, nunits
);
1402 for (i
= 0; i
< nunits
; ++i
)
1403 CONSTRUCTOR_APPEND_ELT (v
, NULL_TREE
, sc
);
1404 return build_constructor (vectype
, v
);
1408 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1409 are in the vec pointed to by VALS. */
1411 build_constructor (tree type
, vec
<constructor_elt
, va_gc
> *vals
)
1413 tree c
= make_node (CONSTRUCTOR
);
1415 constructor_elt
*elt
;
1416 bool constant_p
= true;
1417 bool side_effects_p
= false;
1419 TREE_TYPE (c
) = type
;
1420 CONSTRUCTOR_ELTS (c
) = vals
;
1422 FOR_EACH_VEC_SAFE_ELT (vals
, i
, elt
)
1424 /* Mostly ctors will have elts that don't have side-effects, so
1425 the usual case is to scan all the elements. Hence a single
1426 loop for both const and side effects, rather than one loop
1427 each (with early outs). */
1428 if (!TREE_CONSTANT (elt
->value
))
1430 if (TREE_SIDE_EFFECTS (elt
->value
))
1431 side_effects_p
= true;
1434 TREE_SIDE_EFFECTS (c
) = side_effects_p
;
1435 TREE_CONSTANT (c
) = constant_p
;
1440 /* Build a CONSTRUCTOR node made of a single initializer, with the specified
1443 build_constructor_single (tree type
, tree index
, tree value
)
1445 vec
<constructor_elt
, va_gc
> *v
;
1446 constructor_elt elt
= {index
, value
};
1449 v
->quick_push (elt
);
1451 return build_constructor (type
, v
);
1455 /* Return a new CONSTRUCTOR node whose type is TYPE and whose values
1456 are in a list pointed to by VALS. */
1458 build_constructor_from_list (tree type
, tree vals
)
1461 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1465 vec_alloc (v
, list_length (vals
));
1466 for (t
= vals
; t
; t
= TREE_CHAIN (t
))
1467 CONSTRUCTOR_APPEND_ELT (v
, TREE_PURPOSE (t
), TREE_VALUE (t
));
1470 return build_constructor (type
, v
);
1473 /* Return a new CONSTRUCTOR node whose type is TYPE. NELTS is the number
1474 of elements, provided as index/value pairs. */
1477 build_constructor_va (tree type
, int nelts
, ...)
1479 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1482 va_start (p
, nelts
);
1483 vec_alloc (v
, nelts
);
1486 tree index
= va_arg (p
, tree
);
1487 tree value
= va_arg (p
, tree
);
1488 CONSTRUCTOR_APPEND_ELT (v
, index
, value
);
1491 return build_constructor (type
, v
);
1494 /* Return a new FIXED_CST node whose type is TYPE and value is F. */
1497 build_fixed (tree type
, FIXED_VALUE_TYPE f
)
1500 FIXED_VALUE_TYPE
*fp
;
1502 v
= make_node (FIXED_CST
);
1503 fp
= ggc_alloc_fixed_value ();
1504 memcpy (fp
, &f
, sizeof (FIXED_VALUE_TYPE
));
1506 TREE_TYPE (v
) = type
;
1507 TREE_FIXED_CST_PTR (v
) = fp
;
1511 /* Return a new REAL_CST node whose type is TYPE and value is D. */
1514 build_real (tree type
, REAL_VALUE_TYPE d
)
1517 REAL_VALUE_TYPE
*dp
;
1520 /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE.
1521 Consider doing it via real_convert now. */
1523 v
= make_node (REAL_CST
);
1524 dp
= ggc_alloc_real_value ();
1525 memcpy (dp
, &d
, sizeof (REAL_VALUE_TYPE
));
1527 TREE_TYPE (v
) = type
;
1528 TREE_REAL_CST_PTR (v
) = dp
;
1529 TREE_OVERFLOW (v
) = overflow
;
1533 /* Return a new REAL_CST node whose type is TYPE
1534 and whose value is the integer value of the INTEGER_CST node I. */
1537 real_value_from_int_cst (const_tree type
, const_tree i
)
1541 /* Clear all bits of the real value type so that we can later do
1542 bitwise comparisons to see if two values are the same. */
1543 memset (&d
, 0, sizeof d
);
1545 real_from_integer (&d
, type
? TYPE_MODE (type
) : VOIDmode
,
1546 TREE_INT_CST_LOW (i
), TREE_INT_CST_HIGH (i
),
1547 TYPE_UNSIGNED (TREE_TYPE (i
)));
1551 /* Given a tree representing an integer constant I, return a tree
1552 representing the same value as a floating-point constant of type TYPE. */
1555 build_real_from_int_cst (tree type
, const_tree i
)
1558 int overflow
= TREE_OVERFLOW (i
);
1560 v
= build_real (type
, real_value_from_int_cst (type
, i
));
1562 TREE_OVERFLOW (v
) |= overflow
;
1566 /* Return a newly constructed STRING_CST node whose value is
1567 the LEN characters at STR.
1568 Note that for a C string literal, LEN should include the trailing NUL.
1569 The TREE_TYPE is not initialized. */
1572 build_string (int len
, const char *str
)
1577 /* Do not waste bytes provided by padding of struct tree_string. */
1578 length
= len
+ offsetof (struct tree_string
, str
) + 1;
1580 record_node_allocation_statistics (STRING_CST
, length
);
1582 s
= ggc_alloc_tree_node (length
);
1584 memset (s
, 0, sizeof (struct tree_typed
));
1585 TREE_SET_CODE (s
, STRING_CST
);
1586 TREE_CONSTANT (s
) = 1;
1587 TREE_STRING_LENGTH (s
) = len
;
1588 memcpy (s
->string
.str
, str
, len
);
1589 s
->string
.str
[len
] = '\0';
1594 /* Return a newly constructed COMPLEX_CST node whose value is
1595 specified by the real and imaginary parts REAL and IMAG.
1596 Both REAL and IMAG should be constant nodes. TYPE, if specified,
1597 will be the type of the COMPLEX_CST; otherwise a new type will be made. */
1600 build_complex (tree type
, tree real
, tree imag
)
1602 tree t
= make_node (COMPLEX_CST
);
1604 TREE_REALPART (t
) = real
;
1605 TREE_IMAGPART (t
) = imag
;
1606 TREE_TYPE (t
) = type
? type
: build_complex_type (TREE_TYPE (real
));
1607 TREE_OVERFLOW (t
) = TREE_OVERFLOW (real
) | TREE_OVERFLOW (imag
);
1611 /* Return a constant of arithmetic type TYPE which is the
1612 multiplicative identity of the set TYPE. */
1615 build_one_cst (tree type
)
1617 switch (TREE_CODE (type
))
1619 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1620 case POINTER_TYPE
: case REFERENCE_TYPE
:
1622 return build_int_cst (type
, 1);
1625 return build_real (type
, dconst1
);
1627 case FIXED_POINT_TYPE
:
1628 /* We can only generate 1 for accum types. */
1629 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1630 return build_fixed (type
, FCONST1(TYPE_MODE (type
)));
1634 tree scalar
= build_one_cst (TREE_TYPE (type
));
1636 return build_vector_from_val (type
, scalar
);
1640 return build_complex (type
,
1641 build_one_cst (TREE_TYPE (type
)),
1642 build_zero_cst (TREE_TYPE (type
)));
1649 /* Return a constant of arithmetic type TYPE which is the
1650 opposite of the multiplicative identity of the set TYPE. */
1653 build_minus_one_cst (tree type
)
1655 switch (TREE_CODE (type
))
1657 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1658 case POINTER_TYPE
: case REFERENCE_TYPE
:
1660 return build_int_cst (type
, -1);
1663 return build_real (type
, dconstm1
);
1665 case FIXED_POINT_TYPE
:
1666 /* We can only generate 1 for accum types. */
1667 gcc_assert (ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type
)));
1668 return build_fixed (type
, fixed_from_double_int (double_int_minus_one
,
1673 tree scalar
= build_minus_one_cst (TREE_TYPE (type
));
1675 return build_vector_from_val (type
, scalar
);
1679 return build_complex (type
,
1680 build_minus_one_cst (TREE_TYPE (type
)),
1681 build_zero_cst (TREE_TYPE (type
)));
1688 /* Build 0 constant of type TYPE. This is used by constructor folding
1689 and thus the constant should be represented in memory by
1693 build_zero_cst (tree type
)
1695 switch (TREE_CODE (type
))
1697 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
1698 case POINTER_TYPE
: case REFERENCE_TYPE
:
1699 case OFFSET_TYPE
: case NULLPTR_TYPE
:
1700 return build_int_cst (type
, 0);
1703 return build_real (type
, dconst0
);
1705 case FIXED_POINT_TYPE
:
1706 return build_fixed (type
, FCONST0 (TYPE_MODE (type
)));
1710 tree scalar
= build_zero_cst (TREE_TYPE (type
));
1712 return build_vector_from_val (type
, scalar
);
1717 tree zero
= build_zero_cst (TREE_TYPE (type
));
1719 return build_complex (type
, zero
, zero
);
1723 if (!AGGREGATE_TYPE_P (type
))
1724 return fold_convert (type
, integer_zero_node
);
1725 return build_constructor (type
, NULL
);
1730 /* Build a BINFO with LEN language slots. */
1733 make_tree_binfo_stat (unsigned base_binfos MEM_STAT_DECL
)
1736 size_t length
= (offsetof (struct tree_binfo
, base_binfos
)
1737 + vec
<tree
, va_gc
>::embedded_size (base_binfos
));
1739 record_node_allocation_statistics (TREE_BINFO
, length
);
1741 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
1743 memset (t
, 0, offsetof (struct tree_binfo
, base_binfos
));
1745 TREE_SET_CODE (t
, TREE_BINFO
);
1747 BINFO_BASE_BINFOS (t
)->embedded_init (base_binfos
);
1752 /* Create a CASE_LABEL_EXPR tree node and return it. */
1755 build_case_label (tree low_value
, tree high_value
, tree label_decl
)
1757 tree t
= make_node (CASE_LABEL_EXPR
);
1759 TREE_TYPE (t
) = void_type_node
;
1760 SET_EXPR_LOCATION (t
, DECL_SOURCE_LOCATION (label_decl
));
1762 CASE_LOW (t
) = low_value
;
1763 CASE_HIGH (t
) = high_value
;
1764 CASE_LABEL (t
) = label_decl
;
1765 CASE_CHAIN (t
) = NULL_TREE
;
1770 /* Build a newly constructed TREE_VEC node of length LEN. */
1773 make_tree_vec_stat (int len MEM_STAT_DECL
)
1776 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_vec
);
1778 record_node_allocation_statistics (TREE_VEC
, length
);
1780 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
1782 TREE_SET_CODE (t
, TREE_VEC
);
1783 TREE_VEC_LENGTH (t
) = len
;
1788 /* Return 1 if EXPR is the integer constant zero or a complex constant
1792 integer_zerop (const_tree expr
)
1796 switch (TREE_CODE (expr
))
1799 return (TREE_INT_CST_LOW (expr
) == 0
1800 && TREE_INT_CST_HIGH (expr
) == 0);
1802 return (integer_zerop (TREE_REALPART (expr
))
1803 && integer_zerop (TREE_IMAGPART (expr
)));
1807 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
1808 if (!integer_zerop (VECTOR_CST_ELT (expr
, i
)))
1817 /* Return 1 if EXPR is the integer constant one or the corresponding
1818 complex constant. */
1821 integer_onep (const_tree expr
)
1825 switch (TREE_CODE (expr
))
1828 return (TREE_INT_CST_LOW (expr
) == 1
1829 && TREE_INT_CST_HIGH (expr
) == 0);
1831 return (integer_onep (TREE_REALPART (expr
))
1832 && integer_zerop (TREE_IMAGPART (expr
)));
1836 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
1837 if (!integer_onep (VECTOR_CST_ELT (expr
, i
)))
1846 /* Return 1 if EXPR is an integer containing all 1's in as much precision as
1847 it contains, or a complex or vector whose subparts are such integers. */
1850 integer_all_onesp (const_tree expr
)
1857 if (TREE_CODE (expr
) == COMPLEX_CST
1858 && integer_all_onesp (TREE_REALPART (expr
))
1859 && integer_all_onesp (TREE_IMAGPART (expr
)))
1862 else if (TREE_CODE (expr
) == VECTOR_CST
)
1865 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
1866 if (!integer_all_onesp (VECTOR_CST_ELT (expr
, i
)))
1871 else if (TREE_CODE (expr
) != INTEGER_CST
)
1874 uns
= TYPE_UNSIGNED (TREE_TYPE (expr
));
1875 if (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1876 && TREE_INT_CST_HIGH (expr
) == -1)
1881 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
1882 if (prec
>= HOST_BITS_PER_WIDE_INT
)
1884 HOST_WIDE_INT high_value
;
1887 shift_amount
= prec
- HOST_BITS_PER_WIDE_INT
;
1889 /* Can not handle precisions greater than twice the host int size. */
1890 gcc_assert (shift_amount
<= HOST_BITS_PER_WIDE_INT
);
1891 if (shift_amount
== HOST_BITS_PER_WIDE_INT
)
1892 /* Shifting by the host word size is undefined according to the ANSI
1893 standard, so we must handle this as a special case. */
1896 high_value
= ((HOST_WIDE_INT
) 1 << shift_amount
) - 1;
1898 return (TREE_INT_CST_LOW (expr
) == ~(unsigned HOST_WIDE_INT
) 0
1899 && TREE_INT_CST_HIGH (expr
) == high_value
);
1902 return TREE_INT_CST_LOW (expr
) == ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
1905 /* Return 1 if EXPR is the integer constant minus one. */
1908 integer_minus_onep (const_tree expr
)
1912 if (TREE_CODE (expr
) == COMPLEX_CST
)
1913 return (integer_all_onesp (TREE_REALPART (expr
))
1914 && integer_zerop (TREE_IMAGPART (expr
)));
1916 return integer_all_onesp (expr
);
1919 /* Return 1 if EXPR is an integer constant that is a power of 2 (i.e., has only
1923 integer_pow2p (const_tree expr
)
1926 unsigned HOST_WIDE_INT high
, low
;
1930 if (TREE_CODE (expr
) == COMPLEX_CST
1931 && integer_pow2p (TREE_REALPART (expr
))
1932 && integer_zerop (TREE_IMAGPART (expr
)))
1935 if (TREE_CODE (expr
) != INTEGER_CST
)
1938 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
1939 high
= TREE_INT_CST_HIGH (expr
);
1940 low
= TREE_INT_CST_LOW (expr
);
1942 /* First clear all bits that are beyond the type's precision in case
1943 we've been sign extended. */
1945 if (prec
== HOST_BITS_PER_DOUBLE_INT
)
1947 else if (prec
> HOST_BITS_PER_WIDE_INT
)
1948 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
1952 if (prec
< HOST_BITS_PER_WIDE_INT
)
1953 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
1956 if (high
== 0 && low
== 0)
1959 return ((high
== 0 && (low
& (low
- 1)) == 0)
1960 || (low
== 0 && (high
& (high
- 1)) == 0));
1963 /* Return 1 if EXPR is an integer constant other than zero or a
1964 complex constant other than zero. */
1967 integer_nonzerop (const_tree expr
)
1971 return ((TREE_CODE (expr
) == INTEGER_CST
1972 && (TREE_INT_CST_LOW (expr
) != 0
1973 || TREE_INT_CST_HIGH (expr
) != 0))
1974 || (TREE_CODE (expr
) == COMPLEX_CST
1975 && (integer_nonzerop (TREE_REALPART (expr
))
1976 || integer_nonzerop (TREE_IMAGPART (expr
)))));
1979 /* Return 1 if EXPR is the fixed-point constant zero. */
1982 fixed_zerop (const_tree expr
)
1984 return (TREE_CODE (expr
) == FIXED_CST
1985 && TREE_FIXED_CST (expr
).data
.is_zero ());
1988 /* Return the power of two represented by a tree node known to be a
1992 tree_log2 (const_tree expr
)
1995 HOST_WIDE_INT high
, low
;
1999 if (TREE_CODE (expr
) == COMPLEX_CST
)
2000 return tree_log2 (TREE_REALPART (expr
));
2002 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2003 high
= TREE_INT_CST_HIGH (expr
);
2004 low
= TREE_INT_CST_LOW (expr
);
2006 /* First clear all bits that are beyond the type's precision in case
2007 we've been sign extended. */
2009 if (prec
== HOST_BITS_PER_DOUBLE_INT
)
2011 else if (prec
> HOST_BITS_PER_WIDE_INT
)
2012 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
2016 if (prec
< HOST_BITS_PER_WIDE_INT
)
2017 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
2020 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ exact_log2 (high
)
2021 : exact_log2 (low
));
2024 /* Similar, but return the largest integer Y such that 2 ** Y is less
2025 than or equal to EXPR. */
2028 tree_floor_log2 (const_tree expr
)
2031 HOST_WIDE_INT high
, low
;
2035 if (TREE_CODE (expr
) == COMPLEX_CST
)
2036 return tree_log2 (TREE_REALPART (expr
));
2038 prec
= TYPE_PRECISION (TREE_TYPE (expr
));
2039 high
= TREE_INT_CST_HIGH (expr
);
2040 low
= TREE_INT_CST_LOW (expr
);
2042 /* First clear all bits that are beyond the type's precision in case
2043 we've been sign extended. Ignore if type's precision hasn't been set
2044 since what we are doing is setting it. */
2046 if (prec
== HOST_BITS_PER_DOUBLE_INT
|| prec
== 0)
2048 else if (prec
> HOST_BITS_PER_WIDE_INT
)
2049 high
&= ~((HOST_WIDE_INT
) (-1) << (prec
- HOST_BITS_PER_WIDE_INT
));
2053 if (prec
< HOST_BITS_PER_WIDE_INT
)
2054 low
&= ~((HOST_WIDE_INT
) (-1) << prec
);
2057 return (high
!= 0 ? HOST_BITS_PER_WIDE_INT
+ floor_log2 (high
)
2058 : floor_log2 (low
));
2061 /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for
2062 decimal float constants, so don't return 1 for them. */
2065 real_zerop (const_tree expr
)
2069 switch (TREE_CODE (expr
))
2072 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst0
)
2073 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2075 return real_zerop (TREE_REALPART (expr
))
2076 && real_zerop (TREE_IMAGPART (expr
));
2080 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2081 if (!real_zerop (VECTOR_CST_ELT (expr
, i
)))
2090 /* Return 1 if EXPR is the real constant one in real or complex form.
2091 Trailing zeroes matter for decimal float constants, so don't return
2095 real_onep (const_tree expr
)
2099 switch (TREE_CODE (expr
))
2102 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst1
)
2103 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2105 return real_onep (TREE_REALPART (expr
))
2106 && real_zerop (TREE_IMAGPART (expr
));
2110 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2111 if (!real_onep (VECTOR_CST_ELT (expr
, i
)))
2120 /* Return 1 if EXPR is the real constant two. Trailing zeroes matter
2121 for decimal float constants, so don't return 1 for them. */
2124 real_twop (const_tree expr
)
2128 switch (TREE_CODE (expr
))
2131 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconst2
)
2132 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2134 return real_twop (TREE_REALPART (expr
))
2135 && real_zerop (TREE_IMAGPART (expr
));
2139 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2140 if (!real_twop (VECTOR_CST_ELT (expr
, i
)))
2149 /* Return 1 if EXPR is the real constant minus one. Trailing zeroes
2150 matter for decimal float constants, so don't return 1 for them. */
2153 real_minus_onep (const_tree expr
)
2157 switch (TREE_CODE (expr
))
2160 return REAL_VALUES_EQUAL (TREE_REAL_CST (expr
), dconstm1
)
2161 && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr
))));
2163 return real_minus_onep (TREE_REALPART (expr
))
2164 && real_zerop (TREE_IMAGPART (expr
));
2168 for (i
= 0; i
< VECTOR_CST_NELTS (expr
); ++i
)
2169 if (!real_minus_onep (VECTOR_CST_ELT (expr
, i
)))
2178 /* Nonzero if EXP is a constant or a cast of a constant. */
2181 really_constant_p (const_tree exp
)
2183 /* This is not quite the same as STRIP_NOPS. It does more. */
2184 while (CONVERT_EXPR_P (exp
)
2185 || TREE_CODE (exp
) == NON_LVALUE_EXPR
)
2186 exp
= TREE_OPERAND (exp
, 0);
2187 return TREE_CONSTANT (exp
);
2190 /* Return first list element whose TREE_VALUE is ELEM.
2191 Return 0 if ELEM is not in LIST. */
2194 value_member (tree elem
, tree list
)
2198 if (elem
== TREE_VALUE (list
))
2200 list
= TREE_CHAIN (list
);
2205 /* Return first list element whose TREE_PURPOSE is ELEM.
2206 Return 0 if ELEM is not in LIST. */
2209 purpose_member (const_tree elem
, tree list
)
2213 if (elem
== TREE_PURPOSE (list
))
2215 list
= TREE_CHAIN (list
);
2220 /* Return true if ELEM is in V. */
2223 vec_member (const_tree elem
, vec
<tree
, va_gc
> *v
)
2227 FOR_EACH_VEC_SAFE_ELT (v
, ix
, t
)
2233 /* Returns element number IDX (zero-origin) of chain CHAIN, or
2237 chain_index (int idx
, tree chain
)
2239 for (; chain
&& idx
> 0; --idx
)
2240 chain
= TREE_CHAIN (chain
);
2244 /* Return nonzero if ELEM is part of the chain CHAIN. */
2247 chain_member (const_tree elem
, const_tree chain
)
2253 chain
= DECL_CHAIN (chain
);
2259 /* Return the length of a chain of nodes chained through TREE_CHAIN.
2260 We expect a null pointer to mark the end of the chain.
2261 This is the Lisp primitive `length'. */
2264 list_length (const_tree t
)
2267 #ifdef ENABLE_TREE_CHECKING
2275 #ifdef ENABLE_TREE_CHECKING
2278 gcc_assert (p
!= q
);
2286 /* Returns the number of FIELD_DECLs in TYPE. */
2289 fields_length (const_tree type
)
2291 tree t
= TYPE_FIELDS (type
);
2294 for (; t
; t
= DECL_CHAIN (t
))
2295 if (TREE_CODE (t
) == FIELD_DECL
)
2301 /* Returns the first FIELD_DECL in the TYPE_FIELDS of the RECORD_TYPE or
2302 UNION_TYPE TYPE, or NULL_TREE if none. */
2305 first_field (const_tree type
)
2307 tree t
= TYPE_FIELDS (type
);
2308 while (t
&& TREE_CODE (t
) != FIELD_DECL
)
2313 /* Concatenate two chains of nodes (chained through TREE_CHAIN)
2314 by modifying the last node in chain 1 to point to chain 2.
2315 This is the Lisp primitive `nconc'. */
2318 chainon (tree op1
, tree op2
)
2327 for (t1
= op1
; TREE_CHAIN (t1
); t1
= TREE_CHAIN (t1
))
2329 TREE_CHAIN (t1
) = op2
;
2331 #ifdef ENABLE_TREE_CHECKING
2334 for (t2
= op2
; t2
; t2
= TREE_CHAIN (t2
))
2335 gcc_assert (t2
!= t1
);
2342 /* Return the last node in a chain of nodes (chained through TREE_CHAIN). */
2345 tree_last (tree chain
)
2349 while ((next
= TREE_CHAIN (chain
)))
2354 /* Reverse the order of elements in the chain T,
2355 and return the new head of the chain (old last element). */
2360 tree prev
= 0, decl
, next
;
2361 for (decl
= t
; decl
; decl
= next
)
2363 /* We shouldn't be using this function to reverse BLOCK chains; we
2364 have blocks_nreverse for that. */
2365 gcc_checking_assert (TREE_CODE (decl
) != BLOCK
);
2366 next
= TREE_CHAIN (decl
);
2367 TREE_CHAIN (decl
) = prev
;
2373 /* Return a newly created TREE_LIST node whose
2374 purpose and value fields are PARM and VALUE. */
2377 build_tree_list_stat (tree parm
, tree value MEM_STAT_DECL
)
2379 tree t
= make_node_stat (TREE_LIST PASS_MEM_STAT
);
2380 TREE_PURPOSE (t
) = parm
;
2381 TREE_VALUE (t
) = value
;
2385 /* Build a chain of TREE_LIST nodes from a vector. */
2388 build_tree_list_vec_stat (const vec
<tree
, va_gc
> *vec MEM_STAT_DECL
)
2390 tree ret
= NULL_TREE
;
2394 FOR_EACH_VEC_SAFE_ELT (vec
, i
, t
)
2396 *pp
= build_tree_list_stat (NULL
, t PASS_MEM_STAT
);
2397 pp
= &TREE_CHAIN (*pp
);
2402 /* Return a newly created TREE_LIST node whose
2403 purpose and value fields are PURPOSE and VALUE
2404 and whose TREE_CHAIN is CHAIN. */
2407 tree_cons_stat (tree purpose
, tree value
, tree chain MEM_STAT_DECL
)
2411 node
= ggc_alloc_tree_node_stat (sizeof (struct tree_list
) PASS_MEM_STAT
);
2412 memset (node
, 0, sizeof (struct tree_common
));
2414 record_node_allocation_statistics (TREE_LIST
, sizeof (struct tree_list
));
2416 TREE_SET_CODE (node
, TREE_LIST
);
2417 TREE_CHAIN (node
) = chain
;
2418 TREE_PURPOSE (node
) = purpose
;
2419 TREE_VALUE (node
) = value
;
2423 /* Return the values of the elements of a CONSTRUCTOR as a vector of
2427 ctor_to_vec (tree ctor
)
2429 vec
<tree
, va_gc
> *vec
;
2430 vec_alloc (vec
, CONSTRUCTOR_NELTS (ctor
));
2434 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor
), ix
, val
)
2435 vec
->quick_push (val
);
2440 /* Return the size nominally occupied by an object of type TYPE
2441 when it resides in memory. The value is measured in units of bytes,
2442 and its data type is that normally used for type sizes
2443 (which is the first type created by make_signed_type or
2444 make_unsigned_type). */
2447 size_in_bytes (const_tree type
)
2451 if (type
== error_mark_node
)
2452 return integer_zero_node
;
2454 type
= TYPE_MAIN_VARIANT (type
);
2455 t
= TYPE_SIZE_UNIT (type
);
2459 lang_hooks
.types
.incomplete_type_error (NULL_TREE
, type
);
2460 return size_zero_node
;
2466 /* Return the size of TYPE (in bytes) as a wide integer
2467 or return -1 if the size can vary or is larger than an integer. */
2470 int_size_in_bytes (const_tree type
)
2474 if (type
== error_mark_node
)
2477 type
= TYPE_MAIN_VARIANT (type
);
2478 t
= TYPE_SIZE_UNIT (type
);
2480 || TREE_CODE (t
) != INTEGER_CST
2481 || TREE_INT_CST_HIGH (t
) != 0
2482 /* If the result would appear negative, it's too big to represent. */
2483 || (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0)
2486 return TREE_INT_CST_LOW (t
);
2489 /* Return the maximum size of TYPE (in bytes) as a wide integer
2490 or return -1 if the size can vary or is larger than an integer. */
2493 max_int_size_in_bytes (const_tree type
)
2495 HOST_WIDE_INT size
= -1;
2498 /* If this is an array type, check for a possible MAX_SIZE attached. */
2500 if (TREE_CODE (type
) == ARRAY_TYPE
)
2502 size_tree
= TYPE_ARRAY_MAX_SIZE (type
);
2504 if (size_tree
&& host_integerp (size_tree
, 1))
2505 size
= tree_low_cst (size_tree
, 1);
2508 /* If we still haven't been able to get a size, see if the language
2509 can compute a maximum size. */
2513 size_tree
= lang_hooks
.types
.max_size (type
);
2515 if (size_tree
&& host_integerp (size_tree
, 1))
2516 size
= tree_low_cst (size_tree
, 1);
2522 /* Returns a tree for the size of EXP in bytes. */
2525 tree_expr_size (const_tree exp
)
2528 && DECL_SIZE_UNIT (exp
) != 0)
2529 return DECL_SIZE_UNIT (exp
);
2531 return size_in_bytes (TREE_TYPE (exp
));
2534 /* Return the bit position of FIELD, in bits from the start of the record.
2535 This is a tree of type bitsizetype. */
2538 bit_position (const_tree field
)
2540 return bit_from_pos (DECL_FIELD_OFFSET (field
),
2541 DECL_FIELD_BIT_OFFSET (field
));
2544 /* Likewise, but return as an integer. It must be representable in
2545 that way (since it could be a signed value, we don't have the
2546 option of returning -1 like int_size_in_byte can. */
2549 int_bit_position (const_tree field
)
2551 return tree_low_cst (bit_position (field
), 0);
2554 /* Return the byte position of FIELD, in bytes from the start of the record.
2555 This is a tree of type sizetype. */
2558 byte_position (const_tree field
)
2560 return byte_from_pos (DECL_FIELD_OFFSET (field
),
2561 DECL_FIELD_BIT_OFFSET (field
));
2564 /* Likewise, but return as an integer. It must be representable in
2565 that way (since it could be a signed value, we don't have the
2566 option of returning -1 like int_size_in_byte can. */
2569 int_byte_position (const_tree field
)
2571 return tree_low_cst (byte_position (field
), 0);
2574 /* Return the strictest alignment, in bits, that T is known to have. */
2577 expr_align (const_tree t
)
2579 unsigned int align0
, align1
;
2581 switch (TREE_CODE (t
))
2583 CASE_CONVERT
: case NON_LVALUE_EXPR
:
2584 /* If we have conversions, we know that the alignment of the
2585 object must meet each of the alignments of the types. */
2586 align0
= expr_align (TREE_OPERAND (t
, 0));
2587 align1
= TYPE_ALIGN (TREE_TYPE (t
));
2588 return MAX (align0
, align1
);
2590 case SAVE_EXPR
: case COMPOUND_EXPR
: case MODIFY_EXPR
:
2591 case INIT_EXPR
: case TARGET_EXPR
: case WITH_CLEANUP_EXPR
:
2592 case CLEANUP_POINT_EXPR
:
2593 /* These don't change the alignment of an object. */
2594 return expr_align (TREE_OPERAND (t
, 0));
2597 /* The best we can do is say that the alignment is the least aligned
2599 align0
= expr_align (TREE_OPERAND (t
, 1));
2600 align1
= expr_align (TREE_OPERAND (t
, 2));
2601 return MIN (align0
, align1
);
2603 /* FIXME: LABEL_DECL and CONST_DECL never have DECL_ALIGN set
2604 meaningfully, it's always 1. */
2605 case LABEL_DECL
: case CONST_DECL
:
2606 case VAR_DECL
: case PARM_DECL
: case RESULT_DECL
:
2608 gcc_assert (DECL_ALIGN (t
) != 0);
2609 return DECL_ALIGN (t
);
2615 /* Otherwise take the alignment from that of the type. */
2616 return TYPE_ALIGN (TREE_TYPE (t
));
2619 /* Return, as a tree node, the number of elements for TYPE (which is an
2620 ARRAY_TYPE) minus one. This counts only elements of the top array. */
2623 array_type_nelts (const_tree type
)
2625 tree index_type
, min
, max
;
2627 /* If they did it with unspecified bounds, then we should have already
2628 given an error about it before we got here. */
2629 if (! TYPE_DOMAIN (type
))
2630 return error_mark_node
;
2632 index_type
= TYPE_DOMAIN (type
);
2633 min
= TYPE_MIN_VALUE (index_type
);
2634 max
= TYPE_MAX_VALUE (index_type
);
2636 /* TYPE_MAX_VALUE may not be set if the array has unknown length. */
2638 return error_mark_node
;
2640 return (integer_zerop (min
)
2642 : fold_build2 (MINUS_EXPR
, TREE_TYPE (max
), max
, min
));
2645 /* If arg is static -- a reference to an object in static storage -- then
2646 return the object. This is not the same as the C meaning of `static'.
2647 If arg isn't static, return NULL. */
2652 switch (TREE_CODE (arg
))
2655 /* Nested functions are static, even though taking their address will
2656 involve a trampoline as we unnest the nested function and create
2657 the trampoline on the tree level. */
2661 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2662 && ! DECL_THREAD_LOCAL_P (arg
)
2663 && ! DECL_DLLIMPORT_P (arg
)
2667 return ((TREE_STATIC (arg
) || DECL_EXTERNAL (arg
))
2671 return TREE_STATIC (arg
) ? arg
: NULL
;
2678 /* If the thing being referenced is not a field, then it is
2679 something language specific. */
2680 gcc_assert (TREE_CODE (TREE_OPERAND (arg
, 1)) == FIELD_DECL
);
2682 /* If we are referencing a bitfield, we can't evaluate an
2683 ADDR_EXPR at compile time and so it isn't a constant. */
2684 if (DECL_BIT_FIELD (TREE_OPERAND (arg
, 1)))
2687 return staticp (TREE_OPERAND (arg
, 0));
2693 return TREE_CONSTANT (TREE_OPERAND (arg
, 0)) ? arg
: NULL
;
2696 case ARRAY_RANGE_REF
:
2697 if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg
))) == INTEGER_CST
2698 && TREE_CODE (TREE_OPERAND (arg
, 1)) == INTEGER_CST
)
2699 return staticp (TREE_OPERAND (arg
, 0));
2703 case COMPOUND_LITERAL_EXPR
:
2704 return TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (arg
)) ? arg
: NULL
;
2714 /* Return whether OP is a DECL whose address is function-invariant. */
2717 decl_address_invariant_p (const_tree op
)
2719 /* The conditions below are slightly less strict than the one in
2722 switch (TREE_CODE (op
))
2731 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2732 || DECL_THREAD_LOCAL_P (op
)
2733 || DECL_CONTEXT (op
) == current_function_decl
2734 || decl_function_context (op
) == current_function_decl
)
2739 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2740 || decl_function_context (op
) == current_function_decl
)
2751 /* Return whether OP is a DECL whose address is interprocedural-invariant. */
2754 decl_address_ip_invariant_p (const_tree op
)
2756 /* The conditions below are slightly less strict than the one in
2759 switch (TREE_CODE (op
))
2767 if (((TREE_STATIC (op
) || DECL_EXTERNAL (op
))
2768 && !DECL_DLLIMPORT_P (op
))
2769 || DECL_THREAD_LOCAL_P (op
))
2774 if ((TREE_STATIC (op
) || DECL_EXTERNAL (op
)))
2786 /* Return true if T is function-invariant (internal function, does
2787 not handle arithmetic; that's handled in skip_simple_arithmetic and
2788 tree_invariant_p). */
2790 static bool tree_invariant_p (tree t
);
2793 tree_invariant_p_1 (tree t
)
2797 if (TREE_CONSTANT (t
)
2798 || (TREE_READONLY (t
) && !TREE_SIDE_EFFECTS (t
)))
2801 switch (TREE_CODE (t
))
2807 op
= TREE_OPERAND (t
, 0);
2808 while (handled_component_p (op
))
2810 switch (TREE_CODE (op
))
2813 case ARRAY_RANGE_REF
:
2814 if (!tree_invariant_p (TREE_OPERAND (op
, 1))
2815 || TREE_OPERAND (op
, 2) != NULL_TREE
2816 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2821 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2827 op
= TREE_OPERAND (op
, 0);
2830 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
2839 /* Return true if T is function-invariant. */
2842 tree_invariant_p (tree t
)
2844 tree inner
= skip_simple_arithmetic (t
);
2845 return tree_invariant_p_1 (inner
);
2848 /* Wrap a SAVE_EXPR around EXPR, if appropriate.
2849 Do this to any expression which may be used in more than one place,
2850 but must be evaluated only once.
2852 Normally, expand_expr would reevaluate the expression each time.
2853 Calling save_expr produces something that is evaluated and recorded
2854 the first time expand_expr is called on it. Subsequent calls to
2855 expand_expr just reuse the recorded value.
2857 The call to expand_expr that generates code that actually computes
2858 the value is the first call *at compile time*. Subsequent calls
2859 *at compile time* generate code to use the saved value.
2860 This produces correct result provided that *at run time* control
2861 always flows through the insns made by the first expand_expr
2862 before reaching the other places where the save_expr was evaluated.
2863 You, the caller of save_expr, must make sure this is so.
2865 Constants, and certain read-only nodes, are returned with no
2866 SAVE_EXPR because that is safe. Expressions containing placeholders
2867 are not touched; see tree.def for an explanation of what these
2871 save_expr (tree expr
)
2873 tree t
= fold (expr
);
2876 /* If the tree evaluates to a constant, then we don't want to hide that
2877 fact (i.e. this allows further folding, and direct checks for constants).
2878 However, a read-only object that has side effects cannot be bypassed.
2879 Since it is no problem to reevaluate literals, we just return the
2881 inner
= skip_simple_arithmetic (t
);
2882 if (TREE_CODE (inner
) == ERROR_MARK
)
2885 if (tree_invariant_p_1 (inner
))
2888 /* If INNER contains a PLACEHOLDER_EXPR, we must evaluate it each time, since
2889 it means that the size or offset of some field of an object depends on
2890 the value within another field.
2892 Note that it must not be the case that T contains both a PLACEHOLDER_EXPR
2893 and some variable since it would then need to be both evaluated once and
2894 evaluated more than once. Front-ends must assure this case cannot
2895 happen by surrounding any such subexpressions in their own SAVE_EXPR
2896 and forcing evaluation at the proper time. */
2897 if (contains_placeholder_p (inner
))
2900 t
= build1 (SAVE_EXPR
, TREE_TYPE (expr
), t
);
2901 SET_EXPR_LOCATION (t
, EXPR_LOCATION (expr
));
2903 /* This expression might be placed ahead of a jump to ensure that the
2904 value was computed on both sides of the jump. So make sure it isn't
2905 eliminated as dead. */
2906 TREE_SIDE_EFFECTS (t
) = 1;
2910 /* Look inside EXPR into any simple arithmetic operations. Return the
2911 outermost non-arithmetic or non-invariant node. */
2914 skip_simple_arithmetic (tree expr
)
2916 /* We don't care about whether this can be used as an lvalue in this
2918 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
2919 expr
= TREE_OPERAND (expr
, 0);
2921 /* If we have simple operations applied to a SAVE_EXPR or to a SAVE_EXPR and
2922 a constant, it will be more efficient to not make another SAVE_EXPR since
2923 it will allow better simplification and GCSE will be able to merge the
2924 computations if they actually occur. */
2927 if (UNARY_CLASS_P (expr
))
2928 expr
= TREE_OPERAND (expr
, 0);
2929 else if (BINARY_CLASS_P (expr
))
2931 if (tree_invariant_p (TREE_OPERAND (expr
, 1)))
2932 expr
= TREE_OPERAND (expr
, 0);
2933 else if (tree_invariant_p (TREE_OPERAND (expr
, 0)))
2934 expr
= TREE_OPERAND (expr
, 1);
2945 /* Look inside EXPR into simple arithmetic operations involving constants.
2946 Return the outermost non-arithmetic or non-constant node. */
2949 skip_simple_constant_arithmetic (tree expr
)
2951 while (TREE_CODE (expr
) == NON_LVALUE_EXPR
)
2952 expr
= TREE_OPERAND (expr
, 0);
2956 if (UNARY_CLASS_P (expr
))
2957 expr
= TREE_OPERAND (expr
, 0);
2958 else if (BINARY_CLASS_P (expr
))
2960 if (TREE_CONSTANT (TREE_OPERAND (expr
, 1)))
2961 expr
= TREE_OPERAND (expr
, 0);
2962 else if (TREE_CONSTANT (TREE_OPERAND (expr
, 0)))
2963 expr
= TREE_OPERAND (expr
, 1);
2974 /* Return which tree structure is used by T. */
2976 enum tree_node_structure_enum
2977 tree_node_structure (const_tree t
)
2979 const enum tree_code code
= TREE_CODE (t
);
2980 return tree_node_structure_for_code (code
);
2983 /* Set various status flags when building a CALL_EXPR object T. */
2986 process_call_operands (tree t
)
2988 bool side_effects
= TREE_SIDE_EFFECTS (t
);
2989 bool read_only
= false;
2990 int i
= call_expr_flags (t
);
2992 /* Calls have side-effects, except those to const or pure functions. */
2993 if ((i
& ECF_LOOPING_CONST_OR_PURE
) || !(i
& (ECF_CONST
| ECF_PURE
)))
2994 side_effects
= true;
2995 /* Propagate TREE_READONLY of arguments for const functions. */
2999 if (!side_effects
|| read_only
)
3000 for (i
= 1; i
< TREE_OPERAND_LENGTH (t
); i
++)
3002 tree op
= TREE_OPERAND (t
, i
);
3003 if (op
&& TREE_SIDE_EFFECTS (op
))
3004 side_effects
= true;
3005 if (op
&& !TREE_READONLY (op
) && !CONSTANT_CLASS_P (op
))
3009 TREE_SIDE_EFFECTS (t
) = side_effects
;
3010 TREE_READONLY (t
) = read_only
;
3013 /* Return true if EXP contains a PLACEHOLDER_EXPR, i.e. if it represents a
3014 size or offset that depends on a field within a record. */
3017 contains_placeholder_p (const_tree exp
)
3019 enum tree_code code
;
3024 code
= TREE_CODE (exp
);
3025 if (code
== PLACEHOLDER_EXPR
)
3028 switch (TREE_CODE_CLASS (code
))
3031 /* Don't look at any PLACEHOLDER_EXPRs that might be in index or bit
3032 position computations since they will be converted into a
3033 WITH_RECORD_EXPR involving the reference, which will assume
3034 here will be valid. */
3035 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
3037 case tcc_exceptional
:
3038 if (code
== TREE_LIST
)
3039 return (CONTAINS_PLACEHOLDER_P (TREE_VALUE (exp
))
3040 || CONTAINS_PLACEHOLDER_P (TREE_CHAIN (exp
)));
3045 case tcc_comparison
:
3046 case tcc_expression
:
3050 /* Ignoring the first operand isn't quite right, but works best. */
3051 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1));
3054 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
3055 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1))
3056 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 2)));
3059 /* The save_expr function never wraps anything containing
3060 a PLACEHOLDER_EXPR. */
3067 switch (TREE_CODE_LENGTH (code
))
3070 return CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0));
3072 return (CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 0))
3073 || CONTAINS_PLACEHOLDER_P (TREE_OPERAND (exp
, 1)));
3084 const_call_expr_arg_iterator iter
;
3085 FOR_EACH_CONST_CALL_EXPR_ARG (arg
, iter
, exp
)
3086 if (CONTAINS_PLACEHOLDER_P (arg
))
3100 /* Return true if any part of the structure of TYPE involves a PLACEHOLDER_EXPR
3101 directly. This includes size, bounds, qualifiers (for QUAL_UNION_TYPE) and
3105 type_contains_placeholder_1 (const_tree type
)
3107 /* If the size contains a placeholder or the parent type (component type in
3108 the case of arrays) type involves a placeholder, this type does. */
3109 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (type
))
3110 || CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (type
))
3111 || (!POINTER_TYPE_P (type
)
3113 && type_contains_placeholder_p (TREE_TYPE (type
))))
3116 /* Now do type-specific checks. Note that the last part of the check above
3117 greatly limits what we have to do below. */
3118 switch (TREE_CODE (type
))
3126 case REFERENCE_TYPE
:
3135 case FIXED_POINT_TYPE
:
3136 /* Here we just check the bounds. */
3137 return (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (type
))
3138 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (type
)));
3141 /* We have already checked the component type above, so just check the
3143 return type_contains_placeholder_p (TYPE_DOMAIN (type
));
3147 case QUAL_UNION_TYPE
:
3151 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
3152 if (TREE_CODE (field
) == FIELD_DECL
3153 && (CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (field
))
3154 || (TREE_CODE (type
) == QUAL_UNION_TYPE
3155 && CONTAINS_PLACEHOLDER_P (DECL_QUALIFIER (field
)))
3156 || type_contains_placeholder_p (TREE_TYPE (field
))))
3167 /* Wrapper around above function used to cache its result. */
3170 type_contains_placeholder_p (tree type
)
3174 /* If the contains_placeholder_bits field has been initialized,
3175 then we know the answer. */
3176 if (TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) > 0)
3177 return TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) - 1;
3179 /* Indicate that we've seen this type node, and the answer is false.
3180 This is what we want to return if we run into recursion via fields. */
3181 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = 1;
3183 /* Compute the real value. */
3184 result
= type_contains_placeholder_1 (type
);
3186 /* Store the real value. */
3187 TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type
) = result
+ 1;
3192 /* Push tree EXP onto vector QUEUE if it is not already present. */
3195 push_without_duplicates (tree exp
, vec
<tree
> *queue
)
3200 FOR_EACH_VEC_ELT (*queue
, i
, iter
)
3201 if (simple_cst_equal (iter
, exp
) == 1)
3205 queue
->safe_push (exp
);
3208 /* Given a tree EXP, find all occurrences of references to fields
3209 in a PLACEHOLDER_EXPR and place them in vector REFS without
3210 duplicates. Also record VAR_DECLs and CONST_DECLs. Note that
3211 we assume here that EXP contains only arithmetic expressions
3212 or CALL_EXPRs with PLACEHOLDER_EXPRs occurring only in their
3216 find_placeholder_in_expr (tree exp
, vec
<tree
> *refs
)
3218 enum tree_code code
= TREE_CODE (exp
);
3222 /* We handle TREE_LIST and COMPONENT_REF separately. */
3223 if (code
== TREE_LIST
)
3225 FIND_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), refs
);
3226 FIND_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), refs
);
3228 else if (code
== COMPONENT_REF
)
3230 for (inner
= TREE_OPERAND (exp
, 0);
3231 REFERENCE_CLASS_P (inner
);
3232 inner
= TREE_OPERAND (inner
, 0))
3235 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
)
3236 push_without_duplicates (exp
, refs
);
3238 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), refs
);
3241 switch (TREE_CODE_CLASS (code
))
3246 case tcc_declaration
:
3247 /* Variables allocated to static storage can stay. */
3248 if (!TREE_STATIC (exp
))
3249 push_without_duplicates (exp
, refs
);
3252 case tcc_expression
:
3253 /* This is the pattern built in ada/make_aligning_type. */
3254 if (code
== ADDR_EXPR
3255 && TREE_CODE (TREE_OPERAND (exp
, 0)) == PLACEHOLDER_EXPR
)
3257 push_without_duplicates (exp
, refs
);
3261 /* Fall through... */
3263 case tcc_exceptional
:
3266 case tcc_comparison
:
3268 for (i
= 0; i
< TREE_CODE_LENGTH (code
); i
++)
3269 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3273 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3274 FIND_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, i
), refs
);
3282 /* Given a tree EXP, a FIELD_DECL F, and a replacement value R,
3283 return a tree with all occurrences of references to F in a
3284 PLACEHOLDER_EXPR replaced by R. Also handle VAR_DECLs and
3285 CONST_DECLs. Note that we assume here that EXP contains only
3286 arithmetic expressions or CALL_EXPRs with PLACEHOLDER_EXPRs
3287 occurring only in their argument list. */
3290 substitute_in_expr (tree exp
, tree f
, tree r
)
3292 enum tree_code code
= TREE_CODE (exp
);
3293 tree op0
, op1
, op2
, op3
;
3296 /* We handle TREE_LIST and COMPONENT_REF separately. */
3297 if (code
== TREE_LIST
)
3299 op0
= SUBSTITUTE_IN_EXPR (TREE_CHAIN (exp
), f
, r
);
3300 op1
= SUBSTITUTE_IN_EXPR (TREE_VALUE (exp
), f
, r
);
3301 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3304 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3306 else if (code
== COMPONENT_REF
)
3310 /* If this expression is getting a value from a PLACEHOLDER_EXPR
3311 and it is the right field, replace it with R. */
3312 for (inner
= TREE_OPERAND (exp
, 0);
3313 REFERENCE_CLASS_P (inner
);
3314 inner
= TREE_OPERAND (inner
, 0))
3318 op1
= TREE_OPERAND (exp
, 1);
3320 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& op1
== f
)
3323 /* If this expression hasn't been completed let, leave it alone. */
3324 if (TREE_CODE (inner
) == PLACEHOLDER_EXPR
&& !TREE_TYPE (inner
))
3327 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3328 if (op0
== TREE_OPERAND (exp
, 0))
3332 = fold_build3 (COMPONENT_REF
, TREE_TYPE (exp
), op0
, op1
, NULL_TREE
);
3335 switch (TREE_CODE_CLASS (code
))
3340 case tcc_declaration
:
3346 case tcc_expression
:
3350 /* Fall through... */
3352 case tcc_exceptional
:
3355 case tcc_comparison
:
3357 switch (TREE_CODE_LENGTH (code
))
3363 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3364 if (op0
== TREE_OPERAND (exp
, 0))
3367 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3371 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3372 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3374 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3377 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3381 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3382 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3383 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3385 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3386 && op2
== TREE_OPERAND (exp
, 2))
3389 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3393 op0
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 0), f
, r
);
3394 op1
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 1), f
, r
);
3395 op2
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 2), f
, r
);
3396 op3
= SUBSTITUTE_IN_EXPR (TREE_OPERAND (exp
, 3), f
, r
);
3398 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3399 && op2
== TREE_OPERAND (exp
, 2)
3400 && op3
== TREE_OPERAND (exp
, 3))
3404 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3416 new_tree
= NULL_TREE
;
3418 /* If we are trying to replace F with a constant, inline back
3419 functions which do nothing else than computing a value from
3420 the arguments they are passed. This makes it possible to
3421 fold partially or entirely the replacement expression. */
3422 if (CONSTANT_CLASS_P (r
) && code
== CALL_EXPR
)
3424 tree t
= maybe_inline_call_in_expr (exp
);
3426 return SUBSTITUTE_IN_EXPR (t
, f
, r
);
3429 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3431 tree op
= TREE_OPERAND (exp
, i
);
3432 tree new_op
= SUBSTITUTE_IN_EXPR (op
, f
, r
);
3436 new_tree
= copy_node (exp
);
3437 TREE_OPERAND (new_tree
, i
) = new_op
;
3443 new_tree
= fold (new_tree
);
3444 if (TREE_CODE (new_tree
) == CALL_EXPR
)
3445 process_call_operands (new_tree
);
3456 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
3458 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
3459 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
3464 /* Similar, but look for a PLACEHOLDER_EXPR in EXP and find a replacement
3465 for it within OBJ, a tree that is an object or a chain of references. */
3468 substitute_placeholder_in_expr (tree exp
, tree obj
)
3470 enum tree_code code
= TREE_CODE (exp
);
3471 tree op0
, op1
, op2
, op3
;
3474 /* If this is a PLACEHOLDER_EXPR, see if we find a corresponding type
3475 in the chain of OBJ. */
3476 if (code
== PLACEHOLDER_EXPR
)
3478 tree need_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exp
));
3481 for (elt
= obj
; elt
!= 0;
3482 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3483 || TREE_CODE (elt
) == COND_EXPR
)
3484 ? TREE_OPERAND (elt
, 1)
3485 : (REFERENCE_CLASS_P (elt
)
3486 || UNARY_CLASS_P (elt
)
3487 || BINARY_CLASS_P (elt
)
3488 || VL_EXP_CLASS_P (elt
)
3489 || EXPRESSION_CLASS_P (elt
))
3490 ? TREE_OPERAND (elt
, 0) : 0))
3491 if (TYPE_MAIN_VARIANT (TREE_TYPE (elt
)) == need_type
)
3494 for (elt
= obj
; elt
!= 0;
3495 elt
= ((TREE_CODE (elt
) == COMPOUND_EXPR
3496 || TREE_CODE (elt
) == COND_EXPR
)
3497 ? TREE_OPERAND (elt
, 1)
3498 : (REFERENCE_CLASS_P (elt
)
3499 || UNARY_CLASS_P (elt
)
3500 || BINARY_CLASS_P (elt
)
3501 || VL_EXP_CLASS_P (elt
)
3502 || EXPRESSION_CLASS_P (elt
))
3503 ? TREE_OPERAND (elt
, 0) : 0))
3504 if (POINTER_TYPE_P (TREE_TYPE (elt
))
3505 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (elt
)))
3507 return fold_build1 (INDIRECT_REF
, need_type
, elt
);
3509 /* If we didn't find it, return the original PLACEHOLDER_EXPR. If it
3510 survives until RTL generation, there will be an error. */
3514 /* TREE_LIST is special because we need to look at TREE_VALUE
3515 and TREE_CHAIN, not TREE_OPERANDS. */
3516 else if (code
== TREE_LIST
)
3518 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_CHAIN (exp
), obj
);
3519 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_VALUE (exp
), obj
);
3520 if (op0
== TREE_CHAIN (exp
) && op1
== TREE_VALUE (exp
))
3523 return tree_cons (TREE_PURPOSE (exp
), op1
, op0
);
3526 switch (TREE_CODE_CLASS (code
))
3529 case tcc_declaration
:
3532 case tcc_exceptional
:
3535 case tcc_comparison
:
3536 case tcc_expression
:
3539 switch (TREE_CODE_LENGTH (code
))
3545 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3546 if (op0
== TREE_OPERAND (exp
, 0))
3549 new_tree
= fold_build1 (code
, TREE_TYPE (exp
), op0
);
3553 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3554 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3556 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1))
3559 new_tree
= fold_build2 (code
, TREE_TYPE (exp
), op0
, op1
);
3563 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3564 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3565 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3567 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3568 && op2
== TREE_OPERAND (exp
, 2))
3571 new_tree
= fold_build3 (code
, TREE_TYPE (exp
), op0
, op1
, op2
);
3575 op0
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 0), obj
);
3576 op1
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 1), obj
);
3577 op2
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 2), obj
);
3578 op3
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (TREE_OPERAND (exp
, 3), obj
);
3580 if (op0
== TREE_OPERAND (exp
, 0) && op1
== TREE_OPERAND (exp
, 1)
3581 && op2
== TREE_OPERAND (exp
, 2)
3582 && op3
== TREE_OPERAND (exp
, 3))
3586 = fold (build4 (code
, TREE_TYPE (exp
), op0
, op1
, op2
, op3
));
3598 new_tree
= NULL_TREE
;
3600 for (i
= 1; i
< TREE_OPERAND_LENGTH (exp
); i
++)
3602 tree op
= TREE_OPERAND (exp
, i
);
3603 tree new_op
= SUBSTITUTE_PLACEHOLDER_IN_EXPR (op
, obj
);
3607 new_tree
= copy_node (exp
);
3608 TREE_OPERAND (new_tree
, i
) = new_op
;
3614 new_tree
= fold (new_tree
);
3615 if (TREE_CODE (new_tree
) == CALL_EXPR
)
3616 process_call_operands (new_tree
);
3627 TREE_READONLY (new_tree
) |= TREE_READONLY (exp
);
3629 if (code
== INDIRECT_REF
|| code
== ARRAY_REF
|| code
== ARRAY_RANGE_REF
)
3630 TREE_THIS_NOTRAP (new_tree
) |= TREE_THIS_NOTRAP (exp
);
3635 /* Stabilize a reference so that we can use it any number of times
3636 without causing its operands to be evaluated more than once.
3637 Returns the stabilized reference. This works by means of save_expr,
3638 so see the caveats in the comments about save_expr.
3640 Also allows conversion expressions whose operands are references.
3641 Any other kind of expression is returned unchanged. */
3644 stabilize_reference (tree ref
)
3647 enum tree_code code
= TREE_CODE (ref
);
3654 /* No action is needed in this case. */
3659 case FIX_TRUNC_EXPR
:
3660 result
= build_nt (code
, stabilize_reference (TREE_OPERAND (ref
, 0)));
3664 result
= build_nt (INDIRECT_REF
,
3665 stabilize_reference_1 (TREE_OPERAND (ref
, 0)));
3669 result
= build_nt (COMPONENT_REF
,
3670 stabilize_reference (TREE_OPERAND (ref
, 0)),
3671 TREE_OPERAND (ref
, 1), NULL_TREE
);
3675 result
= build_nt (BIT_FIELD_REF
,
3676 stabilize_reference (TREE_OPERAND (ref
, 0)),
3677 TREE_OPERAND (ref
, 1), TREE_OPERAND (ref
, 2));
3681 result
= build_nt (ARRAY_REF
,
3682 stabilize_reference (TREE_OPERAND (ref
, 0)),
3683 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3684 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
3687 case ARRAY_RANGE_REF
:
3688 result
= build_nt (ARRAY_RANGE_REF
,
3689 stabilize_reference (TREE_OPERAND (ref
, 0)),
3690 stabilize_reference_1 (TREE_OPERAND (ref
, 1)),
3691 TREE_OPERAND (ref
, 2), TREE_OPERAND (ref
, 3));
3695 /* We cannot wrap the first expression in a SAVE_EXPR, as then
3696 it wouldn't be ignored. This matters when dealing with
3698 return stabilize_reference_1 (ref
);
3700 /* If arg isn't a kind of lvalue we recognize, make no change.
3701 Caller should recognize the error for an invalid lvalue. */
3706 return error_mark_node
;
3709 TREE_TYPE (result
) = TREE_TYPE (ref
);
3710 TREE_READONLY (result
) = TREE_READONLY (ref
);
3711 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (ref
);
3712 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (ref
);
3713 TREE_SHARED (result
) = TREE_SHARED (ref
);
3714 TREE_STRICT (result
) = TREE_STRICT (ref
);
3715 TREE_RELAXED (result
) = TREE_RELAXED (ref
);
3720 /* Subroutine of stabilize_reference; this is called for subtrees of
3721 references. Any expression with side-effects must be put in a SAVE_EXPR
3722 to ensure that it is only evaluated once.
3724 We don't put SAVE_EXPR nodes around everything, because assigning very
3725 simple expressions to temporaries causes us to miss good opportunities
3726 for optimizations. Among other things, the opportunity to fold in the
3727 addition of a constant into an addressing mode often gets lost, e.g.
3728 "y[i+1] += x;". In general, we take the approach that we should not make
3729 an assignment unless we are forced into it - i.e., that any non-side effect
3730 operator should be allowed, and that cse should take care of coalescing
3731 multiple utterances of the same expression should that prove fruitful. */
3734 stabilize_reference_1 (tree e
)
3737 enum tree_code code
= TREE_CODE (e
);
3739 /* We cannot ignore const expressions because it might be a reference
3740 to a const array but whose index contains side-effects. But we can
3741 ignore things that are actual constant or that already have been
3742 handled by this function. */
3744 if (tree_invariant_p (e
))
3747 switch (TREE_CODE_CLASS (code
))
3749 case tcc_exceptional
:
3751 case tcc_declaration
:
3752 case tcc_comparison
:
3754 case tcc_expression
:
3757 /* If the expression has side-effects, then encase it in a SAVE_EXPR
3758 so that it will only be evaluated once. */
3759 /* The reference (r) and comparison (<) classes could be handled as
3760 below, but it is generally faster to only evaluate them once. */
3761 if (TREE_SIDE_EFFECTS (e
))
3762 return save_expr (e
);
3766 /* Constants need no processing. In fact, we should never reach
3771 /* Division is slow and tends to be compiled with jumps,
3772 especially the division by powers of 2 that is often
3773 found inside of an array reference. So do it just once. */
3774 if (code
== TRUNC_DIV_EXPR
|| code
== TRUNC_MOD_EXPR
3775 || code
== FLOOR_DIV_EXPR
|| code
== FLOOR_MOD_EXPR
3776 || code
== CEIL_DIV_EXPR
|| code
== CEIL_MOD_EXPR
3777 || code
== ROUND_DIV_EXPR
|| code
== ROUND_MOD_EXPR
)
3778 return save_expr (e
);
3779 /* Recursively stabilize each operand. */
3780 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)),
3781 stabilize_reference_1 (TREE_OPERAND (e
, 1)));
3785 /* Recursively stabilize each operand. */
3786 result
= build_nt (code
, stabilize_reference_1 (TREE_OPERAND (e
, 0)));
3793 TREE_TYPE (result
) = TREE_TYPE (e
);
3794 TREE_READONLY (result
) = TREE_READONLY (e
);
3795 TREE_SIDE_EFFECTS (result
) = TREE_SIDE_EFFECTS (e
);
3796 TREE_THIS_VOLATILE (result
) = TREE_THIS_VOLATILE (e
);
3797 TREE_SHARED (result
) = TREE_SHARED (e
);
3798 TREE_STRICT (result
) = TREE_STRICT (e
);
3799 TREE_RELAXED (result
) = TREE_RELAXED (e
);
3804 /* Low-level constructors for expressions. */
3806 /* A helper function for build1 and constant folders. Set TREE_CONSTANT,
3807 and TREE_SIDE_EFFECTS for an ADDR_EXPR. */
3810 recompute_tree_invariant_for_addr_expr (tree t
)
3813 bool tc
= true, se
= false;
3815 /* We started out assuming this address is both invariant and constant, but
3816 does not have side effects. Now go down any handled components and see if
3817 any of them involve offsets that are either non-constant or non-invariant.
3818 Also check for side-effects.
3820 ??? Note that this code makes no attempt to deal with the case where
3821 taking the address of something causes a copy due to misalignment. */
3823 #define UPDATE_FLAGS(NODE) \
3824 do { tree _node = (NODE); \
3825 if (_node && !TREE_CONSTANT (_node)) tc = false; \
3826 if (_node && TREE_SIDE_EFFECTS (_node)) se = true; } while (0)
3828 for (node
= TREE_OPERAND (t
, 0); handled_component_p (node
);
3829 node
= TREE_OPERAND (node
, 0))
3831 /* If the first operand doesn't have an ARRAY_TYPE, this is a bogus
3832 array reference (probably made temporarily by the G++ front end),
3833 so ignore all the operands. */
3834 if ((TREE_CODE (node
) == ARRAY_REF
3835 || TREE_CODE (node
) == ARRAY_RANGE_REF
)
3836 && TREE_CODE (TREE_TYPE (TREE_OPERAND (node
, 0))) == ARRAY_TYPE
)
3838 UPDATE_FLAGS (TREE_OPERAND (node
, 1));
3839 if (TREE_OPERAND (node
, 2))
3840 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3841 if (TREE_OPERAND (node
, 3))
3842 UPDATE_FLAGS (TREE_OPERAND (node
, 3));
3844 /* Likewise, just because this is a COMPONENT_REF doesn't mean we have a
3845 FIELD_DECL, apparently. The G++ front end can put something else
3846 there, at least temporarily. */
3847 else if (TREE_CODE (node
) == COMPONENT_REF
3848 && TREE_CODE (TREE_OPERAND (node
, 1)) == FIELD_DECL
)
3850 if (TREE_OPERAND (node
, 2))
3851 UPDATE_FLAGS (TREE_OPERAND (node
, 2));
3855 node
= lang_hooks
.expr_to_decl (node
, &tc
, &se
);
3857 /* Now see what's inside. If it's an INDIRECT_REF, copy our properties from
3858 the address, since &(*a)->b is a form of addition. If it's a constant, the
3859 address is constant too. If it's a decl, its address is constant if the
3860 decl is static. Everything else is not constant and, furthermore,
3861 taking the address of a volatile variable is not volatile. */
3862 if (TREE_CODE (node
) == INDIRECT_REF
3863 || TREE_CODE (node
) == MEM_REF
)
3864 UPDATE_FLAGS (TREE_OPERAND (node
, 0));
3865 else if (CONSTANT_CLASS_P (node
))
3867 else if (DECL_P (node
))
3868 tc
&= (staticp (node
) != NULL_TREE
);
3872 se
|= TREE_SIDE_EFFECTS (node
);
3876 TREE_CONSTANT (t
) = tc
;
3877 TREE_SIDE_EFFECTS (t
) = se
;
3881 /* Build an expression of code CODE, data type TYPE, and operands as
3882 specified. Expressions and reference nodes can be created this way.
3883 Constants, decls, types and misc nodes cannot be.
3885 We define 5 non-variadic functions, from 0 to 4 arguments. This is
3886 enough for all extant tree codes. */
3889 build0_stat (enum tree_code code
, tree tt MEM_STAT_DECL
)
3893 gcc_assert (TREE_CODE_LENGTH (code
) == 0);
3895 t
= make_node_stat (code PASS_MEM_STAT
);
3902 build1_stat (enum tree_code code
, tree type
, tree node MEM_STAT_DECL
)
3904 int length
= sizeof (struct tree_exp
);
3907 record_node_allocation_statistics (code
, length
);
3909 gcc_assert (TREE_CODE_LENGTH (code
) == 1);
3911 t
= ggc_alloc_tree_node_stat (length PASS_MEM_STAT
);
3913 memset (t
, 0, sizeof (struct tree_common
));
3915 TREE_SET_CODE (t
, code
);
3917 TREE_TYPE (t
) = type
;
3918 SET_EXPR_LOCATION (t
, UNKNOWN_LOCATION
);
3919 TREE_OPERAND (t
, 0) = node
;
3920 if (node
&& !TYPE_P (node
))
3922 TREE_SIDE_EFFECTS (t
) = TREE_SIDE_EFFECTS (node
);
3923 TREE_READONLY (t
) = TREE_READONLY (node
);
3926 if (TREE_CODE_CLASS (code
) == tcc_statement
)
3927 TREE_SIDE_EFFECTS (t
) = 1;
3931 /* All of these have side-effects, no matter what their
3933 TREE_SIDE_EFFECTS (t
) = 1;
3934 TREE_READONLY (t
) = 0;
3938 /* Whether a dereference is readonly has nothing to do with whether
3939 its operand is readonly. */
3940 TREE_READONLY (t
) = 0;
3941 TREE_SHARED (t
) = upc_shared_type_p (type
);
3946 recompute_tree_invariant_for_addr_expr (t
);
3950 if ((TREE_CODE_CLASS (code
) == tcc_unary
|| code
== VIEW_CONVERT_EXPR
)
3951 && node
&& !TYPE_P (node
)
3952 && TREE_CONSTANT (node
))
3953 TREE_CONSTANT (t
) = 1;
3954 if (TREE_CODE_CLASS (code
) == tcc_reference
3955 && node
&& TREE_THIS_VOLATILE (node
))
3956 TREE_THIS_VOLATILE (t
) = 1;
3957 /* Drop the UPC "shared" type qualifier for
3958 expressions involving UPC shared objects. */
3959 if (TREE_CODE_CLASS (code
) == tcc_unary
3960 && node
&& !TYPE_P (node
)
3961 && upc_shared_type_p (type
))
3962 TREE_TYPE (t
) = build_upc_unshared_type (type
);
3969 #define PROCESS_ARG(N) \
3971 TREE_OPERAND (t, N) = arg##N; \
3972 if (arg##N &&!TYPE_P (arg##N)) \
3974 if (TREE_SIDE_EFFECTS (arg##N)) \
3976 if (!TREE_READONLY (arg##N) \
3977 && !CONSTANT_CLASS_P (arg##N)) \
3978 (void) (read_only = 0); \
3979 if (!TREE_CONSTANT (arg##N)) \
3980 (void) (constant = 0); \
3985 build2_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1 MEM_STAT_DECL
)
3987 bool constant
, read_only
, side_effects
;
3990 gcc_assert (TREE_CODE_LENGTH (code
) == 2);
3992 if ((code
== MINUS_EXPR
|| code
== PLUS_EXPR
|| code
== MULT_EXPR
)
3993 && arg0
&& arg1
&& tt
&& POINTER_TYPE_P (tt
)
3994 /* When sizetype precision doesn't match that of pointers
3995 we need to be able to build explicit extensions or truncations
3996 of the offset argument. */
3997 && TYPE_PRECISION (sizetype
) == TYPE_PRECISION (tt
))
3998 gcc_assert (TREE_CODE (arg0
) == INTEGER_CST
3999 && TREE_CODE (arg1
) == INTEGER_CST
);
4001 if (code
== POINTER_PLUS_EXPR
&& arg0
&& arg1
&& tt
)
4002 gcc_assert (POINTER_TYPE_P (tt
) && POINTER_TYPE_P (TREE_TYPE (arg0
))
4003 && ptrofftype_p (TREE_TYPE (arg1
)));
4005 t
= make_node_stat (code PASS_MEM_STAT
);
4007 /* Remove UPC shared type qualifiers from the result type. */
4008 if (upc_shared_type_p (tt
))
4009 tt
= build_upc_unshared_type (tt
);
4012 /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
4013 result based on those same flags for the arguments. But if the
4014 arguments aren't really even `tree' expressions, we shouldn't be trying
4017 /* Expressions without side effects may be constant if their
4018 arguments are as well. */
4019 constant
= (TREE_CODE_CLASS (code
) == tcc_comparison
4020 || TREE_CODE_CLASS (code
) == tcc_binary
);
4022 side_effects
= TREE_SIDE_EFFECTS (t
);
4027 TREE_READONLY (t
) = read_only
;
4028 TREE_CONSTANT (t
) = constant
;
4029 TREE_SIDE_EFFECTS (t
) = side_effects
;
4030 TREE_THIS_VOLATILE (t
)
4031 = (TREE_CODE_CLASS (code
) == tcc_reference
4032 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4039 build3_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4040 tree arg2 MEM_STAT_DECL
)
4042 bool constant
, read_only
, side_effects
;
4045 gcc_assert (TREE_CODE_LENGTH (code
) == 3);
4046 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4048 t
= make_node_stat (code PASS_MEM_STAT
);
4053 /* As a special exception, if COND_EXPR has NULL branches, we
4054 assume that it is a gimple statement and always consider
4055 it to have side effects. */
4056 if (code
== COND_EXPR
4057 && tt
== void_type_node
4058 && arg1
== NULL_TREE
4059 && arg2
== NULL_TREE
)
4060 side_effects
= true;
4062 side_effects
= TREE_SIDE_EFFECTS (t
);
4068 if (code
== COND_EXPR
)
4069 TREE_READONLY (t
) = read_only
;
4071 TREE_SIDE_EFFECTS (t
) = side_effects
;
4072 TREE_THIS_VOLATILE (t
)
4073 = (TREE_CODE_CLASS (code
) == tcc_reference
4074 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4076 = (TREE_CODE_CLASS (code
) == tcc_reference
4077 && arg0
&& TREE_SHARED (arg0
));
4078 if (TREE_SHARED (t
))
4080 TREE_STRICT (t
) = TREE_STRICT (arg0
);
4081 TREE_RELAXED (t
) = TREE_RELAXED (arg0
);
4088 build4_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4089 tree arg2
, tree arg3 MEM_STAT_DECL
)
4091 bool constant
, read_only
, side_effects
;
4094 gcc_assert (TREE_CODE_LENGTH (code
) == 4);
4096 t
= make_node_stat (code PASS_MEM_STAT
);
4099 side_effects
= TREE_SIDE_EFFECTS (t
);
4106 TREE_SIDE_EFFECTS (t
) = side_effects
;
4107 TREE_THIS_VOLATILE (t
)
4108 = (TREE_CODE_CLASS (code
) == tcc_reference
4109 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4115 build5_stat (enum tree_code code
, tree tt
, tree arg0
, tree arg1
,
4116 tree arg2
, tree arg3
, tree arg4 MEM_STAT_DECL
)
4118 bool constant
, read_only
, side_effects
;
4121 gcc_assert (TREE_CODE_LENGTH (code
) == 5);
4123 t
= make_node_stat (code PASS_MEM_STAT
);
4126 side_effects
= TREE_SIDE_EFFECTS (t
);
4134 TREE_SIDE_EFFECTS (t
) = side_effects
;
4135 TREE_THIS_VOLATILE (t
)
4136 = (TREE_CODE_CLASS (code
) == tcc_reference
4137 && arg0
&& TREE_THIS_VOLATILE (arg0
));
4142 /* Build a simple MEM_REF tree with the sematics of a plain INDIRECT_REF
4143 on the pointer PTR. */
4146 build_simple_mem_ref_loc (location_t loc
, tree ptr
)
4148 HOST_WIDE_INT offset
= 0;
4149 tree ptype
= TREE_TYPE (ptr
);
4151 /* For convenience allow addresses that collapse to a simple base
4153 if (TREE_CODE (ptr
) == ADDR_EXPR
4154 && (handled_component_p (TREE_OPERAND (ptr
, 0))
4155 || TREE_CODE (TREE_OPERAND (ptr
, 0)) == MEM_REF
))
4157 ptr
= get_addr_base_and_unit_offset (TREE_OPERAND (ptr
, 0), &offset
);
4159 ptr
= build_fold_addr_expr (ptr
);
4160 gcc_assert (is_gimple_reg (ptr
) || is_gimple_min_invariant (ptr
));
4162 tem
= build2 (MEM_REF
, TREE_TYPE (ptype
),
4163 ptr
, build_int_cst (ptype
, offset
));
4164 SET_EXPR_LOCATION (tem
, loc
);
4168 /* Return the constant offset of a MEM_REF or TARGET_MEM_REF tree T. */
4171 mem_ref_offset (const_tree t
)
4173 tree toff
= TREE_OPERAND (t
, 1);
4174 return tree_to_double_int (toff
).sext (TYPE_PRECISION (TREE_TYPE (toff
)));
4177 /* Return the pointer-type relevant for TBAA purposes from the
4178 gimple memory reference tree T. This is the type to be used for
4179 the offset operand of MEM_REF or TARGET_MEM_REF replacements of T. */
4182 reference_alias_ptr_type (const_tree t
)
4184 const_tree base
= t
;
4185 while (handled_component_p (base
))
4186 base
= TREE_OPERAND (base
, 0);
4187 if (TREE_CODE (base
) == MEM_REF
)
4188 return TREE_TYPE (TREE_OPERAND (base
, 1));
4189 else if (TREE_CODE (base
) == TARGET_MEM_REF
)
4190 return TREE_TYPE (TMR_OFFSET (base
));
4192 return build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (base
)));
4195 /* Return an invariant ADDR_EXPR of type TYPE taking the address of BASE
4196 offsetted by OFFSET units. */
4199 build_invariant_address (tree type
, tree base
, HOST_WIDE_INT offset
)
4201 tree ref
= fold_build2 (MEM_REF
, TREE_TYPE (type
),
4202 build_fold_addr_expr (base
),
4203 build_int_cst (ptr_type_node
, offset
));
4204 tree addr
= build1 (ADDR_EXPR
, type
, ref
);
4205 recompute_tree_invariant_for_addr_expr (addr
);
4209 /* Similar except don't specify the TREE_TYPE
4210 and leave the TREE_SIDE_EFFECTS as 0.
4211 It is permissible for arguments to be null,
4212 or even garbage if their values do not matter. */
4215 build_nt (enum tree_code code
, ...)
4222 gcc_assert (TREE_CODE_CLASS (code
) != tcc_vl_exp
);
4226 t
= make_node (code
);
4227 length
= TREE_CODE_LENGTH (code
);
4229 for (i
= 0; i
< length
; i
++)
4230 TREE_OPERAND (t
, i
) = va_arg (p
, tree
);
4236 /* Similar to build_nt, but for creating a CALL_EXPR object with a
4240 build_nt_call_vec (tree fn
, vec
<tree
, va_gc
> *args
)
4245 ret
= build_vl_exp (CALL_EXPR
, vec_safe_length (args
) + 3);
4246 CALL_EXPR_FN (ret
) = fn
;
4247 CALL_EXPR_STATIC_CHAIN (ret
) = NULL_TREE
;
4248 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
4249 CALL_EXPR_ARG (ret
, ix
) = t
;
4253 /* Create a DECL_... node of code CODE, name NAME and data type TYPE.
4254 We do NOT enter this node in any sort of symbol table.
4256 LOC is the location of the decl.
4258 layout_decl is used to set up the decl's storage layout.
4259 Other slots are initialized to 0 or null pointers. */
4262 build_decl_stat (location_t loc
, enum tree_code code
, tree name
,
4263 tree type MEM_STAT_DECL
)
4267 t
= make_node_stat (code PASS_MEM_STAT
);
4268 DECL_SOURCE_LOCATION (t
) = loc
;
4270 /* if (type == error_mark_node)
4271 type = integer_type_node; */
4272 /* That is not done, deliberately, so that having error_mark_node
4273 as the type can suppress useless errors in the use of this variable. */
4275 DECL_NAME (t
) = name
;
4276 TREE_TYPE (t
) = type
;
4278 if (code
== VAR_DECL
|| code
== PARM_DECL
|| code
== RESULT_DECL
)
4284 /* Builds and returns function declaration with NAME and TYPE. */
4287 build_fn_decl (const char *name
, tree type
)
4289 tree id
= get_identifier (name
);
4290 tree decl
= build_decl (input_location
, FUNCTION_DECL
, id
, type
);
4292 DECL_EXTERNAL (decl
) = 1;
4293 TREE_PUBLIC (decl
) = 1;
4294 DECL_ARTIFICIAL (decl
) = 1;
4295 TREE_NOTHROW (decl
) = 1;
4300 vec
<tree
, va_gc
> *all_translation_units
;
4302 /* Builds a new translation-unit decl with name NAME, queues it in the
4303 global list of translation-unit decls and returns it. */
4306 build_translation_unit_decl (tree name
)
4308 tree tu
= build_decl (UNKNOWN_LOCATION
, TRANSLATION_UNIT_DECL
,
4310 TRANSLATION_UNIT_LANGUAGE (tu
) = lang_hooks
.name
;
4311 vec_safe_push (all_translation_units
, tu
);
4316 /* BLOCK nodes are used to represent the structure of binding contours
4317 and declarations, once those contours have been exited and their contents
4318 compiled. This information is used for outputting debugging info. */
4321 build_block (tree vars
, tree subblocks
, tree supercontext
, tree chain
)
4323 tree block
= make_node (BLOCK
);
4325 BLOCK_VARS (block
) = vars
;
4326 BLOCK_SUBBLOCKS (block
) = subblocks
;
4327 BLOCK_SUPERCONTEXT (block
) = supercontext
;
4328 BLOCK_CHAIN (block
) = chain
;
4333 /* Like SET_EXPR_LOCATION, but make sure the tree can have a location.
4335 LOC is the location to use in tree T. */
4338 protected_set_expr_location (tree t
, location_t loc
)
4340 if (t
&& CAN_HAVE_LOCATION_P (t
))
4341 SET_EXPR_LOCATION (t
, loc
);
4344 /* Return a declaration like DDECL except that its DECL_ATTRIBUTES
4348 build_decl_attribute_variant (tree ddecl
, tree attribute
)
4350 DECL_ATTRIBUTES (ddecl
) = attribute
;
4354 /* Borrowed from hashtab.c iterative_hash implementation. */
4355 #define mix(a,b,c) \
4357 a -= b; a -= c; a ^= (c>>13); \
4358 b -= c; b -= a; b ^= (a<< 8); \
4359 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
4360 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
4361 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
4362 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
4363 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
4364 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
4365 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
4369 /* Produce good hash value combining VAL and VAL2. */
4371 iterative_hash_hashval_t (hashval_t val
, hashval_t val2
)
4373 /* the golden ratio; an arbitrary value. */
4374 hashval_t a
= 0x9e3779b9;
4380 /* Produce good hash value combining VAL and VAL2. */
4382 iterative_hash_host_wide_int (HOST_WIDE_INT val
, hashval_t val2
)
4384 if (sizeof (HOST_WIDE_INT
) == sizeof (hashval_t
))
4385 return iterative_hash_hashval_t (val
, val2
);
4388 hashval_t a
= (hashval_t
) val
;
4389 /* Avoid warnings about shifting of more than the width of the type on
4390 hosts that won't execute this path. */
4392 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 8 + zero
));
4394 if (sizeof (HOST_WIDE_INT
) > 2 * sizeof (hashval_t
))
4396 hashval_t a
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 16 + zero
));
4397 hashval_t b
= (hashval_t
) (val
>> (sizeof (hashval_t
) * 24 + zero
));
4404 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4405 is ATTRIBUTE and its qualifiers are QUALS.
4407 Record such modified types already made so we don't make duplicates. */
4410 build_type_attribute_qual_variant (tree ttype
, tree attribute
, int quals
)
4412 if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype
), attribute
))
4414 hashval_t hashcode
= 0;
4416 enum tree_code code
= TREE_CODE (ttype
);
4418 /* Building a distinct copy of a tagged type is inappropriate; it
4419 causes breakage in code that expects there to be a one-to-one
4420 relationship between a struct and its fields.
4421 build_duplicate_type is another solution (as used in
4422 handle_transparent_union_attribute), but that doesn't play well
4423 with the stronger C++ type identity model. */
4424 if (TREE_CODE (ttype
) == RECORD_TYPE
4425 || TREE_CODE (ttype
) == UNION_TYPE
4426 || TREE_CODE (ttype
) == QUAL_UNION_TYPE
4427 || TREE_CODE (ttype
) == ENUMERAL_TYPE
)
4429 warning (OPT_Wattributes
,
4430 "ignoring attributes applied to %qT after definition",
4431 TYPE_MAIN_VARIANT (ttype
));
4432 return build_qualified_type (ttype
, quals
);
4435 ttype
= build_qualified_type (ttype
, TYPE_UNQUALIFIED
);
4436 ntype
= build_distinct_type_copy (ttype
);
4438 TYPE_ATTRIBUTES (ntype
) = attribute
;
4440 hashcode
= iterative_hash_object (code
, hashcode
);
4441 if (TREE_TYPE (ntype
))
4442 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (ntype
)),
4444 hashcode
= attribute_hash_list (attribute
, hashcode
);
4446 switch (TREE_CODE (ntype
))
4449 hashcode
= type_hash_list (TYPE_ARG_TYPES (ntype
), hashcode
);
4452 if (TYPE_DOMAIN (ntype
))
4453 hashcode
= iterative_hash_object (TYPE_HASH (TYPE_DOMAIN (ntype
)),
4457 hashcode
= iterative_hash_object
4458 (TREE_INT_CST_LOW (TYPE_MAX_VALUE (ntype
)), hashcode
);
4459 hashcode
= iterative_hash_object
4460 (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (ntype
)), hashcode
);
4463 case FIXED_POINT_TYPE
:
4465 unsigned int precision
= TYPE_PRECISION (ntype
);
4466 hashcode
= iterative_hash_object (precision
, hashcode
);
4473 ntype
= type_hash_canon (hashcode
, ntype
);
4475 /* If the target-dependent attributes make NTYPE different from
4476 its canonical type, we will need to use structural equality
4477 checks for this type. */
4478 if (TYPE_STRUCTURAL_EQUALITY_P (ttype
)
4479 || !comp_type_attributes (ntype
, ttype
))
4480 SET_TYPE_STRUCTURAL_EQUALITY (ntype
);
4481 else if (TYPE_CANONICAL (ntype
) == ntype
)
4482 TYPE_CANONICAL (ntype
) = TYPE_CANONICAL (ttype
);
4484 ttype
= build_qualified_type (ntype
, quals
);
4486 else if (TYPE_QUALS (ttype
) != quals
)
4487 ttype
= build_qualified_type (ttype
, quals
);
4492 /* Compare two attributes for their value identity. Return true if the
4493 attribute values are known to be equal; otherwise return false.
4497 attribute_value_equal (const_tree attr1
, const_tree attr2
)
4499 if (TREE_VALUE (attr1
) == TREE_VALUE (attr2
))
4502 if (TREE_VALUE (attr1
) != NULL_TREE
4503 && TREE_CODE (TREE_VALUE (attr1
)) == TREE_LIST
4504 && TREE_VALUE (attr2
) != NULL
4505 && TREE_CODE (TREE_VALUE (attr2
)) == TREE_LIST
)
4506 return (simple_cst_list_equal (TREE_VALUE (attr1
),
4507 TREE_VALUE (attr2
)) == 1);
4509 return (simple_cst_equal (TREE_VALUE (attr1
), TREE_VALUE (attr2
)) == 1);
4512 /* Return 0 if the attributes for two types are incompatible, 1 if they
4513 are compatible, and 2 if they are nearly compatible (which causes a
4514 warning to be generated). */
4516 comp_type_attributes (const_tree type1
, const_tree type2
)
4518 const_tree a1
= TYPE_ATTRIBUTES (type1
);
4519 const_tree a2
= TYPE_ATTRIBUTES (type2
);
4524 for (a
= a1
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
4526 const struct attribute_spec
*as
;
4529 as
= lookup_attribute_spec (get_attribute_name (a
));
4530 if (!as
|| as
->affects_type_identity
== false)
4533 attr
= lookup_attribute (as
->name
, CONST_CAST_TREE (a2
));
4534 if (!attr
|| !attribute_value_equal (a
, attr
))
4539 for (a
= a2
; a
!= NULL_TREE
; a
= TREE_CHAIN (a
))
4541 const struct attribute_spec
*as
;
4543 as
= lookup_attribute_spec (get_attribute_name (a
));
4544 if (!as
|| as
->affects_type_identity
== false)
4547 if (!lookup_attribute (as
->name
, CONST_CAST_TREE (a1
)))
4549 /* We don't need to compare trees again, as we did this
4550 already in first loop. */
4552 /* All types - affecting identity - are equal, so
4553 there is no need to call target hook for comparison. */
4557 /* As some type combinations - like default calling-convention - might
4558 be compatible, we have to call the target hook to get the final result. */
4559 return targetm
.comp_type_attributes (type1
, type2
);
4562 /* Return a type like TTYPE except that its TYPE_ATTRIBUTE
4565 Record such modified types already made so we don't make duplicates. */
4568 build_type_attribute_variant (tree ttype
, tree attribute
)
4570 return build_type_attribute_qual_variant (ttype
, attribute
,
4571 TYPE_QUALS (ttype
));
4575 /* Reset the expression *EXPR_P, a size or position.
4577 ??? We could reset all non-constant sizes or positions. But it's cheap
4578 enough to not do so and refrain from adding workarounds to dwarf2out.c.
4580 We need to reset self-referential sizes or positions because they cannot
4581 be gimplified and thus can contain a CALL_EXPR after the gimplification
4582 is finished, which will run afoul of LTO streaming. And they need to be
4583 reset to something essentially dummy but not constant, so as to preserve
4584 the properties of the object they are attached to. */
4587 free_lang_data_in_one_sizepos (tree
*expr_p
)
4589 tree expr
= *expr_p
;
4590 if (CONTAINS_PLACEHOLDER_P (expr
))
4591 *expr_p
= build0 (PLACEHOLDER_EXPR
, TREE_TYPE (expr
));
4595 /* Reset all the fields in a binfo node BINFO. We only keep
4596 BINFO_VTABLE, which is used by gimple_fold_obj_type_ref. */
4599 free_lang_data_in_binfo (tree binfo
)
4604 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
4606 BINFO_VIRTUALS (binfo
) = NULL_TREE
;
4607 BINFO_BASE_ACCESSES (binfo
) = NULL
;
4608 BINFO_INHERITANCE_CHAIN (binfo
) = NULL_TREE
;
4609 BINFO_SUBVTT_INDEX (binfo
) = NULL_TREE
;
4611 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (binfo
), i
, t
)
4612 free_lang_data_in_binfo (t
);
4616 /* Reset all language specific information still present in TYPE. */
4619 free_lang_data_in_type (tree type
)
4621 gcc_assert (TYPE_P (type
));
4623 /* Give the FE a chance to remove its own data first. */
4624 lang_hooks
.free_lang_data (type
);
4626 TREE_LANG_FLAG_0 (type
) = 0;
4627 TREE_LANG_FLAG_1 (type
) = 0;
4628 TREE_LANG_FLAG_2 (type
) = 0;
4629 TREE_LANG_FLAG_3 (type
) = 0;
4630 TREE_LANG_FLAG_4 (type
) = 0;
4631 TREE_LANG_FLAG_5 (type
) = 0;
4632 TREE_LANG_FLAG_6 (type
) = 0;
4634 if (TREE_CODE (type
) == FUNCTION_TYPE
)
4636 /* Remove the const and volatile qualifiers from arguments. The
4637 C++ front end removes them, but the C front end does not,
4638 leading to false ODR violation errors when merging two
4639 instances of the same function signature compiled by
4640 different front ends. */
4643 for (p
= TYPE_ARG_TYPES (type
); p
; p
= TREE_CHAIN (p
))
4645 tree arg_type
= TREE_VALUE (p
);
4647 if (TYPE_READONLY (arg_type
) || TYPE_VOLATILE (arg_type
))
4649 int quals
= TYPE_QUALS (arg_type
)
4651 & ~TYPE_QUAL_VOLATILE
;
4652 TREE_VALUE (p
) = build_qualified_type (arg_type
, quals
);
4653 free_lang_data_in_type (TREE_VALUE (p
));
4658 /* Remove members that are not actually FIELD_DECLs from the field
4659 list of an aggregate. These occur in C++. */
4660 if (RECORD_OR_UNION_TYPE_P (type
))
4664 /* Note that TYPE_FIELDS can be shared across distinct
4665 TREE_TYPEs. Therefore, if the first field of TYPE_FIELDS is
4666 to be removed, we cannot set its TREE_CHAIN to NULL.
4667 Otherwise, we would not be able to find all the other fields
4668 in the other instances of this TREE_TYPE.
4670 This was causing an ICE in testsuite/g++.dg/lto/20080915.C. */
4672 member
= TYPE_FIELDS (type
);
4675 if (TREE_CODE (member
) == FIELD_DECL
4676 || TREE_CODE (member
) == TYPE_DECL
)
4679 TREE_CHAIN (prev
) = member
;
4681 TYPE_FIELDS (type
) = member
;
4685 member
= TREE_CHAIN (member
);
4689 TREE_CHAIN (prev
) = NULL_TREE
;
4691 TYPE_FIELDS (type
) = NULL_TREE
;
4693 TYPE_METHODS (type
) = NULL_TREE
;
4694 if (TYPE_BINFO (type
))
4695 free_lang_data_in_binfo (TYPE_BINFO (type
));
4699 /* For non-aggregate types, clear out the language slot (which
4700 overloads TYPE_BINFO). */
4701 TYPE_LANG_SLOT_1 (type
) = NULL_TREE
;
4703 if (INTEGRAL_TYPE_P (type
)
4704 || SCALAR_FLOAT_TYPE_P (type
)
4705 || FIXED_POINT_TYPE_P (type
))
4707 free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type
));
4708 free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type
));
4712 free_lang_data_in_one_sizepos (&TYPE_SIZE (type
));
4713 free_lang_data_in_one_sizepos (&TYPE_SIZE_UNIT (type
));
4715 if (TYPE_CONTEXT (type
)
4716 && TREE_CODE (TYPE_CONTEXT (type
)) == BLOCK
)
4718 tree ctx
= TYPE_CONTEXT (type
);
4721 ctx
= BLOCK_SUPERCONTEXT (ctx
);
4723 while (ctx
&& TREE_CODE (ctx
) == BLOCK
);
4724 TYPE_CONTEXT (type
) = ctx
;
4729 /* Return true if DECL may need an assembler name to be set. */
4732 need_assembler_name_p (tree decl
)
4734 /* Only FUNCTION_DECLs and VAR_DECLs are considered. */
4735 if (TREE_CODE (decl
) != FUNCTION_DECL
4736 && TREE_CODE (decl
) != VAR_DECL
)
4739 /* If DECL already has its assembler name set, it does not need a
4741 if (!HAS_DECL_ASSEMBLER_NAME_P (decl
)
4742 || DECL_ASSEMBLER_NAME_SET_P (decl
))
4745 /* Abstract decls do not need an assembler name. */
4746 if (DECL_ABSTRACT (decl
))
4749 /* For VAR_DECLs, only static, public and external symbols need an
4751 if (TREE_CODE (decl
) == VAR_DECL
4752 && !TREE_STATIC (decl
)
4753 && !TREE_PUBLIC (decl
)
4754 && !DECL_EXTERNAL (decl
))
4757 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4759 /* Do not set assembler name on builtins. Allow RTL expansion to
4760 decide whether to expand inline or via a regular call. */
4761 if (DECL_BUILT_IN (decl
)
4762 && DECL_BUILT_IN_CLASS (decl
) != BUILT_IN_FRONTEND
)
4765 /* Functions represented in the callgraph need an assembler name. */
4766 if (cgraph_get_node (decl
) != NULL
)
4769 /* Unused and not public functions don't need an assembler name. */
4770 if (!TREE_USED (decl
) && !TREE_PUBLIC (decl
))
4778 /* Reset all language specific information still present in symbol
4782 free_lang_data_in_decl (tree decl
)
4784 gcc_assert (DECL_P (decl
));
4786 /* Give the FE a chance to remove its own data first. */
4787 lang_hooks
.free_lang_data (decl
);
4789 TREE_LANG_FLAG_0 (decl
) = 0;
4790 TREE_LANG_FLAG_1 (decl
) = 0;
4791 TREE_LANG_FLAG_2 (decl
) = 0;
4792 TREE_LANG_FLAG_3 (decl
) = 0;
4793 TREE_LANG_FLAG_4 (decl
) = 0;
4794 TREE_LANG_FLAG_5 (decl
) = 0;
4795 TREE_LANG_FLAG_6 (decl
) = 0;
4797 free_lang_data_in_one_sizepos (&DECL_SIZE (decl
));
4798 free_lang_data_in_one_sizepos (&DECL_SIZE_UNIT (decl
));
4799 if (TREE_CODE (decl
) == FIELD_DECL
)
4801 free_lang_data_in_one_sizepos (&DECL_FIELD_OFFSET (decl
));
4802 if (TREE_CODE (DECL_CONTEXT (decl
)) == QUAL_UNION_TYPE
)
4803 DECL_QUALIFIER (decl
) = NULL_TREE
;
4806 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4808 if (gimple_has_body_p (decl
))
4812 /* If DECL has a gimple body, then the context for its
4813 arguments must be DECL. Otherwise, it doesn't really
4814 matter, as we will not be emitting any code for DECL. In
4815 general, there may be other instances of DECL created by
4816 the front end and since PARM_DECLs are generally shared,
4817 their DECL_CONTEXT changes as the replicas of DECL are
4818 created. The only time where DECL_CONTEXT is important
4819 is for the FUNCTION_DECLs that have a gimple body (since
4820 the PARM_DECL will be used in the function's body). */
4821 for (t
= DECL_ARGUMENTS (decl
); t
; t
= TREE_CHAIN (t
))
4822 DECL_CONTEXT (t
) = decl
;
4825 /* DECL_SAVED_TREE holds the GENERIC representation for DECL.
4826 At this point, it is not needed anymore. */
4827 DECL_SAVED_TREE (decl
) = NULL_TREE
;
4829 /* Clear the abstract origin if it refers to a method. Otherwise
4830 dwarf2out.c will ICE as we clear TYPE_METHODS and thus the
4831 origin will not be output correctly. */
4832 if (DECL_ABSTRACT_ORIGIN (decl
)
4833 && DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))
4834 && RECORD_OR_UNION_TYPE_P
4835 (DECL_CONTEXT (DECL_ABSTRACT_ORIGIN (decl
))))
4836 DECL_ABSTRACT_ORIGIN (decl
) = NULL_TREE
;
4838 /* Sometimes the C++ frontend doesn't manage to transform a temporary
4839 DECL_VINDEX referring to itself into a vtable slot number as it
4840 should. Happens with functions that are copied and then forgotten
4841 about. Just clear it, it won't matter anymore. */
4842 if (DECL_VINDEX (decl
) && !host_integerp (DECL_VINDEX (decl
), 0))
4843 DECL_VINDEX (decl
) = NULL_TREE
;
4845 else if (TREE_CODE (decl
) == VAR_DECL
)
4847 if ((DECL_EXTERNAL (decl
)
4848 && (!TREE_STATIC (decl
) || !TREE_READONLY (decl
)))
4849 || (decl_function_context (decl
) && !TREE_STATIC (decl
)))
4850 DECL_INITIAL (decl
) = NULL_TREE
;
4852 else if (TREE_CODE (decl
) == TYPE_DECL
4853 || TREE_CODE (decl
) == FIELD_DECL
)
4854 DECL_INITIAL (decl
) = NULL_TREE
;
4855 else if (TREE_CODE (decl
) == TRANSLATION_UNIT_DECL
4856 && DECL_INITIAL (decl
)
4857 && TREE_CODE (DECL_INITIAL (decl
)) == BLOCK
)
4859 /* Strip builtins from the translation-unit BLOCK. We still have targets
4860 without builtin_decl_explicit support and also builtins are shared
4861 nodes and thus we can't use TREE_CHAIN in multiple lists. */
4862 tree
*nextp
= &BLOCK_VARS (DECL_INITIAL (decl
));
4866 if (TREE_CODE (var
) == FUNCTION_DECL
4867 && DECL_BUILT_IN (var
))
4868 *nextp
= TREE_CHAIN (var
);
4870 nextp
= &TREE_CHAIN (var
);
4876 /* Data used when collecting DECLs and TYPEs for language data removal. */
4878 struct free_lang_data_d
4880 /* Worklist to avoid excessive recursion. */
4883 /* Set of traversed objects. Used to avoid duplicate visits. */
4884 struct pointer_set_t
*pset
;
4886 /* Array of symbols to process with free_lang_data_in_decl. */
4889 /* Array of types to process with free_lang_data_in_type. */
4894 /* Save all language fields needed to generate proper debug information
4895 for DECL. This saves most fields cleared out by free_lang_data_in_decl. */
4898 save_debug_info_for_decl (tree t
)
4900 /*struct saved_debug_info_d *sdi;*/
4902 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& DECL_P (t
));
4904 /* FIXME. Partial implementation for saving debug info removed. */
4908 /* Save all language fields needed to generate proper debug information
4909 for TYPE. This saves most fields cleared out by free_lang_data_in_type. */
4912 save_debug_info_for_type (tree t
)
4914 /*struct saved_debug_info_d *sdi;*/
4916 gcc_assert (debug_info_level
> DINFO_LEVEL_TERSE
&& t
&& TYPE_P (t
));
4918 /* FIXME. Partial implementation for saving debug info removed. */
4922 /* Add type or decl T to one of the list of tree nodes that need their
4923 language data removed. The lists are held inside FLD. */
4926 add_tree_to_fld_list (tree t
, struct free_lang_data_d
*fld
)
4930 fld
->decls
.safe_push (t
);
4931 if (debug_info_level
> DINFO_LEVEL_TERSE
)
4932 save_debug_info_for_decl (t
);
4934 else if (TYPE_P (t
))
4936 fld
->types
.safe_push (t
);
4937 if (debug_info_level
> DINFO_LEVEL_TERSE
)
4938 save_debug_info_for_type (t
);
4944 /* Push tree node T into FLD->WORKLIST. */
4947 fld_worklist_push (tree t
, struct free_lang_data_d
*fld
)
4949 if (t
&& !is_lang_specific (t
) && !pointer_set_contains (fld
->pset
, t
))
4950 fld
->worklist
.safe_push ((t
));
4954 /* Operand callback helper for free_lang_data_in_node. *TP is the
4955 subtree operand being considered. */
4958 find_decls_types_r (tree
*tp
, int *ws
, void *data
)
4961 struct free_lang_data_d
*fld
= (struct free_lang_data_d
*) data
;
4963 if (TREE_CODE (t
) == TREE_LIST
)
4966 /* Language specific nodes will be removed, so there is no need
4967 to gather anything under them. */
4968 if (is_lang_specific (t
))
4976 /* Note that walk_tree does not traverse every possible field in
4977 decls, so we have to do our own traversals here. */
4978 add_tree_to_fld_list (t
, fld
);
4980 fld_worklist_push (DECL_NAME (t
), fld
);
4981 fld_worklist_push (DECL_CONTEXT (t
), fld
);
4982 fld_worklist_push (DECL_SIZE (t
), fld
);
4983 fld_worklist_push (DECL_SIZE_UNIT (t
), fld
);
4985 /* We are going to remove everything under DECL_INITIAL for
4986 TYPE_DECLs. No point walking them. */
4987 if (TREE_CODE (t
) != TYPE_DECL
)
4988 fld_worklist_push (DECL_INITIAL (t
), fld
);
4990 fld_worklist_push (DECL_ATTRIBUTES (t
), fld
);
4991 fld_worklist_push (DECL_ABSTRACT_ORIGIN (t
), fld
);
4993 if (TREE_CODE (t
) == FUNCTION_DECL
)
4995 fld_worklist_push (DECL_ARGUMENTS (t
), fld
);
4996 fld_worklist_push (DECL_RESULT (t
), fld
);
4998 else if (TREE_CODE (t
) == TYPE_DECL
)
5000 fld_worklist_push (DECL_ARGUMENT_FLD (t
), fld
);
5001 fld_worklist_push (DECL_VINDEX (t
), fld
);
5002 fld_worklist_push (DECL_ORIGINAL_TYPE (t
), fld
);
5004 else if (TREE_CODE (t
) == FIELD_DECL
)
5006 fld_worklist_push (DECL_FIELD_OFFSET (t
), fld
);
5007 fld_worklist_push (DECL_BIT_FIELD_TYPE (t
), fld
);
5008 fld_worklist_push (DECL_FIELD_BIT_OFFSET (t
), fld
);
5009 fld_worklist_push (DECL_FCONTEXT (t
), fld
);
5011 else if (TREE_CODE (t
) == VAR_DECL
)
5013 fld_worklist_push (DECL_SECTION_NAME (t
), fld
);
5014 fld_worklist_push (DECL_COMDAT_GROUP (t
), fld
);
5017 if ((TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == PARM_DECL
)
5018 && DECL_HAS_VALUE_EXPR_P (t
))
5019 fld_worklist_push (DECL_VALUE_EXPR (t
), fld
);
5021 if (TREE_CODE (t
) != FIELD_DECL
5022 && TREE_CODE (t
) != TYPE_DECL
)
5023 fld_worklist_push (TREE_CHAIN (t
), fld
);
5026 else if (TYPE_P (t
))
5028 /* Note that walk_tree does not traverse every possible field in
5029 types, so we have to do our own traversals here. */
5030 add_tree_to_fld_list (t
, fld
);
5032 if (!RECORD_OR_UNION_TYPE_P (t
))
5033 fld_worklist_push (TYPE_CACHED_VALUES (t
), fld
);
5034 fld_worklist_push (TYPE_SIZE (t
), fld
);
5035 fld_worklist_push (TYPE_SIZE_UNIT (t
), fld
);
5036 fld_worklist_push (TYPE_ATTRIBUTES (t
), fld
);
5037 fld_worklist_push (TYPE_POINTER_TO (t
), fld
);
5038 fld_worklist_push (TYPE_REFERENCE_TO (t
), fld
);
5039 fld_worklist_push (TYPE_NAME (t
), fld
);
5040 /* Do not walk TYPE_NEXT_PTR_TO or TYPE_NEXT_REF_TO. We do not stream
5041 them and thus do not and want not to reach unused pointer types
5043 if (!POINTER_TYPE_P (t
))
5044 fld_worklist_push (TYPE_MINVAL (t
), fld
);
5045 if (!RECORD_OR_UNION_TYPE_P (t
))
5046 fld_worklist_push (TYPE_MAXVAL (t
), fld
);
5047 fld_worklist_push (TYPE_MAIN_VARIANT (t
), fld
);
5048 /* Do not walk TYPE_NEXT_VARIANT. We do not stream it and thus
5049 do not and want not to reach unused variants this way. */
5050 if (TYPE_CONTEXT (t
))
5052 tree ctx
= TYPE_CONTEXT (t
);
5053 /* We adjust BLOCK TYPE_CONTEXTs to the innermost non-BLOCK one.
5054 So push that instead. */
5055 while (ctx
&& TREE_CODE (ctx
) == BLOCK
)
5056 ctx
= BLOCK_SUPERCONTEXT (ctx
);
5057 fld_worklist_push (ctx
, fld
);
5059 /* Do not walk TYPE_CANONICAL. We do not stream it and thus do not
5060 and want not to reach unused types this way. */
5062 if (RECORD_OR_UNION_TYPE_P (t
) && TYPE_BINFO (t
))
5066 FOR_EACH_VEC_ELT (*BINFO_BASE_BINFOS (TYPE_BINFO (t
)), i
, tem
)
5067 fld_worklist_push (TREE_TYPE (tem
), fld
);
5068 tem
= BINFO_VIRTUALS (TYPE_BINFO (t
));
5070 /* The Java FE overloads BINFO_VIRTUALS for its own purpose. */
5071 && TREE_CODE (tem
) == TREE_LIST
)
5074 fld_worklist_push (TREE_VALUE (tem
), fld
);
5075 tem
= TREE_CHAIN (tem
);
5079 if (RECORD_OR_UNION_TYPE_P (t
))
5082 /* Push all TYPE_FIELDS - there can be interleaving interesting
5083 and non-interesting things. */
5084 tem
= TYPE_FIELDS (t
);
5087 if (TREE_CODE (tem
) == FIELD_DECL
5088 || TREE_CODE (tem
) == TYPE_DECL
)
5089 fld_worklist_push (tem
, fld
);
5090 tem
= TREE_CHAIN (tem
);
5094 fld_worklist_push (TYPE_STUB_DECL (t
), fld
);
5097 else if (TREE_CODE (t
) == BLOCK
)
5100 for (tem
= BLOCK_VARS (t
); tem
; tem
= TREE_CHAIN (tem
))
5101 fld_worklist_push (tem
, fld
);
5102 for (tem
= BLOCK_SUBBLOCKS (t
); tem
; tem
= BLOCK_CHAIN (tem
))
5103 fld_worklist_push (tem
, fld
);
5104 fld_worklist_push (BLOCK_ABSTRACT_ORIGIN (t
), fld
);
5107 if (TREE_CODE (t
) != IDENTIFIER_NODE
5108 && CODE_CONTAINS_STRUCT (TREE_CODE (t
), TS_TYPED
))
5109 fld_worklist_push (TREE_TYPE (t
), fld
);
5115 /* Find decls and types in T. */
5118 find_decls_types (tree t
, struct free_lang_data_d
*fld
)
5122 if (!pointer_set_contains (fld
->pset
, t
))
5123 walk_tree (&t
, find_decls_types_r
, fld
, fld
->pset
);
5124 if (fld
->worklist
.is_empty ())
5126 t
= fld
->worklist
.pop ();
5130 /* Translate all the types in LIST with the corresponding runtime
5134 get_eh_types_for_runtime (tree list
)
5138 if (list
== NULL_TREE
)
5141 head
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
5143 list
= TREE_CHAIN (list
);
5146 tree n
= build_tree_list (0, lookup_type_for_runtime (TREE_VALUE (list
)));
5147 TREE_CHAIN (prev
) = n
;
5148 prev
= TREE_CHAIN (prev
);
5149 list
= TREE_CHAIN (list
);
5156 /* Find decls and types referenced in EH region R and store them in
5157 FLD->DECLS and FLD->TYPES. */
5160 find_decls_types_in_eh_region (eh_region r
, struct free_lang_data_d
*fld
)
5171 /* The types referenced in each catch must first be changed to the
5172 EH types used at runtime. This removes references to FE types
5174 for (c
= r
->u
.eh_try
.first_catch
; c
; c
= c
->next_catch
)
5176 c
->type_list
= get_eh_types_for_runtime (c
->type_list
);
5177 walk_tree (&c
->type_list
, find_decls_types_r
, fld
, fld
->pset
);
5182 case ERT_ALLOWED_EXCEPTIONS
:
5183 r
->u
.allowed
.type_list
5184 = get_eh_types_for_runtime (r
->u
.allowed
.type_list
);
5185 walk_tree (&r
->u
.allowed
.type_list
, find_decls_types_r
, fld
, fld
->pset
);
5188 case ERT_MUST_NOT_THROW
:
5189 walk_tree (&r
->u
.must_not_throw
.failure_decl
,
5190 find_decls_types_r
, fld
, fld
->pset
);
5196 /* Find decls and types referenced in cgraph node N and store them in
5197 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5198 look for *every* kind of DECL and TYPE node reachable from N,
5199 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5200 NAMESPACE_DECLs, etc). */
5203 find_decls_types_in_node (struct cgraph_node
*n
, struct free_lang_data_d
*fld
)
5206 struct function
*fn
;
5210 find_decls_types (n
->symbol
.decl
, fld
);
5212 if (!gimple_has_body_p (n
->symbol
.decl
))
5215 gcc_assert (current_function_decl
== NULL_TREE
&& cfun
== NULL
);
5217 fn
= DECL_STRUCT_FUNCTION (n
->symbol
.decl
);
5219 /* Traverse locals. */
5220 FOR_EACH_LOCAL_DECL (fn
, ix
, t
)
5221 find_decls_types (t
, fld
);
5223 /* Traverse EH regions in FN. */
5226 FOR_ALL_EH_REGION_FN (r
, fn
)
5227 find_decls_types_in_eh_region (r
, fld
);
5230 /* Traverse every statement in FN. */
5231 FOR_EACH_BB_FN (bb
, fn
)
5233 gimple_stmt_iterator si
;
5236 for (si
= gsi_start_phis (bb
); !gsi_end_p (si
); gsi_next (&si
))
5238 gimple phi
= gsi_stmt (si
);
5240 for (i
= 0; i
< gimple_phi_num_args (phi
); i
++)
5242 tree
*arg_p
= gimple_phi_arg_def_ptr (phi
, i
);
5243 find_decls_types (*arg_p
, fld
);
5247 for (si
= gsi_start_bb (bb
); !gsi_end_p (si
); gsi_next (&si
))
5249 gimple stmt
= gsi_stmt (si
);
5251 if (is_gimple_call (stmt
))
5252 find_decls_types (gimple_call_fntype (stmt
), fld
);
5254 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
5256 tree arg
= gimple_op (stmt
, i
);
5257 find_decls_types (arg
, fld
);
5264 /* Find decls and types referenced in varpool node N and store them in
5265 FLD->DECLS and FLD->TYPES. Unlike pass_referenced_vars, this will
5266 look for *every* kind of DECL and TYPE node reachable from N,
5267 including those embedded inside types and decls (i.e,, TYPE_DECLs,
5268 NAMESPACE_DECLs, etc). */
5271 find_decls_types_in_var (struct varpool_node
*v
, struct free_lang_data_d
*fld
)
5273 find_decls_types (v
->symbol
.decl
, fld
);
5276 /* If T needs an assembler name, have one created for it. */
5279 assign_assembler_name_if_neeeded (tree t
)
5281 if (need_assembler_name_p (t
))
5283 /* When setting DECL_ASSEMBLER_NAME, the C++ mangler may emit
5284 diagnostics that use input_location to show locus
5285 information. The problem here is that, at this point,
5286 input_location is generally anchored to the end of the file
5287 (since the parser is long gone), so we don't have a good
5288 position to pin it to.
5290 To alleviate this problem, this uses the location of T's
5291 declaration. Examples of this are
5292 testsuite/g++.dg/template/cond2.C and
5293 testsuite/g++.dg/template/pr35240.C. */
5294 location_t saved_location
= input_location
;
5295 input_location
= DECL_SOURCE_LOCATION (t
);
5297 decl_assembler_name (t
);
5299 input_location
= saved_location
;
5304 /* Free language specific information for every operand and expression
5305 in every node of the call graph. This process operates in three stages:
5307 1- Every callgraph node and varpool node is traversed looking for
5308 decls and types embedded in them. This is a more exhaustive
5309 search than that done by find_referenced_vars, because it will
5310 also collect individual fields, decls embedded in types, etc.
5312 2- All the decls found are sent to free_lang_data_in_decl.
5314 3- All the types found are sent to free_lang_data_in_type.
5316 The ordering between decls and types is important because
5317 free_lang_data_in_decl sets assembler names, which includes
5318 mangling. So types cannot be freed up until assembler names have
5322 free_lang_data_in_cgraph (void)
5324 struct cgraph_node
*n
;
5325 struct varpool_node
*v
;
5326 struct free_lang_data_d fld
;
5331 /* Initialize sets and arrays to store referenced decls and types. */
5332 fld
.pset
= pointer_set_create ();
5333 fld
.worklist
.create (0);
5334 fld
.decls
.create (100);
5335 fld
.types
.create (100);
5337 /* Find decls and types in the body of every function in the callgraph. */
5338 FOR_EACH_FUNCTION (n
)
5339 find_decls_types_in_node (n
, &fld
);
5341 FOR_EACH_VEC_SAFE_ELT (alias_pairs
, i
, p
)
5342 find_decls_types (p
->decl
, &fld
);
5344 /* Find decls and types in every varpool symbol. */
5345 FOR_EACH_VARIABLE (v
)
5346 find_decls_types_in_var (v
, &fld
);
5348 /* Set the assembler name on every decl found. We need to do this
5349 now because free_lang_data_in_decl will invalidate data needed
5350 for mangling. This breaks mangling on interdependent decls. */
5351 FOR_EACH_VEC_ELT (fld
.decls
, i
, t
)
5352 assign_assembler_name_if_neeeded (t
);
5354 /* Traverse every decl found freeing its language data. */
5355 FOR_EACH_VEC_ELT (fld
.decls
, i
, t
)
5356 free_lang_data_in_decl (t
);
5358 /* Traverse every type found freeing its language data. */
5359 FOR_EACH_VEC_ELT (fld
.types
, i
, t
)
5360 free_lang_data_in_type (t
);
5362 pointer_set_destroy (fld
.pset
);
5363 fld
.worklist
.release ();
5364 fld
.decls
.release ();
5365 fld
.types
.release ();
5369 /* Free resources that are used by FE but are not needed once they are done. */
5372 free_lang_data (void)
5376 /* If we are the LTO frontend we have freed lang-specific data already. */
5378 || !flag_generate_lto
)
5381 /* Allocate and assign alias sets to the standard integer types
5382 while the slots are still in the way the frontends generated them. */
5383 for (i
= 0; i
< itk_none
; ++i
)
5384 if (integer_types
[i
])
5385 TYPE_ALIAS_SET (integer_types
[i
]) = get_alias_set (integer_types
[i
]);
5387 /* Traverse the IL resetting language specific information for
5388 operands, expressions, etc. */
5389 free_lang_data_in_cgraph ();
5391 /* Create gimple variants for common types. */
5392 ptrdiff_type_node
= integer_type_node
;
5393 fileptr_type_node
= ptr_type_node
;
5395 /* Reset some langhooks. Do not reset types_compatible_p, it may
5396 still be used indirectly via the get_alias_set langhook. */
5397 lang_hooks
.dwarf_name
= lhd_dwarf_name
;
5398 lang_hooks
.decl_printable_name
= gimple_decl_printable_name
;
5399 /* We do not want the default decl_assembler_name implementation,
5400 rather if we have fixed everything we want a wrapper around it
5401 asserting that all non-local symbols already got their assembler
5402 name and only produce assembler names for local symbols. Or rather
5403 make sure we never call decl_assembler_name on local symbols and
5404 devise a separate, middle-end private scheme for it. */
5406 /* Reset diagnostic machinery. */
5407 tree_diagnostics_defaults (global_dc
);
5413 struct simple_ipa_opt_pass pass_ipa_free_lang_data
=
5417 "*free_lang_data", /* name */
5418 OPTGROUP_NONE
, /* optinfo_flags */
5420 free_lang_data
, /* execute */
5423 0, /* static_pass_number */
5424 TV_IPA_FREE_LANG_DATA
, /* tv_id */
5425 0, /* properties_required */
5426 0, /* properties_provided */
5427 0, /* properties_destroyed */
5428 0, /* todo_flags_start */
5429 0 /* todo_flags_finish */
5433 /* The backbone of is_attribute_p(). ATTR_LEN is the string length of
5434 ATTR_NAME. Also used internally by remove_attribute(). */
5436 private_is_attribute_p (const char *attr_name
, size_t attr_len
, const_tree ident
)
5438 size_t ident_len
= IDENTIFIER_LENGTH (ident
);
5440 if (ident_len
== attr_len
)
5442 if (strcmp (attr_name
, IDENTIFIER_POINTER (ident
)) == 0)
5445 else if (ident_len
== attr_len
+ 4)
5447 /* There is the possibility that ATTR is 'text' and IDENT is
5449 const char *p
= IDENTIFIER_POINTER (ident
);
5450 if (p
[0] == '_' && p
[1] == '_'
5451 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
5452 && strncmp (attr_name
, p
+ 2, attr_len
) == 0)
5459 /* The backbone of lookup_attribute(). ATTR_LEN is the string length
5460 of ATTR_NAME, and LIST is not NULL_TREE. */
5462 private_lookup_attribute (const char *attr_name
, size_t attr_len
, tree list
)
5466 size_t ident_len
= IDENTIFIER_LENGTH (get_attribute_name (list
));
5468 if (ident_len
== attr_len
)
5470 if (!strcmp (attr_name
,
5471 IDENTIFIER_POINTER (get_attribute_name (list
))))
5474 /* TODO: If we made sure that attributes were stored in the
5475 canonical form without '__...__' (ie, as in 'text' as opposed
5476 to '__text__') then we could avoid the following case. */
5477 else if (ident_len
== attr_len
+ 4)
5479 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
5480 if (p
[0] == '_' && p
[1] == '_'
5481 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
5482 && strncmp (attr_name
, p
+ 2, attr_len
) == 0)
5485 list
= TREE_CHAIN (list
);
5491 /* A variant of lookup_attribute() that can be used with an identifier
5492 as the first argument, and where the identifier can be either
5493 'text' or '__text__'.
5495 Given an attribute ATTR_IDENTIFIER, and a list of attributes LIST,
5496 return a pointer to the attribute's list element if the attribute
5497 is part of the list, or NULL_TREE if not found. If the attribute
5498 appears more than once, this only returns the first occurrence; the
5499 TREE_CHAIN of the return value should be passed back in if further
5500 occurrences are wanted. ATTR_IDENTIFIER must be an identifier but
5501 can be in the form 'text' or '__text__'. */
5503 lookup_ident_attribute (tree attr_identifier
, tree list
)
5505 gcc_checking_assert (TREE_CODE (attr_identifier
) == IDENTIFIER_NODE
);
5509 gcc_checking_assert (TREE_CODE (get_attribute_name (list
))
5510 == IDENTIFIER_NODE
);
5512 /* Identifiers can be compared directly for equality. */
5513 if (attr_identifier
== get_attribute_name (list
))
5516 /* If they are not equal, they may still be one in the form
5517 'text' while the other one is in the form '__text__'. TODO:
5518 If we were storing attributes in normalized 'text' form, then
5519 this could all go away and we could take full advantage of
5520 the fact that we're comparing identifiers. :-) */
5522 size_t attr_len
= IDENTIFIER_LENGTH (attr_identifier
);
5523 size_t ident_len
= IDENTIFIER_LENGTH (get_attribute_name (list
));
5525 if (ident_len
== attr_len
+ 4)
5527 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
5528 const char *q
= IDENTIFIER_POINTER (attr_identifier
);
5529 if (p
[0] == '_' && p
[1] == '_'
5530 && p
[ident_len
- 2] == '_' && p
[ident_len
- 1] == '_'
5531 && strncmp (q
, p
+ 2, attr_len
) == 0)
5534 else if (ident_len
+ 4 == attr_len
)
5536 const char *p
= IDENTIFIER_POINTER (get_attribute_name (list
));
5537 const char *q
= IDENTIFIER_POINTER (attr_identifier
);
5538 if (q
[0] == '_' && q
[1] == '_'
5539 && q
[attr_len
- 2] == '_' && q
[attr_len
- 1] == '_'
5540 && strncmp (q
+ 2, p
, ident_len
) == 0)
5544 list
= TREE_CHAIN (list
);
5550 /* Remove any instances of attribute ATTR_NAME in LIST and return the
5554 remove_attribute (const char *attr_name
, tree list
)
5557 size_t attr_len
= strlen (attr_name
);
5559 gcc_checking_assert (attr_name
[0] != '_');
5561 for (p
= &list
; *p
; )
5564 /* TODO: If we were storing attributes in normalized form, here
5565 we could use a simple strcmp(). */
5566 if (private_is_attribute_p (attr_name
, attr_len
, get_attribute_name (l
)))
5567 *p
= TREE_CHAIN (l
);
5569 p
= &TREE_CHAIN (l
);
5575 /* Return an attribute list that is the union of a1 and a2. */
5578 merge_attributes (tree a1
, tree a2
)
5582 /* Either one unset? Take the set one. */
5584 if ((attributes
= a1
) == 0)
5587 /* One that completely contains the other? Take it. */
5589 else if (a2
!= 0 && ! attribute_list_contained (a1
, a2
))
5591 if (attribute_list_contained (a2
, a1
))
5595 /* Pick the longest list, and hang on the other list. */
5597 if (list_length (a1
) < list_length (a2
))
5598 attributes
= a2
, a2
= a1
;
5600 for (; a2
!= 0; a2
= TREE_CHAIN (a2
))
5603 for (a
= lookup_ident_attribute (get_attribute_name (a2
),
5605 a
!= NULL_TREE
&& !attribute_value_equal (a
, a2
);
5606 a
= lookup_ident_attribute (get_attribute_name (a2
),
5611 a1
= copy_node (a2
);
5612 TREE_CHAIN (a1
) = attributes
;
5621 /* Given types T1 and T2, merge their attributes and return
5625 merge_type_attributes (tree t1
, tree t2
)
5627 return merge_attributes (TYPE_ATTRIBUTES (t1
),
5628 TYPE_ATTRIBUTES (t2
));
5631 /* Given decls OLDDECL and NEWDECL, merge their attributes and return
5635 merge_decl_attributes (tree olddecl
, tree newdecl
)
5637 return merge_attributes (DECL_ATTRIBUTES (olddecl
),
5638 DECL_ATTRIBUTES (newdecl
));
5641 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
5643 /* Specialization of merge_decl_attributes for various Windows targets.
5645 This handles the following situation:
5647 __declspec (dllimport) int foo;
5650 The second instance of `foo' nullifies the dllimport. */
5653 merge_dllimport_decl_attributes (tree old
, tree new_tree
)
5656 int delete_dllimport_p
= 1;
5658 /* What we need to do here is remove from `old' dllimport if it doesn't
5659 appear in `new'. dllimport behaves like extern: if a declaration is
5660 marked dllimport and a definition appears later, then the object
5661 is not dllimport'd. We also remove a `new' dllimport if the old list
5662 contains dllexport: dllexport always overrides dllimport, regardless
5663 of the order of declaration. */
5664 if (!VAR_OR_FUNCTION_DECL_P (new_tree
))
5665 delete_dllimport_p
= 0;
5666 else if (DECL_DLLIMPORT_P (new_tree
)
5667 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old
)))
5669 DECL_DLLIMPORT_P (new_tree
) = 0;
5670 warning (OPT_Wattributes
, "%q+D already declared with dllexport attribute: "
5671 "dllimport ignored", new_tree
);
5673 else if (DECL_DLLIMPORT_P (old
) && !DECL_DLLIMPORT_P (new_tree
))
5675 /* Warn about overriding a symbol that has already been used, e.g.:
5676 extern int __attribute__ ((dllimport)) foo;
5677 int* bar () {return &foo;}
5680 if (TREE_USED (old
))
5682 warning (0, "%q+D redeclared without dllimport attribute "
5683 "after being referenced with dll linkage", new_tree
);
5684 /* If we have used a variable's address with dllimport linkage,
5685 keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
5686 decl may already have had TREE_CONSTANT computed.
5687 We still remove the attribute so that assembler code refers
5688 to '&foo rather than '_imp__foo'. */
5689 if (TREE_CODE (old
) == VAR_DECL
&& TREE_ADDRESSABLE (old
))
5690 DECL_DLLIMPORT_P (new_tree
) = 1;
5693 /* Let an inline definition silently override the external reference,
5694 but otherwise warn about attribute inconsistency. */
5695 else if (TREE_CODE (new_tree
) == VAR_DECL
5696 || !DECL_DECLARED_INLINE_P (new_tree
))
5697 warning (OPT_Wattributes
, "%q+D redeclared without dllimport attribute: "
5698 "previous dllimport ignored", new_tree
);
5701 delete_dllimport_p
= 0;
5703 a
= merge_attributes (DECL_ATTRIBUTES (old
), DECL_ATTRIBUTES (new_tree
));
5705 if (delete_dllimport_p
)
5706 a
= remove_attribute ("dllimport", a
);
5711 /* Handle a "dllimport" or "dllexport" attribute; arguments as in
5712 struct attribute_spec.handler. */
5715 handle_dll_attribute (tree
* pnode
, tree name
, tree args
, int flags
,
5721 /* These attributes may apply to structure and union types being created,
5722 but otherwise should pass to the declaration involved. */
5725 if (flags
& ((int) ATTR_FLAG_DECL_NEXT
| (int) ATTR_FLAG_FUNCTION_NEXT
5726 | (int) ATTR_FLAG_ARRAY_NEXT
))
5728 *no_add_attrs
= true;
5729 return tree_cons (name
, args
, NULL_TREE
);
5731 if (TREE_CODE (node
) == RECORD_TYPE
5732 || TREE_CODE (node
) == UNION_TYPE
)
5734 node
= TYPE_NAME (node
);
5740 warning (OPT_Wattributes
, "%qE attribute ignored",
5742 *no_add_attrs
= true;
5747 if (TREE_CODE (node
) != FUNCTION_DECL
5748 && TREE_CODE (node
) != VAR_DECL
5749 && TREE_CODE (node
) != TYPE_DECL
)
5751 *no_add_attrs
= true;
5752 warning (OPT_Wattributes
, "%qE attribute ignored",
5757 if (TREE_CODE (node
) == TYPE_DECL
5758 && TREE_CODE (TREE_TYPE (node
)) != RECORD_TYPE
5759 && TREE_CODE (TREE_TYPE (node
)) != UNION_TYPE
)
5761 *no_add_attrs
= true;
5762 warning (OPT_Wattributes
, "%qE attribute ignored",
5767 is_dllimport
= is_attribute_p ("dllimport", name
);
5769 /* Report error on dllimport ambiguities seen now before they cause
5773 /* Honor any target-specific overrides. */
5774 if (!targetm
.valid_dllimport_attribute_p (node
))
5775 *no_add_attrs
= true;
5777 else if (TREE_CODE (node
) == FUNCTION_DECL
5778 && DECL_DECLARED_INLINE_P (node
))
5780 warning (OPT_Wattributes
, "inline function %q+D declared as "
5781 " dllimport: attribute ignored", node
);
5782 *no_add_attrs
= true;
5784 /* Like MS, treat definition of dllimported variables and
5785 non-inlined functions on declaration as syntax errors. */
5786 else if (TREE_CODE (node
) == FUNCTION_DECL
&& DECL_INITIAL (node
))
5788 error ("function %q+D definition is marked dllimport", node
);
5789 *no_add_attrs
= true;
5792 else if (TREE_CODE (node
) == VAR_DECL
)
5794 if (DECL_INITIAL (node
))
5796 error ("variable %q+D definition is marked dllimport",
5798 *no_add_attrs
= true;
5801 /* `extern' needn't be specified with dllimport.
5802 Specify `extern' now and hope for the best. Sigh. */
5803 DECL_EXTERNAL (node
) = 1;
5804 /* Also, implicitly give dllimport'd variables declared within
5805 a function global scope, unless declared static. */
5806 if (current_function_decl
!= NULL_TREE
&& !TREE_STATIC (node
))
5807 TREE_PUBLIC (node
) = 1;
5810 if (*no_add_attrs
== false)
5811 DECL_DLLIMPORT_P (node
) = 1;
5813 else if (TREE_CODE (node
) == FUNCTION_DECL
5814 && DECL_DECLARED_INLINE_P (node
)
5815 && flag_keep_inline_dllexport
)
5816 /* An exported function, even if inline, must be emitted. */
5817 DECL_EXTERNAL (node
) = 0;
5819 /* Report error if symbol is not accessible at global scope. */
5820 if (!TREE_PUBLIC (node
)
5821 && (TREE_CODE (node
) == VAR_DECL
5822 || TREE_CODE (node
) == FUNCTION_DECL
))
5824 error ("external linkage required for symbol %q+D because of "
5825 "%qE attribute", node
, name
);
5826 *no_add_attrs
= true;
5829 /* A dllexport'd entity must have default visibility so that other
5830 program units (shared libraries or the main executable) can see
5831 it. A dllimport'd entity must have default visibility so that
5832 the linker knows that undefined references within this program
5833 unit can be resolved by the dynamic linker. */
5836 if (DECL_VISIBILITY_SPECIFIED (node
)
5837 && DECL_VISIBILITY (node
) != VISIBILITY_DEFAULT
)
5838 error ("%qE implies default visibility, but %qD has already "
5839 "been declared with a different visibility",
5841 DECL_VISIBILITY (node
) = VISIBILITY_DEFAULT
;
5842 DECL_VISIBILITY_SPECIFIED (node
) = 1;
5848 #endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
5850 /* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
5851 of the various TYPE_QUAL values. Also, set the UPC layout qualifier,
5852 which is either null or a reference to an integral constant. */
5855 set_type_quals (tree type
, int type_quals
, tree layout_qualifier
)
5857 TYPE_READONLY (type
) = (type_quals
& TYPE_QUAL_CONST
) != 0;
5858 TYPE_VOLATILE (type
) = (type_quals
& TYPE_QUAL_VOLATILE
) != 0;
5859 TYPE_RESTRICT (type
) = (type_quals
& TYPE_QUAL_RESTRICT
) != 0;
5860 TYPE_ADDR_SPACE (type
) = DECODE_QUAL_ADDR_SPACE (type_quals
);
5861 TYPE_SHARED (type
) = (type_quals
& TYPE_QUAL_SHARED
) != 0;
5862 TYPE_STRICT (type
) = (type_quals
& TYPE_QUAL_STRICT
) != 0;
5863 TYPE_RELAXED (type
) = (type_quals
& TYPE_QUAL_RELAXED
) != 0;
5864 if (TYPE_SHARED (type
))
5865 SET_TYPE_BLOCK_FACTOR (type
, layout_qualifier
);
5868 /* Returns true iff CAND is equivalent to BASE with
5869 TYPE_QUALS and LAYOUT_QUALIFIER. */
5872 check_qualified_type (const_tree cand
, const_tree base
,
5873 int type_quals
, tree layout_qualifier
)
5875 return (TYPE_QUALS (cand
) == type_quals
5876 && (TYPE_BLOCK_FACTOR (cand
) == layout_qualifier
5877 || tree_int_cst_equal (TYPE_BLOCK_FACTOR (cand
),
5879 && TYPE_NAME (cand
) == TYPE_NAME (base
)
5880 /* Apparently this is needed for Objective-C. */
5881 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
5882 /* Check alignment. */
5883 && TYPE_ALIGN (cand
) == TYPE_ALIGN (base
)
5884 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
5885 TYPE_ATTRIBUTES (base
)));
5888 /* Returns true iff CAND is equivalent to BASE with ALIGN. */
5891 check_aligned_type (const_tree cand
, const_tree base
, unsigned int align
)
5893 return (TYPE_QUALS (cand
) == TYPE_QUALS (base
)
5894 && (TYPE_BLOCK_FACTOR (cand
) == TYPE_BLOCK_FACTOR (base
)
5895 || tree_int_cst_equal (TYPE_BLOCK_FACTOR (cand
),
5896 TYPE_BLOCK_FACTOR (base
)))
5897 && TYPE_NAME (cand
) == TYPE_NAME (base
)
5898 /* Apparently this is needed for Objective-C. */
5899 && TYPE_CONTEXT (cand
) == TYPE_CONTEXT (base
)
5900 /* Check alignment. */
5901 && TYPE_ALIGN (cand
) == align
5902 && attribute_list_equal (TYPE_ATTRIBUTES (cand
),
5903 TYPE_ATTRIBUTES (base
)));
5906 /* Return a version of the TYPE, qualified as indicated by the
5907 TYPE_QUALS, if one exists. If no qualified version exists yet,
5908 return NULL_TREE. */
5911 get_qualified_type_1 (tree type
, int type_quals
, tree layout_qualifier
)
5915 if (TYPE_QUALS (type
) == type_quals
)
5918 /* Search the chain of variants to see if there is already one there just
5919 like the one we need to have. If so, use that existing one. We must
5920 preserve the TYPE_NAME, since there is code that depends on this. */
5921 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
5922 if (check_qualified_type (t
, type
, type_quals
, layout_qualifier
))
5928 /* Like get_qualified_type_1, but creates the type if it does not
5929 exist. This function never returns NULL_TREE. */
5932 build_qualified_type_1 (tree type
, int type_quals
, tree layout_qualifier
)
5936 /* See if we already have the appropriate qualified variant. */
5937 t
= get_qualified_type_1 (type
, type_quals
, layout_qualifier
);
5939 /* If not, build it. */
5942 t
= build_variant_type_copy (type
);
5943 set_type_quals (t
, type_quals
, layout_qualifier
);
5945 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
5946 /* Propagate structural equality. */
5947 SET_TYPE_STRUCTURAL_EQUALITY (t
);
5948 else if (TYPE_CANONICAL (type
) != type
)
5949 /* Build the underlying canonical type, since it is different
5951 TYPE_CANONICAL (t
) = build_qualified_type (TYPE_CANONICAL (type
),
5954 /* T is its own canonical type. */
5955 TYPE_CANONICAL (t
) = t
;
5962 /* Return a variant of TYPE, where all UPC qualifiers
5963 have been removed. */
5966 build_upc_unshared_type (tree type
)
5969 if (TREE_CODE (type
) == ARRAY_TYPE
)
5971 const tree elem_type
= TREE_TYPE(type
);
5972 const tree u_elem_type
= build_upc_unshared_type (elem_type
);
5973 if (u_elem_type
!= elem_type
)
5975 for (u_type
= TYPE_MAIN_VARIANT (type
);
5976 u_type
&& TREE_TYPE(u_type
) != u_elem_type
;
5977 u_type
= TYPE_NEXT_VARIANT (u_type
)) /* loop */;
5980 u_type
= build_variant_type_copy (type
);
5981 TREE_TYPE (u_type
) = u_elem_type
;
5987 const int quals
= TYPE_QUALS (type
);
5988 const int u_quals
= quals
& ~(TYPE_QUAL_SHARED
5990 | TYPE_QUAL_STRICT
);
5991 u_type
= build_qualified_type (type
, u_quals
);
5996 /* Create a variant of type T with alignment ALIGN. */
5999 build_aligned_type (tree type
, unsigned int align
)
6003 if (TYPE_PACKED (type
)
6004 || TYPE_ALIGN (type
) == align
)
6007 for (t
= TYPE_MAIN_VARIANT (type
); t
; t
= TYPE_NEXT_VARIANT (t
))
6008 if (check_aligned_type (t
, type
, align
))
6011 t
= build_variant_type_copy (type
);
6012 TYPE_ALIGN (t
) = align
;
6017 /* Create a new distinct copy of TYPE. The new type is made its own
6018 MAIN_VARIANT. If TYPE requires structural equality checks, the
6019 resulting type requires structural equality checks; otherwise, its
6020 TYPE_CANONICAL points to itself. */
6023 build_distinct_type_copy (tree type
)
6025 tree t
= copy_node (type
);
6027 TYPE_POINTER_TO (t
) = 0;
6028 TYPE_REFERENCE_TO (t
) = 0;
6030 /* Set the canonical type either to a new equivalence class, or
6031 propagate the need for structural equality checks. */
6032 if (TYPE_STRUCTURAL_EQUALITY_P (type
))
6033 SET_TYPE_STRUCTURAL_EQUALITY (t
);
6035 TYPE_CANONICAL (t
) = t
;
6037 /* Make it its own variant. */
6038 TYPE_MAIN_VARIANT (t
) = t
;
6039 TYPE_NEXT_VARIANT (t
) = 0;
6041 /* Note that it is now possible for TYPE_MIN_VALUE to be a value
6042 whose TREE_TYPE is not t. This can also happen in the Ada
6043 frontend when using subtypes. */
6048 /* Create a new variant of TYPE, equivalent but distinct. This is so
6049 the caller can modify it. TYPE_CANONICAL for the return type will
6050 be equivalent to TYPE_CANONICAL of TYPE, indicating that the types
6051 are considered equal by the language itself (or that both types
6052 require structural equality checks). */
6055 build_variant_type_copy (tree type
)
6057 tree t
, m
= TYPE_MAIN_VARIANT (type
);
6059 t
= build_distinct_type_copy (type
);
6061 /* Since we're building a variant, assume that it is a non-semantic
6062 variant. This also propagates TYPE_STRUCTURAL_EQUALITY_P. */
6063 TYPE_CANONICAL (t
) = TYPE_CANONICAL (type
);
6065 /* Add the new type to the chain of variants of TYPE. */
6066 TYPE_NEXT_VARIANT (t
) = TYPE_NEXT_VARIANT (m
);
6067 TYPE_NEXT_VARIANT (m
) = t
;
6068 TYPE_MAIN_VARIANT (t
) = m
;
6073 /* Return true if the from tree in both tree maps are equal. */
6076 tree_map_base_eq (const void *va
, const void *vb
)
6078 const struct tree_map_base
*const a
= (const struct tree_map_base
*) va
,
6079 *const b
= (const struct tree_map_base
*) vb
;
6080 return (a
->from
== b
->from
);
6083 /* Hash a from tree in a tree_base_map. */
6086 tree_map_base_hash (const void *item
)
6088 return htab_hash_pointer (((const struct tree_map_base
*)item
)->from
);
6091 /* Return true if this tree map structure is marked for garbage collection
6092 purposes. We simply return true if the from tree is marked, so that this
6093 structure goes away when the from tree goes away. */
6096 tree_map_base_marked_p (const void *p
)
6098 return ggc_marked_p (((const struct tree_map_base
*) p
)->from
);
6101 /* Hash a from tree in a tree_map. */
6104 tree_map_hash (const void *item
)
6106 return (((const struct tree_map
*) item
)->hash
);
6109 /* Hash a from tree in a tree_decl_map. */
6112 tree_decl_map_hash (const void *item
)
6114 return DECL_UID (((const struct tree_decl_map
*) item
)->base
.from
);
6117 /* Return the initialization priority for DECL. */
6120 decl_init_priority_lookup (tree decl
)
6122 struct tree_priority_map
*h
;
6123 struct tree_map_base in
;
6125 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
6127 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
6128 return h
? h
->init
: DEFAULT_INIT_PRIORITY
;
6131 /* Return the finalization priority for DECL. */
6134 decl_fini_priority_lookup (tree decl
)
6136 struct tree_priority_map
*h
;
6137 struct tree_map_base in
;
6139 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
6141 h
= (struct tree_priority_map
*) htab_find (init_priority_for_decl
, &in
);
6142 return h
? h
->fini
: DEFAULT_INIT_PRIORITY
;
6145 /* Return the initialization and finalization priority information for
6146 DECL. If there is no previous priority information, a freshly
6147 allocated structure is returned. */
6149 static struct tree_priority_map
*
6150 decl_priority_info (tree decl
)
6152 struct tree_priority_map in
;
6153 struct tree_priority_map
*h
;
6156 in
.base
.from
= decl
;
6157 loc
= htab_find_slot (init_priority_for_decl
, &in
, INSERT
);
6158 h
= (struct tree_priority_map
*) *loc
;
6161 h
= ggc_alloc_cleared_tree_priority_map ();
6163 h
->base
.from
= decl
;
6164 h
->init
= DEFAULT_INIT_PRIORITY
;
6165 h
->fini
= DEFAULT_INIT_PRIORITY
;
6171 /* Set the initialization priority for DECL to PRIORITY. */
6174 decl_init_priority_insert (tree decl
, priority_type priority
)
6176 struct tree_priority_map
*h
;
6178 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
6179 if (priority
== DEFAULT_INIT_PRIORITY
)
6181 h
= decl_priority_info (decl
);
6185 /* Set the finalization priority for DECL to PRIORITY. */
6188 decl_fini_priority_insert (tree decl
, priority_type priority
)
6190 struct tree_priority_map
*h
;
6192 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
6193 if (priority
== DEFAULT_INIT_PRIORITY
)
6195 h
= decl_priority_info (decl
);
6199 /* Print out the statistics for the DECL_DEBUG_EXPR hash table. */
6202 print_debug_expr_statistics (void)
6204 fprintf (stderr
, "DECL_DEBUG_EXPR hash: size %ld, %ld elements, %f collisions\n",
6205 (long) htab_size (debug_expr_for_decl
),
6206 (long) htab_elements (debug_expr_for_decl
),
6207 htab_collisions (debug_expr_for_decl
));
6210 /* Print out the statistics for the DECL_VALUE_EXPR hash table. */
6213 print_value_expr_statistics (void)
6215 fprintf (stderr
, "DECL_VALUE_EXPR hash: size %ld, %ld elements, %f collisions\n",
6216 (long) htab_size (value_expr_for_decl
),
6217 (long) htab_elements (value_expr_for_decl
),
6218 htab_collisions (value_expr_for_decl
));
6221 /* Lookup a debug expression for FROM, and return it if we find one. */
6224 decl_debug_expr_lookup (tree from
)
6226 struct tree_decl_map
*h
, in
;
6227 in
.base
.from
= from
;
6229 h
= (struct tree_decl_map
*)
6230 htab_find_with_hash (debug_expr_for_decl
, &in
, DECL_UID (from
));
6236 /* Insert a mapping FROM->TO in the debug expression hashtable. */
6239 decl_debug_expr_insert (tree from
, tree to
)
6241 struct tree_decl_map
*h
;
6244 h
= ggc_alloc_tree_decl_map ();
6245 h
->base
.from
= from
;
6247 loc
= htab_find_slot_with_hash (debug_expr_for_decl
, h
, DECL_UID (from
),
6249 *(struct tree_decl_map
**) loc
= h
;
6252 /* Lookup a value expression for FROM, and return it if we find one. */
6255 decl_value_expr_lookup (tree from
)
6257 struct tree_decl_map
*h
, in
;
6258 in
.base
.from
= from
;
6260 h
= (struct tree_decl_map
*)
6261 htab_find_with_hash (value_expr_for_decl
, &in
, DECL_UID (from
));
6267 /* Insert a mapping FROM->TO in the value expression hashtable. */
6270 decl_value_expr_insert (tree from
, tree to
)
6272 struct tree_decl_map
*h
;
6275 h
= ggc_alloc_tree_decl_map ();
6276 h
->base
.from
= from
;
6278 loc
= htab_find_slot_with_hash (value_expr_for_decl
, h
, DECL_UID (from
),
6280 *(struct tree_decl_map
**) loc
= h
;
6283 /* Lookup a vector of debug arguments for FROM, and return it if we
6287 decl_debug_args_lookup (tree from
)
6289 struct tree_vec_map
*h
, in
;
6291 if (!DECL_HAS_DEBUG_ARGS_P (from
))
6293 gcc_checking_assert (debug_args_for_decl
!= NULL
);
6294 in
.base
.from
= from
;
6295 h
= (struct tree_vec_map
*)
6296 htab_find_with_hash (debug_args_for_decl
, &in
, DECL_UID (from
));
6302 /* Insert a mapping FROM->empty vector of debug arguments in the value
6303 expression hashtable. */
6306 decl_debug_args_insert (tree from
)
6308 struct tree_vec_map
*h
;
6311 if (DECL_HAS_DEBUG_ARGS_P (from
))
6312 return decl_debug_args_lookup (from
);
6313 if (debug_args_for_decl
== NULL
)
6314 debug_args_for_decl
= htab_create_ggc (64, tree_vec_map_hash
,
6315 tree_vec_map_eq
, 0);
6316 h
= ggc_alloc_tree_vec_map ();
6317 h
->base
.from
= from
;
6319 loc
= htab_find_slot_with_hash (debug_args_for_decl
, h
, DECL_UID (from
),
6321 *(struct tree_vec_map
**) loc
= h
;
6322 DECL_HAS_DEBUG_ARGS_P (from
) = 1;
6326 /* Hashing of types so that we don't make duplicates.
6327 The entry point is `type_hash_canon'. */
6329 /* Compute a hash code for a list of types (chain of TREE_LIST nodes
6330 with types in the TREE_VALUE slots), by adding the hash codes
6331 of the individual types. */
6334 type_hash_list (const_tree list
, hashval_t hashcode
)
6338 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6339 if (TREE_VALUE (tail
) != error_mark_node
)
6340 hashcode
= iterative_hash_object (TYPE_HASH (TREE_VALUE (tail
)),
6346 /* These are the Hashtable callback functions. */
6348 /* Returns true iff the types are equivalent. */
6351 type_hash_eq (const void *va
, const void *vb
)
6353 const struct type_hash
*const a
= (const struct type_hash
*) va
,
6354 *const b
= (const struct type_hash
*) vb
;
6356 /* First test the things that are the same for all types. */
6357 if (a
->hash
!= b
->hash
6358 || TREE_CODE (a
->type
) != TREE_CODE (b
->type
)
6359 || TREE_TYPE (a
->type
) != TREE_TYPE (b
->type
)
6360 || !attribute_list_equal (TYPE_ATTRIBUTES (a
->type
),
6361 TYPE_ATTRIBUTES (b
->type
))
6362 || (TREE_CODE (a
->type
) != COMPLEX_TYPE
6363 && TYPE_NAME (a
->type
) != TYPE_NAME (b
->type
)))
6366 /* Be careful about comparing arrays before and after the element type
6367 has been completed; don't compare TYPE_ALIGN unless both types are
6369 if (COMPLETE_TYPE_P (a
->type
) && COMPLETE_TYPE_P (b
->type
)
6370 && (TYPE_ALIGN (a
->type
) != TYPE_ALIGN (b
->type
)
6371 || TYPE_MODE (a
->type
) != TYPE_MODE (b
->type
)))
6374 switch (TREE_CODE (a
->type
))
6379 case REFERENCE_TYPE
:
6384 return TYPE_VECTOR_SUBPARTS (a
->type
) == TYPE_VECTOR_SUBPARTS (b
->type
);
6387 if (TYPE_VALUES (a
->type
) != TYPE_VALUES (b
->type
)
6388 && !(TYPE_VALUES (a
->type
)
6389 && TREE_CODE (TYPE_VALUES (a
->type
)) == TREE_LIST
6390 && TYPE_VALUES (b
->type
)
6391 && TREE_CODE (TYPE_VALUES (b
->type
)) == TREE_LIST
6392 && type_list_equal (TYPE_VALUES (a
->type
),
6393 TYPE_VALUES (b
->type
))))
6396 /* ... fall through ... */
6401 return ((TYPE_MAX_VALUE (a
->type
) == TYPE_MAX_VALUE (b
->type
)
6402 || tree_int_cst_equal (TYPE_MAX_VALUE (a
->type
),
6403 TYPE_MAX_VALUE (b
->type
)))
6404 && (TYPE_MIN_VALUE (a
->type
) == TYPE_MIN_VALUE (b
->type
)
6405 || tree_int_cst_equal (TYPE_MIN_VALUE (a
->type
),
6406 TYPE_MIN_VALUE (b
->type
))));
6408 case FIXED_POINT_TYPE
:
6409 return TYPE_SATURATING (a
->type
) == TYPE_SATURATING (b
->type
);
6412 return TYPE_OFFSET_BASETYPE (a
->type
) == TYPE_OFFSET_BASETYPE (b
->type
);
6415 if (TYPE_METHOD_BASETYPE (a
->type
) == TYPE_METHOD_BASETYPE (b
->type
)
6416 && (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6417 || (TYPE_ARG_TYPES (a
->type
)
6418 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6419 && TYPE_ARG_TYPES (b
->type
)
6420 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6421 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6422 TYPE_ARG_TYPES (b
->type
)))))
6426 return TYPE_DOMAIN (a
->type
) == TYPE_DOMAIN (b
->type
);
6430 case QUAL_UNION_TYPE
:
6431 return (TYPE_FIELDS (a
->type
) == TYPE_FIELDS (b
->type
)
6432 || (TYPE_FIELDS (a
->type
)
6433 && TREE_CODE (TYPE_FIELDS (a
->type
)) == TREE_LIST
6434 && TYPE_FIELDS (b
->type
)
6435 && TREE_CODE (TYPE_FIELDS (b
->type
)) == TREE_LIST
6436 && type_list_equal (TYPE_FIELDS (a
->type
),
6437 TYPE_FIELDS (b
->type
))));
6440 if (TYPE_ARG_TYPES (a
->type
) == TYPE_ARG_TYPES (b
->type
)
6441 || (TYPE_ARG_TYPES (a
->type
)
6442 && TREE_CODE (TYPE_ARG_TYPES (a
->type
)) == TREE_LIST
6443 && TYPE_ARG_TYPES (b
->type
)
6444 && TREE_CODE (TYPE_ARG_TYPES (b
->type
)) == TREE_LIST
6445 && type_list_equal (TYPE_ARG_TYPES (a
->type
),
6446 TYPE_ARG_TYPES (b
->type
))))
6454 if (lang_hooks
.types
.type_hash_eq
!= NULL
)
6455 return lang_hooks
.types
.type_hash_eq (a
->type
, b
->type
);
6460 /* Return the cached hash value. */
6463 type_hash_hash (const void *item
)
6465 return ((const struct type_hash
*) item
)->hash
;
6468 /* Look in the type hash table for a type isomorphic to TYPE.
6469 If one is found, return it. Otherwise return 0. */
6472 type_hash_lookup (hashval_t hashcode
, tree type
)
6474 struct type_hash
*h
, in
;
6476 /* The TYPE_ALIGN field of a type is set by layout_type(), so we
6477 must call that routine before comparing TYPE_ALIGNs. */
6483 h
= (struct type_hash
*) htab_find_with_hash (type_hash_table
, &in
,
6490 /* Add an entry to the type-hash-table
6491 for a type TYPE whose hash code is HASHCODE. */
6494 type_hash_add (hashval_t hashcode
, tree type
)
6496 struct type_hash
*h
;
6499 h
= ggc_alloc_type_hash ();
6502 loc
= htab_find_slot_with_hash (type_hash_table
, h
, hashcode
, INSERT
);
6506 /* Given TYPE, and HASHCODE its hash code, return the canonical
6507 object for an identical type if one already exists.
6508 Otherwise, return TYPE, and record it as the canonical object.
6510 To use this function, first create a type of the sort you want.
6511 Then compute its hash code from the fields of the type that
6512 make it different from other similar types.
6513 Then call this function and use the value. */
6516 type_hash_canon (unsigned int hashcode
, tree type
)
6520 /* The hash table only contains main variants, so ensure that's what we're
6522 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
6524 /* See if the type is in the hash table already. If so, return it.
6525 Otherwise, add the type. */
6526 t1
= type_hash_lookup (hashcode
, type
);
6529 if (GATHER_STATISTICS
)
6531 tree_code_counts
[(int) TREE_CODE (type
)]--;
6532 tree_node_counts
[(int) t_kind
]--;
6533 tree_node_sizes
[(int) t_kind
] -= sizeof (struct tree_type_non_common
);
6539 type_hash_add (hashcode
, type
);
6544 /* See if the data pointed to by the type hash table is marked. We consider
6545 it marked if the type is marked or if a debug type number or symbol
6546 table entry has been made for the type. */
6549 type_hash_marked_p (const void *p
)
6551 const_tree
const type
= ((const struct type_hash
*) p
)->type
;
6553 return ggc_marked_p (type
);
6557 print_type_hash_statistics (void)
6559 fprintf (stderr
, "Type hash: size %ld, %ld elements, %f collisions\n",
6560 (long) htab_size (type_hash_table
),
6561 (long) htab_elements (type_hash_table
),
6562 htab_collisions (type_hash_table
));
6565 /* Compute a hash code for a list of attributes (chain of TREE_LIST nodes
6566 with names in the TREE_PURPOSE slots and args in the TREE_VALUE slots),
6567 by adding the hash codes of the individual attributes. */
6570 attribute_hash_list (const_tree list
, hashval_t hashcode
)
6574 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
6575 /* ??? Do we want to add in TREE_VALUE too? */
6576 hashcode
= iterative_hash_object
6577 (IDENTIFIER_HASH_VALUE (get_attribute_name (tail
)), hashcode
);
6581 /* Given two lists of attributes, return true if list l2 is
6582 equivalent to l1. */
6585 attribute_list_equal (const_tree l1
, const_tree l2
)
6590 return attribute_list_contained (l1
, l2
)
6591 && attribute_list_contained (l2
, l1
);
6594 /* Given two lists of attributes, return true if list L2 is
6595 completely contained within L1. */
6596 /* ??? This would be faster if attribute names were stored in a canonicalized
6597 form. Otherwise, if L1 uses `foo' and L2 uses `__foo__', the long method
6598 must be used to show these elements are equivalent (which they are). */
6599 /* ??? It's not clear that attributes with arguments will always be handled
6603 attribute_list_contained (const_tree l1
, const_tree l2
)
6607 /* First check the obvious, maybe the lists are identical. */
6611 /* Maybe the lists are similar. */
6612 for (t1
= l1
, t2
= l2
;
6614 && get_attribute_name (t1
) == get_attribute_name (t2
)
6615 && TREE_VALUE (t1
) == TREE_VALUE (t2
);
6616 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
6619 /* Maybe the lists are equal. */
6620 if (t1
== 0 && t2
== 0)
6623 for (; t2
!= 0; t2
= TREE_CHAIN (t2
))
6626 /* This CONST_CAST is okay because lookup_attribute does not
6627 modify its argument and the return value is assigned to a
6629 for (attr
= lookup_ident_attribute (get_attribute_name (t2
), CONST_CAST_TREE(l1
));
6630 attr
!= NULL_TREE
&& !attribute_value_equal (t2
, attr
);
6631 attr
= lookup_ident_attribute (get_attribute_name (t2
), TREE_CHAIN (attr
)))
6634 if (attr
== NULL_TREE
)
6641 /* Given two lists of types
6642 (chains of TREE_LIST nodes with types in the TREE_VALUE slots)
6643 return 1 if the lists contain the same types in the same order.
6644 Also, the TREE_PURPOSEs must match. */
6647 type_list_equal (const_tree l1
, const_tree l2
)
6651 for (t1
= l1
, t2
= l2
; t1
&& t2
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
6652 if (TREE_VALUE (t1
) != TREE_VALUE (t2
)
6653 || (TREE_PURPOSE (t1
) != TREE_PURPOSE (t2
)
6654 && ! (1 == simple_cst_equal (TREE_PURPOSE (t1
), TREE_PURPOSE (t2
))
6655 && (TREE_TYPE (TREE_PURPOSE (t1
))
6656 == TREE_TYPE (TREE_PURPOSE (t2
))))))
6662 /* Returns the number of arguments to the FUNCTION_TYPE or METHOD_TYPE
6663 given by TYPE. If the argument list accepts variable arguments,
6664 then this function counts only the ordinary arguments. */
6667 type_num_arguments (const_tree type
)
6672 for (t
= TYPE_ARG_TYPES (type
); t
; t
= TREE_CHAIN (t
))
6673 /* If the function does not take a variable number of arguments,
6674 the last element in the list will have type `void'. */
6675 if (VOID_TYPE_P (TREE_VALUE (t
)))
6683 /* Nonzero if integer constants T1 and T2
6684 represent the same constant value. */
6687 tree_int_cst_equal (const_tree t1
, const_tree t2
)
6692 if (t1
== 0 || t2
== 0)
6695 if (TREE_CODE (t1
) == INTEGER_CST
6696 && TREE_CODE (t2
) == INTEGER_CST
6697 && TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
6698 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
))
6704 /* Nonzero if integer constants T1 and T2 represent values that satisfy <.
6705 The precise way of comparison depends on their data type. */
6708 tree_int_cst_lt (const_tree t1
, const_tree t2
)
6713 if (TYPE_UNSIGNED (TREE_TYPE (t1
)) != TYPE_UNSIGNED (TREE_TYPE (t2
)))
6715 int t1_sgn
= tree_int_cst_sgn (t1
);
6716 int t2_sgn
= tree_int_cst_sgn (t2
);
6718 if (t1_sgn
< t2_sgn
)
6720 else if (t1_sgn
> t2_sgn
)
6722 /* Otherwise, both are non-negative, so we compare them as
6723 unsigned just in case one of them would overflow a signed
6726 else if (!TYPE_UNSIGNED (TREE_TYPE (t1
)))
6727 return INT_CST_LT (t1
, t2
);
6729 return INT_CST_LT_UNSIGNED (t1
, t2
);
6732 /* Returns -1 if T1 < T2, 0 if T1 == T2, and 1 if T1 > T2. */
6735 tree_int_cst_compare (const_tree t1
, const_tree t2
)
6737 if (tree_int_cst_lt (t1
, t2
))
6739 else if (tree_int_cst_lt (t2
, t1
))
6745 /* Return 1 if T is an INTEGER_CST that can be manipulated efficiently on
6746 the host. If POS is zero, the value can be represented in a single
6747 HOST_WIDE_INT. If POS is nonzero, the value must be non-negative and can
6748 be represented in a single unsigned HOST_WIDE_INT. */
6751 host_integerp (const_tree t
, int pos
)
6756 return (TREE_CODE (t
) == INTEGER_CST
6757 && ((TREE_INT_CST_HIGH (t
) == 0
6758 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) >= 0)
6759 || (! pos
&& TREE_INT_CST_HIGH (t
) == -1
6760 && (HOST_WIDE_INT
) TREE_INT_CST_LOW (t
) < 0
6761 && !TYPE_UNSIGNED (TREE_TYPE (t
)))
6762 || (pos
&& TREE_INT_CST_HIGH (t
) == 0)));
6765 /* Return the HOST_WIDE_INT least significant bits of T if it is an
6766 INTEGER_CST and there is no overflow. POS is nonzero if the result must
6767 be non-negative. We must be able to satisfy the above conditions. */
6770 tree_low_cst (const_tree t
, int pos
)
6772 gcc_assert (host_integerp (t
, pos
));
6773 return TREE_INT_CST_LOW (t
);
6776 /* Return the HOST_WIDE_INT least significant bits of T, a sizetype
6777 kind INTEGER_CST. This makes sure to properly sign-extend the
6781 size_low_cst (const_tree t
)
6783 double_int d
= tree_to_double_int (t
);
6784 return d
.sext (TYPE_PRECISION (TREE_TYPE (t
))).low
;
6787 /* Return the most significant (sign) bit of T. */
6790 tree_int_cst_sign_bit (const_tree t
)
6792 unsigned bitno
= TYPE_PRECISION (TREE_TYPE (t
)) - 1;
6793 unsigned HOST_WIDE_INT w
;
6795 if (bitno
< HOST_BITS_PER_WIDE_INT
)
6796 w
= TREE_INT_CST_LOW (t
);
6799 w
= TREE_INT_CST_HIGH (t
);
6800 bitno
-= HOST_BITS_PER_WIDE_INT
;
6803 return (w
>> bitno
) & 1;
6806 /* Return an indication of the sign of the integer constant T.
6807 The return value is -1 if T < 0, 0 if T == 0, and 1 if T > 0.
6808 Note that -1 will never be returned if T's type is unsigned. */
6811 tree_int_cst_sgn (const_tree t
)
6813 if (TREE_INT_CST_LOW (t
) == 0 && TREE_INT_CST_HIGH (t
) == 0)
6815 else if (TYPE_UNSIGNED (TREE_TYPE (t
)))
6817 else if (TREE_INT_CST_HIGH (t
) < 0)
6823 /* Return the minimum number of bits needed to represent VALUE in a
6824 signed or unsigned type, UNSIGNEDP says which. */
6827 tree_int_cst_min_precision (tree value
, bool unsignedp
)
6829 /* If the value is negative, compute its negative minus 1. The latter
6830 adjustment is because the absolute value of the largest negative value
6831 is one larger than the largest positive value. This is equivalent to
6832 a bit-wise negation, so use that operation instead. */
6834 if (tree_int_cst_sgn (value
) < 0)
6835 value
= fold_build1 (BIT_NOT_EXPR
, TREE_TYPE (value
), value
);
6837 /* Return the number of bits needed, taking into account the fact
6838 that we need one more bit for a signed than unsigned type.
6839 If value is 0 or -1, the minimum precision is 1 no matter
6840 whether unsignedp is true or false. */
6842 if (integer_zerop (value
))
6845 return tree_floor_log2 (value
) + 1 + !unsignedp
;
6848 /* Compare two constructor-element-type constants. Return 1 if the lists
6849 are known to be equal; otherwise return 0. */
6852 simple_cst_list_equal (const_tree l1
, const_tree l2
)
6854 while (l1
!= NULL_TREE
&& l2
!= NULL_TREE
)
6856 if (simple_cst_equal (TREE_VALUE (l1
), TREE_VALUE (l2
)) != 1)
6859 l1
= TREE_CHAIN (l1
);
6860 l2
= TREE_CHAIN (l2
);
6866 /* Return truthvalue of whether T1 is the same tree structure as T2.
6867 Return 1 if they are the same.
6868 Return 0 if they are understandably different.
6869 Return -1 if either contains tree structure not understood by
6873 simple_cst_equal (const_tree t1
, const_tree t2
)
6875 enum tree_code code1
, code2
;
6881 if (t1
== 0 || t2
== 0)
6884 code1
= TREE_CODE (t1
);
6885 code2
= TREE_CODE (t2
);
6887 if (CONVERT_EXPR_CODE_P (code1
) || code1
== NON_LVALUE_EXPR
)
6889 if (CONVERT_EXPR_CODE_P (code2
)
6890 || code2
== NON_LVALUE_EXPR
)
6891 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6893 return simple_cst_equal (TREE_OPERAND (t1
, 0), t2
);
6896 else if (CONVERT_EXPR_CODE_P (code2
)
6897 || code2
== NON_LVALUE_EXPR
)
6898 return simple_cst_equal (t1
, TREE_OPERAND (t2
, 0));
6906 return (TREE_INT_CST_LOW (t1
) == TREE_INT_CST_LOW (t2
)
6907 && TREE_INT_CST_HIGH (t1
) == TREE_INT_CST_HIGH (t2
));
6910 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
6913 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
6916 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
6917 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
6918 TREE_STRING_LENGTH (t1
)));
6922 unsigned HOST_WIDE_INT idx
;
6923 vec
<constructor_elt
, va_gc
> *v1
= CONSTRUCTOR_ELTS (t1
);
6924 vec
<constructor_elt
, va_gc
> *v2
= CONSTRUCTOR_ELTS (t2
);
6926 if (vec_safe_length (v1
) != vec_safe_length (v2
))
6929 for (idx
= 0; idx
< vec_safe_length (v1
); ++idx
)
6930 /* ??? Should we handle also fields here? */
6931 if (!simple_cst_equal ((*v1
)[idx
].value
, (*v2
)[idx
].value
))
6937 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6940 cmp
= simple_cst_equal (CALL_EXPR_FN (t1
), CALL_EXPR_FN (t2
));
6943 if (call_expr_nargs (t1
) != call_expr_nargs (t2
))
6946 const_tree arg1
, arg2
;
6947 const_call_expr_arg_iterator iter1
, iter2
;
6948 for (arg1
= first_const_call_expr_arg (t1
, &iter1
),
6949 arg2
= first_const_call_expr_arg (t2
, &iter2
);
6951 arg1
= next_const_call_expr_arg (&iter1
),
6952 arg2
= next_const_call_expr_arg (&iter2
))
6954 cmp
= simple_cst_equal (arg1
, arg2
);
6958 return arg1
== arg2
;
6962 /* Special case: if either target is an unallocated VAR_DECL,
6963 it means that it's going to be unified with whatever the
6964 TARGET_EXPR is really supposed to initialize, so treat it
6965 as being equivalent to anything. */
6966 if ((TREE_CODE (TREE_OPERAND (t1
, 0)) == VAR_DECL
6967 && DECL_NAME (TREE_OPERAND (t1
, 0)) == NULL_TREE
6968 && !DECL_RTL_SET_P (TREE_OPERAND (t1
, 0)))
6969 || (TREE_CODE (TREE_OPERAND (t2
, 0)) == VAR_DECL
6970 && DECL_NAME (TREE_OPERAND (t2
, 0)) == NULL_TREE
6971 && !DECL_RTL_SET_P (TREE_OPERAND (t2
, 0))))
6974 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6979 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1));
6981 case WITH_CLEANUP_EXPR
:
6982 cmp
= simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
6986 return simple_cst_equal (TREE_OPERAND (t1
, 1), TREE_OPERAND (t1
, 1));
6989 if (TREE_OPERAND (t1
, 1) == TREE_OPERAND (t2
, 1))
6990 return simple_cst_equal (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
7004 /* This general rule works for most tree codes. All exceptions should be
7005 handled above. If this is a language-specific tree code, we can't
7006 trust what might be in the operand, so say we don't know
7008 if ((int) code1
>= (int) LAST_AND_UNUSED_TREE_CODE
)
7011 switch (TREE_CODE_CLASS (code1
))
7015 case tcc_comparison
:
7016 case tcc_expression
:
7020 for (i
= 0; i
< TREE_CODE_LENGTH (code1
); i
++)
7022 cmp
= simple_cst_equal (TREE_OPERAND (t1
, i
), TREE_OPERAND (t2
, i
));
7034 /* Compare the value of T, an INTEGER_CST, with U, an unsigned integer value.
7035 Return -1, 0, or 1 if the value of T is less than, equal to, or greater
7036 than U, respectively. */
7039 compare_tree_int (const_tree t
, unsigned HOST_WIDE_INT u
)
7041 if (tree_int_cst_sgn (t
) < 0)
7043 else if (TREE_INT_CST_HIGH (t
) != 0)
7045 else if (TREE_INT_CST_LOW (t
) == u
)
7047 else if (TREE_INT_CST_LOW (t
) < u
)
7053 /* Return true if SIZE represents a constant size that is in bounds of
7054 what the middle-end and the backend accepts (covering not more than
7055 half of the address-space). */
7058 valid_constant_size_p (const_tree size
)
7060 if (! host_integerp (size
, 1)
7061 || TREE_OVERFLOW (size
)
7062 || tree_int_cst_sign_bit (size
) != 0)
7067 /* Return the precision of the type, or for a complex or vector type the
7068 precision of the type of its elements. */
7071 element_precision (const_tree type
)
7073 enum tree_code code
= TREE_CODE (type
);
7074 if (code
== COMPLEX_TYPE
|| code
== VECTOR_TYPE
)
7075 type
= TREE_TYPE (type
);
7077 return TYPE_PRECISION (type
);
7080 /* Return true if CODE represents an associative tree code. Otherwise
7083 associative_tree_code (enum tree_code code
)
7102 /* Return true if CODE represents a commutative tree code. Otherwise
7105 commutative_tree_code (enum tree_code code
)
7111 case MULT_HIGHPART_EXPR
:
7119 case UNORDERED_EXPR
:
7123 case TRUTH_AND_EXPR
:
7124 case TRUTH_XOR_EXPR
:
7126 case WIDEN_MULT_EXPR
:
7127 case VEC_WIDEN_MULT_HI_EXPR
:
7128 case VEC_WIDEN_MULT_LO_EXPR
:
7129 case VEC_WIDEN_MULT_EVEN_EXPR
:
7130 case VEC_WIDEN_MULT_ODD_EXPR
:
7139 /* Return true if CODE represents a ternary tree code for which the
7140 first two operands are commutative. Otherwise return false. */
7142 commutative_ternary_tree_code (enum tree_code code
)
7146 case WIDEN_MULT_PLUS_EXPR
:
7147 case WIDEN_MULT_MINUS_EXPR
:
7156 /* Generate a hash value for an expression. This can be used iteratively
7157 by passing a previous result as the VAL argument.
7159 This function is intended to produce the same hash for expressions which
7160 would compare equal using operand_equal_p. */
7163 iterative_hash_expr (const_tree t
, hashval_t val
)
7166 enum tree_code code
;
7170 return iterative_hash_hashval_t (0, val
);
7172 code
= TREE_CODE (t
);
7176 /* Alas, constants aren't shared, so we can't rely on pointer
7179 val
= iterative_hash_host_wide_int (TREE_INT_CST_LOW (t
), val
);
7180 return iterative_hash_host_wide_int (TREE_INT_CST_HIGH (t
), val
);
7183 unsigned int val2
= real_hash (TREE_REAL_CST_PTR (t
));
7185 return iterative_hash_hashval_t (val2
, val
);
7189 unsigned int val2
= fixed_hash (TREE_FIXED_CST_PTR (t
));
7191 return iterative_hash_hashval_t (val2
, val
);
7194 return iterative_hash (TREE_STRING_POINTER (t
),
7195 TREE_STRING_LENGTH (t
), val
);
7197 val
= iterative_hash_expr (TREE_REALPART (t
), val
);
7198 return iterative_hash_expr (TREE_IMAGPART (t
), val
);
7202 for (i
= 0; i
< VECTOR_CST_NELTS (t
); ++i
)
7203 val
= iterative_hash_expr (VECTOR_CST_ELT (t
, i
), val
);
7207 /* We can just compare by pointer. */
7208 return iterative_hash_host_wide_int (SSA_NAME_VERSION (t
), val
);
7209 case PLACEHOLDER_EXPR
:
7210 /* The node itself doesn't matter. */
7213 /* A list of expressions, for a CALL_EXPR or as the elements of a
7215 for (; t
; t
= TREE_CHAIN (t
))
7216 val
= iterative_hash_expr (TREE_VALUE (t
), val
);
7220 unsigned HOST_WIDE_INT idx
;
7222 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t
), idx
, field
, value
)
7224 val
= iterative_hash_expr (field
, val
);
7225 val
= iterative_hash_expr (value
, val
);
7231 /* The type of the second operand is relevant, except for
7232 its top-level qualifiers. */
7233 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (t
, 1)));
7235 val
= iterative_hash_object (TYPE_HASH (type
), val
);
7237 /* We could use the standard hash computation from this point
7239 val
= iterative_hash_object (code
, val
);
7240 val
= iterative_hash_expr (TREE_OPERAND (t
, 1), val
);
7241 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
7245 /* When referring to a built-in FUNCTION_DECL, use the __builtin__ form.
7246 Otherwise nodes that compare equal according to operand_equal_p might
7247 get different hash codes. However, don't do this for machine specific
7248 or front end builtins, since the function code is overloaded in those
7250 if (DECL_BUILT_IN_CLASS (t
) == BUILT_IN_NORMAL
7251 && builtin_decl_explicit_p (DECL_FUNCTION_CODE (t
)))
7253 t
= builtin_decl_explicit (DECL_FUNCTION_CODE (t
));
7254 code
= TREE_CODE (t
);
7258 tclass
= TREE_CODE_CLASS (code
);
7260 if (tclass
== tcc_declaration
)
7262 /* DECL's have a unique ID */
7263 val
= iterative_hash_host_wide_int (DECL_UID (t
), val
);
7267 gcc_assert (IS_EXPR_CODE_CLASS (tclass
));
7269 val
= iterative_hash_object (code
, val
);
7271 /* Don't hash the type, that can lead to having nodes which
7272 compare equal according to operand_equal_p, but which
7273 have different hash codes. */
7274 if (CONVERT_EXPR_CODE_P (code
)
7275 || code
== NON_LVALUE_EXPR
)
7277 /* Make sure to include signness in the hash computation. */
7278 val
+= TYPE_UNSIGNED (TREE_TYPE (t
));
7279 val
= iterative_hash_expr (TREE_OPERAND (t
, 0), val
);
7282 else if (commutative_tree_code (code
))
7284 /* It's a commutative expression. We want to hash it the same
7285 however it appears. We do this by first hashing both operands
7286 and then rehashing based on the order of their independent
7288 hashval_t one
= iterative_hash_expr (TREE_OPERAND (t
, 0), 0);
7289 hashval_t two
= iterative_hash_expr (TREE_OPERAND (t
, 1), 0);
7293 t
= one
, one
= two
, two
= t
;
7295 val
= iterative_hash_hashval_t (one
, val
);
7296 val
= iterative_hash_hashval_t (two
, val
);
7299 for (i
= TREE_OPERAND_LENGTH (t
) - 1; i
>= 0; --i
)
7300 val
= iterative_hash_expr (TREE_OPERAND (t
, i
), val
);
7306 /* Generate a hash value for a pair of expressions. This can be used
7307 iteratively by passing a previous result as the VAL argument.
7309 The same hash value is always returned for a given pair of expressions,
7310 regardless of the order in which they are presented. This is useful in
7311 hashing the operands of commutative functions. */
7314 iterative_hash_exprs_commutative (const_tree t1
,
7315 const_tree t2
, hashval_t val
)
7317 hashval_t one
= iterative_hash_expr (t1
, 0);
7318 hashval_t two
= iterative_hash_expr (t2
, 0);
7322 t
= one
, one
= two
, two
= t
;
7323 val
= iterative_hash_hashval_t (one
, val
);
7324 val
= iterative_hash_hashval_t (two
, val
);
7329 /* Constructors for pointer, array and function types.
7330 (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
7331 constructed by language-dependent code, not here.) */
7333 /* Construct, lay out and return the type of pointers to TO_TYPE with
7334 mode MODE. If CAN_ALIAS_ALL is TRUE, indicate this type can
7335 reference all of memory. If such a type has already been
7336 constructed, reuse it. */
7339 build_pointer_type_for_mode (tree to_type
, enum machine_mode mode
,
7344 if (to_type
== error_mark_node
)
7345 return error_mark_node
;
7347 /* If the pointed-to type has the may_alias attribute set, force
7348 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7349 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7350 can_alias_all
= true;
7352 /* In some cases, languages will have things that aren't a POINTER_TYPE
7353 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_POINTER_TO.
7354 In that case, return that type without regard to the rest of our
7357 ??? This is a kludge, but consistent with the way this function has
7358 always operated and there doesn't seem to be a good way to avoid this
7360 if (TYPE_POINTER_TO (to_type
) != 0
7361 && TREE_CODE (TYPE_POINTER_TO (to_type
)) != POINTER_TYPE
)
7362 return TYPE_POINTER_TO (to_type
);
7364 /* First, if we already have a type for pointers to TO_TYPE and it's
7365 the proper mode, use it. */
7366 for (t
= TYPE_POINTER_TO (to_type
); t
; t
= TYPE_NEXT_PTR_TO (t
))
7367 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7370 t
= make_node (POINTER_TYPE
);
7372 TREE_TYPE (t
) = to_type
;
7373 SET_TYPE_MODE (t
, mode
);
7374 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7375 TYPE_NEXT_PTR_TO (t
) = TYPE_POINTER_TO (to_type
);
7376 TYPE_POINTER_TO (to_type
) = t
;
7378 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7379 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7380 else if (TYPE_CANONICAL (to_type
) != to_type
)
7382 = build_pointer_type_for_mode (TYPE_CANONICAL (to_type
),
7383 mode
, can_alias_all
);
7385 /* Lay out the type. This function has many callers that are concerned
7386 with expression-construction, and this simplifies them all. */
7392 /* By default build pointers in ptr_mode. */
7395 build_pointer_type (tree to_type
)
7397 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7398 : TYPE_ADDR_SPACE (to_type
);
7399 enum machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7400 if (upc_shared_type_p (to_type
))
7403 pointer_mode
= TYPE_MODE (upc_pts_rep_type_node
);
7404 upc_pts_type
= build_pointer_type_for_mode (to_type
, pointer_mode
,
7406 TYPE_USER_ALIGN (upc_pts_type
) = TYPE_USER_ALIGN (upc_pts_rep_type_node
);
7407 TYPE_ALIGN (upc_pts_type
) = TYPE_ALIGN (upc_pts_rep_type_node
);
7408 return upc_pts_type
;
7410 return build_pointer_type_for_mode (to_type
, pointer_mode
, false);
7413 /* Same as build_pointer_type_for_mode, but for REFERENCE_TYPE. */
7416 build_reference_type_for_mode (tree to_type
, enum machine_mode mode
,
7421 if (to_type
== error_mark_node
)
7422 return error_mark_node
;
7424 /* If the pointed-to type has the may_alias attribute set, force
7425 a TYPE_REF_CAN_ALIAS_ALL pointer to be generated. */
7426 if (lookup_attribute ("may_alias", TYPE_ATTRIBUTES (to_type
)))
7427 can_alias_all
= true;
7429 /* In some cases, languages will have things that aren't a REFERENCE_TYPE
7430 (such as a RECORD_TYPE for fat pointers in Ada) as TYPE_REFERENCE_TO.
7431 In that case, return that type without regard to the rest of our
7434 ??? This is a kludge, but consistent with the way this function has
7435 always operated and there doesn't seem to be a good way to avoid this
7437 if (TYPE_REFERENCE_TO (to_type
) != 0
7438 && TREE_CODE (TYPE_REFERENCE_TO (to_type
)) != REFERENCE_TYPE
)
7439 return TYPE_REFERENCE_TO (to_type
);
7441 /* First, if we already have a type for pointers to TO_TYPE and it's
7442 the proper mode, use it. */
7443 for (t
= TYPE_REFERENCE_TO (to_type
); t
; t
= TYPE_NEXT_REF_TO (t
))
7444 if (TYPE_MODE (t
) == mode
&& TYPE_REF_CAN_ALIAS_ALL (t
) == can_alias_all
)
7447 t
= make_node (REFERENCE_TYPE
);
7449 TREE_TYPE (t
) = to_type
;
7450 SET_TYPE_MODE (t
, mode
);
7451 TYPE_REF_CAN_ALIAS_ALL (t
) = can_alias_all
;
7452 TYPE_NEXT_REF_TO (t
) = TYPE_REFERENCE_TO (to_type
);
7453 TYPE_REFERENCE_TO (to_type
) = t
;
7455 if (TYPE_STRUCTURAL_EQUALITY_P (to_type
))
7456 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7457 else if (TYPE_CANONICAL (to_type
) != to_type
)
7459 = build_reference_type_for_mode (TYPE_CANONICAL (to_type
),
7460 mode
, can_alias_all
);
7468 /* Build the node for the type of references-to-TO_TYPE by default
7472 build_reference_type (tree to_type
)
7474 addr_space_t as
= to_type
== error_mark_node
? ADDR_SPACE_GENERIC
7475 : TYPE_ADDR_SPACE (to_type
);
7476 enum machine_mode pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
7477 return build_reference_type_for_mode (to_type
, pointer_mode
, false);
7480 /* Build a type that is compatible with t but has no cv quals anywhere
7483 const char *const *const * -> char ***. */
7486 build_type_no_quals (tree t
)
7488 switch (TREE_CODE (t
))
7491 return build_pointer_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
7493 TYPE_REF_CAN_ALIAS_ALL (t
));
7494 case REFERENCE_TYPE
:
7496 build_reference_type_for_mode (build_type_no_quals (TREE_TYPE (t
)),
7498 TYPE_REF_CAN_ALIAS_ALL (t
));
7500 return TYPE_MAIN_VARIANT (t
);
7504 #define MAX_INT_CACHED_PREC \
7505 (HOST_BITS_PER_WIDE_INT > 64 ? HOST_BITS_PER_WIDE_INT : 64)
7506 static GTY(()) tree nonstandard_integer_type_cache
[2 * MAX_INT_CACHED_PREC
+ 2];
7508 /* Builds a signed or unsigned integer type of precision PRECISION.
7509 Used for C bitfields whose precision does not match that of
7510 built-in target types. */
7512 build_nonstandard_integer_type (unsigned HOST_WIDE_INT precision
,
7518 unsignedp
= MAX_INT_CACHED_PREC
+ 1;
7520 if (precision
<= MAX_INT_CACHED_PREC
)
7522 itype
= nonstandard_integer_type_cache
[precision
+ unsignedp
];
7527 itype
= make_node (INTEGER_TYPE
);
7528 TYPE_PRECISION (itype
) = precision
;
7531 fixup_unsigned_type (itype
);
7533 fixup_signed_type (itype
);
7536 if (host_integerp (TYPE_MAX_VALUE (itype
), 1))
7537 ret
= type_hash_canon (tree_low_cst (TYPE_MAX_VALUE (itype
), 1), itype
);
7538 if (precision
<= MAX_INT_CACHED_PREC
)
7539 nonstandard_integer_type_cache
[precision
+ unsignedp
] = ret
;
7544 /* Create a range of some discrete type TYPE (an INTEGER_TYPE, ENUMERAL_TYPE
7545 or BOOLEAN_TYPE) with low bound LOWVAL and high bound HIGHVAL. If SHARED
7546 is true, reuse such a type that has already been constructed. */
7549 build_range_type_1 (tree type
, tree lowval
, tree highval
, bool shared
)
7551 tree itype
= make_node (INTEGER_TYPE
);
7552 hashval_t hashcode
= 0;
7554 TREE_TYPE (itype
) = type
;
7556 TYPE_MIN_VALUE (itype
) = fold_convert (type
, lowval
);
7557 TYPE_MAX_VALUE (itype
) = highval
? fold_convert (type
, highval
) : NULL
;
7559 TYPE_PRECISION (itype
) = TYPE_PRECISION (type
);
7560 SET_TYPE_MODE (itype
, TYPE_MODE (type
));
7561 TYPE_SIZE (itype
) = TYPE_SIZE (type
);
7562 TYPE_SIZE_UNIT (itype
) = TYPE_SIZE_UNIT (type
);
7563 TYPE_ALIGN (itype
) = TYPE_ALIGN (type
);
7564 TYPE_USER_ALIGN (itype
) = TYPE_USER_ALIGN (type
);
7569 if ((TYPE_MIN_VALUE (itype
)
7570 && TREE_CODE (TYPE_MIN_VALUE (itype
)) != INTEGER_CST
)
7571 || (TYPE_MAX_VALUE (itype
)
7572 && TREE_CODE (TYPE_MAX_VALUE (itype
)) != INTEGER_CST
))
7574 /* Since we cannot reliably merge this type, we need to compare it using
7575 structural equality checks. */
7576 SET_TYPE_STRUCTURAL_EQUALITY (itype
);
7580 hashcode
= iterative_hash_expr (TYPE_MIN_VALUE (itype
), hashcode
);
7581 hashcode
= iterative_hash_expr (TYPE_MAX_VALUE (itype
), hashcode
);
7582 hashcode
= iterative_hash_hashval_t (TYPE_HASH (type
), hashcode
);
7583 itype
= type_hash_canon (hashcode
, itype
);
7588 /* Wrapper around build_range_type_1 with SHARED set to true. */
7591 build_range_type (tree type
, tree lowval
, tree highval
)
7593 return build_range_type_1 (type
, lowval
, highval
, true);
7596 /* Wrapper around build_range_type_1 with SHARED set to false. */
7599 build_nonshared_range_type (tree type
, tree lowval
, tree highval
)
7601 return build_range_type_1 (type
, lowval
, highval
, false);
7604 /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
7605 MAXVAL should be the maximum value in the domain
7606 (one less than the length of the array).
7608 The maximum value that MAXVAL can have is INT_MAX for a HOST_WIDE_INT.
7609 We don't enforce this limit, that is up to caller (e.g. language front end).
7610 The limit exists because the result is a signed type and we don't handle
7611 sizes that use more than one HOST_WIDE_INT. */
7614 build_index_type (tree maxval
)
7616 return build_range_type (sizetype
, size_zero_node
, maxval
);
7619 /* Return true if the debug information for TYPE, a subtype, should be emitted
7620 as a subrange type. If so, set LOWVAL to the low bound and HIGHVAL to the
7621 high bound, respectively. Sometimes doing so unnecessarily obfuscates the
7622 debug info and doesn't reflect the source code. */
7625 subrange_type_for_debug_p (const_tree type
, tree
*lowval
, tree
*highval
)
7627 tree base_type
= TREE_TYPE (type
), low
, high
;
7629 /* Subrange types have a base type which is an integral type. */
7630 if (!INTEGRAL_TYPE_P (base_type
))
7633 /* Get the real bounds of the subtype. */
7634 if (lang_hooks
.types
.get_subrange_bounds
)
7635 lang_hooks
.types
.get_subrange_bounds (type
, &low
, &high
);
7638 low
= TYPE_MIN_VALUE (type
);
7639 high
= TYPE_MAX_VALUE (type
);
7642 /* If the type and its base type have the same representation and the same
7643 name, then the type is not a subrange but a copy of the base type. */
7644 if ((TREE_CODE (base_type
) == INTEGER_TYPE
7645 || TREE_CODE (base_type
) == BOOLEAN_TYPE
)
7646 && int_size_in_bytes (type
) == int_size_in_bytes (base_type
)
7647 && tree_int_cst_equal (low
, TYPE_MIN_VALUE (base_type
))
7648 && tree_int_cst_equal (high
, TYPE_MAX_VALUE (base_type
)))
7650 tree type_name
= TYPE_NAME (type
);
7651 tree base_type_name
= TYPE_NAME (base_type
);
7653 if (type_name
&& TREE_CODE (type_name
) == TYPE_DECL
)
7654 type_name
= DECL_NAME (type_name
);
7656 if (base_type_name
&& TREE_CODE (base_type_name
) == TYPE_DECL
)
7657 base_type_name
= DECL_NAME (base_type_name
);
7659 if (type_name
== base_type_name
)
7670 /* Construct, lay out and return the type of arrays of elements with ELT_TYPE
7671 and number of elements specified by the range of values of INDEX_TYPE.
7672 If SHARED is true, reuse such a type that has already been constructed. */
7675 build_array_type_1 (tree elt_type
, tree index_type
, bool shared
)
7679 if (TREE_CODE (elt_type
) == FUNCTION_TYPE
)
7681 error ("arrays of functions are not meaningful");
7682 elt_type
= integer_type_node
;
7685 t
= make_node (ARRAY_TYPE
);
7686 TREE_TYPE (t
) = elt_type
;
7687 TYPE_DOMAIN (t
) = index_type
;
7688 TYPE_ADDR_SPACE (t
) = TYPE_ADDR_SPACE (elt_type
);
7691 /* If the element type is incomplete at this point we get marked for
7692 structural equality. Do not record these types in the canonical
7694 if (TYPE_STRUCTURAL_EQUALITY_P (t
))
7699 hashval_t hashcode
= iterative_hash_object (TYPE_HASH (elt_type
), 0);
7701 hashcode
= iterative_hash_object (TYPE_HASH (index_type
), hashcode
);
7702 t
= type_hash_canon (hashcode
, t
);
7705 if (TYPE_CANONICAL (t
) == t
)
7707 if (TYPE_STRUCTURAL_EQUALITY_P (elt_type
)
7708 || (index_type
&& TYPE_STRUCTURAL_EQUALITY_P (index_type
)))
7709 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7710 else if (TYPE_CANONICAL (elt_type
) != elt_type
7711 || (index_type
&& TYPE_CANONICAL (index_type
) != index_type
))
7713 = build_array_type_1 (TYPE_CANONICAL (elt_type
),
7715 ? TYPE_CANONICAL (index_type
) : NULL_TREE
,
7722 /* Wrapper around build_array_type_1 with SHARED set to true. */
7725 build_array_type (tree elt_type
, tree index_type
)
7727 return build_array_type_1 (elt_type
, index_type
, true);
7730 /* Wrapper around build_array_type_1 with SHARED set to false. */
7733 build_nonshared_array_type (tree elt_type
, tree index_type
)
7735 return build_array_type_1 (elt_type
, index_type
, false);
7738 /* Return a representation of ELT_TYPE[NELTS], using indices of type
7742 build_array_type_nelts (tree elt_type
, unsigned HOST_WIDE_INT nelts
)
7744 return build_array_type (elt_type
, build_index_type (size_int (nelts
- 1)));
7747 /* Recursively examines the array elements of TYPE, until a non-array
7748 element type is found. */
7751 strip_array_types (tree type
)
7753 while (TREE_CODE (type
) == ARRAY_TYPE
)
7754 type
= TREE_TYPE (type
);
7759 /* Computes the canonical argument types from the argument type list
7762 Upon return, *ANY_STRUCTURAL_P will be true iff either it was true
7763 on entry to this function, or if any of the ARGTYPES are
7766 Upon return, *ANY_NONCANONICAL_P will be true iff either it was
7767 true on entry to this function, or if any of the ARGTYPES are
7770 Returns a canonical argument list, which may be ARGTYPES when the
7771 canonical argument list is unneeded (i.e., *ANY_STRUCTURAL_P is
7772 true) or would not differ from ARGTYPES. */
7775 maybe_canonicalize_argtypes(tree argtypes
,
7776 bool *any_structural_p
,
7777 bool *any_noncanonical_p
)
7780 bool any_noncanonical_argtypes_p
= false;
7782 for (arg
= argtypes
; arg
&& !(*any_structural_p
); arg
= TREE_CHAIN (arg
))
7784 if (!TREE_VALUE (arg
) || TREE_VALUE (arg
) == error_mark_node
)
7785 /* Fail gracefully by stating that the type is structural. */
7786 *any_structural_p
= true;
7787 else if (TYPE_STRUCTURAL_EQUALITY_P (TREE_VALUE (arg
)))
7788 *any_structural_p
= true;
7789 else if (TYPE_CANONICAL (TREE_VALUE (arg
)) != TREE_VALUE (arg
)
7790 || TREE_PURPOSE (arg
))
7791 /* If the argument has a default argument, we consider it
7792 non-canonical even though the type itself is canonical.
7793 That way, different variants of function and method types
7794 with default arguments will all point to the variant with
7795 no defaults as their canonical type. */
7796 any_noncanonical_argtypes_p
= true;
7799 if (*any_structural_p
)
7802 if (any_noncanonical_argtypes_p
)
7804 /* Build the canonical list of argument types. */
7805 tree canon_argtypes
= NULL_TREE
;
7806 bool is_void
= false;
7808 for (arg
= argtypes
; arg
; arg
= TREE_CHAIN (arg
))
7810 if (arg
== void_list_node
)
7813 canon_argtypes
= tree_cons (NULL_TREE
,
7814 TYPE_CANONICAL (TREE_VALUE (arg
)),
7818 canon_argtypes
= nreverse (canon_argtypes
);
7820 canon_argtypes
= chainon (canon_argtypes
, void_list_node
);
7822 /* There is a non-canonical type. */
7823 *any_noncanonical_p
= true;
7824 return canon_argtypes
;
7827 /* The canonical argument types are the same as ARGTYPES. */
7831 /* Construct, lay out and return
7832 the type of functions returning type VALUE_TYPE
7833 given arguments of types ARG_TYPES.
7834 ARG_TYPES is a chain of TREE_LIST nodes whose TREE_VALUEs
7835 are data type nodes for the arguments of the function.
7836 If such a type has already been constructed, reuse it. */
7839 build_function_type (tree value_type
, tree arg_types
)
7842 hashval_t hashcode
= 0;
7843 bool any_structural_p
, any_noncanonical_p
;
7844 tree canon_argtypes
;
7846 if (TREE_CODE (value_type
) == FUNCTION_TYPE
)
7848 error ("function return type cannot be function");
7849 value_type
= integer_type_node
;
7852 /* Make a node of the sort we want. */
7853 t
= make_node (FUNCTION_TYPE
);
7854 TREE_TYPE (t
) = value_type
;
7855 TYPE_ARG_TYPES (t
) = arg_types
;
7857 /* If we already have such a type, use the old one. */
7858 hashcode
= iterative_hash_object (TYPE_HASH (value_type
), hashcode
);
7859 hashcode
= type_hash_list (arg_types
, hashcode
);
7860 t
= type_hash_canon (hashcode
, t
);
7862 /* Set up the canonical type. */
7863 any_structural_p
= TYPE_STRUCTURAL_EQUALITY_P (value_type
);
7864 any_noncanonical_p
= TYPE_CANONICAL (value_type
) != value_type
;
7865 canon_argtypes
= maybe_canonicalize_argtypes (arg_types
,
7867 &any_noncanonical_p
);
7868 if (any_structural_p
)
7869 SET_TYPE_STRUCTURAL_EQUALITY (t
);
7870 else if (any_noncanonical_p
)
7871 TYPE_CANONICAL (t
) = build_function_type (TYPE_CANONICAL (value_type
),
7874 if (!COMPLETE_TYPE_P (t
))
7879 /* Build variant of function type ORIG_TYPE skipping ARGS_TO_SKIP and the
7880 return value if SKIP_RETURN is true. */
7883 build_function_type_skip_args (tree orig_type
, bitmap args_to_skip
,
7886 tree new_type
= NULL
;
7887 tree args
, new_args
= NULL
, t
;
7891 for (args
= TYPE_ARG_TYPES (orig_type
); args
&& args
!= void_list_node
;
7892 args
= TREE_CHAIN (args
), i
++)
7893 if (!args_to_skip
|| !bitmap_bit_p (args_to_skip
, i
))
7894 new_args
= tree_cons (NULL_TREE
, TREE_VALUE (args
), new_args
);
7896 new_reversed
= nreverse (new_args
);
7900 TREE_CHAIN (new_args
) = void_list_node
;
7902 new_reversed
= void_list_node
;
7905 /* Use copy_node to preserve as much as possible from original type
7906 (debug info, attribute lists etc.)
7907 Exception is METHOD_TYPEs must have THIS argument.
7908 When we are asked to remove it, we need to build new FUNCTION_TYPE
7910 if (TREE_CODE (orig_type
) != METHOD_TYPE
7912 || !bitmap_bit_p (args_to_skip
, 0))
7914 new_type
= build_distinct_type_copy (orig_type
);
7915 TYPE_ARG_TYPES (new_type
) = new_reversed
;
7920 = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type
),
7922 TYPE_CONTEXT (new_type
) = TYPE_CONTEXT (orig_type
);
7926 TREE_TYPE (new_type
) = void_type_node
;
7928 /* This is a new type, not a copy of an old type. Need to reassociate
7929 variants. We can handle everything except the main variant lazily. */
7930 t
= TYPE_MAIN_VARIANT (orig_type
);
7933 t
= build_function_type_skip_args (t
, args_to_skip
, skip_return
);
7934 TYPE_MAIN_VARIANT (new_type
) = t
;
7935 TYPE_NEXT_VARIANT (new_type
) = TYPE_NEXT_VARIANT (t
);
7936 TYPE_NEXT_VARIANT (t
) = new_type
;
7940 TYPE_MAIN_VARIANT (new_type
) = new_type
;
7941 TYPE_NEXT_VARIANT (new_type
) = NULL
;
7947 /* Build variant of function decl ORIG_DECL skipping ARGS_TO_SKIP and the
7948 return value if SKIP_RETURN is true.
7950 Arguments from DECL_ARGUMENTS list can't be removed now, since they are
7951 linked by TREE_CHAIN directly. The caller is responsible for eliminating
7952 them when they are being duplicated (i.e. copy_arguments_for_versioning). */
7955 build_function_decl_skip_args (tree orig_decl
, bitmap args_to_skip
,
7958 tree new_decl
= copy_node (orig_decl
);
7961 new_type
= TREE_TYPE (orig_decl
);
7962 if (prototype_p (new_type
)
7963 || (skip_return
&& !VOID_TYPE_P (TREE_TYPE (new_type
))))
7965 = build_function_type_skip_args (new_type
, args_to_skip
, skip_return
);
7966 TREE_TYPE (new_decl
) = new_type
;
7968 /* For declarations setting DECL_VINDEX (i.e. methods)
7969 we expect first argument to be THIS pointer. */
7970 if (args_to_skip
&& bitmap_bit_p (args_to_skip
, 0))
7971 DECL_VINDEX (new_decl
) = NULL_TREE
;
7973 /* When signature changes, we need to clear builtin info. */
7974 if (DECL_BUILT_IN (new_decl
)
7976 && !bitmap_empty_p (args_to_skip
))
7978 DECL_BUILT_IN_CLASS (new_decl
) = NOT_BUILT_IN
;
7979 DECL_FUNCTION_CODE (new_decl
) = (enum built_in_function
) 0;
7984 /* Build a function type. The RETURN_TYPE is the type returned by the
7985 function. If VAARGS is set, no void_type_node is appended to the
7986 the list. ARGP must be always be terminated be a NULL_TREE. */
7989 build_function_type_list_1 (bool vaargs
, tree return_type
, va_list argp
)
7993 t
= va_arg (argp
, tree
);
7994 for (args
= NULL_TREE
; t
!= NULL_TREE
; t
= va_arg (argp
, tree
))
7995 args
= tree_cons (NULL_TREE
, t
, args
);
8000 if (args
!= NULL_TREE
)
8001 args
= nreverse (args
);
8002 gcc_assert (last
!= void_list_node
);
8004 else if (args
== NULL_TREE
)
8005 args
= void_list_node
;
8009 args
= nreverse (args
);
8010 TREE_CHAIN (last
) = void_list_node
;
8012 args
= build_function_type (return_type
, args
);
8017 /* Build a function type. The RETURN_TYPE is the type returned by the
8018 function. If additional arguments are provided, they are
8019 additional argument types. The list of argument types must always
8020 be terminated by NULL_TREE. */
8023 build_function_type_list (tree return_type
, ...)
8028 va_start (p
, return_type
);
8029 args
= build_function_type_list_1 (false, return_type
, p
);
8034 /* Build a variable argument function type. The RETURN_TYPE is the
8035 type returned by the function. If additional arguments are provided,
8036 they are additional argument types. The list of argument types must
8037 always be terminated by NULL_TREE. */
8040 build_varargs_function_type_list (tree return_type
, ...)
8045 va_start (p
, return_type
);
8046 args
= build_function_type_list_1 (true, return_type
, p
);
8052 /* Build a function type. RETURN_TYPE is the type returned by the
8053 function; VAARGS indicates whether the function takes varargs. The
8054 function takes N named arguments, the types of which are provided in
8058 build_function_type_array_1 (bool vaargs
, tree return_type
, int n
,
8062 tree t
= vaargs
? NULL_TREE
: void_list_node
;
8064 for (i
= n
- 1; i
>= 0; i
--)
8065 t
= tree_cons (NULL_TREE
, arg_types
[i
], t
);
8067 return build_function_type (return_type
, t
);
8070 /* Build a function type. RETURN_TYPE is the type returned by the
8071 function. The function takes N named arguments, the types of which
8072 are provided in ARG_TYPES. */
8075 build_function_type_array (tree return_type
, int n
, tree
*arg_types
)
8077 return build_function_type_array_1 (false, return_type
, n
, arg_types
);
8080 /* Build a variable argument function type. RETURN_TYPE is the type
8081 returned by the function. The function takes N named arguments, the
8082 types of which are provided in ARG_TYPES. */
8085 build_varargs_function_type_array (tree return_type
, int n
, tree
*arg_types
)
8087 return build_function_type_array_1 (true, return_type
, n
, arg_types
);
8090 /* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE)
8091 and ARGTYPES (a TREE_LIST) are the return type and arguments types
8092 for the method. An implicit additional parameter (of type
8093 pointer-to-BASETYPE) is added to the ARGTYPES. */
8096 build_method_type_directly (tree basetype
,
8103 bool any_structural_p
, any_noncanonical_p
;
8104 tree canon_argtypes
;
8106 /* Make a node of the sort we want. */
8107 t
= make_node (METHOD_TYPE
);
8109 TYPE_METHOD_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
8110 TREE_TYPE (t
) = rettype
;
8111 ptype
= build_pointer_type (basetype
);
8113 /* The actual arglist for this function includes a "hidden" argument
8114 which is "this". Put it into the list of argument types. */
8115 argtypes
= tree_cons (NULL_TREE
, ptype
, argtypes
);
8116 TYPE_ARG_TYPES (t
) = argtypes
;
8118 /* If we already have such a type, use the old one. */
8119 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
8120 hashcode
= iterative_hash_object (TYPE_HASH (rettype
), hashcode
);
8121 hashcode
= type_hash_list (argtypes
, hashcode
);
8122 t
= type_hash_canon (hashcode
, t
);
8124 /* Set up the canonical type. */
8126 = (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
8127 || TYPE_STRUCTURAL_EQUALITY_P (rettype
));
8129 = (TYPE_CANONICAL (basetype
) != basetype
8130 || TYPE_CANONICAL (rettype
) != rettype
);
8131 canon_argtypes
= maybe_canonicalize_argtypes (TREE_CHAIN (argtypes
),
8133 &any_noncanonical_p
);
8134 if (any_structural_p
)
8135 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8136 else if (any_noncanonical_p
)
8138 = build_method_type_directly (TYPE_CANONICAL (basetype
),
8139 TYPE_CANONICAL (rettype
),
8141 if (!COMPLETE_TYPE_P (t
))
8147 /* Construct, lay out and return the type of methods belonging to class
8148 BASETYPE and whose arguments and values are described by TYPE.
8149 If that type exists already, reuse it.
8150 TYPE must be a FUNCTION_TYPE node. */
8153 build_method_type (tree basetype
, tree type
)
8155 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
8157 return build_method_type_directly (basetype
,
8159 TYPE_ARG_TYPES (type
));
8162 /* Construct, lay out and return the type of offsets to a value
8163 of type TYPE, within an object of type BASETYPE.
8164 If a suitable offset type exists already, reuse it. */
8167 build_offset_type (tree basetype
, tree type
)
8170 hashval_t hashcode
= 0;
8172 /* Make a node of the sort we want. */
8173 t
= make_node (OFFSET_TYPE
);
8175 TYPE_OFFSET_BASETYPE (t
) = TYPE_MAIN_VARIANT (basetype
);
8176 TREE_TYPE (t
) = type
;
8178 /* If we already have such a type, use the old one. */
8179 hashcode
= iterative_hash_object (TYPE_HASH (basetype
), hashcode
);
8180 hashcode
= iterative_hash_object (TYPE_HASH (type
), hashcode
);
8181 t
= type_hash_canon (hashcode
, t
);
8183 if (!COMPLETE_TYPE_P (t
))
8186 if (TYPE_CANONICAL (t
) == t
)
8188 if (TYPE_STRUCTURAL_EQUALITY_P (basetype
)
8189 || TYPE_STRUCTURAL_EQUALITY_P (type
))
8190 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8191 else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)) != basetype
8192 || TYPE_CANONICAL (type
) != type
)
8194 = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype
)),
8195 TYPE_CANONICAL (type
));
8201 /* Create a complex type whose components are COMPONENT_TYPE. */
8204 build_complex_type (tree component_type
)
8209 gcc_assert (INTEGRAL_TYPE_P (component_type
)
8210 || SCALAR_FLOAT_TYPE_P (component_type
)
8211 || FIXED_POINT_TYPE_P (component_type
));
8213 /* Make a node of the sort we want. */
8214 t
= make_node (COMPLEX_TYPE
);
8216 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (component_type
);
8218 /* If we already have such a type, use the old one. */
8219 hashcode
= iterative_hash_object (TYPE_HASH (component_type
), 0);
8220 t
= type_hash_canon (hashcode
, t
);
8222 if (!COMPLETE_TYPE_P (t
))
8225 if (TYPE_CANONICAL (t
) == t
)
8227 if (TYPE_STRUCTURAL_EQUALITY_P (component_type
))
8228 SET_TYPE_STRUCTURAL_EQUALITY (t
);
8229 else if (TYPE_CANONICAL (component_type
) != component_type
)
8231 = build_complex_type (TYPE_CANONICAL (component_type
));
8234 /* We need to create a name, since complex is a fundamental type. */
8235 if (! TYPE_NAME (t
))
8238 if (component_type
== char_type_node
)
8239 name
= "complex char";
8240 else if (component_type
== signed_char_type_node
)
8241 name
= "complex signed char";
8242 else if (component_type
== unsigned_char_type_node
)
8243 name
= "complex unsigned char";
8244 else if (component_type
== short_integer_type_node
)
8245 name
= "complex short int";
8246 else if (component_type
== short_unsigned_type_node
)
8247 name
= "complex short unsigned int";
8248 else if (component_type
== integer_type_node
)
8249 name
= "complex int";
8250 else if (component_type
== unsigned_type_node
)
8251 name
= "complex unsigned int";
8252 else if (component_type
== long_integer_type_node
)
8253 name
= "complex long int";
8254 else if (component_type
== long_unsigned_type_node
)
8255 name
= "complex long unsigned int";
8256 else if (component_type
== long_long_integer_type_node
)
8257 name
= "complex long long int";
8258 else if (component_type
== long_long_unsigned_type_node
)
8259 name
= "complex long long unsigned int";
8264 TYPE_NAME (t
) = build_decl (UNKNOWN_LOCATION
, TYPE_DECL
,
8265 get_identifier (name
), t
);
8268 return build_qualified_type (t
, TYPE_QUALS (component_type
));
8271 /* If TYPE is a real or complex floating-point type and the target
8272 does not directly support arithmetic on TYPE then return the wider
8273 type to be used for arithmetic on TYPE. Otherwise, return
8277 excess_precision_type (tree type
)
8279 if (flag_excess_precision
!= EXCESS_PRECISION_FAST
)
8281 int flt_eval_method
= TARGET_FLT_EVAL_METHOD
;
8282 switch (TREE_CODE (type
))
8285 switch (flt_eval_method
)
8288 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
))
8289 return double_type_node
;
8292 if (TYPE_MODE (type
) == TYPE_MODE (float_type_node
)
8293 || TYPE_MODE (type
) == TYPE_MODE (double_type_node
))
8294 return long_double_type_node
;
8301 if (TREE_CODE (TREE_TYPE (type
)) != REAL_TYPE
)
8303 switch (flt_eval_method
)
8306 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
))
8307 return complex_double_type_node
;
8310 if (TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (float_type_node
)
8311 || (TYPE_MODE (TREE_TYPE (type
))
8312 == TYPE_MODE (double_type_node
)))
8313 return complex_long_double_type_node
;
8326 /* Return OP, stripped of any conversions to wider types as much as is safe.
8327 Converting the value back to OP's type makes a value equivalent to OP.
8329 If FOR_TYPE is nonzero, we return a value which, if converted to
8330 type FOR_TYPE, would be equivalent to converting OP to type FOR_TYPE.
8332 OP must have integer, real or enumeral type. Pointers are not allowed!
8334 There are some cases where the obvious value we could return
8335 would regenerate to OP if converted to OP's type,
8336 but would not extend like OP to wider types.
8337 If FOR_TYPE indicates such extension is contemplated, we eschew such values.
8338 For example, if OP is (unsigned short)(signed char)-1,
8339 we avoid returning (signed char)-1 if FOR_TYPE is int,
8340 even though extending that to an unsigned short would regenerate OP,
8341 since the result of extending (signed char)-1 to (int)
8342 is different from (int) OP. */
8345 get_unwidened (tree op
, tree for_type
)
8347 /* Set UNS initially if converting OP to FOR_TYPE is a zero-extension. */
8348 tree type
= TREE_TYPE (op
);
8350 = TYPE_PRECISION (for_type
!= 0 ? for_type
: type
);
8352 = (for_type
!= 0 && for_type
!= type
8353 && final_prec
> TYPE_PRECISION (type
)
8354 && TYPE_UNSIGNED (type
));
8357 while (CONVERT_EXPR_P (op
))
8361 /* TYPE_PRECISION on vector types has different meaning
8362 (TYPE_VECTOR_SUBPARTS) and casts from vectors are view conversions,
8363 so avoid them here. */
8364 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (op
, 0))) == VECTOR_TYPE
)
8367 bitschange
= TYPE_PRECISION (TREE_TYPE (op
))
8368 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0)));
8370 /* Truncations are many-one so cannot be removed.
8371 Unless we are later going to truncate down even farther. */
8373 && final_prec
> TYPE_PRECISION (TREE_TYPE (op
)))
8376 /* See what's inside this conversion. If we decide to strip it,
8378 op
= TREE_OPERAND (op
, 0);
8380 /* If we have not stripped any zero-extensions (uns is 0),
8381 we can strip any kind of extension.
8382 If we have previously stripped a zero-extension,
8383 only zero-extensions can safely be stripped.
8384 Any extension can be stripped if the bits it would produce
8385 are all going to be discarded later by truncating to FOR_TYPE. */
8389 if (! uns
|| final_prec
<= TYPE_PRECISION (TREE_TYPE (op
)))
8391 /* TYPE_UNSIGNED says whether this is a zero-extension.
8392 Let's avoid computing it if it does not affect WIN
8393 and if UNS will not be needed again. */
8395 || CONVERT_EXPR_P (op
))
8396 && TYPE_UNSIGNED (TREE_TYPE (op
)))
8404 /* If we finally reach a constant see if it fits in for_type and
8405 in that case convert it. */
8407 && TREE_CODE (win
) == INTEGER_CST
8408 && TREE_TYPE (win
) != for_type
8409 && int_fits_type_p (win
, for_type
))
8410 win
= fold_convert (for_type
, win
);
8415 /* Return OP or a simpler expression for a narrower value
8416 which can be sign-extended or zero-extended to give back OP.
8417 Store in *UNSIGNEDP_PTR either 1 if the value should be zero-extended
8418 or 0 if the value should be sign-extended. */
8421 get_narrower (tree op
, int *unsignedp_ptr
)
8426 bool integral_p
= INTEGRAL_TYPE_P (TREE_TYPE (op
));
8428 while (TREE_CODE (op
) == NOP_EXPR
)
8431 = (TYPE_PRECISION (TREE_TYPE (op
))
8432 - TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op
, 0))));
8434 /* Truncations are many-one so cannot be removed. */
8438 /* See what's inside this conversion. If we decide to strip it,
8443 op
= TREE_OPERAND (op
, 0);
8444 /* An extension: the outermost one can be stripped,
8445 but remember whether it is zero or sign extension. */
8447 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8448 /* Otherwise, if a sign extension has been stripped,
8449 only sign extensions can now be stripped;
8450 if a zero extension has been stripped, only zero-extensions. */
8451 else if (uns
!= TYPE_UNSIGNED (TREE_TYPE (op
)))
8455 else /* bitschange == 0 */
8457 /* A change in nominal type can always be stripped, but we must
8458 preserve the unsignedness. */
8460 uns
= TYPE_UNSIGNED (TREE_TYPE (op
));
8462 op
= TREE_OPERAND (op
, 0);
8463 /* Keep trying to narrow, but don't assign op to win if it
8464 would turn an integral type into something else. */
8465 if (INTEGRAL_TYPE_P (TREE_TYPE (op
)) != integral_p
)
8472 if (TREE_CODE (op
) == COMPONENT_REF
8473 /* Since type_for_size always gives an integer type. */
8474 && TREE_CODE (TREE_TYPE (op
)) != REAL_TYPE
8475 && TREE_CODE (TREE_TYPE (op
)) != FIXED_POINT_TYPE
8476 /* Ensure field is laid out already. */
8477 && DECL_SIZE (TREE_OPERAND (op
, 1)) != 0
8478 && host_integerp (DECL_SIZE (TREE_OPERAND (op
, 1)), 1))
8480 unsigned HOST_WIDE_INT innerprec
8481 = tree_low_cst (DECL_SIZE (TREE_OPERAND (op
, 1)), 1);
8482 int unsignedp
= (DECL_UNSIGNED (TREE_OPERAND (op
, 1))
8483 || TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op
, 1))));
8484 tree type
= lang_hooks
.types
.type_for_size (innerprec
, unsignedp
);
8486 /* We can get this structure field in a narrower type that fits it,
8487 but the resulting extension to its nominal type (a fullword type)
8488 must satisfy the same conditions as for other extensions.
8490 Do this only for fields that are aligned (not bit-fields),
8491 because when bit-field insns will be used there is no
8492 advantage in doing this. */
8494 if (innerprec
< TYPE_PRECISION (TREE_TYPE (op
))
8495 && ! DECL_BIT_FIELD (TREE_OPERAND (op
, 1))
8496 && (first
|| uns
== DECL_UNSIGNED (TREE_OPERAND (op
, 1)))
8500 uns
= DECL_UNSIGNED (TREE_OPERAND (op
, 1));
8501 win
= fold_convert (type
, op
);
8505 *unsignedp_ptr
= uns
;
8509 /* Returns true if integer constant C has a value that is permissible
8510 for type TYPE (an INTEGER_TYPE). */
8513 int_fits_type_p (const_tree c
, const_tree type
)
8515 tree type_low_bound
, type_high_bound
;
8516 bool ok_for_low_bound
, ok_for_high_bound
, unsc
;
8519 dc
= tree_to_double_int (c
);
8520 unsc
= TYPE_UNSIGNED (TREE_TYPE (c
));
8523 type_low_bound
= TYPE_MIN_VALUE (type
);
8524 type_high_bound
= TYPE_MAX_VALUE (type
);
8526 /* If at least one bound of the type is a constant integer, we can check
8527 ourselves and maybe make a decision. If no such decision is possible, but
8528 this type is a subtype, try checking against that. Otherwise, use
8529 double_int_fits_to_tree_p, which checks against the precision.
8531 Compute the status for each possibly constant bound, and return if we see
8532 one does not match. Use ok_for_xxx_bound for this purpose, assigning -1
8533 for "unknown if constant fits", 0 for "constant known *not* to fit" and 1
8534 for "constant known to fit". */
8536 /* Check if c >= type_low_bound. */
8537 if (type_low_bound
&& TREE_CODE (type_low_bound
) == INTEGER_CST
)
8539 dd
= tree_to_double_int (type_low_bound
);
8540 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_low_bound
)))
8542 int c_neg
= (!unsc
&& dc
.is_negative ());
8543 int t_neg
= (unsc
&& dd
.is_negative ());
8545 if (c_neg
&& !t_neg
)
8547 if ((c_neg
|| !t_neg
) && dc
.ult (dd
))
8550 else if (dc
.cmp (dd
, unsc
) < 0)
8552 ok_for_low_bound
= true;
8555 ok_for_low_bound
= false;
8557 /* Check if c <= type_high_bound. */
8558 if (type_high_bound
&& TREE_CODE (type_high_bound
) == INTEGER_CST
)
8560 dd
= tree_to_double_int (type_high_bound
);
8561 if (unsc
!= TYPE_UNSIGNED (TREE_TYPE (type_high_bound
)))
8563 int c_neg
= (!unsc
&& dc
.is_negative ());
8564 int t_neg
= (unsc
&& dd
.is_negative ());
8566 if (t_neg
&& !c_neg
)
8568 if ((t_neg
|| !c_neg
) && dc
.ugt (dd
))
8571 else if (dc
.cmp (dd
, unsc
) > 0)
8573 ok_for_high_bound
= true;
8576 ok_for_high_bound
= false;
8578 /* If the constant fits both bounds, the result is known. */
8579 if (ok_for_low_bound
&& ok_for_high_bound
)
8582 /* Perform some generic filtering which may allow making a decision
8583 even if the bounds are not constant. First, negative integers
8584 never fit in unsigned types, */
8585 if (TYPE_UNSIGNED (type
) && !unsc
&& dc
.is_negative ())
8588 /* Second, narrower types always fit in wider ones. */
8589 if (TYPE_PRECISION (type
) > TYPE_PRECISION (TREE_TYPE (c
)))
8592 /* Third, unsigned integers with top bit set never fit signed types. */
8593 if (! TYPE_UNSIGNED (type
) && unsc
)
8595 int prec
= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (c
))) - 1;
8596 if (prec
< HOST_BITS_PER_WIDE_INT
)
8598 if (((((unsigned HOST_WIDE_INT
) 1) << prec
) & dc
.low
) != 0)
8601 else if (((((unsigned HOST_WIDE_INT
) 1)
8602 << (prec
- HOST_BITS_PER_WIDE_INT
)) & dc
.high
) != 0)
8606 /* If we haven't been able to decide at this point, there nothing more we
8607 can check ourselves here. Look at the base type if we have one and it
8608 has the same precision. */
8609 if (TREE_CODE (type
) == INTEGER_TYPE
8610 && TREE_TYPE (type
) != 0
8611 && TYPE_PRECISION (type
) == TYPE_PRECISION (TREE_TYPE (type
)))
8613 type
= TREE_TYPE (type
);
8617 /* Or to double_int_fits_to_tree_p, if nothing else. */
8618 return double_int_fits_to_tree_p (type
, dc
);
8621 /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant
8622 bounds or is a POINTER_TYPE, the maximum and/or minimum values that can be
8623 represented (assuming two's-complement arithmetic) within the bit
8624 precision of the type are returned instead. */
8627 get_type_static_bounds (const_tree type
, mpz_t min
, mpz_t max
)
8629 if (!POINTER_TYPE_P (type
) && TYPE_MIN_VALUE (type
)
8630 && TREE_CODE (TYPE_MIN_VALUE (type
)) == INTEGER_CST
)
8631 mpz_set_double_int (min
, tree_to_double_int (TYPE_MIN_VALUE (type
)),
8632 TYPE_UNSIGNED (type
));
8635 if (TYPE_UNSIGNED (type
))
8636 mpz_set_ui (min
, 0);
8640 mn
= double_int::mask (TYPE_PRECISION (type
) - 1);
8641 mn
= (mn
+ double_int_one
).sext (TYPE_PRECISION (type
));
8642 mpz_set_double_int (min
, mn
, false);
8646 if (!POINTER_TYPE_P (type
) && TYPE_MAX_VALUE (type
)
8647 && TREE_CODE (TYPE_MAX_VALUE (type
)) == INTEGER_CST
)
8648 mpz_set_double_int (max
, tree_to_double_int (TYPE_MAX_VALUE (type
)),
8649 TYPE_UNSIGNED (type
));
8652 if (TYPE_UNSIGNED (type
))
8653 mpz_set_double_int (max
, double_int::mask (TYPE_PRECISION (type
)),
8656 mpz_set_double_int (max
, double_int::mask (TYPE_PRECISION (type
) - 1),
8661 /* Return true if VAR is an automatic variable defined in function FN. */
8664 auto_var_in_fn_p (const_tree var
, const_tree fn
)
8666 return (DECL_P (var
) && DECL_CONTEXT (var
) == fn
8667 && ((((TREE_CODE (var
) == VAR_DECL
&& ! DECL_EXTERNAL (var
))
8668 || TREE_CODE (var
) == PARM_DECL
)
8669 && ! TREE_STATIC (var
))
8670 || TREE_CODE (var
) == LABEL_DECL
8671 || TREE_CODE (var
) == RESULT_DECL
));
8674 /* Subprogram of following function. Called by walk_tree.
8676 Return *TP if it is an automatic variable or parameter of the
8677 function passed in as DATA. */
8680 find_var_from_fn (tree
*tp
, int *walk_subtrees
, void *data
)
8682 tree fn
= (tree
) data
;
8687 else if (DECL_P (*tp
)
8688 && auto_var_in_fn_p (*tp
, fn
))
8694 /* Returns true if T is, contains, or refers to a type with variable
8695 size. For METHOD_TYPEs and FUNCTION_TYPEs we exclude the
8696 arguments, but not the return type. If FN is nonzero, only return
8697 true if a modifier of the type or position of FN is a variable or
8698 parameter inside FN.
8700 This concept is more general than that of C99 'variably modified types':
8701 in C99, a struct type is never variably modified because a VLA may not
8702 appear as a structure member. However, in GNU C code like:
8704 struct S { int i[f()]; };
8706 is valid, and other languages may define similar constructs. */
8709 variably_modified_type_p (tree type
, tree fn
)
8713 /* Test if T is either variable (if FN is zero) or an expression containing
8714 a variable in FN. If TYPE isn't gimplified, return true also if
8715 gimplify_one_sizepos would gimplify the expression into a local
8717 #define RETURN_TRUE_IF_VAR(T) \
8718 do { tree _t = (T); \
8719 if (_t != NULL_TREE \
8720 && _t != error_mark_node \
8721 && TREE_CODE (_t) != INTEGER_CST \
8722 && TREE_CODE (_t) != PLACEHOLDER_EXPR \
8724 || (!TYPE_SIZES_GIMPLIFIED (type) \
8725 && !is_gimple_sizepos (_t)) \
8726 || walk_tree (&_t, find_var_from_fn, fn, NULL))) \
8727 return true; } while (0)
8729 if (type
== error_mark_node
)
8732 /* If TYPE itself has variable size, it is variably modified. */
8733 RETURN_TRUE_IF_VAR (TYPE_SIZE (type
));
8734 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type
));
8736 switch (TREE_CODE (type
))
8739 case REFERENCE_TYPE
:
8741 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8747 /* If TYPE is a function type, it is variably modified if the
8748 return type is variably modified. */
8749 if (variably_modified_type_p (TREE_TYPE (type
), fn
))
8755 case FIXED_POINT_TYPE
:
8758 /* Scalar types are variably modified if their end points
8760 RETURN_TRUE_IF_VAR (TYPE_MIN_VALUE (type
));
8761 RETURN_TRUE_IF_VAR (TYPE_MAX_VALUE (type
));
8766 case QUAL_UNION_TYPE
:
8767 /* We can't see if any of the fields are variably-modified by the
8768 definition we normally use, since that would produce infinite
8769 recursion via pointers. */
8770 /* This is variably modified if some field's type is. */
8771 for (t
= TYPE_FIELDS (type
); t
; t
= DECL_CHAIN (t
))
8772 if (TREE_CODE (t
) == FIELD_DECL
)
8774 RETURN_TRUE_IF_VAR (DECL_FIELD_OFFSET (t
));
8775 RETURN_TRUE_IF_VAR (DECL_SIZE (t
));
8776 RETURN_TRUE_IF_VAR (DECL_SIZE_UNIT (t
));
8778 if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
8779 RETURN_TRUE_IF_VAR (DECL_QUALIFIER (t
));
8784 /* Do not call ourselves to avoid infinite recursion. This is
8785 variably modified if the element type is. */
8786 RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type
)));
8787 RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type
)));
8794 /* The current language may have other cases to check, but in general,
8795 all other types are not variably modified. */
8796 return lang_hooks
.tree_inlining
.var_mod_type_p (type
, fn
);
8798 #undef RETURN_TRUE_IF_VAR
8801 /* Given a DECL or TYPE, return the scope in which it was declared, or
8802 NULL_TREE if there is no containing scope. */
8805 get_containing_scope (const_tree t
)
8807 return (TYPE_P (t
) ? TYPE_CONTEXT (t
) : DECL_CONTEXT (t
));
8810 /* Return the innermost context enclosing DECL that is
8811 a FUNCTION_DECL, or zero if none. */
8814 decl_function_context (const_tree decl
)
8818 if (TREE_CODE (decl
) == ERROR_MARK
)
8821 /* C++ virtual functions use DECL_CONTEXT for the class of the vtable
8822 where we look up the function at runtime. Such functions always take
8823 a first argument of type 'pointer to real context'.
8825 C++ should really be fixed to use DECL_CONTEXT for the real context,
8826 and use something else for the "virtual context". */
8827 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VINDEX (decl
))
8830 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
8832 context
= DECL_CONTEXT (decl
);
8834 while (context
&& TREE_CODE (context
) != FUNCTION_DECL
)
8836 if (TREE_CODE (context
) == BLOCK
)
8837 context
= BLOCK_SUPERCONTEXT (context
);
8839 context
= get_containing_scope (context
);
8845 /* Return the innermost context enclosing DECL that is
8846 a RECORD_TYPE, UNION_TYPE or QUAL_UNION_TYPE, or zero if none.
8847 TYPE_DECLs and FUNCTION_DECLs are transparent to this function. */
8850 decl_type_context (const_tree decl
)
8852 tree context
= DECL_CONTEXT (decl
);
8855 switch (TREE_CODE (context
))
8857 case NAMESPACE_DECL
:
8858 case TRANSLATION_UNIT_DECL
:
8863 case QUAL_UNION_TYPE
:
8868 context
= DECL_CONTEXT (context
);
8872 context
= BLOCK_SUPERCONTEXT (context
);
8882 /* CALL is a CALL_EXPR. Return the declaration for the function
8883 called, or NULL_TREE if the called function cannot be
8887 get_callee_fndecl (const_tree call
)
8891 if (call
== error_mark_node
)
8892 return error_mark_node
;
8894 /* It's invalid to call this function with anything but a
8896 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
8898 /* The first operand to the CALL is the address of the function
8900 addr
= CALL_EXPR_FN (call
);
8904 /* If this is a readonly function pointer, extract its initial value. */
8905 if (DECL_P (addr
) && TREE_CODE (addr
) != FUNCTION_DECL
8906 && TREE_READONLY (addr
) && ! TREE_THIS_VOLATILE (addr
)
8907 && DECL_INITIAL (addr
))
8908 addr
= DECL_INITIAL (addr
);
8910 /* If the address is just `&f' for some function `f', then we know
8911 that `f' is being called. */
8912 if (TREE_CODE (addr
) == ADDR_EXPR
8913 && TREE_CODE (TREE_OPERAND (addr
, 0)) == FUNCTION_DECL
)
8914 return TREE_OPERAND (addr
, 0);
8916 /* We couldn't figure out what was being called. */
8920 /* Print debugging information about tree nodes generated during the compile,
8921 and any language-specific information. */
8924 dump_tree_statistics (void)
8926 if (GATHER_STATISTICS
)
8929 int total_nodes
, total_bytes
;
8930 fprintf (stderr
, "Kind Nodes Bytes\n");
8931 fprintf (stderr
, "---------------------------------------\n");
8932 total_nodes
= total_bytes
= 0;
8933 for (i
= 0; i
< (int) all_kinds
; i
++)
8935 fprintf (stderr
, "%-20s %7d %10d\n", tree_node_kind_names
[i
],
8936 tree_node_counts
[i
], tree_node_sizes
[i
]);
8937 total_nodes
+= tree_node_counts
[i
];
8938 total_bytes
+= tree_node_sizes
[i
];
8940 fprintf (stderr
, "---------------------------------------\n");
8941 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_nodes
, total_bytes
);
8942 fprintf (stderr
, "---------------------------------------\n");
8943 fprintf (stderr
, "Code Nodes\n");
8944 fprintf (stderr
, "----------------------------\n");
8945 for (i
= 0; i
< (int) MAX_TREE_CODES
; i
++)
8946 fprintf (stderr
, "%-20s %7d\n", tree_code_name
[i
], tree_code_counts
[i
]);
8947 fprintf (stderr
, "----------------------------\n");
8948 ssanames_print_statistics ();
8949 phinodes_print_statistics ();
8952 fprintf (stderr
, "(No per-node statistics)\n");
8954 print_type_hash_statistics ();
8955 print_debug_expr_statistics ();
8956 print_value_expr_statistics ();
8957 lang_hooks
.print_statistics ();
8960 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
8962 /* Generate a crc32 of a byte. */
8965 crc32_unsigned_bits (unsigned chksum
, unsigned value
, unsigned bits
)
8969 for (ix
= bits
; ix
--; value
<<= 1)
8973 feedback
= (value
^ chksum
) & 0x80000000 ? 0x04c11db7 : 0;
8980 /* Generate a crc32 of a 32-bit unsigned. */
8983 crc32_unsigned (unsigned chksum
, unsigned value
)
8985 return crc32_unsigned_bits (chksum
, value
, 32);
8988 /* Generate a crc32 of a byte. */
8991 crc32_byte (unsigned chksum
, char byte
)
8993 return crc32_unsigned_bits (chksum
, (unsigned) byte
<< 24, 8);
8996 /* Generate a crc32 of a string. */
8999 crc32_string (unsigned chksum
, const char *string
)
9003 chksum
= crc32_byte (chksum
, *string
);
9009 /* P is a string that will be used in a symbol. Mask out any characters
9010 that are not valid in that context. */
9013 clean_symbol_name (char *p
)
9017 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
9020 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
9027 /* Generate a name for a special-purpose function.
9028 The generated name may need to be unique across the whole link.
9029 Changes to this function may also require corresponding changes to
9030 xstrdup_mask_random.
9031 TYPE is some string to identify the purpose of this function to the
9032 linker or collect2; it must start with an uppercase letter,
9034 I - for constructors
9036 N - for C++ anonymous namespaces
9037 F - for DWARF unwind frame information. */
9040 get_file_function_name (const char *type
)
9046 /* If we already have a name we know to be unique, just use that. */
9047 if (first_global_object_name
)
9048 p
= q
= ASTRDUP (first_global_object_name
);
9049 /* If the target is handling the constructors/destructors, they
9050 will be local to this file and the name is only necessary for
9052 We also assign sub_I and sub_D sufixes to constructors called from
9053 the global static constructors. These are always local. */
9054 else if (((type
[0] == 'I' || type
[0] == 'D') && targetm
.have_ctors_dtors
)
9055 || (strncmp (type
, "sub_", 4) == 0
9056 && (type
[4] == 'I' || type
[4] == 'D')))
9058 const char *file
= main_input_filename
;
9060 file
= input_filename
;
9061 /* Just use the file's basename, because the full pathname
9062 might be quite long. */
9063 p
= q
= ASTRDUP (lbasename (file
));
9067 /* Otherwise, the name must be unique across the entire link.
9068 We don't have anything that we know to be unique to this translation
9069 unit, so use what we do have and throw in some randomness. */
9071 const char *name
= weak_global_object_name
;
9072 const char *file
= main_input_filename
;
9077 file
= input_filename
;
9079 len
= strlen (file
);
9080 q
= (char *) alloca (9 + 17 + len
+ 1);
9081 memcpy (q
, file
, len
+ 1);
9083 snprintf (q
+ len
, 9 + 17 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX
,
9084 crc32_string (0, name
), get_random_seed (false));
9089 clean_symbol_name (q
);
9090 buf
= (char *) alloca (sizeof (FILE_FUNCTION_FORMAT
) + strlen (p
)
9093 /* Set up the name of the file-level functions we may need.
9094 Use a global object (which is already required to be unique over
9095 the program) rather than the file name (which imposes extra
9097 sprintf (buf
, FILE_FUNCTION_FORMAT
, type
, p
);
9099 return get_identifier (buf
);
9102 #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
9104 /* Complain that the tree code of NODE does not match the expected 0
9105 terminated list of trailing codes. The trailing code list can be
9106 empty, for a more vague error message. FILE, LINE, and FUNCTION
9107 are of the caller. */
9110 tree_check_failed (const_tree node
, const char *file
,
9111 int line
, const char *function
, ...)
9115 unsigned length
= 0;
9118 va_start (args
, function
);
9119 while ((code
= va_arg (args
, int)))
9120 length
+= 4 + strlen (tree_code_name
[code
]);
9125 va_start (args
, function
);
9126 length
+= strlen ("expected ");
9127 buffer
= tmp
= (char *) alloca (length
);
9129 while ((code
= va_arg (args
, int)))
9131 const char *prefix
= length
? " or " : "expected ";
9133 strcpy (tmp
+ length
, prefix
);
9134 length
+= strlen (prefix
);
9135 strcpy (tmp
+ length
, tree_code_name
[code
]);
9136 length
+= strlen (tree_code_name
[code
]);
9141 buffer
= "unexpected node";
9143 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9144 buffer
, tree_code_name
[TREE_CODE (node
)],
9145 function
, trim_filename (file
), line
);
9148 /* Complain that the tree code of NODE does match the expected 0
9149 terminated list of trailing codes. FILE, LINE, and FUNCTION are of
9153 tree_not_check_failed (const_tree node
, const char *file
,
9154 int line
, const char *function
, ...)
9158 unsigned length
= 0;
9161 va_start (args
, function
);
9162 while ((code
= va_arg (args
, int)))
9163 length
+= 4 + strlen (tree_code_name
[code
]);
9165 va_start (args
, function
);
9166 buffer
= (char *) alloca (length
);
9168 while ((code
= va_arg (args
, int)))
9172 strcpy (buffer
+ length
, " or ");
9175 strcpy (buffer
+ length
, tree_code_name
[code
]);
9176 length
+= strlen (tree_code_name
[code
]);
9180 internal_error ("tree check: expected none of %s, have %s in %s, at %s:%d",
9181 buffer
, tree_code_name
[TREE_CODE (node
)],
9182 function
, trim_filename (file
), line
);
9185 /* Similar to tree_check_failed, except that we check for a class of tree
9186 code, given in CL. */
9189 tree_class_check_failed (const_tree node
, const enum tree_code_class cl
,
9190 const char *file
, int line
, const char *function
)
9193 ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
9194 TREE_CODE_CLASS_STRING (cl
),
9195 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
9196 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
9199 /* Similar to tree_check_failed, except that instead of specifying a
9200 dozen codes, use the knowledge that they're all sequential. */
9203 tree_range_check_failed (const_tree node
, const char *file
, int line
,
9204 const char *function
, enum tree_code c1
,
9208 unsigned length
= 0;
9211 for (c
= c1
; c
<= c2
; ++c
)
9212 length
+= 4 + strlen (tree_code_name
[c
]);
9214 length
+= strlen ("expected ");
9215 buffer
= (char *) alloca (length
);
9218 for (c
= c1
; c
<= c2
; ++c
)
9220 const char *prefix
= length
? " or " : "expected ";
9222 strcpy (buffer
+ length
, prefix
);
9223 length
+= strlen (prefix
);
9224 strcpy (buffer
+ length
, tree_code_name
[c
]);
9225 length
+= strlen (tree_code_name
[c
]);
9228 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9229 buffer
, tree_code_name
[TREE_CODE (node
)],
9230 function
, trim_filename (file
), line
);
9234 /* Similar to tree_check_failed, except that we check that a tree does
9235 not have the specified code, given in CL. */
9238 tree_not_class_check_failed (const_tree node
, const enum tree_code_class cl
,
9239 const char *file
, int line
, const char *function
)
9242 ("tree check: did not expect class %qs, have %qs (%s) in %s, at %s:%d",
9243 TREE_CODE_CLASS_STRING (cl
),
9244 TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node
))),
9245 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
9249 /* Similar to tree_check_failed but applied to OMP_CLAUSE codes. */
9252 omp_clause_check_failed (const_tree node
, const char *file
, int line
,
9253 const char *function
, enum omp_clause_code code
)
9255 internal_error ("tree check: expected omp_clause %s, have %s in %s, at %s:%d",
9256 omp_clause_code_name
[code
], tree_code_name
[TREE_CODE (node
)],
9257 function
, trim_filename (file
), line
);
9261 /* Similar to tree_range_check_failed but applied to OMP_CLAUSE codes. */
9264 omp_clause_range_check_failed (const_tree node
, const char *file
, int line
,
9265 const char *function
, enum omp_clause_code c1
,
9266 enum omp_clause_code c2
)
9269 unsigned length
= 0;
9272 for (c
= c1
; c
<= c2
; ++c
)
9273 length
+= 4 + strlen (omp_clause_code_name
[c
]);
9275 length
+= strlen ("expected ");
9276 buffer
= (char *) alloca (length
);
9279 for (c
= c1
; c
<= c2
; ++c
)
9281 const char *prefix
= length
? " or " : "expected ";
9283 strcpy (buffer
+ length
, prefix
);
9284 length
+= strlen (prefix
);
9285 strcpy (buffer
+ length
, omp_clause_code_name
[c
]);
9286 length
+= strlen (omp_clause_code_name
[c
]);
9289 internal_error ("tree check: %s, have %s in %s, at %s:%d",
9290 buffer
, omp_clause_code_name
[TREE_CODE (node
)],
9291 function
, trim_filename (file
), line
);
9295 #undef DEFTREESTRUCT
9296 #define DEFTREESTRUCT(VAL, NAME) NAME,
9298 static const char *ts_enum_names
[] = {
9299 #include "treestruct.def"
9301 #undef DEFTREESTRUCT
9303 #define TS_ENUM_NAME(EN) (ts_enum_names[(EN)])
9305 /* Similar to tree_class_check_failed, except that we check for
9306 whether CODE contains the tree structure identified by EN. */
9309 tree_contains_struct_check_failed (const_tree node
,
9310 const enum tree_node_structure_enum en
,
9311 const char *file
, int line
,
9312 const char *function
)
9315 ("tree check: expected tree that contains %qs structure, have %qs in %s, at %s:%d",
9317 tree_code_name
[TREE_CODE (node
)], function
, trim_filename (file
), line
);
9321 /* Similar to above, except that the check is for the bounds of a TREE_VEC's
9322 (dynamically sized) vector. */
9325 tree_vec_elt_check_failed (int idx
, int len
, const char *file
, int line
,
9326 const char *function
)
9329 ("tree check: accessed elt %d of tree_vec with %d elts in %s, at %s:%d",
9330 idx
+ 1, len
, function
, trim_filename (file
), line
);
9333 /* Similar to above, except that the check is for the bounds of the operand
9334 vector of an expression node EXP. */
9337 tree_operand_check_failed (int idx
, const_tree exp
, const char *file
,
9338 int line
, const char *function
)
9340 int code
= TREE_CODE (exp
);
9342 ("tree check: accessed operand %d of %s with %d operands in %s, at %s:%d",
9343 idx
+ 1, tree_code_name
[code
], TREE_OPERAND_LENGTH (exp
),
9344 function
, trim_filename (file
), line
);
9347 /* Similar to above, except that the check is for the number of
9348 operands of an OMP_CLAUSE node. */
9351 omp_clause_operand_check_failed (int idx
, const_tree t
, const char *file
,
9352 int line
, const char *function
)
9355 ("tree check: accessed operand %d of omp_clause %s with %d operands "
9356 "in %s, at %s:%d", idx
+ 1, omp_clause_code_name
[OMP_CLAUSE_CODE (t
)],
9357 omp_clause_num_ops
[OMP_CLAUSE_CODE (t
)], function
,
9358 trim_filename (file
), line
);
9360 #endif /* ENABLE_TREE_CHECKING */
9362 /* Create a new vector type node holding SUBPARTS units of type INNERTYPE,
9363 and mapped to the machine mode MODE. Initialize its fields and build
9364 the information necessary for debugging output. */
9367 make_vector_type (tree innertype
, int nunits
, enum machine_mode mode
)
9370 hashval_t hashcode
= 0;
9372 t
= make_node (VECTOR_TYPE
);
9373 TREE_TYPE (t
) = TYPE_MAIN_VARIANT (innertype
);
9374 SET_TYPE_VECTOR_SUBPARTS (t
, nunits
);
9375 SET_TYPE_MODE (t
, mode
);
9377 if (TYPE_STRUCTURAL_EQUALITY_P (innertype
))
9378 SET_TYPE_STRUCTURAL_EQUALITY (t
);
9379 else if (TYPE_CANONICAL (innertype
) != innertype
9380 || mode
!= VOIDmode
)
9382 = make_vector_type (TYPE_CANONICAL (innertype
), nunits
, VOIDmode
);
9386 hashcode
= iterative_hash_host_wide_int (VECTOR_TYPE
, hashcode
);
9387 hashcode
= iterative_hash_host_wide_int (nunits
, hashcode
);
9388 hashcode
= iterative_hash_host_wide_int (mode
, hashcode
);
9389 hashcode
= iterative_hash_object (TYPE_HASH (TREE_TYPE (t
)), hashcode
);
9390 t
= type_hash_canon (hashcode
, t
);
9392 /* We have built a main variant, based on the main variant of the
9393 inner type. Use it to build the variant we return. */
9394 if ((TYPE_ATTRIBUTES (innertype
) || TYPE_QUALS (innertype
))
9395 && TREE_TYPE (t
) != innertype
)
9396 return build_type_attribute_qual_variant (t
,
9397 TYPE_ATTRIBUTES (innertype
),
9398 TYPE_QUALS (innertype
));
9404 make_or_reuse_type (unsigned size
, int unsignedp
)
9406 if (size
== INT_TYPE_SIZE
)
9407 return unsignedp
? unsigned_type_node
: integer_type_node
;
9408 if (size
== CHAR_TYPE_SIZE
)
9409 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
9410 if (size
== SHORT_TYPE_SIZE
)
9411 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
9412 if (size
== LONG_TYPE_SIZE
)
9413 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
9414 if (size
== LONG_LONG_TYPE_SIZE
)
9415 return (unsignedp
? long_long_unsigned_type_node
9416 : long_long_integer_type_node
);
9417 if (size
== 128 && int128_integer_type_node
)
9418 return (unsignedp
? int128_unsigned_type_node
9419 : int128_integer_type_node
);
9422 return make_unsigned_type (size
);
9424 return make_signed_type (size
);
9427 /* Create or reuse a fract type by SIZE, UNSIGNEDP, and SATP. */
9430 make_or_reuse_fract_type (unsigned size
, int unsignedp
, int satp
)
9434 if (size
== SHORT_FRACT_TYPE_SIZE
)
9435 return unsignedp
? sat_unsigned_short_fract_type_node
9436 : sat_short_fract_type_node
;
9437 if (size
== FRACT_TYPE_SIZE
)
9438 return unsignedp
? sat_unsigned_fract_type_node
: sat_fract_type_node
;
9439 if (size
== LONG_FRACT_TYPE_SIZE
)
9440 return unsignedp
? sat_unsigned_long_fract_type_node
9441 : sat_long_fract_type_node
;
9442 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9443 return unsignedp
? sat_unsigned_long_long_fract_type_node
9444 : sat_long_long_fract_type_node
;
9448 if (size
== SHORT_FRACT_TYPE_SIZE
)
9449 return unsignedp
? unsigned_short_fract_type_node
9450 : short_fract_type_node
;
9451 if (size
== FRACT_TYPE_SIZE
)
9452 return unsignedp
? unsigned_fract_type_node
: fract_type_node
;
9453 if (size
== LONG_FRACT_TYPE_SIZE
)
9454 return unsignedp
? unsigned_long_fract_type_node
9455 : long_fract_type_node
;
9456 if (size
== LONG_LONG_FRACT_TYPE_SIZE
)
9457 return unsignedp
? unsigned_long_long_fract_type_node
9458 : long_long_fract_type_node
;
9461 return make_fract_type (size
, unsignedp
, satp
);
9464 /* Create or reuse an accum type by SIZE, UNSIGNEDP, and SATP. */
9467 make_or_reuse_accum_type (unsigned size
, int unsignedp
, int satp
)
9471 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9472 return unsignedp
? sat_unsigned_short_accum_type_node
9473 : sat_short_accum_type_node
;
9474 if (size
== ACCUM_TYPE_SIZE
)
9475 return unsignedp
? sat_unsigned_accum_type_node
: sat_accum_type_node
;
9476 if (size
== LONG_ACCUM_TYPE_SIZE
)
9477 return unsignedp
? sat_unsigned_long_accum_type_node
9478 : sat_long_accum_type_node
;
9479 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9480 return unsignedp
? sat_unsigned_long_long_accum_type_node
9481 : sat_long_long_accum_type_node
;
9485 if (size
== SHORT_ACCUM_TYPE_SIZE
)
9486 return unsignedp
? unsigned_short_accum_type_node
9487 : short_accum_type_node
;
9488 if (size
== ACCUM_TYPE_SIZE
)
9489 return unsignedp
? unsigned_accum_type_node
: accum_type_node
;
9490 if (size
== LONG_ACCUM_TYPE_SIZE
)
9491 return unsignedp
? unsigned_long_accum_type_node
9492 : long_accum_type_node
;
9493 if (size
== LONG_LONG_ACCUM_TYPE_SIZE
)
9494 return unsignedp
? unsigned_long_long_accum_type_node
9495 : long_long_accum_type_node
;
9498 return make_accum_type (size
, unsignedp
, satp
);
9501 /* Create nodes for all integer types (and error_mark_node) using the sizes
9502 of C datatypes. SIGNED_CHAR specifies whether char is signed,
9503 SHORT_DOUBLE specifies whether double should be of the same precision
9507 build_common_tree_nodes (bool signed_char
, bool short_double
)
9509 error_mark_node
= make_node (ERROR_MARK
);
9510 TREE_TYPE (error_mark_node
) = error_mark_node
;
9512 initialize_sizetypes ();
9514 /* Define both `signed char' and `unsigned char'. */
9515 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
9516 TYPE_STRING_FLAG (signed_char_type_node
) = 1;
9517 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
9518 TYPE_STRING_FLAG (unsigned_char_type_node
) = 1;
9520 /* Define `char', which is like either `signed char' or `unsigned char'
9521 but not the same as either. */
9524 ? make_signed_type (CHAR_TYPE_SIZE
)
9525 : make_unsigned_type (CHAR_TYPE_SIZE
));
9526 TYPE_STRING_FLAG (char_type_node
) = 1;
9528 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
9529 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
9530 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
9531 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
9532 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
9533 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
9534 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
9535 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
9536 #if HOST_BITS_PER_WIDE_INT >= 64
9537 /* TODO: This isn't correct, but as logic depends at the moment on
9538 host's instead of target's wide-integer.
9539 If there is a target not supporting TImode, but has an 128-bit
9540 integer-scalar register, this target check needs to be adjusted. */
9541 if (targetm
.scalar_mode_supported_p (TImode
))
9543 int128_integer_type_node
= make_signed_type (128);
9544 int128_unsigned_type_node
= make_unsigned_type (128);
9548 /* Define a boolean type. This type only represents boolean values but
9549 may be larger than char depending on the value of BOOL_TYPE_SIZE.
9550 Front ends which want to override this size (i.e. Java) can redefine
9551 boolean_type_node before calling build_common_tree_nodes_2. */
9552 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
9553 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
9554 TYPE_MAX_VALUE (boolean_type_node
) = build_int_cst (boolean_type_node
, 1);
9555 TYPE_PRECISION (boolean_type_node
) = 1;
9557 /* Define what type to use for size_t. */
9558 if (strcmp (SIZE_TYPE
, "unsigned int") == 0)
9559 size_type_node
= unsigned_type_node
;
9560 else if (strcmp (SIZE_TYPE
, "long unsigned int") == 0)
9561 size_type_node
= long_unsigned_type_node
;
9562 else if (strcmp (SIZE_TYPE
, "long long unsigned int") == 0)
9563 size_type_node
= long_long_unsigned_type_node
;
9564 else if (strcmp (SIZE_TYPE
, "short unsigned int") == 0)
9565 size_type_node
= short_unsigned_type_node
;
9569 /* Fill in the rest of the sized types. Reuse existing type nodes
9571 intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 0);
9572 intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 0);
9573 intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 0);
9574 intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 0);
9575 intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 0);
9577 unsigned_intQI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (QImode
), 1);
9578 unsigned_intHI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (HImode
), 1);
9579 unsigned_intSI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (SImode
), 1);
9580 unsigned_intDI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (DImode
), 1);
9581 unsigned_intTI_type_node
= make_or_reuse_type (GET_MODE_BITSIZE (TImode
), 1);
9583 access_public_node
= get_identifier ("public");
9584 access_protected_node
= get_identifier ("protected");
9585 access_private_node
= get_identifier ("private");
9587 /* Define these next since types below may used them. */
9588 integer_zero_node
= build_int_cst (integer_type_node
, 0);
9589 integer_one_node
= build_int_cst (integer_type_node
, 1);
9590 integer_three_node
= build_int_cst (integer_type_node
, 3);
9591 integer_minus_one_node
= build_int_cst (integer_type_node
, -1);
9593 size_zero_node
= size_int (0);
9594 size_one_node
= size_int (1);
9595 bitsize_zero_node
= bitsize_int (0);
9596 bitsize_one_node
= bitsize_int (1);
9597 bitsize_unit_node
= bitsize_int (BITS_PER_UNIT
);
9599 boolean_false_node
= TYPE_MIN_VALUE (boolean_type_node
);
9600 boolean_true_node
= TYPE_MAX_VALUE (boolean_type_node
);
9602 void_type_node
= make_node (VOID_TYPE
);
9603 layout_type (void_type_node
);
9605 /* We are not going to have real types in C with less than byte alignment,
9606 so we might as well not have any types that claim to have it. */
9607 TYPE_ALIGN (void_type_node
) = BITS_PER_UNIT
;
9608 TYPE_USER_ALIGN (void_type_node
) = 0;
9610 null_pointer_node
= build_int_cst (build_pointer_type (void_type_node
), 0);
9611 layout_type (TREE_TYPE (null_pointer_node
));
9613 ptr_type_node
= build_pointer_type (void_type_node
);
9615 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
9616 fileptr_type_node
= ptr_type_node
;
9618 float_type_node
= make_node (REAL_TYPE
);
9619 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
9620 layout_type (float_type_node
);
9622 double_type_node
= make_node (REAL_TYPE
);
9624 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
9626 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
9627 layout_type (double_type_node
);
9629 long_double_type_node
= make_node (REAL_TYPE
);
9630 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
9631 layout_type (long_double_type_node
);
9633 float_ptr_type_node
= build_pointer_type (float_type_node
);
9634 double_ptr_type_node
= build_pointer_type (double_type_node
);
9635 long_double_ptr_type_node
= build_pointer_type (long_double_type_node
);
9636 integer_ptr_type_node
= build_pointer_type (integer_type_node
);
9638 /* Fixed size integer types. */
9639 uint16_type_node
= build_nonstandard_integer_type (16, true);
9640 uint32_type_node
= build_nonstandard_integer_type (32, true);
9641 uint64_type_node
= build_nonstandard_integer_type (64, true);
9643 /* Decimal float types. */
9644 dfloat32_type_node
= make_node (REAL_TYPE
);
9645 TYPE_PRECISION (dfloat32_type_node
) = DECIMAL32_TYPE_SIZE
;
9646 layout_type (dfloat32_type_node
);
9647 SET_TYPE_MODE (dfloat32_type_node
, SDmode
);
9648 dfloat32_ptr_type_node
= build_pointer_type (dfloat32_type_node
);
9650 dfloat64_type_node
= make_node (REAL_TYPE
);
9651 TYPE_PRECISION (dfloat64_type_node
) = DECIMAL64_TYPE_SIZE
;
9652 layout_type (dfloat64_type_node
);
9653 SET_TYPE_MODE (dfloat64_type_node
, DDmode
);
9654 dfloat64_ptr_type_node
= build_pointer_type (dfloat64_type_node
);
9656 dfloat128_type_node
= make_node (REAL_TYPE
);
9657 TYPE_PRECISION (dfloat128_type_node
) = DECIMAL128_TYPE_SIZE
;
9658 layout_type (dfloat128_type_node
);
9659 SET_TYPE_MODE (dfloat128_type_node
, TDmode
);
9660 dfloat128_ptr_type_node
= build_pointer_type (dfloat128_type_node
);
9662 complex_integer_type_node
= build_complex_type (integer_type_node
);
9663 complex_float_type_node
= build_complex_type (float_type_node
);
9664 complex_double_type_node
= build_complex_type (double_type_node
);
9665 complex_long_double_type_node
= build_complex_type (long_double_type_node
);
9667 /* Make fixed-point nodes based on sat/non-sat and signed/unsigned. */
9668 #define MAKE_FIXED_TYPE_NODE(KIND,SIZE) \
9669 sat_ ## KIND ## _type_node = \
9670 make_sat_signed_ ## KIND ## _type (SIZE); \
9671 sat_unsigned_ ## KIND ## _type_node = \
9672 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9673 KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9674 unsigned_ ## KIND ## _type_node = \
9675 make_unsigned_ ## KIND ## _type (SIZE);
9677 #define MAKE_FIXED_TYPE_NODE_WIDTH(KIND,WIDTH,SIZE) \
9678 sat_ ## WIDTH ## KIND ## _type_node = \
9679 make_sat_signed_ ## KIND ## _type (SIZE); \
9680 sat_unsigned_ ## WIDTH ## KIND ## _type_node = \
9681 make_sat_unsigned_ ## KIND ## _type (SIZE); \
9682 WIDTH ## KIND ## _type_node = make_signed_ ## KIND ## _type (SIZE); \
9683 unsigned_ ## WIDTH ## KIND ## _type_node = \
9684 make_unsigned_ ## KIND ## _type (SIZE);
9686 /* Make fixed-point type nodes based on four different widths. */
9687 #define MAKE_FIXED_TYPE_NODE_FAMILY(N1,N2) \
9688 MAKE_FIXED_TYPE_NODE_WIDTH (N1, short_, SHORT_ ## N2 ## _TYPE_SIZE) \
9689 MAKE_FIXED_TYPE_NODE (N1, N2 ## _TYPE_SIZE) \
9690 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_, LONG_ ## N2 ## _TYPE_SIZE) \
9691 MAKE_FIXED_TYPE_NODE_WIDTH (N1, long_long_, LONG_LONG_ ## N2 ## _TYPE_SIZE)
9693 /* Make fixed-point mode nodes based on sat/non-sat and signed/unsigned. */
9694 #define MAKE_FIXED_MODE_NODE(KIND,NAME,MODE) \
9695 NAME ## _type_node = \
9696 make_or_reuse_signed_ ## KIND ## _type (GET_MODE_BITSIZE (MODE ## mode)); \
9697 u ## NAME ## _type_node = \
9698 make_or_reuse_unsigned_ ## KIND ## _type \
9699 (GET_MODE_BITSIZE (U ## MODE ## mode)); \
9700 sat_ ## NAME ## _type_node = \
9701 make_or_reuse_sat_signed_ ## KIND ## _type \
9702 (GET_MODE_BITSIZE (MODE ## mode)); \
9703 sat_u ## NAME ## _type_node = \
9704 make_or_reuse_sat_unsigned_ ## KIND ## _type \
9705 (GET_MODE_BITSIZE (U ## MODE ## mode));
9707 /* Fixed-point type and mode nodes. */
9708 MAKE_FIXED_TYPE_NODE_FAMILY (fract
, FRACT
)
9709 MAKE_FIXED_TYPE_NODE_FAMILY (accum
, ACCUM
)
9710 MAKE_FIXED_MODE_NODE (fract
, qq
, QQ
)
9711 MAKE_FIXED_MODE_NODE (fract
, hq
, HQ
)
9712 MAKE_FIXED_MODE_NODE (fract
, sq
, SQ
)
9713 MAKE_FIXED_MODE_NODE (fract
, dq
, DQ
)
9714 MAKE_FIXED_MODE_NODE (fract
, tq
, TQ
)
9715 MAKE_FIXED_MODE_NODE (accum
, ha
, HA
)
9716 MAKE_FIXED_MODE_NODE (accum
, sa
, SA
)
9717 MAKE_FIXED_MODE_NODE (accum
, da
, DA
)
9718 MAKE_FIXED_MODE_NODE (accum
, ta
, TA
)
9721 tree t
= targetm
.build_builtin_va_list ();
9723 /* Many back-ends define record types without setting TYPE_NAME.
9724 If we copied the record type here, we'd keep the original
9725 record type without a name. This breaks name mangling. So,
9726 don't copy record types and let c_common_nodes_and_builtins()
9727 declare the type to be __builtin_va_list. */
9728 if (TREE_CODE (t
) != RECORD_TYPE
)
9729 t
= build_variant_type_copy (t
);
9731 va_list_type_node
= t
;
9735 /* Modify DECL for given flags. */
9737 set_call_expr_flags (tree decl
, int flags
)
9739 if (flags
& ECF_NOTHROW
)
9740 TREE_NOTHROW (decl
) = 1;
9741 if (flags
& ECF_CONST
)
9742 TREE_READONLY (decl
) = 1;
9743 if (flags
& ECF_PURE
)
9744 DECL_PURE_P (decl
) = 1;
9745 if (flags
& ECF_LOOPING_CONST_OR_PURE
)
9746 DECL_LOOPING_CONST_OR_PURE_P (decl
) = 1;
9747 if (flags
& ECF_NOVOPS
)
9748 DECL_IS_NOVOPS (decl
) = 1;
9749 if (flags
& ECF_NORETURN
)
9750 TREE_THIS_VOLATILE (decl
) = 1;
9751 if (flags
& ECF_MALLOC
)
9752 DECL_IS_MALLOC (decl
) = 1;
9753 if (flags
& ECF_RETURNS_TWICE
)
9754 DECL_IS_RETURNS_TWICE (decl
) = 1;
9755 if (flags
& ECF_LEAF
)
9756 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("leaf"),
9757 NULL
, DECL_ATTRIBUTES (decl
));
9758 if ((flags
& ECF_TM_PURE
) && flag_tm
)
9759 DECL_ATTRIBUTES (decl
) = tree_cons (get_identifier ("transaction_pure"),
9760 NULL
, DECL_ATTRIBUTES (decl
));
9761 /* Looping const or pure is implied by noreturn.
9762 There is currently no way to declare looping const or looping pure alone. */
9763 gcc_assert (!(flags
& ECF_LOOPING_CONST_OR_PURE
)
9764 || ((flags
& ECF_NORETURN
) && (flags
& (ECF_CONST
| ECF_PURE
))));
9768 /* A subroutine of build_common_builtin_nodes. Define a builtin function. */
9771 local_define_builtin (const char *name
, tree type
, enum built_in_function code
,
9772 const char *library_name
, int ecf_flags
)
9776 decl
= add_builtin_function (name
, type
, code
, BUILT_IN_NORMAL
,
9777 library_name
, NULL_TREE
);
9778 set_call_expr_flags (decl
, ecf_flags
);
9780 set_builtin_decl (code
, decl
, true);
9783 /* Call this function after instantiating all builtins that the language
9784 front end cares about. This will build the rest of the builtins that
9785 are relied upon by the tree optimizers and the middle-end. */
9788 build_common_builtin_nodes (void)
9793 if (!builtin_decl_explicit_p (BUILT_IN_UNREACHABLE
))
9795 ftype
= build_function_type (void_type_node
, void_list_node
);
9796 local_define_builtin ("__builtin_unreachable", ftype
, BUILT_IN_UNREACHABLE
,
9797 "__builtin_unreachable",
9798 ECF_NOTHROW
| ECF_LEAF
| ECF_NORETURN
9799 | ECF_CONST
| ECF_LEAF
);
9802 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
)
9803 || !builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
9805 ftype
= build_function_type_list (ptr_type_node
,
9806 ptr_type_node
, const_ptr_type_node
,
9807 size_type_node
, NULL_TREE
);
9809 if (!builtin_decl_explicit_p (BUILT_IN_MEMCPY
))
9810 local_define_builtin ("__builtin_memcpy", ftype
, BUILT_IN_MEMCPY
,
9811 "memcpy", ECF_NOTHROW
| ECF_LEAF
);
9812 if (!builtin_decl_explicit_p (BUILT_IN_MEMMOVE
))
9813 local_define_builtin ("__builtin_memmove", ftype
, BUILT_IN_MEMMOVE
,
9814 "memmove", ECF_NOTHROW
| ECF_LEAF
);
9817 if (!builtin_decl_explicit_p (BUILT_IN_MEMCMP
))
9819 ftype
= build_function_type_list (integer_type_node
, const_ptr_type_node
,
9820 const_ptr_type_node
, size_type_node
,
9822 local_define_builtin ("__builtin_memcmp", ftype
, BUILT_IN_MEMCMP
,
9823 "memcmp", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9826 if (!builtin_decl_explicit_p (BUILT_IN_MEMSET
))
9828 ftype
= build_function_type_list (ptr_type_node
,
9829 ptr_type_node
, integer_type_node
,
9830 size_type_node
, NULL_TREE
);
9831 local_define_builtin ("__builtin_memset", ftype
, BUILT_IN_MEMSET
,
9832 "memset", ECF_NOTHROW
| ECF_LEAF
);
9835 if (!builtin_decl_explicit_p (BUILT_IN_ALLOCA
))
9837 ftype
= build_function_type_list (ptr_type_node
,
9838 size_type_node
, NULL_TREE
);
9839 local_define_builtin ("__builtin_alloca", ftype
, BUILT_IN_ALLOCA
,
9840 "alloca", ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
9843 ftype
= build_function_type_list (ptr_type_node
, size_type_node
,
9844 size_type_node
, NULL_TREE
);
9845 local_define_builtin ("__builtin_alloca_with_align", ftype
,
9846 BUILT_IN_ALLOCA_WITH_ALIGN
, "alloca",
9847 ECF_MALLOC
| ECF_NOTHROW
| ECF_LEAF
);
9849 /* If we're checking the stack, `alloca' can throw. */
9850 if (flag_stack_check
)
9852 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA
)) = 0;
9853 TREE_NOTHROW (builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
)) = 0;
9856 ftype
= build_function_type_list (void_type_node
,
9857 ptr_type_node
, ptr_type_node
,
9858 ptr_type_node
, NULL_TREE
);
9859 local_define_builtin ("__builtin_init_trampoline", ftype
,
9860 BUILT_IN_INIT_TRAMPOLINE
,
9861 "__builtin_init_trampoline", ECF_NOTHROW
| ECF_LEAF
);
9862 local_define_builtin ("__builtin_init_heap_trampoline", ftype
,
9863 BUILT_IN_INIT_HEAP_TRAMPOLINE
,
9864 "__builtin_init_heap_trampoline",
9865 ECF_NOTHROW
| ECF_LEAF
);
9867 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
9868 local_define_builtin ("__builtin_adjust_trampoline", ftype
,
9869 BUILT_IN_ADJUST_TRAMPOLINE
,
9870 "__builtin_adjust_trampoline",
9871 ECF_CONST
| ECF_NOTHROW
);
9873 ftype
= build_function_type_list (void_type_node
,
9874 ptr_type_node
, ptr_type_node
, NULL_TREE
);
9875 local_define_builtin ("__builtin_nonlocal_goto", ftype
,
9876 BUILT_IN_NONLOCAL_GOTO
,
9877 "__builtin_nonlocal_goto",
9878 ECF_NORETURN
| ECF_NOTHROW
);
9880 ftype
= build_function_type_list (void_type_node
,
9881 ptr_type_node
, ptr_type_node
, NULL_TREE
);
9882 local_define_builtin ("__builtin_setjmp_setup", ftype
,
9883 BUILT_IN_SETJMP_SETUP
,
9884 "__builtin_setjmp_setup", ECF_NOTHROW
);
9886 ftype
= build_function_type_list (ptr_type_node
, ptr_type_node
, NULL_TREE
);
9887 local_define_builtin ("__builtin_setjmp_dispatcher", ftype
,
9888 BUILT_IN_SETJMP_DISPATCHER
,
9889 "__builtin_setjmp_dispatcher",
9890 ECF_PURE
| ECF_NOTHROW
);
9892 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9893 local_define_builtin ("__builtin_setjmp_receiver", ftype
,
9894 BUILT_IN_SETJMP_RECEIVER
,
9895 "__builtin_setjmp_receiver", ECF_NOTHROW
);
9897 ftype
= build_function_type_list (ptr_type_node
, NULL_TREE
);
9898 local_define_builtin ("__builtin_stack_save", ftype
, BUILT_IN_STACK_SAVE
,
9899 "__builtin_stack_save", ECF_NOTHROW
| ECF_LEAF
);
9901 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9902 local_define_builtin ("__builtin_stack_restore", ftype
,
9903 BUILT_IN_STACK_RESTORE
,
9904 "__builtin_stack_restore", ECF_NOTHROW
| ECF_LEAF
);
9906 /* If there's a possibility that we might use the ARM EABI, build the
9907 alternate __cxa_end_cleanup node used to resume from C++ and Java. */
9908 if (targetm
.arm_eabi_unwinder
)
9910 ftype
= build_function_type_list (void_type_node
, NULL_TREE
);
9911 local_define_builtin ("__builtin_cxa_end_cleanup", ftype
,
9912 BUILT_IN_CXA_END_CLEANUP
,
9913 "__cxa_end_cleanup", ECF_NORETURN
| ECF_LEAF
);
9916 ftype
= build_function_type_list (void_type_node
, ptr_type_node
, NULL_TREE
);
9917 local_define_builtin ("__builtin_unwind_resume", ftype
,
9918 BUILT_IN_UNWIND_RESUME
,
9919 ((targetm_common
.except_unwind_info (&global_options
)
9921 ? "_Unwind_SjLj_Resume" : "_Unwind_Resume"),
9924 if (builtin_decl_explicit (BUILT_IN_RETURN_ADDRESS
) == NULL_TREE
)
9926 ftype
= build_function_type_list (ptr_type_node
, integer_type_node
,
9928 local_define_builtin ("__builtin_return_address", ftype
,
9929 BUILT_IN_RETURN_ADDRESS
,
9930 "__builtin_return_address",
9934 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
)
9935 || !builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
9937 ftype
= build_function_type_list (void_type_node
, ptr_type_node
,
9938 ptr_type_node
, NULL_TREE
);
9939 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_ENTER
))
9940 local_define_builtin ("__cyg_profile_func_enter", ftype
,
9941 BUILT_IN_PROFILE_FUNC_ENTER
,
9942 "__cyg_profile_func_enter", 0);
9943 if (!builtin_decl_explicit_p (BUILT_IN_PROFILE_FUNC_EXIT
))
9944 local_define_builtin ("__cyg_profile_func_exit", ftype
,
9945 BUILT_IN_PROFILE_FUNC_EXIT
,
9946 "__cyg_profile_func_exit", 0);
9949 /* The exception object and filter values from the runtime. The argument
9950 must be zero before exception lowering, i.e. from the front end. After
9951 exception lowering, it will be the region number for the exception
9952 landing pad. These functions are PURE instead of CONST to prevent
9953 them from being hoisted past the exception edge that will initialize
9954 its value in the landing pad. */
9955 ftype
= build_function_type_list (ptr_type_node
,
9956 integer_type_node
, NULL_TREE
);
9957 ecf_flags
= ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
;
9958 /* Only use TM_PURE if we we have TM language support. */
9959 if (builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1
))
9960 ecf_flags
|= ECF_TM_PURE
;
9961 local_define_builtin ("__builtin_eh_pointer", ftype
, BUILT_IN_EH_POINTER
,
9962 "__builtin_eh_pointer", ecf_flags
);
9964 tmp
= lang_hooks
.types
.type_for_mode (targetm
.eh_return_filter_mode (), 0);
9965 ftype
= build_function_type_list (tmp
, integer_type_node
, NULL_TREE
);
9966 local_define_builtin ("__builtin_eh_filter", ftype
, BUILT_IN_EH_FILTER
,
9967 "__builtin_eh_filter", ECF_PURE
| ECF_NOTHROW
| ECF_LEAF
);
9969 ftype
= build_function_type_list (void_type_node
,
9970 integer_type_node
, integer_type_node
,
9972 local_define_builtin ("__builtin_eh_copy_values", ftype
,
9973 BUILT_IN_EH_COPY_VALUES
,
9974 "__builtin_eh_copy_values", ECF_NOTHROW
);
9976 /* Complex multiplication and division. These are handled as builtins
9977 rather than optabs because emit_library_call_value doesn't support
9978 complex. Further, we can do slightly better with folding these
9979 beasties if the real and complex parts of the arguments are separate. */
9983 for (mode
= MIN_MODE_COMPLEX_FLOAT
; mode
<= MAX_MODE_COMPLEX_FLOAT
; ++mode
)
9985 char mode_name_buf
[4], *q
;
9987 enum built_in_function mcode
, dcode
;
9988 tree type
, inner_type
;
9989 const char *prefix
= "__";
9991 if (targetm
.libfunc_gnu_prefix
)
9994 type
= lang_hooks
.types
.type_for_mode ((enum machine_mode
) mode
, 0);
9997 inner_type
= TREE_TYPE (type
);
9999 ftype
= build_function_type_list (type
, inner_type
, inner_type
,
10000 inner_type
, inner_type
, NULL_TREE
);
10002 mcode
= ((enum built_in_function
)
10003 (BUILT_IN_COMPLEX_MUL_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
10004 dcode
= ((enum built_in_function
)
10005 (BUILT_IN_COMPLEX_DIV_MIN
+ mode
- MIN_MODE_COMPLEX_FLOAT
));
10007 for (p
= GET_MODE_NAME (mode
), q
= mode_name_buf
; *p
; p
++, q
++)
10011 built_in_names
[mcode
] = concat (prefix
, "mul", mode_name_buf
, "3",
10013 local_define_builtin (built_in_names
[mcode
], ftype
, mcode
,
10014 built_in_names
[mcode
],
10015 ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
10017 built_in_names
[dcode
] = concat (prefix
, "div", mode_name_buf
, "3",
10019 local_define_builtin (built_in_names
[dcode
], ftype
, dcode
,
10020 built_in_names
[dcode
],
10021 ECF_CONST
| ECF_NOTHROW
| ECF_LEAF
);
10026 /* HACK. GROSS. This is absolutely disgusting. I wish there was a
10029 If we requested a pointer to a vector, build up the pointers that
10030 we stripped off while looking for the inner type. Similarly for
10031 return values from functions.
10033 The argument TYPE is the top of the chain, and BOTTOM is the
10034 new type which we will point to. */
10037 reconstruct_complex_type (tree type
, tree bottom
)
10041 if (TREE_CODE (type
) == POINTER_TYPE
)
10043 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10044 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
10045 TYPE_REF_CAN_ALIAS_ALL (type
));
10047 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
10049 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10050 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
10051 TYPE_REF_CAN_ALIAS_ALL (type
));
10053 else if (TREE_CODE (type
) == ARRAY_TYPE
)
10055 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10056 outer
= build_array_type (inner
, TYPE_DOMAIN (type
));
10058 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
10060 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10061 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
10063 else if (TREE_CODE (type
) == METHOD_TYPE
)
10065 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10066 /* The build_method_type_directly() routine prepends 'this' to argument list,
10067 so we must compensate by getting rid of it. */
10069 = build_method_type_directly
10070 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (type
))),
10072 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
10074 else if (TREE_CODE (type
) == OFFSET_TYPE
)
10076 inner
= reconstruct_complex_type (TREE_TYPE (type
), bottom
);
10077 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
10082 return build_type_attribute_qual_variant (outer
, TYPE_ATTRIBUTES (type
),
10083 TYPE_QUALS (type
));
10086 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
10089 build_vector_type_for_mode (tree innertype
, enum machine_mode mode
)
10093 switch (GET_MODE_CLASS (mode
))
10095 case MODE_VECTOR_INT
:
10096 case MODE_VECTOR_FLOAT
:
10097 case MODE_VECTOR_FRACT
:
10098 case MODE_VECTOR_UFRACT
:
10099 case MODE_VECTOR_ACCUM
:
10100 case MODE_VECTOR_UACCUM
:
10101 nunits
= GET_MODE_NUNITS (mode
);
10105 /* Check that there are no leftover bits. */
10106 gcc_assert (GET_MODE_BITSIZE (mode
)
10107 % TREE_INT_CST_LOW (TYPE_SIZE (innertype
)) == 0);
10109 nunits
= GET_MODE_BITSIZE (mode
)
10110 / TREE_INT_CST_LOW (TYPE_SIZE (innertype
));
10114 gcc_unreachable ();
10117 return make_vector_type (innertype
, nunits
, mode
);
10120 /* Similarly, but takes the inner type and number of units, which must be
10124 build_vector_type (tree innertype
, int nunits
)
10126 return make_vector_type (innertype
, nunits
, VOIDmode
);
10129 /* Similarly, but builds a variant type with TYPE_VECTOR_OPAQUE set. */
10132 build_opaque_vector_type (tree innertype
, int nunits
)
10134 tree t
= make_vector_type (innertype
, nunits
, VOIDmode
);
10136 /* We always build the non-opaque variant before the opaque one,
10137 so if it already exists, it is TYPE_NEXT_VARIANT of this one. */
10138 cand
= TYPE_NEXT_VARIANT (t
);
10140 && TYPE_VECTOR_OPAQUE (cand
)
10141 && check_qualified_type (cand
, t
, TYPE_QUALS (t
), NULL_TREE
))
10143 /* Othewise build a variant type and make sure to queue it after
10144 the non-opaque type. */
10145 cand
= build_distinct_type_copy (t
);
10146 TYPE_VECTOR_OPAQUE (cand
) = true;
10147 TYPE_CANONICAL (cand
) = TYPE_CANONICAL (t
);
10148 TYPE_NEXT_VARIANT (cand
) = TYPE_NEXT_VARIANT (t
);
10149 TYPE_NEXT_VARIANT (t
) = cand
;
10150 TYPE_MAIN_VARIANT (cand
) = TYPE_MAIN_VARIANT (t
);
10155 /* Given an initializer INIT, return TRUE if INIT is zero or some
10156 aggregate of zeros. Otherwise return FALSE. */
10158 initializer_zerop (const_tree init
)
10164 switch (TREE_CODE (init
))
10167 return integer_zerop (init
);
10170 /* ??? Note that this is not correct for C4X float formats. There,
10171 a bit pattern of all zeros is 1.0; 0.0 is encoded with the most
10172 negative exponent. */
10173 return real_zerop (init
)
10174 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (init
));
10177 return fixed_zerop (init
);
10180 return integer_zerop (init
)
10181 || (real_zerop (init
)
10182 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_REALPART (init
)))
10183 && ! REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (TREE_IMAGPART (init
))));
10188 for (i
= 0; i
< VECTOR_CST_NELTS (init
); ++i
)
10189 if (!initializer_zerop (VECTOR_CST_ELT (init
, i
)))
10196 unsigned HOST_WIDE_INT idx
;
10198 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init
), idx
, elt
)
10199 if (!initializer_zerop (elt
))
10208 /* We need to loop through all elements to handle cases like
10209 "\0" and "\0foobar". */
10210 for (i
= 0; i
< TREE_STRING_LENGTH (init
); ++i
)
10211 if (TREE_STRING_POINTER (init
)[i
] != '\0')
10222 /* Check if vector VEC consists of all the equal elements and
10223 that the number of elements corresponds to the type of VEC.
10224 The function returns first element of the vector
10225 or NULL_TREE if the vector is not uniform. */
10227 uniform_vector_p (const_tree vec
)
10232 if (vec
== NULL_TREE
)
10235 gcc_assert (VECTOR_TYPE_P (TREE_TYPE (vec
)));
10237 if (TREE_CODE (vec
) == VECTOR_CST
)
10239 first
= VECTOR_CST_ELT (vec
, 0);
10240 for (i
= 1; i
< VECTOR_CST_NELTS (vec
); ++i
)
10241 if (!operand_equal_p (first
, VECTOR_CST_ELT (vec
, i
), 0))
10247 else if (TREE_CODE (vec
) == CONSTRUCTOR
)
10249 first
= error_mark_node
;
10251 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (vec
), i
, t
)
10258 if (!operand_equal_p (first
, t
, 0))
10261 if (i
!= TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec
)))
10270 /* Build an empty statement at location LOC. */
10273 build_empty_stmt (location_t loc
)
10275 tree t
= build1 (NOP_EXPR
, void_type_node
, size_zero_node
);
10276 SET_EXPR_LOCATION (t
, loc
);
10281 /* Build an OpenMP clause with code CODE. LOC is the location of the
10285 build_omp_clause (location_t loc
, enum omp_clause_code code
)
10290 length
= omp_clause_num_ops
[code
];
10291 size
= (sizeof (struct tree_omp_clause
) + (length
- 1) * sizeof (tree
));
10293 record_node_allocation_statistics (OMP_CLAUSE
, size
);
10295 t
= ggc_alloc_tree_node (size
);
10296 memset (t
, 0, size
);
10297 TREE_SET_CODE (t
, OMP_CLAUSE
);
10298 OMP_CLAUSE_SET_CODE (t
, code
);
10299 OMP_CLAUSE_LOCATION (t
) = loc
;
10304 /* Build a tcc_vl_exp object with code CODE and room for LEN operands. LEN
10305 includes the implicit operand count in TREE_OPERAND 0, and so must be >= 1.
10306 Except for the CODE and operand count field, other storage for the
10307 object is initialized to zeros. */
10310 build_vl_exp_stat (enum tree_code code
, int len MEM_STAT_DECL
)
10313 int length
= (len
- 1) * sizeof (tree
) + sizeof (struct tree_exp
);
10315 gcc_assert (TREE_CODE_CLASS (code
) == tcc_vl_exp
);
10316 gcc_assert (len
>= 1);
10318 record_node_allocation_statistics (code
, length
);
10320 t
= ggc_alloc_cleared_tree_node_stat (length PASS_MEM_STAT
);
10322 TREE_SET_CODE (t
, code
);
10324 /* Can't use TREE_OPERAND to store the length because if checking is
10325 enabled, it will try to check the length before we store it. :-P */
10326 t
->exp
.operands
[0] = build_int_cst (sizetype
, len
);
10331 /* Helper function for build_call_* functions; build a CALL_EXPR with
10332 indicated RETURN_TYPE, FN, and NARGS, but do not initialize any of
10333 the argument slots. */
10336 build_call_1 (tree return_type
, tree fn
, int nargs
)
10340 t
= build_vl_exp (CALL_EXPR
, nargs
+ 3);
10341 TREE_TYPE (t
) = return_type
;
10342 CALL_EXPR_FN (t
) = fn
;
10343 CALL_EXPR_STATIC_CHAIN (t
) = NULL
;
10348 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10349 FN and a null static chain slot. NARGS is the number of call arguments
10350 which are specified as "..." arguments. */
10353 build_call_nary (tree return_type
, tree fn
, int nargs
, ...)
10357 va_start (args
, nargs
);
10358 ret
= build_call_valist (return_type
, fn
, nargs
, args
);
10363 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10364 FN and a null static chain slot. NARGS is the number of call arguments
10365 which are specified as a va_list ARGS. */
10368 build_call_valist (tree return_type
, tree fn
, int nargs
, va_list args
)
10373 t
= build_call_1 (return_type
, fn
, nargs
);
10374 for (i
= 0; i
< nargs
; i
++)
10375 CALL_EXPR_ARG (t
, i
) = va_arg (args
, tree
);
10376 process_call_operands (t
);
10380 /* Build a CALL_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE and
10381 FN and a null static chain slot. NARGS is the number of call arguments
10382 which are specified as a tree array ARGS. */
10385 build_call_array_loc (location_t loc
, tree return_type
, tree fn
,
10386 int nargs
, const tree
*args
)
10391 t
= build_call_1 (return_type
, fn
, nargs
);
10392 for (i
= 0; i
< nargs
; i
++)
10393 CALL_EXPR_ARG (t
, i
) = args
[i
];
10394 process_call_operands (t
);
10395 SET_EXPR_LOCATION (t
, loc
);
10399 /* Like build_call_array, but takes a vec. */
10402 build_call_vec (tree return_type
, tree fn
, vec
<tree
, va_gc
> *args
)
10407 ret
= build_call_1 (return_type
, fn
, vec_safe_length (args
));
10408 FOR_EACH_VEC_SAFE_ELT (args
, ix
, t
)
10409 CALL_EXPR_ARG (ret
, ix
) = t
;
10410 process_call_operands (ret
);
10415 /* Returns true if it is possible to prove that the index of
10416 an array access REF (an ARRAY_REF expression) falls into the
10420 in_array_bounds_p (tree ref
)
10422 tree idx
= TREE_OPERAND (ref
, 1);
10425 if (TREE_CODE (idx
) != INTEGER_CST
)
10428 min
= array_ref_low_bound (ref
);
10429 max
= array_ref_up_bound (ref
);
10432 || TREE_CODE (min
) != INTEGER_CST
10433 || TREE_CODE (max
) != INTEGER_CST
)
10436 if (tree_int_cst_lt (idx
, min
)
10437 || tree_int_cst_lt (max
, idx
))
10443 /* Returns true if it is possible to prove that the range of
10444 an array access REF (an ARRAY_RANGE_REF expression) falls
10445 into the array bounds. */
10448 range_in_array_bounds_p (tree ref
)
10450 tree domain_type
= TYPE_DOMAIN (TREE_TYPE (ref
));
10451 tree range_min
, range_max
, min
, max
;
10453 range_min
= TYPE_MIN_VALUE (domain_type
);
10454 range_max
= TYPE_MAX_VALUE (domain_type
);
10457 || TREE_CODE (range_min
) != INTEGER_CST
10458 || TREE_CODE (range_max
) != INTEGER_CST
)
10461 min
= array_ref_low_bound (ref
);
10462 max
= array_ref_up_bound (ref
);
10465 || TREE_CODE (min
) != INTEGER_CST
10466 || TREE_CODE (max
) != INTEGER_CST
)
10469 if (tree_int_cst_lt (range_min
, min
)
10470 || tree_int_cst_lt (max
, range_max
))
10476 /* Return true if T (assumed to be a DECL) must be assigned a memory
10480 needs_to_live_in_memory (const_tree t
)
10482 return (TREE_ADDRESSABLE (t
)
10483 || is_global_var (t
)
10484 || (TREE_CODE (t
) == RESULT_DECL
10485 && !DECL_BY_REFERENCE (t
)
10486 && aggregate_value_p (t
, current_function_decl
)));
10489 /* Return value of a constant X and sign-extend it. */
10492 int_cst_value (const_tree x
)
10494 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
10495 unsigned HOST_WIDE_INT val
= TREE_INT_CST_LOW (x
);
10497 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
10498 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
10499 || TREE_INT_CST_HIGH (x
) == -1);
10501 if (bits
< HOST_BITS_PER_WIDE_INT
)
10503 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
10505 val
|= (~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1;
10507 val
&= ~((~(unsigned HOST_WIDE_INT
) 0) << (bits
- 1) << 1);
10513 /* Return value of a constant X and sign-extend it. */
10516 widest_int_cst_value (const_tree x
)
10518 unsigned bits
= TYPE_PRECISION (TREE_TYPE (x
));
10519 unsigned HOST_WIDEST_INT val
= TREE_INT_CST_LOW (x
);
10521 #if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT
10522 gcc_assert (HOST_BITS_PER_WIDEST_INT
>= HOST_BITS_PER_DOUBLE_INT
);
10523 val
|= (((unsigned HOST_WIDEST_INT
) TREE_INT_CST_HIGH (x
))
10524 << HOST_BITS_PER_WIDE_INT
);
10526 /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
10527 gcc_assert (TREE_INT_CST_HIGH (x
) == 0
10528 || TREE_INT_CST_HIGH (x
) == -1);
10531 if (bits
< HOST_BITS_PER_WIDEST_INT
)
10533 bool negative
= ((val
>> (bits
- 1)) & 1) != 0;
10535 val
|= (~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1;
10537 val
&= ~((~(unsigned HOST_WIDEST_INT
) 0) << (bits
- 1) << 1);
10543 /* If TYPE is an integral or pointer type, return an integer type with
10544 the same precision which is unsigned iff UNSIGNEDP is true, or itself
10545 if TYPE is already an integer type of signedness UNSIGNEDP. */
10548 signed_or_unsigned_type_for (int unsignedp
, tree type
)
10550 if (TREE_CODE (type
) == INTEGER_TYPE
&& TYPE_UNSIGNED (type
) == unsignedp
)
10553 if (TREE_CODE (type
) == VECTOR_TYPE
)
10555 tree inner
= TREE_TYPE (type
);
10556 tree inner2
= signed_or_unsigned_type_for (unsignedp
, inner
);
10559 if (inner
== inner2
)
10561 return build_vector_type (inner2
, TYPE_VECTOR_SUBPARTS (type
));
10564 if (!INTEGRAL_TYPE_P (type
)
10565 && !POINTER_TYPE_P (type
))
10568 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
10571 /* If TYPE is an integral or pointer type, return an integer type with
10572 the same precision which is unsigned, or itself if TYPE is already an
10573 unsigned integer type. */
10576 unsigned_type_for (tree type
)
10578 return signed_or_unsigned_type_for (1, type
);
10581 /* If TYPE is an integral or pointer type, return an integer type with
10582 the same precision which is signed, or itself if TYPE is already a
10583 signed integer type. */
10586 signed_type_for (tree type
)
10588 return signed_or_unsigned_type_for (0, type
);
10591 /* If TYPE is a vector type, return a signed integer vector type with the
10592 same width and number of subparts. Otherwise return boolean_type_node. */
10595 truth_type_for (tree type
)
10597 if (TREE_CODE (type
) == VECTOR_TYPE
)
10599 tree elem
= lang_hooks
.types
.type_for_size
10600 (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type
))), 0);
10601 return build_opaque_vector_type (elem
, TYPE_VECTOR_SUBPARTS (type
));
10604 return boolean_type_node
;
10607 /* Returns the largest value obtainable by casting something in INNER type to
10611 upper_bound_in_type (tree outer
, tree inner
)
10614 unsigned int det
= 0;
10615 unsigned oprec
= TYPE_PRECISION (outer
);
10616 unsigned iprec
= TYPE_PRECISION (inner
);
10619 /* Compute a unique number for every combination. */
10620 det
|= (oprec
> iprec
) ? 4 : 0;
10621 det
|= TYPE_UNSIGNED (outer
) ? 2 : 0;
10622 det
|= TYPE_UNSIGNED (inner
) ? 1 : 0;
10624 /* Determine the exponent to use. */
10629 /* oprec <= iprec, outer: signed, inner: don't care. */
10634 /* oprec <= iprec, outer: unsigned, inner: don't care. */
10638 /* oprec > iprec, outer: signed, inner: signed. */
10642 /* oprec > iprec, outer: signed, inner: unsigned. */
10646 /* oprec > iprec, outer: unsigned, inner: signed. */
10650 /* oprec > iprec, outer: unsigned, inner: unsigned. */
10654 gcc_unreachable ();
10657 /* Compute 2^^prec - 1. */
10658 if (prec
<= HOST_BITS_PER_WIDE_INT
)
10661 high
.low
= ((~(unsigned HOST_WIDE_INT
) 0)
10662 >> (HOST_BITS_PER_WIDE_INT
- prec
));
10666 high
.high
= ((~(unsigned HOST_WIDE_INT
) 0)
10667 >> (HOST_BITS_PER_DOUBLE_INT
- prec
));
10668 high
.low
= ~(unsigned HOST_WIDE_INT
) 0;
10671 return double_int_to_tree (outer
, high
);
10674 /* Returns the smallest value obtainable by casting something in INNER type to
10678 lower_bound_in_type (tree outer
, tree inner
)
10681 unsigned oprec
= TYPE_PRECISION (outer
);
10682 unsigned iprec
= TYPE_PRECISION (inner
);
10684 /* If OUTER type is unsigned, we can definitely cast 0 to OUTER type
10686 if (TYPE_UNSIGNED (outer
)
10687 /* If we are widening something of an unsigned type, OUTER type
10688 contains all values of INNER type. In particular, both INNER
10689 and OUTER types have zero in common. */
10690 || (oprec
> iprec
&& TYPE_UNSIGNED (inner
)))
10691 low
.low
= low
.high
= 0;
10694 /* If we are widening a signed type to another signed type, we
10695 want to obtain -2^^(iprec-1). If we are keeping the
10696 precision or narrowing to a signed type, we want to obtain
10698 unsigned prec
= oprec
> iprec
? iprec
: oprec
;
10700 if (prec
<= HOST_BITS_PER_WIDE_INT
)
10702 low
.high
= ~(unsigned HOST_WIDE_INT
) 0;
10703 low
.low
= (~(unsigned HOST_WIDE_INT
) 0) << (prec
- 1);
10707 low
.high
= ((~(unsigned HOST_WIDE_INT
) 0)
10708 << (prec
- HOST_BITS_PER_WIDE_INT
- 1));
10713 return double_int_to_tree (outer
, low
);
10716 /* Return nonzero if two operands that are suitable for PHI nodes are
10717 necessarily equal. Specifically, both ARG0 and ARG1 must be either
10718 SSA_NAME or invariant. Note that this is strictly an optimization.
10719 That is, callers of this function can directly call operand_equal_p
10720 and get the same result, only slower. */
10723 operand_equal_for_phi_arg_p (const_tree arg0
, const_tree arg1
)
10727 if (TREE_CODE (arg0
) == SSA_NAME
|| TREE_CODE (arg1
) == SSA_NAME
)
10729 return operand_equal_p (arg0
, arg1
, 0);
10732 /* Returns number of zeros at the end of binary representation of X.
10734 ??? Use ffs if available? */
10737 num_ending_zeros (const_tree x
)
10739 unsigned HOST_WIDE_INT fr
, nfr
;
10740 unsigned num
, abits
;
10741 tree type
= TREE_TYPE (x
);
10743 if (TREE_INT_CST_LOW (x
) == 0)
10745 num
= HOST_BITS_PER_WIDE_INT
;
10746 fr
= TREE_INT_CST_HIGH (x
);
10751 fr
= TREE_INT_CST_LOW (x
);
10754 for (abits
= HOST_BITS_PER_WIDE_INT
/ 2; abits
; abits
/= 2)
10757 if (nfr
<< abits
== fr
)
10764 if (num
> TYPE_PRECISION (type
))
10765 num
= TYPE_PRECISION (type
);
10767 return build_int_cst_type (type
, num
);
10771 #define WALK_SUBTREE(NODE) \
10774 result = walk_tree_1 (&(NODE), func, data, pset, lh); \
10780 /* This is a subroutine of walk_tree that walks field of TYPE that are to
10781 be walked whenever a type is seen in the tree. Rest of operands and return
10782 value are as for walk_tree. */
10785 walk_type_fields (tree type
, walk_tree_fn func
, void *data
,
10786 struct pointer_set_t
*pset
, walk_tree_lh lh
)
10788 tree result
= NULL_TREE
;
10790 switch (TREE_CODE (type
))
10793 case REFERENCE_TYPE
:
10794 /* We have to worry about mutually recursive pointers. These can't
10795 be written in C. They can in Ada. It's pathological, but
10796 there's an ACATS test (c38102a) that checks it. Deal with this
10797 by checking if we're pointing to another pointer, that one
10798 points to another pointer, that one does too, and we have no htab.
10799 If so, get a hash table. We check three levels deep to avoid
10800 the cost of the hash table if we don't need one. */
10801 if (POINTER_TYPE_P (TREE_TYPE (type
))
10802 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (type
)))
10803 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (TREE_TYPE (type
))))
10806 result
= walk_tree_without_duplicates (&TREE_TYPE (type
),
10814 /* ... fall through ... */
10817 WALK_SUBTREE (TREE_TYPE (type
));
10821 WALK_SUBTREE (TYPE_METHOD_BASETYPE (type
));
10823 /* Fall through. */
10825 case FUNCTION_TYPE
:
10826 WALK_SUBTREE (TREE_TYPE (type
));
10830 /* We never want to walk into default arguments. */
10831 for (arg
= TYPE_ARG_TYPES (type
); arg
; arg
= TREE_CHAIN (arg
))
10832 WALK_SUBTREE (TREE_VALUE (arg
));
10837 /* Don't follow this nodes's type if a pointer for fear that
10838 we'll have infinite recursion. If we have a PSET, then we
10841 || (!POINTER_TYPE_P (TREE_TYPE (type
))
10842 && TREE_CODE (TREE_TYPE (type
)) != OFFSET_TYPE
))
10843 WALK_SUBTREE (TREE_TYPE (type
));
10844 WALK_SUBTREE (TYPE_DOMAIN (type
));
10848 WALK_SUBTREE (TREE_TYPE (type
));
10849 WALK_SUBTREE (TYPE_OFFSET_BASETYPE (type
));
10859 /* Apply FUNC to all the sub-trees of TP in a pre-order traversal. FUNC is
10860 called with the DATA and the address of each sub-tree. If FUNC returns a
10861 non-NULL value, the traversal is stopped, and the value returned by FUNC
10862 is returned. If PSET is non-NULL it is used to record the nodes visited,
10863 and to avoid visiting a node more than once. */
10866 walk_tree_1 (tree
*tp
, walk_tree_fn func
, void *data
,
10867 struct pointer_set_t
*pset
, walk_tree_lh lh
)
10869 enum tree_code code
;
10873 #define WALK_SUBTREE_TAIL(NODE) \
10877 goto tail_recurse; \
10882 /* Skip empty subtrees. */
10886 /* Don't walk the same tree twice, if the user has requested
10887 that we avoid doing so. */
10888 if (pset
&& pointer_set_insert (pset
, *tp
))
10891 /* Call the function. */
10893 result
= (*func
) (tp
, &walk_subtrees
, data
);
10895 /* If we found something, return it. */
10899 code
= TREE_CODE (*tp
);
10901 /* Even if we didn't, FUNC may have decided that there was nothing
10902 interesting below this point in the tree. */
10903 if (!walk_subtrees
)
10905 /* But we still need to check our siblings. */
10906 if (code
== TREE_LIST
)
10907 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
10908 else if (code
== OMP_CLAUSE
)
10909 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
10916 result
= (*lh
) (tp
, &walk_subtrees
, func
, data
, pset
);
10917 if (result
|| !walk_subtrees
)
10924 case IDENTIFIER_NODE
:
10931 case PLACEHOLDER_EXPR
:
10935 /* None of these have subtrees other than those already walked
10940 WALK_SUBTREE (TREE_VALUE (*tp
));
10941 WALK_SUBTREE_TAIL (TREE_CHAIN (*tp
));
10946 int len
= TREE_VEC_LENGTH (*tp
);
10951 /* Walk all elements but the first. */
10953 WALK_SUBTREE (TREE_VEC_ELT (*tp
, len
));
10955 /* Now walk the first one as a tail call. */
10956 WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp
, 0));
10960 WALK_SUBTREE (TREE_REALPART (*tp
));
10961 WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp
));
10965 unsigned HOST_WIDE_INT idx
;
10966 constructor_elt
*ce
;
10968 for (idx
= 0; vec_safe_iterate(CONSTRUCTOR_ELTS (*tp
), idx
, &ce
); idx
++)
10969 WALK_SUBTREE (ce
->value
);
10974 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, 0));
10979 for (decl
= BIND_EXPR_VARS (*tp
); decl
; decl
= DECL_CHAIN (decl
))
10981 /* Walk the DECL_INITIAL and DECL_SIZE. We don't want to walk
10982 into declarations that are just mentioned, rather than
10983 declared; they don't really belong to this part of the tree.
10984 And, we can see cycles: the initializer for a declaration
10985 can refer to the declaration itself. */
10986 WALK_SUBTREE (DECL_INITIAL (decl
));
10987 WALK_SUBTREE (DECL_SIZE (decl
));
10988 WALK_SUBTREE (DECL_SIZE_UNIT (decl
));
10990 WALK_SUBTREE_TAIL (BIND_EXPR_BODY (*tp
));
10993 case STATEMENT_LIST
:
10995 tree_stmt_iterator i
;
10996 for (i
= tsi_start (*tp
); !tsi_end_p (i
); tsi_next (&i
))
10997 WALK_SUBTREE (*tsi_stmt_ptr (i
));
11002 switch (OMP_CLAUSE_CODE (*tp
))
11004 case OMP_CLAUSE_PRIVATE
:
11005 case OMP_CLAUSE_SHARED
:
11006 case OMP_CLAUSE_FIRSTPRIVATE
:
11007 case OMP_CLAUSE_COPYIN
:
11008 case OMP_CLAUSE_COPYPRIVATE
:
11009 case OMP_CLAUSE_FINAL
:
11010 case OMP_CLAUSE_IF
:
11011 case OMP_CLAUSE_NUM_THREADS
:
11012 case OMP_CLAUSE_SCHEDULE
:
11013 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, 0));
11016 case OMP_CLAUSE_NOWAIT
:
11017 case OMP_CLAUSE_ORDERED
:
11018 case OMP_CLAUSE_DEFAULT
:
11019 case OMP_CLAUSE_UNTIED
:
11020 case OMP_CLAUSE_MERGEABLE
:
11021 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11023 case OMP_CLAUSE_LASTPRIVATE
:
11024 WALK_SUBTREE (OMP_CLAUSE_DECL (*tp
));
11025 WALK_SUBTREE (OMP_CLAUSE_LASTPRIVATE_STMT (*tp
));
11026 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11028 case OMP_CLAUSE_COLLAPSE
:
11031 for (i
= 0; i
< 3; i
++)
11032 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
11033 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11036 case OMP_CLAUSE_REDUCTION
:
11039 for (i
= 0; i
< 4; i
++)
11040 WALK_SUBTREE (OMP_CLAUSE_OPERAND (*tp
, i
));
11041 WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp
));
11045 gcc_unreachable ();
11053 /* TARGET_EXPRs are peculiar: operands 1 and 3 can be the same.
11054 But, we only want to walk once. */
11055 len
= (TREE_OPERAND (*tp
, 3) == TREE_OPERAND (*tp
, 1)) ? 2 : 3;
11056 for (i
= 0; i
< len
; ++i
)
11057 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11058 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
));
11062 /* If this is a TYPE_DECL, walk into the fields of the type that it's
11063 defining. We only want to walk into these fields of a type in this
11064 case and not in the general case of a mere reference to the type.
11066 The criterion is as follows: if the field can be an expression, it
11067 must be walked only here. This should be in keeping with the fields
11068 that are directly gimplified in gimplify_type_sizes in order for the
11069 mark/copy-if-shared/unmark machinery of the gimplifier to work with
11070 variable-sized types.
11072 Note that DECLs get walked as part of processing the BIND_EXPR. */
11073 if (TREE_CODE (DECL_EXPR_DECL (*tp
)) == TYPE_DECL
)
11075 tree
*type_p
= &TREE_TYPE (DECL_EXPR_DECL (*tp
));
11076 if (TREE_CODE (*type_p
) == ERROR_MARK
)
11079 /* Call the function for the type. See if it returns anything or
11080 doesn't want us to continue. If we are to continue, walk both
11081 the normal fields and those for the declaration case. */
11082 result
= (*func
) (type_p
, &walk_subtrees
, data
);
11083 if (result
|| !walk_subtrees
)
11086 /* But do not walk a pointed-to type since it may itself need to
11087 be walked in the declaration case if it isn't anonymous. */
11088 if (!POINTER_TYPE_P (*type_p
))
11090 result
= walk_type_fields (*type_p
, func
, data
, pset
, lh
);
11095 /* If this is a record type, also walk the fields. */
11096 if (RECORD_OR_UNION_TYPE_P (*type_p
))
11100 for (field
= TYPE_FIELDS (*type_p
); field
;
11101 field
= DECL_CHAIN (field
))
11103 /* We'd like to look at the type of the field, but we can
11104 easily get infinite recursion. So assume it's pointed
11105 to elsewhere in the tree. Also, ignore things that
11107 if (TREE_CODE (field
) != FIELD_DECL
)
11110 WALK_SUBTREE (DECL_FIELD_OFFSET (field
));
11111 WALK_SUBTREE (DECL_SIZE (field
));
11112 WALK_SUBTREE (DECL_SIZE_UNIT (field
));
11113 if (TREE_CODE (*type_p
) == QUAL_UNION_TYPE
)
11114 WALK_SUBTREE (DECL_QUALIFIER (field
));
11118 /* Same for scalar types. */
11119 else if (TREE_CODE (*type_p
) == BOOLEAN_TYPE
11120 || TREE_CODE (*type_p
) == ENUMERAL_TYPE
11121 || TREE_CODE (*type_p
) == INTEGER_TYPE
11122 || TREE_CODE (*type_p
) == FIXED_POINT_TYPE
11123 || TREE_CODE (*type_p
) == REAL_TYPE
)
11125 WALK_SUBTREE (TYPE_MIN_VALUE (*type_p
));
11126 WALK_SUBTREE (TYPE_MAX_VALUE (*type_p
));
11129 WALK_SUBTREE (TYPE_SIZE (*type_p
));
11130 WALK_SUBTREE_TAIL (TYPE_SIZE_UNIT (*type_p
));
11135 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code
)))
11139 /* Walk over all the sub-trees of this operand. */
11140 len
= TREE_OPERAND_LENGTH (*tp
);
11142 /* Go through the subtrees. We need to do this in forward order so
11143 that the scope of a FOR_EXPR is handled properly. */
11146 for (i
= 0; i
< len
- 1; ++i
)
11147 WALK_SUBTREE (TREE_OPERAND (*tp
, i
));
11148 WALK_SUBTREE_TAIL (TREE_OPERAND (*tp
, len
- 1));
11151 /* If this is a type, walk the needed fields in the type. */
11152 else if (TYPE_P (*tp
))
11153 return walk_type_fields (*tp
, func
, data
, pset
, lh
);
11157 /* We didn't find what we were looking for. */
11160 #undef WALK_SUBTREE_TAIL
11162 #undef WALK_SUBTREE
11164 /* Like walk_tree, but does not walk duplicate nodes more than once. */
11167 walk_tree_without_duplicates_1 (tree
*tp
, walk_tree_fn func
, void *data
,
11171 struct pointer_set_t
*pset
;
11173 pset
= pointer_set_create ();
11174 result
= walk_tree_1 (tp
, func
, data
, pset
, lh
);
11175 pointer_set_destroy (pset
);
11181 tree_block (tree t
)
11183 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
11185 if (IS_EXPR_CODE_CLASS (c
))
11186 return LOCATION_BLOCK (t
->exp
.locus
);
11187 gcc_unreachable ();
11192 tree_set_block (tree t
, tree b
)
11194 char const c
= TREE_CODE_CLASS (TREE_CODE (t
));
11196 if (IS_EXPR_CODE_CLASS (c
))
11199 t
->exp
.locus
= COMBINE_LOCATION_DATA (line_table
, t
->exp
.locus
, b
);
11201 t
->exp
.locus
= LOCATION_LOCUS (t
->exp
.locus
);
11204 gcc_unreachable ();
11207 /* Create a nameless artificial label and put it in the current
11208 function context. The label has a location of LOC. Returns the
11209 newly created label. */
11212 create_artificial_label (location_t loc
)
11214 tree lab
= build_decl (loc
,
11215 LABEL_DECL
, NULL_TREE
, void_type_node
);
11217 DECL_ARTIFICIAL (lab
) = 1;
11218 DECL_IGNORED_P (lab
) = 1;
11219 DECL_CONTEXT (lab
) = current_function_decl
;
11223 /* Given a tree, try to return a useful variable name that we can use
11224 to prefix a temporary that is being assigned the value of the tree.
11225 I.E. given <temp> = &A, return A. */
11230 tree stripped_decl
;
11233 STRIP_NOPS (stripped_decl
);
11234 if (DECL_P (stripped_decl
) && DECL_NAME (stripped_decl
))
11235 return IDENTIFIER_POINTER (DECL_NAME (stripped_decl
));
11236 else if (TREE_CODE (stripped_decl
) == SSA_NAME
)
11238 tree name
= SSA_NAME_IDENTIFIER (stripped_decl
);
11241 return IDENTIFIER_POINTER (name
);
11245 switch (TREE_CODE (stripped_decl
))
11248 return get_name (TREE_OPERAND (stripped_decl
, 0));
11255 /* Return true if TYPE has a variable argument list. */
11258 stdarg_p (const_tree fntype
)
11260 function_args_iterator args_iter
;
11261 tree n
= NULL_TREE
, t
;
11266 FOREACH_FUNCTION_ARGS(fntype
, t
, args_iter
)
11271 return n
!= NULL_TREE
&& n
!= void_type_node
;
11274 /* Return true if TYPE has a prototype. */
11277 prototype_p (tree fntype
)
11281 gcc_assert (fntype
!= NULL_TREE
);
11283 t
= TYPE_ARG_TYPES (fntype
);
11284 return (t
!= NULL_TREE
);
11287 /* If BLOCK is inlined from an __attribute__((__artificial__))
11288 routine, return pointer to location from where it has been
11291 block_nonartificial_location (tree block
)
11293 location_t
*ret
= NULL
;
11295 while (block
&& TREE_CODE (block
) == BLOCK
11296 && BLOCK_ABSTRACT_ORIGIN (block
))
11298 tree ao
= BLOCK_ABSTRACT_ORIGIN (block
);
11300 while (TREE_CODE (ao
) == BLOCK
11301 && BLOCK_ABSTRACT_ORIGIN (ao
)
11302 && BLOCK_ABSTRACT_ORIGIN (ao
) != ao
)
11303 ao
= BLOCK_ABSTRACT_ORIGIN (ao
);
11305 if (TREE_CODE (ao
) == FUNCTION_DECL
)
11307 /* If AO is an artificial inline, point RET to the
11308 call site locus at which it has been inlined and continue
11309 the loop, in case AO's caller is also an artificial
11311 if (DECL_DECLARED_INLINE_P (ao
)
11312 && lookup_attribute ("artificial", DECL_ATTRIBUTES (ao
)))
11313 ret
= &BLOCK_SOURCE_LOCATION (block
);
11317 else if (TREE_CODE (ao
) != BLOCK
)
11320 block
= BLOCK_SUPERCONTEXT (block
);
11326 /* If EXP is inlined from an __attribute__((__artificial__))
11327 function, return the location of the original call expression. */
11330 tree_nonartificial_location (tree exp
)
11332 location_t
*loc
= block_nonartificial_location (TREE_BLOCK (exp
));
11337 return EXPR_LOCATION (exp
);
11341 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
11344 /* Return the hash code code X, an OPTIMIZATION_NODE or TARGET_OPTION code. */
11347 cl_option_hash_hash (const void *x
)
11349 const_tree
const t
= (const_tree
) x
;
11353 hashval_t hash
= 0;
11355 if (TREE_CODE (t
) == OPTIMIZATION_NODE
)
11357 p
= (const char *)TREE_OPTIMIZATION (t
);
11358 len
= sizeof (struct cl_optimization
);
11361 else if (TREE_CODE (t
) == TARGET_OPTION_NODE
)
11363 p
= (const char *)TREE_TARGET_OPTION (t
);
11364 len
= sizeof (struct cl_target_option
);
11368 gcc_unreachable ();
11370 /* assume most opt flags are just 0/1, some are 2-3, and a few might be
11372 for (i
= 0; i
< len
; i
++)
11374 hash
= (hash
<< 4) ^ ((i
<< 2) | p
[i
]);
11379 /* Return nonzero if the value represented by *X (an OPTIMIZATION or
11380 TARGET_OPTION tree node) is the same as that given by *Y, which is the
11384 cl_option_hash_eq (const void *x
, const void *y
)
11386 const_tree
const xt
= (const_tree
) x
;
11387 const_tree
const yt
= (const_tree
) y
;
11392 if (TREE_CODE (xt
) != TREE_CODE (yt
))
11395 if (TREE_CODE (xt
) == OPTIMIZATION_NODE
)
11397 xp
= (const char *)TREE_OPTIMIZATION (xt
);
11398 yp
= (const char *)TREE_OPTIMIZATION (yt
);
11399 len
= sizeof (struct cl_optimization
);
11402 else if (TREE_CODE (xt
) == TARGET_OPTION_NODE
)
11404 xp
= (const char *)TREE_TARGET_OPTION (xt
);
11405 yp
= (const char *)TREE_TARGET_OPTION (yt
);
11406 len
= sizeof (struct cl_target_option
);
11410 gcc_unreachable ();
11412 return (memcmp (xp
, yp
, len
) == 0);
11415 /* Build an OPTIMIZATION_NODE based on the current options. */
11418 build_optimization_node (void)
11423 /* Use the cache of optimization nodes. */
11425 cl_optimization_save (TREE_OPTIMIZATION (cl_optimization_node
),
11428 slot
= htab_find_slot (cl_option_hash_table
, cl_optimization_node
, INSERT
);
11432 /* Insert this one into the hash table. */
11433 t
= cl_optimization_node
;
11436 /* Make a new node for next time round. */
11437 cl_optimization_node
= make_node (OPTIMIZATION_NODE
);
11443 /* Build a TARGET_OPTION_NODE based on the current options. */
11446 build_target_option_node (void)
11451 /* Use the cache of optimization nodes. */
11453 cl_target_option_save (TREE_TARGET_OPTION (cl_target_option_node
),
11456 slot
= htab_find_slot (cl_option_hash_table
, cl_target_option_node
, INSERT
);
11460 /* Insert this one into the hash table. */
11461 t
= cl_target_option_node
;
11464 /* Make a new node for next time round. */
11465 cl_target_option_node
= make_node (TARGET_OPTION_NODE
);
11471 /* Determine the "ultimate origin" of a block. The block may be an inlined
11472 instance of an inlined instance of a block which is local to an inline
11473 function, so we have to trace all of the way back through the origin chain
11474 to find out what sort of node actually served as the original seed for the
11478 block_ultimate_origin (const_tree block
)
11480 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
11482 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
11483 nodes in the function to point to themselves; ignore that if
11484 we're trying to output the abstract instance of this function. */
11485 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
11488 if (immediate_origin
== NULL_TREE
)
11493 tree lookahead
= immediate_origin
;
11497 ret_val
= lookahead
;
11498 lookahead
= (TREE_CODE (ret_val
) == BLOCK
11499 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
11501 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
11503 /* The block's abstract origin chain may not be the *ultimate* origin of
11504 the block. It could lead to a DECL that has an abstract origin set.
11505 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
11506 will give us if it has one). Note that DECL's abstract origins are
11507 supposed to be the most distant ancestor (or so decl_ultimate_origin
11508 claims), so we don't need to loop following the DECL origins. */
11509 if (DECL_P (ret_val
))
11510 return DECL_ORIGIN (ret_val
);
11516 /* Return true if T1 and T2 are equivalent lists. */
11519 list_equal_p (const_tree t1
, const_tree t2
)
11521 for (; t1
&& t2
; t1
= TREE_CHAIN (t1
) , t2
= TREE_CHAIN (t2
))
11522 if (TREE_VALUE (t1
) != TREE_VALUE (t2
))
11527 /* Return true iff conversion in EXP generates no instruction. Mark
11528 it inline so that we fully inline into the stripping functions even
11529 though we have two uses of this function. */
11532 tree_nop_conversion (const_tree exp
)
11534 tree outer_type
, inner_type
;
11535 int outer_is_pts_p
, inner_is_pts_p
;
11537 if (!CONVERT_EXPR_P (exp
)
11538 && TREE_CODE (exp
) != NON_LVALUE_EXPR
)
11540 if (TREE_OPERAND (exp
, 0) == error_mark_node
)
11543 outer_type
= TREE_TYPE (exp
);
11544 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
11549 outer_is_pts_p
= (POINTER_TYPE_P (outer_type
)
11550 && upc_shared_type_p (TREE_TYPE (outer_type
)));
11551 inner_is_pts_p
= (POINTER_TYPE_P (inner_type
)
11552 && upc_shared_type_p (TREE_TYPE (inner_type
)));
11554 /* UPC pointer-to-shared types have special
11555 equivalence rules that must be checked. */
11556 if (outer_is_pts_p
&& inner_is_pts_p
11557 && lang_hooks
.types_compatible_p
)
11558 return lang_hooks
.types_compatible_p (outer_type
, inner_type
);
11560 /* UPC pointer-to-shared types are not interchangeable
11561 with integral types. */
11562 if (outer_is_pts_p
|| inner_is_pts_p
)
11565 /* Use precision rather then machine mode when we can, which gives
11566 the correct answer even for submode (bit-field) types. */
11567 if ((INTEGRAL_TYPE_P (outer_type
)
11568 || POINTER_TYPE_P (outer_type
)
11569 || TREE_CODE (outer_type
) == OFFSET_TYPE
)
11570 && (INTEGRAL_TYPE_P (inner_type
)
11571 || POINTER_TYPE_P (inner_type
)
11572 || TREE_CODE (inner_type
) == OFFSET_TYPE
))
11573 return TYPE_PRECISION (outer_type
) == TYPE_PRECISION (inner_type
);
11575 /* Otherwise fall back on comparing machine modes (e.g. for
11576 aggregate types, floats). */
11577 return TYPE_MODE (outer_type
) == TYPE_MODE (inner_type
);
11580 /* Return true iff conversion in EXP generates no instruction. Don't
11581 consider conversions changing the signedness. */
11584 tree_sign_nop_conversion (const_tree exp
)
11586 tree outer_type
, inner_type
;
11588 if (!tree_nop_conversion (exp
))
11591 outer_type
= TREE_TYPE (exp
);
11592 inner_type
= TREE_TYPE (TREE_OPERAND (exp
, 0));
11594 return (TYPE_UNSIGNED (outer_type
) == TYPE_UNSIGNED (inner_type
)
11595 && POINTER_TYPE_P (outer_type
) == POINTER_TYPE_P (inner_type
));
11598 /* Strip conversions from EXP according to tree_nop_conversion and
11599 return the resulting expression. */
11602 tree_strip_nop_conversions (tree exp
)
11604 while (tree_nop_conversion (exp
))
11605 exp
= TREE_OPERAND (exp
, 0);
11609 /* Strip conversions from EXP according to tree_sign_nop_conversion
11610 and return the resulting expression. */
11613 tree_strip_sign_nop_conversions (tree exp
)
11615 while (tree_sign_nop_conversion (exp
))
11616 exp
= TREE_OPERAND (exp
, 0);
11620 /* Avoid any floating point extensions from EXP. */
11622 strip_float_extensions (tree exp
)
11624 tree sub
, expt
, subt
;
11626 /* For floating point constant look up the narrowest type that can hold
11627 it properly and handle it like (type)(narrowest_type)constant.
11628 This way we can optimize for instance a=a*2.0 where "a" is float
11629 but 2.0 is double constant. */
11630 if (TREE_CODE (exp
) == REAL_CST
&& !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp
)))
11632 REAL_VALUE_TYPE orig
;
11635 orig
= TREE_REAL_CST (exp
);
11636 if (TYPE_PRECISION (TREE_TYPE (exp
)) > TYPE_PRECISION (float_type_node
)
11637 && exact_real_truncate (TYPE_MODE (float_type_node
), &orig
))
11638 type
= float_type_node
;
11639 else if (TYPE_PRECISION (TREE_TYPE (exp
))
11640 > TYPE_PRECISION (double_type_node
)
11641 && exact_real_truncate (TYPE_MODE (double_type_node
), &orig
))
11642 type
= double_type_node
;
11644 return build_real (type
, real_value_truncate (TYPE_MODE (type
), orig
));
11647 if (!CONVERT_EXPR_P (exp
))
11650 sub
= TREE_OPERAND (exp
, 0);
11651 subt
= TREE_TYPE (sub
);
11652 expt
= TREE_TYPE (exp
);
11654 if (!FLOAT_TYPE_P (subt
))
11657 if (DECIMAL_FLOAT_TYPE_P (expt
) != DECIMAL_FLOAT_TYPE_P (subt
))
11660 if (TYPE_PRECISION (subt
) > TYPE_PRECISION (expt
))
11663 return strip_float_extensions (sub
);
11666 /* Strip out all handled components that produce invariant
11670 strip_invariant_refs (const_tree op
)
11672 while (handled_component_p (op
))
11674 switch (TREE_CODE (op
))
11677 case ARRAY_RANGE_REF
:
11678 if (!is_gimple_constant (TREE_OPERAND (op
, 1))
11679 || TREE_OPERAND (op
, 2) != NULL_TREE
11680 || TREE_OPERAND (op
, 3) != NULL_TREE
)
11684 case COMPONENT_REF
:
11685 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
11691 op
= TREE_OPERAND (op
, 0);
11697 static GTY(()) tree gcc_eh_personality_decl
;
11699 /* Return the GCC personality function decl. */
11702 lhd_gcc_personality (void)
11704 if (!gcc_eh_personality_decl
)
11705 gcc_eh_personality_decl
= build_personality_function ("gcc");
11706 return gcc_eh_personality_decl
;
11709 /* Try to find a base info of BINFO that would have its field decl at offset
11710 OFFSET within the BINFO type and which is of EXPECTED_TYPE. If it can be
11711 found, return, otherwise return NULL_TREE. */
11714 get_binfo_at_offset (tree binfo
, HOST_WIDE_INT offset
, tree expected_type
)
11716 tree type
= BINFO_TYPE (binfo
);
11720 HOST_WIDE_INT pos
, size
;
11724 if (TYPE_MAIN_VARIANT (type
) == TYPE_MAIN_VARIANT (expected_type
))
11729 for (fld
= TYPE_FIELDS (type
); fld
; fld
= DECL_CHAIN (fld
))
11731 if (TREE_CODE (fld
) != FIELD_DECL
)
11734 pos
= int_bit_position (fld
);
11735 size
= tree_low_cst (DECL_SIZE (fld
), 1);
11736 if (pos
<= offset
&& (pos
+ size
) > offset
)
11739 if (!fld
|| TREE_CODE (TREE_TYPE (fld
)) != RECORD_TYPE
)
11742 if (!DECL_ARTIFICIAL (fld
))
11744 binfo
= TYPE_BINFO (TREE_TYPE (fld
));
11748 /* Offset 0 indicates the primary base, whose vtable contents are
11749 represented in the binfo for the derived class. */
11750 else if (offset
!= 0)
11752 tree base_binfo
, found_binfo
= NULL_TREE
;
11753 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
11754 if (TREE_TYPE (base_binfo
) == TREE_TYPE (fld
))
11756 found_binfo
= base_binfo
;
11761 binfo
= found_binfo
;
11764 type
= TREE_TYPE (fld
);
11769 /* Returns true if X is a typedef decl. */
11772 is_typedef_decl (tree x
)
11774 return (x
&& TREE_CODE (x
) == TYPE_DECL
11775 && DECL_ORIGINAL_TYPE (x
) != NULL_TREE
);
11778 /* Returns true iff TYPE is a type variant created for a typedef. */
11781 typedef_variant_p (tree type
)
11783 return is_typedef_decl (TYPE_NAME (type
));
11786 /* Warn about a use of an identifier which was marked deprecated. */
11788 warn_deprecated_use (tree node
, tree attr
)
11792 if (node
== 0 || !warn_deprecated_decl
)
11798 attr
= DECL_ATTRIBUTES (node
);
11799 else if (TYPE_P (node
))
11801 tree decl
= TYPE_STUB_DECL (node
);
11803 attr
= lookup_attribute ("deprecated",
11804 TYPE_ATTRIBUTES (TREE_TYPE (decl
)));
11809 attr
= lookup_attribute ("deprecated", attr
);
11812 msg
= TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
)));
11818 expanded_location xloc
= expand_location (DECL_SOURCE_LOCATION (node
));
11820 warning (OPT_Wdeprecated_declarations
,
11821 "%qD is deprecated (declared at %r%s:%d%R): %s",
11822 node
, "locus", xloc
.file
, xloc
.line
, msg
);
11824 warning (OPT_Wdeprecated_declarations
,
11825 "%qD is deprecated (declared at %r%s:%d%R)",
11826 node
, "locus", xloc
.file
, xloc
.line
);
11828 else if (TYPE_P (node
))
11830 tree what
= NULL_TREE
;
11831 tree decl
= TYPE_STUB_DECL (node
);
11833 if (TYPE_NAME (node
))
11835 if (TREE_CODE (TYPE_NAME (node
)) == IDENTIFIER_NODE
)
11836 what
= TYPE_NAME (node
);
11837 else if (TREE_CODE (TYPE_NAME (node
)) == TYPE_DECL
11838 && DECL_NAME (TYPE_NAME (node
)))
11839 what
= DECL_NAME (TYPE_NAME (node
));
11844 expanded_location xloc
11845 = expand_location (DECL_SOURCE_LOCATION (decl
));
11849 warning (OPT_Wdeprecated_declarations
,
11850 "%qE is deprecated (declared at %r%s:%d%R): %s",
11851 what
, "locus", xloc
.file
, xloc
.line
, msg
);
11853 warning (OPT_Wdeprecated_declarations
,
11854 "%qE is deprecated (declared at %r%s:%d%R)",
11855 what
, "locus", xloc
.file
, xloc
.line
);
11860 warning (OPT_Wdeprecated_declarations
,
11861 "type is deprecated (declared at %r%s:%d%R): %s",
11862 "locus", xloc
.file
, xloc
.line
, msg
);
11864 warning (OPT_Wdeprecated_declarations
,
11865 "type is deprecated (declared at %r%s:%d%R)",
11866 "locus", xloc
.file
, xloc
.line
);
11874 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated: %s",
11877 warning (OPT_Wdeprecated_declarations
, "%qE is deprecated", what
);
11882 warning (OPT_Wdeprecated_declarations
, "type is deprecated: %s",
11885 warning (OPT_Wdeprecated_declarations
, "type is deprecated");
11891 #include "gt-tree.h"