1 /* Gimple IR support functions.
3 Copyright 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4 Contributed by Aldy Hernandez <aldyh@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
29 #include "hard-reg-set.h"
30 #include "basic-block.h"
32 #include "diagnostic.h"
33 #include "tree-flow.h"
34 #include "value-prof.h"
38 #include "langhooks.h"
40 /* Global type table. FIXME lto, it should be possible to re-use some
41 of the type hashing routines in tree.c (type_hash_canon, type_hash_lookup,
42 etc), but those assume that types were built with the various
43 build_*_type routines which is not the case with the streamer. */
44 static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
46 static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
47 htab_t gimple_canonical_types
;
48 static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map
)))
49 htab_t type_hash_cache
;
50 static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map
)))
51 htab_t canonical_type_hash_cache
;
53 /* All the tuples have their operand vector (if present) at the very bottom
54 of the structure. Therefore, the offset required to find the
55 operands vector the size of the structure minus the size of the 1
56 element tree array at the end (see gimple_ops). */
57 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \
58 (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0),
59 EXPORTED_CONST
size_t gimple_ops_offset_
[] = {
60 #include "gsstruct.def"
64 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof(struct STRUCT),
65 static const size_t gsstruct_code_size
[] = {
66 #include "gsstruct.def"
70 #define DEFGSCODE(SYM, NAME, GSSCODE) NAME,
71 const char *const gimple_code_name
[] = {
76 #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE,
77 EXPORTED_CONST
enum gimple_statement_structure_enum gss_for_code_
[] = {
82 #ifdef GATHER_STATISTICS
85 int gimple_alloc_counts
[(int) gimple_alloc_kind_all
];
86 int gimple_alloc_sizes
[(int) gimple_alloc_kind_all
];
88 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */
89 static const char * const gimple_alloc_kind_names
[] = {
96 #endif /* GATHER_STATISTICS */
98 /* Private API manipulation functions shared only with some
100 extern void gimple_set_stored_syms (gimple
, bitmap
, bitmap_obstack
*);
101 extern void gimple_set_loaded_syms (gimple
, bitmap
, bitmap_obstack
*);
103 /* Gimple tuple constructors.
104 Note: Any constructor taking a ``gimple_seq'' as a parameter, can
105 be passed a NULL to start with an empty sequence. */
107 /* Set the code for statement G to CODE. */
110 gimple_set_code (gimple g
, enum gimple_code code
)
112 g
->gsbase
.code
= code
;
115 /* Return the number of bytes needed to hold a GIMPLE statement with
119 gimple_size (enum gimple_code code
)
121 return gsstruct_code_size
[gss_for_code (code
)];
124 /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
128 gimple_alloc_stat (enum gimple_code code
, unsigned num_ops MEM_STAT_DECL
)
133 size
= gimple_size (code
);
135 size
+= sizeof (tree
) * (num_ops
- 1);
137 #ifdef GATHER_STATISTICS
139 enum gimple_alloc_kind kind
= gimple_alloc_kind (code
);
140 gimple_alloc_counts
[(int) kind
]++;
141 gimple_alloc_sizes
[(int) kind
] += size
;
145 stmt
= ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT
);
146 gimple_set_code (stmt
, code
);
147 gimple_set_num_ops (stmt
, num_ops
);
149 /* Do not call gimple_set_modified here as it has other side
150 effects and this tuple is still not completely built. */
151 stmt
->gsbase
.modified
= 1;
152 gimple_init_singleton (stmt
);
157 /* Set SUBCODE to be the code of the expression computed by statement G. */
160 gimple_set_subcode (gimple g
, unsigned subcode
)
162 /* We only have 16 bits for the RHS code. Assert that we are not
164 gcc_assert (subcode
< (1 << 16));
165 g
->gsbase
.subcode
= subcode
;
170 /* Build a tuple with operands. CODE is the statement to build (which
171 must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the sub-code
172 for the new tuple. NUM_OPS is the number of operands to allocate. */
174 #define gimple_build_with_ops(c, s, n) \
175 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
178 gimple_build_with_ops_stat (enum gimple_code code
, unsigned subcode
,
179 unsigned num_ops MEM_STAT_DECL
)
181 gimple s
= gimple_alloc_stat (code
, num_ops PASS_MEM_STAT
);
182 gimple_set_subcode (s
, subcode
);
188 /* Build a GIMPLE_RETURN statement returning RETVAL. */
191 gimple_build_return (tree retval
)
193 gimple s
= gimple_build_with_ops (GIMPLE_RETURN
, ERROR_MARK
, 1);
195 gimple_return_set_retval (s
, retval
);
199 /* Reset alias information on call S. */
202 gimple_call_reset_alias_info (gimple s
)
204 if (gimple_call_flags (s
) & ECF_CONST
)
205 memset (gimple_call_use_set (s
), 0, sizeof (struct pt_solution
));
207 pt_solution_reset (gimple_call_use_set (s
));
208 if (gimple_call_flags (s
) & (ECF_CONST
|ECF_PURE
|ECF_NOVOPS
))
209 memset (gimple_call_clobber_set (s
), 0, sizeof (struct pt_solution
));
211 pt_solution_reset (gimple_call_clobber_set (s
));
214 /* Helper for gimple_build_call, gimple_build_call_valist,
215 gimple_build_call_vec and gimple_build_call_from_tree. Build the basic
216 components of a GIMPLE_CALL statement to function FN with NARGS
220 gimple_build_call_1 (tree fn
, unsigned nargs
)
222 gimple s
= gimple_build_with_ops (GIMPLE_CALL
, ERROR_MARK
, nargs
+ 3);
223 if (TREE_CODE (fn
) == FUNCTION_DECL
)
224 fn
= build_fold_addr_expr (fn
);
225 gimple_set_op (s
, 1, fn
);
226 gimple_call_set_fntype (s
, TREE_TYPE (TREE_TYPE (fn
)));
227 gimple_call_reset_alias_info (s
);
232 /* Build a GIMPLE_CALL statement to function FN with the arguments
233 specified in vector ARGS. */
236 gimple_build_call_vec (tree fn
, VEC(tree
, heap
) *args
)
239 unsigned nargs
= VEC_length (tree
, args
);
240 gimple call
= gimple_build_call_1 (fn
, nargs
);
242 for (i
= 0; i
< nargs
; i
++)
243 gimple_call_set_arg (call
, i
, VEC_index (tree
, args
, i
));
249 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
250 arguments. The ... are the arguments. */
253 gimple_build_call (tree fn
, unsigned nargs
, ...)
259 gcc_assert (TREE_CODE (fn
) == FUNCTION_DECL
|| is_gimple_call_addr (fn
));
261 call
= gimple_build_call_1 (fn
, nargs
);
263 va_start (ap
, nargs
);
264 for (i
= 0; i
< nargs
; i
++)
265 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
272 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
273 arguments. AP contains the arguments. */
276 gimple_build_call_valist (tree fn
, unsigned nargs
, va_list ap
)
281 gcc_assert (TREE_CODE (fn
) == FUNCTION_DECL
|| is_gimple_call_addr (fn
));
283 call
= gimple_build_call_1 (fn
, nargs
);
285 for (i
= 0; i
< nargs
; i
++)
286 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
292 /* Helper for gimple_build_call_internal and gimple_build_call_internal_vec.
293 Build the basic components of a GIMPLE_CALL statement to internal
294 function FN with NARGS arguments. */
297 gimple_build_call_internal_1 (enum internal_fn fn
, unsigned nargs
)
299 gimple s
= gimple_build_with_ops (GIMPLE_CALL
, ERROR_MARK
, nargs
+ 3);
300 s
->gsbase
.subcode
|= GF_CALL_INTERNAL
;
301 gimple_call_set_internal_fn (s
, fn
);
302 gimple_call_reset_alias_info (s
);
307 /* Build a GIMPLE_CALL statement to internal function FN. NARGS is
308 the number of arguments. The ... are the arguments. */
311 gimple_build_call_internal (enum internal_fn fn
, unsigned nargs
, ...)
317 call
= gimple_build_call_internal_1 (fn
, nargs
);
318 va_start (ap
, nargs
);
319 for (i
= 0; i
< nargs
; i
++)
320 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
327 /* Build a GIMPLE_CALL statement to internal function FN with the arguments
328 specified in vector ARGS. */
331 gimple_build_call_internal_vec (enum internal_fn fn
, VEC(tree
, heap
) *args
)
336 nargs
= VEC_length (tree
, args
);
337 call
= gimple_build_call_internal_1 (fn
, nargs
);
338 for (i
= 0; i
< nargs
; i
++)
339 gimple_call_set_arg (call
, i
, VEC_index (tree
, args
, i
));
345 /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
346 assumed to be in GIMPLE form already. Minimal checking is done of
350 gimple_build_call_from_tree (tree t
)
354 tree fndecl
= get_callee_fndecl (t
);
356 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
358 nargs
= call_expr_nargs (t
);
359 call
= gimple_build_call_1 (fndecl
? fndecl
: CALL_EXPR_FN (t
), nargs
);
361 for (i
= 0; i
< nargs
; i
++)
362 gimple_call_set_arg (call
, i
, CALL_EXPR_ARG (t
, i
));
364 gimple_set_block (call
, TREE_BLOCK (t
));
366 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
367 gimple_call_set_chain (call
, CALL_EXPR_STATIC_CHAIN (t
));
368 gimple_call_set_tail (call
, CALL_EXPR_TAILCALL (t
));
369 gimple_call_set_return_slot_opt (call
, CALL_EXPR_RETURN_SLOT_OPT (t
));
371 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
372 && (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_ALLOCA
373 || DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_ALLOCA_WITH_ALIGN
))
374 gimple_call_set_alloca_for_var (call
, CALL_ALLOCA_FOR_VAR_P (t
));
376 gimple_call_set_from_thunk (call
, CALL_FROM_THUNK_P (t
));
377 gimple_call_set_va_arg_pack (call
, CALL_EXPR_VA_ARG_PACK (t
));
378 gimple_call_set_nothrow (call
, TREE_NOTHROW (t
));
379 gimple_set_no_warning (call
, TREE_NO_WARNING (t
));
385 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
386 *OP1_P, *OP2_P and *OP3_P respectively. */
389 extract_ops_from_tree_1 (tree expr
, enum tree_code
*subcode_p
, tree
*op1_p
,
390 tree
*op2_p
, tree
*op3_p
)
392 enum gimple_rhs_class grhs_class
;
394 *subcode_p
= TREE_CODE (expr
);
395 grhs_class
= get_gimple_rhs_class (*subcode_p
);
397 if (grhs_class
== GIMPLE_TERNARY_RHS
)
399 *op1_p
= TREE_OPERAND (expr
, 0);
400 *op2_p
= TREE_OPERAND (expr
, 1);
401 *op3_p
= TREE_OPERAND (expr
, 2);
403 else if (grhs_class
== GIMPLE_BINARY_RHS
)
405 *op1_p
= TREE_OPERAND (expr
, 0);
406 *op2_p
= TREE_OPERAND (expr
, 1);
409 else if (grhs_class
== GIMPLE_UNARY_RHS
)
411 *op1_p
= TREE_OPERAND (expr
, 0);
415 else if (grhs_class
== GIMPLE_SINGLE_RHS
)
426 /* Build a GIMPLE_ASSIGN statement.
428 LHS of the assignment.
429 RHS of the assignment which can be unary or binary. */
432 gimple_build_assign_stat (tree lhs
, tree rhs MEM_STAT_DECL
)
434 enum tree_code subcode
;
437 extract_ops_from_tree_1 (rhs
, &subcode
, &op1
, &op2
, &op3
);
438 return gimple_build_assign_with_ops_stat (subcode
, lhs
, op1
, op2
, op3
443 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands
444 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
445 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
448 gimple_build_assign_with_ops_stat (enum tree_code subcode
, tree lhs
, tree op1
,
449 tree op2
, tree op3 MEM_STAT_DECL
)
454 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
456 num_ops
= get_gimple_rhs_num_ops (subcode
) + 1;
458 p
= gimple_build_with_ops_stat (GIMPLE_ASSIGN
, (unsigned)subcode
, num_ops
460 gimple_assign_set_lhs (p
, lhs
);
461 gimple_assign_set_rhs1 (p
, op1
);
464 gcc_assert (num_ops
> 2);
465 gimple_assign_set_rhs2 (p
, op2
);
470 gcc_assert (num_ops
> 3);
471 gimple_assign_set_rhs3 (p
, op3
);
478 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
480 DST/SRC are the destination and source respectively. You can pass
481 ungimplified trees in DST or SRC, in which case they will be
482 converted to a gimple operand if necessary.
484 This function returns the newly created GIMPLE_ASSIGN tuple. */
487 gimplify_assign (tree dst
, tree src
, gimple_seq
*seq_p
)
489 tree t
= build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
490 gimplify_and_add (t
, seq_p
);
492 return gimple_seq_last_stmt (*seq_p
);
496 /* Build a GIMPLE_COND statement.
498 PRED is the condition used to compare LHS and the RHS.
499 T_LABEL is the label to jump to if the condition is true.
500 F_LABEL is the label to jump to otherwise. */
503 gimple_build_cond (enum tree_code pred_code
, tree lhs
, tree rhs
,
504 tree t_label
, tree f_label
)
508 gcc_assert (TREE_CODE_CLASS (pred_code
) == tcc_comparison
);
509 p
= gimple_build_with_ops (GIMPLE_COND
, pred_code
, 4);
510 gimple_cond_set_lhs (p
, lhs
);
511 gimple_cond_set_rhs (p
, rhs
);
512 gimple_cond_set_true_label (p
, t_label
);
513 gimple_cond_set_false_label (p
, f_label
);
518 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
521 gimple_cond_get_ops_from_tree (tree cond
, enum tree_code
*code_p
,
522 tree
*lhs_p
, tree
*rhs_p
)
524 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond
)) == tcc_comparison
525 || TREE_CODE (cond
) == TRUTH_NOT_EXPR
526 || is_gimple_min_invariant (cond
)
527 || SSA_VAR_P (cond
));
529 extract_ops_from_tree (cond
, code_p
, lhs_p
, rhs_p
);
531 /* Canonicalize conditionals of the form 'if (!VAL)'. */
532 if (*code_p
== TRUTH_NOT_EXPR
)
535 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
536 *rhs_p
= build_zero_cst (TREE_TYPE (*lhs_p
));
538 /* Canonicalize conditionals of the form 'if (VAL)' */
539 else if (TREE_CODE_CLASS (*code_p
) != tcc_comparison
)
542 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
543 *rhs_p
= build_zero_cst (TREE_TYPE (*lhs_p
));
548 /* Build a GIMPLE_COND statement from the conditional expression tree
549 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
552 gimple_build_cond_from_tree (tree cond
, tree t_label
, tree f_label
)
557 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
558 return gimple_build_cond (code
, lhs
, rhs
, t_label
, f_label
);
561 /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
562 boolean expression tree COND. */
565 gimple_cond_set_condition_from_tree (gimple stmt
, tree cond
)
570 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
571 gimple_cond_set_condition (stmt
, code
, lhs
, rhs
);
574 /* Build a GIMPLE_LABEL statement for LABEL. */
577 gimple_build_label (tree label
)
579 gimple p
= gimple_build_with_ops (GIMPLE_LABEL
, ERROR_MARK
, 1);
580 gimple_label_set_label (p
, label
);
584 /* Build a GIMPLE_GOTO statement to label DEST. */
587 gimple_build_goto (tree dest
)
589 gimple p
= gimple_build_with_ops (GIMPLE_GOTO
, ERROR_MARK
, 1);
590 gimple_goto_set_dest (p
, dest
);
595 /* Build a GIMPLE_NOP statement. */
598 gimple_build_nop (void)
600 return gimple_alloc (GIMPLE_NOP
, 0);
604 /* Build a GIMPLE_BIND statement.
605 VARS are the variables in BODY.
606 BLOCK is the containing block. */
609 gimple_build_bind (tree vars
, gimple_seq body
, tree block
)
611 gimple p
= gimple_alloc (GIMPLE_BIND
, 0);
612 gimple_bind_set_vars (p
, vars
);
614 gimple_bind_set_body (p
, body
);
616 gimple_bind_set_block (p
, block
);
620 /* Helper function to set the simple fields of a asm stmt.
622 STRING is a pointer to a string that is the asm blocks assembly code.
623 NINPUT is the number of register inputs.
624 NOUTPUT is the number of register outputs.
625 NCLOBBERS is the number of clobbered registers.
629 gimple_build_asm_1 (const char *string
, unsigned ninputs
, unsigned noutputs
,
630 unsigned nclobbers
, unsigned nlabels
)
633 int size
= strlen (string
);
635 /* ASMs with labels cannot have outputs. This should have been
636 enforced by the front end. */
637 gcc_assert (nlabels
== 0 || noutputs
== 0);
639 p
= gimple_build_with_ops (GIMPLE_ASM
, ERROR_MARK
,
640 ninputs
+ noutputs
+ nclobbers
+ nlabels
);
642 p
->gimple_asm
.ni
= ninputs
;
643 p
->gimple_asm
.no
= noutputs
;
644 p
->gimple_asm
.nc
= nclobbers
;
645 p
->gimple_asm
.nl
= nlabels
;
646 p
->gimple_asm
.string
= ggc_alloc_string (string
, size
);
648 #ifdef GATHER_STATISTICS
649 gimple_alloc_sizes
[(int) gimple_alloc_kind (GIMPLE_ASM
)] += size
;
655 /* Build a GIMPLE_ASM statement.
657 STRING is the assembly code.
658 NINPUT is the number of register inputs.
659 NOUTPUT is the number of register outputs.
660 NCLOBBERS is the number of clobbered registers.
661 INPUTS is a vector of the input register parameters.
662 OUTPUTS is a vector of the output register parameters.
663 CLOBBERS is a vector of the clobbered register parameters.
664 LABELS is a vector of destination labels. */
667 gimple_build_asm_vec (const char *string
, VEC(tree
,gc
)* inputs
,
668 VEC(tree
,gc
)* outputs
, VEC(tree
,gc
)* clobbers
,
669 VEC(tree
,gc
)* labels
)
674 p
= gimple_build_asm_1 (string
,
675 VEC_length (tree
, inputs
),
676 VEC_length (tree
, outputs
),
677 VEC_length (tree
, clobbers
),
678 VEC_length (tree
, labels
));
680 for (i
= 0; i
< VEC_length (tree
, inputs
); i
++)
681 gimple_asm_set_input_op (p
, i
, VEC_index (tree
, inputs
, i
));
683 for (i
= 0; i
< VEC_length (tree
, outputs
); i
++)
684 gimple_asm_set_output_op (p
, i
, VEC_index (tree
, outputs
, i
));
686 for (i
= 0; i
< VEC_length (tree
, clobbers
); i
++)
687 gimple_asm_set_clobber_op (p
, i
, VEC_index (tree
, clobbers
, i
));
689 for (i
= 0; i
< VEC_length (tree
, labels
); i
++)
690 gimple_asm_set_label_op (p
, i
, VEC_index (tree
, labels
, i
));
695 /* Build a GIMPLE_CATCH statement.
697 TYPES are the catch types.
698 HANDLER is the exception handler. */
701 gimple_build_catch (tree types
, gimple_seq handler
)
703 gimple p
= gimple_alloc (GIMPLE_CATCH
, 0);
704 gimple_catch_set_types (p
, types
);
706 gimple_catch_set_handler (p
, handler
);
711 /* Build a GIMPLE_EH_FILTER statement.
713 TYPES are the filter's types.
714 FAILURE is the filter's failure action. */
717 gimple_build_eh_filter (tree types
, gimple_seq failure
)
719 gimple p
= gimple_alloc (GIMPLE_EH_FILTER
, 0);
720 gimple_eh_filter_set_types (p
, types
);
722 gimple_eh_filter_set_failure (p
, failure
);
727 /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
730 gimple_build_eh_must_not_throw (tree decl
)
732 gimple p
= gimple_alloc (GIMPLE_EH_MUST_NOT_THROW
, 0);
734 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
735 gcc_assert (flags_from_decl_or_type (decl
) & ECF_NORETURN
);
736 gimple_eh_must_not_throw_set_fndecl (p
, decl
);
741 /* Build a GIMPLE_EH_ELSE statement. */
744 gimple_build_eh_else (gimple_seq n_body
, gimple_seq e_body
)
746 gimple p
= gimple_alloc (GIMPLE_EH_ELSE
, 0);
747 gimple_eh_else_set_n_body (p
, n_body
);
748 gimple_eh_else_set_e_body (p
, e_body
);
752 /* Build a GIMPLE_TRY statement.
754 EVAL is the expression to evaluate.
755 CLEANUP is the cleanup expression.
756 KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
757 whether this is a try/catch or a try/finally respectively. */
760 gimple_build_try (gimple_seq eval
, gimple_seq cleanup
,
761 enum gimple_try_flags kind
)
765 gcc_assert (kind
== GIMPLE_TRY_CATCH
|| kind
== GIMPLE_TRY_FINALLY
);
766 p
= gimple_alloc (GIMPLE_TRY
, 0);
767 gimple_set_subcode (p
, kind
);
769 gimple_try_set_eval (p
, eval
);
771 gimple_try_set_cleanup (p
, cleanup
);
776 /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
778 CLEANUP is the cleanup expression. */
781 gimple_build_wce (gimple_seq cleanup
)
783 gimple p
= gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR
, 0);
785 gimple_wce_set_cleanup (p
, cleanup
);
791 /* Build a GIMPLE_RESX statement. */
794 gimple_build_resx (int region
)
796 gimple p
= gimple_build_with_ops (GIMPLE_RESX
, ERROR_MARK
, 0);
797 p
->gimple_eh_ctrl
.region
= region
;
802 /* The helper for constructing a gimple switch statement.
803 INDEX is the switch's index.
804 NLABELS is the number of labels in the switch excluding the default.
805 DEFAULT_LABEL is the default label for the switch statement. */
808 gimple_build_switch_nlabels (unsigned nlabels
, tree index
, tree default_label
)
810 /* nlabels + 1 default label + 1 index. */
811 gimple p
= gimple_build_with_ops (GIMPLE_SWITCH
, ERROR_MARK
,
812 1 + (default_label
!= NULL
) + nlabels
);
813 gimple_switch_set_index (p
, index
);
815 gimple_switch_set_default_label (p
, default_label
);
820 /* Build a GIMPLE_SWITCH statement.
822 INDEX is the switch's index.
823 NLABELS is the number of labels in the switch excluding the DEFAULT_LABEL.
824 ... are the labels excluding the default. */
827 gimple_build_switch (unsigned nlabels
, tree index
, tree default_label
, ...)
831 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
833 /* Store the rest of the labels. */
834 va_start (al
, default_label
);
835 offset
= (default_label
!= NULL
);
836 for (i
= 0; i
< nlabels
; i
++)
837 gimple_switch_set_label (p
, i
+ offset
, va_arg (al
, tree
));
844 /* Build a GIMPLE_SWITCH statement.
846 INDEX is the switch's index.
847 DEFAULT_LABEL is the default label
848 ARGS is a vector of labels excluding the default. */
851 gimple_build_switch_vec (tree index
, tree default_label
, VEC(tree
, heap
) *args
)
853 unsigned i
, offset
, nlabels
= VEC_length (tree
, args
);
854 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
856 /* Copy the labels from the vector to the switch statement. */
857 offset
= (default_label
!= NULL
);
858 for (i
= 0; i
< nlabels
; i
++)
859 gimple_switch_set_label (p
, i
+ offset
, VEC_index (tree
, args
, i
));
864 /* Build a GIMPLE_EH_DISPATCH statement. */
867 gimple_build_eh_dispatch (int region
)
869 gimple p
= gimple_build_with_ops (GIMPLE_EH_DISPATCH
, ERROR_MARK
, 0);
870 p
->gimple_eh_ctrl
.region
= region
;
874 /* Build a new GIMPLE_DEBUG_BIND statement.
876 VAR is bound to VALUE; block and location are taken from STMT. */
879 gimple_build_debug_bind_stat (tree var
, tree value
, gimple stmt MEM_STAT_DECL
)
881 gimple p
= gimple_build_with_ops_stat (GIMPLE_DEBUG
,
882 (unsigned)GIMPLE_DEBUG_BIND
, 2
885 gimple_debug_bind_set_var (p
, var
);
886 gimple_debug_bind_set_value (p
, value
);
889 gimple_set_block (p
, gimple_block (stmt
));
890 gimple_set_location (p
, gimple_location (stmt
));
897 /* Build a new GIMPLE_DEBUG_SOURCE_BIND statement.
899 VAR is bound to VALUE; block and location are taken from STMT. */
902 gimple_build_debug_source_bind_stat (tree var
, tree value
,
903 gimple stmt MEM_STAT_DECL
)
905 gimple p
= gimple_build_with_ops_stat (GIMPLE_DEBUG
,
906 (unsigned)GIMPLE_DEBUG_SOURCE_BIND
, 2
909 gimple_debug_source_bind_set_var (p
, var
);
910 gimple_debug_source_bind_set_value (p
, value
);
913 gimple_set_block (p
, gimple_block (stmt
));
914 gimple_set_location (p
, gimple_location (stmt
));
921 /* Build a GIMPLE_OMP_CRITICAL statement.
923 BODY is the sequence of statements for which only one thread can execute.
924 NAME is optional identifier for this critical block. */
927 gimple_build_omp_critical (gimple_seq body
, tree name
)
929 gimple p
= gimple_alloc (GIMPLE_OMP_CRITICAL
, 0);
930 gimple_omp_critical_set_name (p
, name
);
932 gimple_omp_set_body (p
, body
);
937 /* Build a GIMPLE_OMP_FOR statement.
939 BODY is sequence of statements inside the for loop.
940 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate,
941 lastprivate, reductions, ordered, schedule, and nowait.
942 COLLAPSE is the collapse count.
943 PRE_BODY is the sequence of statements that are loop invariant. */
946 gimple_build_omp_for (gimple_seq body
, tree clauses
, size_t collapse
,
949 gimple p
= gimple_alloc (GIMPLE_OMP_FOR
, 0);
951 gimple_omp_set_body (p
, body
);
952 gimple_omp_for_set_clauses (p
, clauses
);
953 p
->gimple_omp_for
.collapse
= collapse
;
954 p
->gimple_omp_for
.iter
955 = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse
);
957 gimple_omp_for_set_pre_body (p
, pre_body
);
963 /* Build a GIMPLE_OMP_PARALLEL statement.
965 BODY is sequence of statements which are executed in parallel.
966 CLAUSES, are the OMP parallel construct's clauses.
967 CHILD_FN is the function created for the parallel threads to execute.
968 DATA_ARG are the shared data argument(s). */
971 gimple_build_omp_parallel (gimple_seq body
, tree clauses
, tree child_fn
,
974 gimple p
= gimple_alloc (GIMPLE_OMP_PARALLEL
, 0);
976 gimple_omp_set_body (p
, body
);
977 gimple_omp_parallel_set_clauses (p
, clauses
);
978 gimple_omp_parallel_set_child_fn (p
, child_fn
);
979 gimple_omp_parallel_set_data_arg (p
, data_arg
);
985 /* Build a GIMPLE_OMP_TASK statement.
987 BODY is sequence of statements which are executed by the explicit task.
988 CLAUSES, are the OMP parallel construct's clauses.
989 CHILD_FN is the function created for the parallel threads to execute.
990 DATA_ARG are the shared data argument(s).
991 COPY_FN is the optional function for firstprivate initialization.
992 ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
995 gimple_build_omp_task (gimple_seq body
, tree clauses
, tree child_fn
,
996 tree data_arg
, tree copy_fn
, tree arg_size
,
999 gimple p
= gimple_alloc (GIMPLE_OMP_TASK
, 0);
1001 gimple_omp_set_body (p
, body
);
1002 gimple_omp_task_set_clauses (p
, clauses
);
1003 gimple_omp_task_set_child_fn (p
, child_fn
);
1004 gimple_omp_task_set_data_arg (p
, data_arg
);
1005 gimple_omp_task_set_copy_fn (p
, copy_fn
);
1006 gimple_omp_task_set_arg_size (p
, arg_size
);
1007 gimple_omp_task_set_arg_align (p
, arg_align
);
1013 /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
1015 BODY is the sequence of statements in the section. */
1018 gimple_build_omp_section (gimple_seq body
)
1020 gimple p
= gimple_alloc (GIMPLE_OMP_SECTION
, 0);
1022 gimple_omp_set_body (p
, body
);
1028 /* Build a GIMPLE_OMP_MASTER statement.
1030 BODY is the sequence of statements to be executed by just the master. */
1033 gimple_build_omp_master (gimple_seq body
)
1035 gimple p
= gimple_alloc (GIMPLE_OMP_MASTER
, 0);
1037 gimple_omp_set_body (p
, body
);
1043 /* Build a GIMPLE_OMP_CONTINUE statement.
1045 CONTROL_DEF is the definition of the control variable.
1046 CONTROL_USE is the use of the control variable. */
1049 gimple_build_omp_continue (tree control_def
, tree control_use
)
1051 gimple p
= gimple_alloc (GIMPLE_OMP_CONTINUE
, 0);
1052 gimple_omp_continue_set_control_def (p
, control_def
);
1053 gimple_omp_continue_set_control_use (p
, control_use
);
1057 /* Build a GIMPLE_OMP_ORDERED statement.
1059 BODY is the sequence of statements inside a loop that will executed in
1063 gimple_build_omp_ordered (gimple_seq body
)
1065 gimple p
= gimple_alloc (GIMPLE_OMP_ORDERED
, 0);
1067 gimple_omp_set_body (p
, body
);
1073 /* Build a GIMPLE_OMP_RETURN statement.
1074 WAIT_P is true if this is a non-waiting return. */
1077 gimple_build_omp_return (bool wait_p
)
1079 gimple p
= gimple_alloc (GIMPLE_OMP_RETURN
, 0);
1081 gimple_omp_return_set_nowait (p
);
1087 /* Build a GIMPLE_OMP_SECTIONS statement.
1089 BODY is a sequence of section statements.
1090 CLAUSES are any of the OMP sections contsruct's clauses: private,
1091 firstprivate, lastprivate, reduction, and nowait. */
1094 gimple_build_omp_sections (gimple_seq body
, tree clauses
)
1096 gimple p
= gimple_alloc (GIMPLE_OMP_SECTIONS
, 0);
1098 gimple_omp_set_body (p
, body
);
1099 gimple_omp_sections_set_clauses (p
, clauses
);
1105 /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
1108 gimple_build_omp_sections_switch (void)
1110 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH
, 0);
1114 /* Build a GIMPLE_OMP_SINGLE statement.
1116 BODY is the sequence of statements that will be executed once.
1117 CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
1118 copyprivate, nowait. */
1121 gimple_build_omp_single (gimple_seq body
, tree clauses
)
1123 gimple p
= gimple_alloc (GIMPLE_OMP_SINGLE
, 0);
1125 gimple_omp_set_body (p
, body
);
1126 gimple_omp_single_set_clauses (p
, clauses
);
1132 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1135 gimple_build_omp_atomic_load (tree lhs
, tree rhs
)
1137 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD
, 0);
1138 gimple_omp_atomic_load_set_lhs (p
, lhs
);
1139 gimple_omp_atomic_load_set_rhs (p
, rhs
);
1143 /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1145 VAL is the value we are storing. */
1148 gimple_build_omp_atomic_store (tree val
)
1150 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_STORE
, 0);
1151 gimple_omp_atomic_store_set_val (p
, val
);
1155 /* Build a GIMPLE_TRANSACTION statement. */
1158 gimple_build_transaction (gimple_seq body
, tree label
)
1160 gimple p
= gimple_alloc (GIMPLE_TRANSACTION
, 0);
1161 gimple_transaction_set_body (p
, body
);
1162 gimple_transaction_set_label (p
, label
);
1166 /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
1167 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
1170 gimple_build_predict (enum br_predictor predictor
, enum prediction outcome
)
1172 gimple p
= gimple_alloc (GIMPLE_PREDICT
, 0);
1173 /* Ensure all the predictors fit into the lower bits of the subcode. */
1174 gcc_assert ((int) END_PREDICTORS
<= GF_PREDICT_TAKEN
);
1175 gimple_predict_set_predictor (p
, predictor
);
1176 gimple_predict_set_outcome (p
, outcome
);
1180 #if defined ENABLE_GIMPLE_CHECKING
1181 /* Complain of a gimple type mismatch and die. */
1184 gimple_check_failed (const_gimple gs
, const char *file
, int line
,
1185 const char *function
, enum gimple_code code
,
1186 enum tree_code subcode
)
1188 internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1189 gimple_code_name
[code
],
1190 tree_code_name
[subcode
],
1191 gimple_code_name
[gimple_code (gs
)],
1192 gs
->gsbase
.subcode
> 0
1193 ? tree_code_name
[gs
->gsbase
.subcode
]
1195 function
, trim_filename (file
), line
);
1197 #endif /* ENABLE_GIMPLE_CHECKING */
1200 /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1201 *SEQ_P is NULL, a new sequence is allocated. */
1204 gimple_seq_add_stmt (gimple_seq
*seq_p
, gimple gs
)
1206 gimple_stmt_iterator si
;
1210 si
= gsi_last (*seq_p
);
1211 gsi_insert_after (&si
, gs
, GSI_NEW_STMT
);
1215 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1216 NULL, a new sequence is allocated. */
1219 gimple_seq_add_seq (gimple_seq
*dst_p
, gimple_seq src
)
1221 gimple_stmt_iterator si
;
1225 si
= gsi_last (*dst_p
);
1226 gsi_insert_seq_after (&si
, src
, GSI_NEW_STMT
);
1230 /* Helper function of empty_body_p. Return true if STMT is an empty
1234 empty_stmt_p (gimple stmt
)
1236 if (gimple_code (stmt
) == GIMPLE_NOP
)
1238 if (gimple_code (stmt
) == GIMPLE_BIND
)
1239 return empty_body_p (gimple_bind_body (stmt
));
1244 /* Return true if BODY contains nothing but empty statements. */
1247 empty_body_p (gimple_seq body
)
1249 gimple_stmt_iterator i
;
1251 if (gimple_seq_empty_p (body
))
1253 for (i
= gsi_start (body
); !gsi_end_p (i
); gsi_next (&i
))
1254 if (!empty_stmt_p (gsi_stmt (i
))
1255 && !is_gimple_debug (gsi_stmt (i
)))
1262 /* Perform a deep copy of sequence SRC and return the result. */
1265 gimple_seq_copy (gimple_seq src
)
1267 gimple_stmt_iterator gsi
;
1268 gimple_seq new_seq
= NULL
;
1271 for (gsi
= gsi_start (src
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1273 stmt
= gimple_copy (gsi_stmt (gsi
));
1274 gimple_seq_add_stmt (&new_seq
, stmt
);
1281 /* Walk all the statements in the sequence *PSEQ calling walk_gimple_stmt
1282 on each one. WI is as in walk_gimple_stmt.
1284 If walk_gimple_stmt returns non-NULL, the walk is stopped, and the
1285 value is stored in WI->CALLBACK_RESULT. Also, the statement that
1286 produced the value is returned if this statement has not been
1287 removed by a callback (wi->removed_stmt). If the statement has
1288 been removed, NULL is returned.
1290 Otherwise, all the statements are walked and NULL returned. */
1293 walk_gimple_seq_mod (gimple_seq
*pseq
, walk_stmt_fn callback_stmt
,
1294 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1296 gimple_stmt_iterator gsi
;
1298 for (gsi
= gsi_start (*pseq
); !gsi_end_p (gsi
); )
1300 tree ret
= walk_gimple_stmt (&gsi
, callback_stmt
, callback_op
, wi
);
1303 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
1306 wi
->callback_result
= ret
;
1308 return wi
->removed_stmt
? NULL
: gsi_stmt (gsi
);
1311 if (!wi
->removed_stmt
)
1316 wi
->callback_result
= NULL_TREE
;
1322 /* Like walk_gimple_seq_mod, but ensure that the head of SEQ isn't
1323 changed by the callbacks. */
1326 walk_gimple_seq (gimple_seq seq
, walk_stmt_fn callback_stmt
,
1327 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1329 gimple_seq seq2
= seq
;
1330 gimple ret
= walk_gimple_seq_mod (&seq2
, callback_stmt
, callback_op
, wi
);
1331 gcc_assert (seq2
== seq
);
1336 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
1339 walk_gimple_asm (gimple stmt
, walk_tree_fn callback_op
,
1340 struct walk_stmt_info
*wi
)
1344 const char **oconstraints
;
1346 const char *constraint
;
1347 bool allows_mem
, allows_reg
, is_inout
;
1349 noutputs
= gimple_asm_noutputs (stmt
);
1350 oconstraints
= (const char **) alloca ((noutputs
) * sizeof (const char *));
1355 for (i
= 0; i
< noutputs
; i
++)
1357 op
= gimple_asm_output_op (stmt
, i
);
1358 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1359 oconstraints
[i
] = constraint
;
1360 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
, &allows_reg
,
1363 wi
->val_only
= (allows_reg
|| !allows_mem
);
1364 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1369 n
= gimple_asm_ninputs (stmt
);
1370 for (i
= 0; i
< n
; i
++)
1372 op
= gimple_asm_input_op (stmt
, i
);
1373 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1374 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
1375 oconstraints
, &allows_mem
, &allows_reg
);
1378 wi
->val_only
= (allows_reg
|| !allows_mem
);
1379 /* Although input "m" is not really a LHS, we need a lvalue. */
1380 wi
->is_lhs
= !wi
->val_only
;
1382 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1390 wi
->val_only
= true;
1393 n
= gimple_asm_nlabels (stmt
);
1394 for (i
= 0; i
< n
; i
++)
1396 op
= gimple_asm_label_op (stmt
, i
);
1397 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1406 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
1407 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
1409 CALLBACK_OP is called on each operand of STMT via walk_tree.
1410 Additional parameters to walk_tree must be stored in WI. For each operand
1411 OP, walk_tree is called as:
1413 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
1415 If CALLBACK_OP returns non-NULL for an operand, the remaining
1416 operands are not scanned.
1418 The return value is that returned by the last call to walk_tree, or
1419 NULL_TREE if no CALLBACK_OP is specified. */
1422 walk_gimple_op (gimple stmt
, walk_tree_fn callback_op
,
1423 struct walk_stmt_info
*wi
)
1425 struct pointer_set_t
*pset
= (wi
) ? wi
->pset
: NULL
;
1427 tree ret
= NULL_TREE
;
1429 switch (gimple_code (stmt
))
1432 /* Walk the RHS operands. If the LHS is of a non-renamable type or
1433 is a register variable, we may use a COMPONENT_REF on the RHS. */
1436 tree lhs
= gimple_assign_lhs (stmt
);
1438 = (is_gimple_reg_type (TREE_TYPE (lhs
)) && !is_gimple_reg (lhs
))
1439 || gimple_assign_rhs_class (stmt
) != GIMPLE_SINGLE_RHS
;
1442 for (i
= 1; i
< gimple_num_ops (stmt
); i
++)
1444 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
,
1450 /* Walk the LHS. If the RHS is appropriate for a memory, we
1451 may use a COMPONENT_REF on the LHS. */
1454 /* If the RHS is of a non-renamable type or is a register variable,
1455 we may use a COMPONENT_REF on the LHS. */
1456 tree rhs1
= gimple_assign_rhs1 (stmt
);
1458 = (is_gimple_reg_type (TREE_TYPE (rhs1
)) && !is_gimple_reg (rhs1
))
1459 || gimple_assign_rhs_class (stmt
) != GIMPLE_SINGLE_RHS
;
1463 ret
= walk_tree (gimple_op_ptr (stmt
, 0), callback_op
, wi
, pset
);
1469 wi
->val_only
= true;
1478 wi
->val_only
= true;
1481 ret
= walk_tree (gimple_call_chain_ptr (stmt
), callback_op
, wi
, pset
);
1485 ret
= walk_tree (gimple_call_fn_ptr (stmt
), callback_op
, wi
, pset
);
1489 for (i
= 0; i
< gimple_call_num_args (stmt
); i
++)
1493 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt
, i
)));
1494 ret
= walk_tree (gimple_call_arg_ptr (stmt
, i
), callback_op
, wi
,
1500 if (gimple_call_lhs (stmt
))
1506 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt
)));
1509 ret
= walk_tree (gimple_call_lhs_ptr (stmt
), callback_op
, wi
, pset
);
1517 wi
->val_only
= true;
1522 ret
= walk_tree (gimple_catch_types_ptr (stmt
), callback_op
, wi
,
1528 case GIMPLE_EH_FILTER
:
1529 ret
= walk_tree (gimple_eh_filter_types_ptr (stmt
), callback_op
, wi
,
1536 ret
= walk_gimple_asm (stmt
, callback_op
, wi
);
1541 case GIMPLE_OMP_CONTINUE
:
1542 ret
= walk_tree (gimple_omp_continue_control_def_ptr (stmt
),
1543 callback_op
, wi
, pset
);
1547 ret
= walk_tree (gimple_omp_continue_control_use_ptr (stmt
),
1548 callback_op
, wi
, pset
);
1553 case GIMPLE_OMP_CRITICAL
:
1554 ret
= walk_tree (gimple_omp_critical_name_ptr (stmt
), callback_op
, wi
,
1560 case GIMPLE_OMP_FOR
:
1561 ret
= walk_tree (gimple_omp_for_clauses_ptr (stmt
), callback_op
, wi
,
1565 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
1567 ret
= walk_tree (gimple_omp_for_index_ptr (stmt
, i
), callback_op
,
1571 ret
= walk_tree (gimple_omp_for_initial_ptr (stmt
, i
), callback_op
,
1575 ret
= walk_tree (gimple_omp_for_final_ptr (stmt
, i
), callback_op
,
1579 ret
= walk_tree (gimple_omp_for_incr_ptr (stmt
, i
), callback_op
,
1586 case GIMPLE_OMP_PARALLEL
:
1587 ret
= walk_tree (gimple_omp_parallel_clauses_ptr (stmt
), callback_op
,
1591 ret
= walk_tree (gimple_omp_parallel_child_fn_ptr (stmt
), callback_op
,
1595 ret
= walk_tree (gimple_omp_parallel_data_arg_ptr (stmt
), callback_op
,
1601 case GIMPLE_OMP_TASK
:
1602 ret
= walk_tree (gimple_omp_task_clauses_ptr (stmt
), callback_op
,
1606 ret
= walk_tree (gimple_omp_task_child_fn_ptr (stmt
), callback_op
,
1610 ret
= walk_tree (gimple_omp_task_data_arg_ptr (stmt
), callback_op
,
1614 ret
= walk_tree (gimple_omp_task_copy_fn_ptr (stmt
), callback_op
,
1618 ret
= walk_tree (gimple_omp_task_arg_size_ptr (stmt
), callback_op
,
1622 ret
= walk_tree (gimple_omp_task_arg_align_ptr (stmt
), callback_op
,
1628 case GIMPLE_OMP_SECTIONS
:
1629 ret
= walk_tree (gimple_omp_sections_clauses_ptr (stmt
), callback_op
,
1634 ret
= walk_tree (gimple_omp_sections_control_ptr (stmt
), callback_op
,
1641 case GIMPLE_OMP_SINGLE
:
1642 ret
= walk_tree (gimple_omp_single_clauses_ptr (stmt
), callback_op
, wi
,
1648 case GIMPLE_OMP_ATOMIC_LOAD
:
1649 ret
= walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt
), callback_op
, wi
,
1654 ret
= walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt
), callback_op
, wi
,
1660 case GIMPLE_OMP_ATOMIC_STORE
:
1661 ret
= walk_tree (gimple_omp_atomic_store_val_ptr (stmt
), callback_op
,
1667 case GIMPLE_TRANSACTION
:
1668 ret
= walk_tree (gimple_transaction_label_ptr (stmt
), callback_op
,
1674 /* Tuples that do not have operands. */
1677 case GIMPLE_OMP_RETURN
:
1678 case GIMPLE_PREDICT
:
1683 enum gimple_statement_structure_enum gss
;
1684 gss
= gimple_statement_structure (stmt
);
1685 if (gss
== GSS_WITH_OPS
|| gss
== GSS_WITH_MEM_OPS
)
1686 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
1688 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
, pset
);
1700 /* Walk the current statement in GSI (optionally using traversal state
1701 stored in WI). If WI is NULL, no state is kept during traversal.
1702 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
1703 that it has handled all the operands of the statement, its return
1704 value is returned. Otherwise, the return value from CALLBACK_STMT
1705 is discarded and its operands are scanned.
1707 If CALLBACK_STMT is NULL or it didn't handle the operands,
1708 CALLBACK_OP is called on each operand of the statement via
1709 walk_gimple_op. If walk_gimple_op returns non-NULL for any
1710 operand, the remaining operands are not scanned. In this case, the
1711 return value from CALLBACK_OP is returned.
1713 In any other case, NULL_TREE is returned. */
1716 walk_gimple_stmt (gimple_stmt_iterator
*gsi
, walk_stmt_fn callback_stmt
,
1717 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1721 gimple stmt
= gsi_stmt (*gsi
);
1726 wi
->removed_stmt
= false;
1728 if (wi
->want_locations
&& gimple_has_location (stmt
))
1729 input_location
= gimple_location (stmt
);
1734 /* Invoke the statement callback. Return if the callback handled
1735 all of STMT operands by itself. */
1738 bool handled_ops
= false;
1739 tree_ret
= callback_stmt (gsi
, &handled_ops
, wi
);
1743 /* If CALLBACK_STMT did not handle operands, it should not have
1744 a value to return. */
1745 gcc_assert (tree_ret
== NULL
);
1747 if (wi
&& wi
->removed_stmt
)
1750 /* Re-read stmt in case the callback changed it. */
1751 stmt
= gsi_stmt (*gsi
);
1754 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
1757 tree_ret
= walk_gimple_op (stmt
, callback_op
, wi
);
1762 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
1763 switch (gimple_code (stmt
))
1766 ret
= walk_gimple_seq_mod (gimple_bind_body_ptr (stmt
), callback_stmt
,
1769 return wi
->callback_result
;
1773 ret
= walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt
), callback_stmt
,
1776 return wi
->callback_result
;
1779 case GIMPLE_EH_FILTER
:
1780 ret
= walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt
), callback_stmt
,
1783 return wi
->callback_result
;
1786 case GIMPLE_EH_ELSE
:
1787 ret
= walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (stmt
),
1788 callback_stmt
, callback_op
, wi
);
1790 return wi
->callback_result
;
1791 ret
= walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (stmt
),
1792 callback_stmt
, callback_op
, wi
);
1794 return wi
->callback_result
;
1798 ret
= walk_gimple_seq_mod (gimple_try_eval_ptr (stmt
), callback_stmt
, callback_op
,
1801 return wi
->callback_result
;
1803 ret
= walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt
), callback_stmt
,
1806 return wi
->callback_result
;
1809 case GIMPLE_OMP_FOR
:
1810 ret
= walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt
), callback_stmt
,
1813 return wi
->callback_result
;
1816 case GIMPLE_OMP_CRITICAL
:
1817 case GIMPLE_OMP_MASTER
:
1818 case GIMPLE_OMP_ORDERED
:
1819 case GIMPLE_OMP_SECTION
:
1820 case GIMPLE_OMP_PARALLEL
:
1821 case GIMPLE_OMP_TASK
:
1822 case GIMPLE_OMP_SECTIONS
:
1823 case GIMPLE_OMP_SINGLE
:
1824 ret
= walk_gimple_seq_mod (gimple_omp_body_ptr (stmt
), callback_stmt
,
1827 return wi
->callback_result
;
1830 case GIMPLE_WITH_CLEANUP_EXPR
:
1831 ret
= walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt
), callback_stmt
,
1834 return wi
->callback_result
;
1837 case GIMPLE_TRANSACTION
:
1838 ret
= walk_gimple_seq_mod (gimple_transaction_body_ptr (stmt
),
1839 callback_stmt
, callback_op
, wi
);
1841 return wi
->callback_result
;
1845 gcc_assert (!gimple_has_substatements (stmt
));
1853 /* Set sequence SEQ to be the GIMPLE body for function FN. */
1856 gimple_set_body (tree fndecl
, gimple_seq seq
)
1858 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1861 /* If FNDECL still does not have a function structure associated
1862 with it, then it does not make sense for it to receive a
1864 gcc_assert (seq
== NULL
);
1867 fn
->gimple_body
= seq
;
1871 /* Return the body of GIMPLE statements for function FN. After the
1872 CFG pass, the function body doesn't exist anymore because it has
1873 been split up into basic blocks. In this case, it returns
1877 gimple_body (tree fndecl
)
1879 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1880 return fn
? fn
->gimple_body
: NULL
;
1883 /* Return true when FNDECL has Gimple body either in unlowered
1886 gimple_has_body_p (tree fndecl
)
1888 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1889 return (gimple_body (fndecl
) || (fn
&& fn
->cfg
));
1892 /* Return true if calls C1 and C2 are known to go to the same function. */
1895 gimple_call_same_target_p (const_gimple c1
, const_gimple c2
)
1897 if (gimple_call_internal_p (c1
))
1898 return (gimple_call_internal_p (c2
)
1899 && gimple_call_internal_fn (c1
) == gimple_call_internal_fn (c2
));
1901 return (gimple_call_fn (c1
) == gimple_call_fn (c2
)
1902 || (gimple_call_fndecl (c1
)
1903 && gimple_call_fndecl (c1
) == gimple_call_fndecl (c2
)));
1906 /* Detect flags from a GIMPLE_CALL. This is just like
1907 call_expr_flags, but for gimple tuples. */
1910 gimple_call_flags (const_gimple stmt
)
1913 tree decl
= gimple_call_fndecl (stmt
);
1916 flags
= flags_from_decl_or_type (decl
);
1917 else if (gimple_call_internal_p (stmt
))
1918 flags
= internal_fn_flags (gimple_call_internal_fn (stmt
));
1920 flags
= flags_from_decl_or_type (gimple_call_fntype (stmt
));
1922 if (stmt
->gsbase
.subcode
& GF_CALL_NOTHROW
)
1923 flags
|= ECF_NOTHROW
;
1928 /* Return the "fn spec" string for call STMT. */
1931 gimple_call_fnspec (const_gimple stmt
)
1935 type
= gimple_call_fntype (stmt
);
1939 attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
1943 return TREE_VALUE (TREE_VALUE (attr
));
1946 /* Detects argument flags for argument number ARG on call STMT. */
1949 gimple_call_arg_flags (const_gimple stmt
, unsigned arg
)
1951 tree attr
= gimple_call_fnspec (stmt
);
1953 if (!attr
|| 1 + arg
>= (unsigned) TREE_STRING_LENGTH (attr
))
1956 switch (TREE_STRING_POINTER (attr
)[1 + arg
])
1963 return EAF_DIRECT
| EAF_NOCLOBBER
| EAF_NOESCAPE
;
1966 return EAF_NOCLOBBER
| EAF_NOESCAPE
;
1969 return EAF_DIRECT
| EAF_NOESCAPE
;
1972 return EAF_NOESCAPE
;
1980 /* Detects return flags for the call STMT. */
1983 gimple_call_return_flags (const_gimple stmt
)
1987 if (gimple_call_flags (stmt
) & ECF_MALLOC
)
1990 attr
= gimple_call_fnspec (stmt
);
1991 if (!attr
|| TREE_STRING_LENGTH (attr
) < 1)
1994 switch (TREE_STRING_POINTER (attr
)[0])
2000 return ERF_RETURNS_ARG
| (TREE_STRING_POINTER (attr
)[0] - '1');
2012 /* Return true if GS is a copy assignment. */
2015 gimple_assign_copy_p (gimple gs
)
2017 return (gimple_assign_single_p (gs
)
2018 && is_gimple_val (gimple_op (gs
, 1)));
2022 /* Return true if GS is a SSA_NAME copy assignment. */
2025 gimple_assign_ssa_name_copy_p (gimple gs
)
2027 return (gimple_assign_single_p (gs
)
2028 && TREE_CODE (gimple_assign_lhs (gs
)) == SSA_NAME
2029 && TREE_CODE (gimple_assign_rhs1 (gs
)) == SSA_NAME
);
2033 /* Return true if GS is an assignment with a unary RHS, but the
2034 operator has no effect on the assigned value. The logic is adapted
2035 from STRIP_NOPS. This predicate is intended to be used in tuplifying
2036 instances in which STRIP_NOPS was previously applied to the RHS of
2039 NOTE: In the use cases that led to the creation of this function
2040 and of gimple_assign_single_p, it is typical to test for either
2041 condition and to proceed in the same manner. In each case, the
2042 assigned value is represented by the single RHS operand of the
2043 assignment. I suspect there may be cases where gimple_assign_copy_p,
2044 gimple_assign_single_p, or equivalent logic is used where a similar
2045 treatment of unary NOPs is appropriate. */
2048 gimple_assign_unary_nop_p (gimple gs
)
2050 return (is_gimple_assign (gs
)
2051 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs
))
2052 || gimple_assign_rhs_code (gs
) == NON_LVALUE_EXPR
)
2053 && gimple_assign_rhs1 (gs
) != error_mark_node
2054 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs
)))
2055 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs
)))));
2058 /* Set BB to be the basic block holding G. */
2061 gimple_set_bb (gimple stmt
, basic_block bb
)
2063 stmt
->gsbase
.bb
= bb
;
2065 /* If the statement is a label, add the label to block-to-labels map
2066 so that we can speed up edge creation for GIMPLE_GOTOs. */
2067 if (cfun
->cfg
&& gimple_code (stmt
) == GIMPLE_LABEL
)
2072 t
= gimple_label_label (stmt
);
2073 uid
= LABEL_DECL_UID (t
);
2076 unsigned old_len
= VEC_length (basic_block
, label_to_block_map
);
2077 LABEL_DECL_UID (t
) = uid
= cfun
->cfg
->last_label_uid
++;
2078 if (old_len
<= (unsigned) uid
)
2080 unsigned new_len
= 3 * uid
/ 2 + 1;
2082 VEC_safe_grow_cleared (basic_block
, gc
, label_to_block_map
,
2087 VEC_replace (basic_block
, label_to_block_map
, uid
, bb
);
2092 /* Modify the RHS of the assignment pointed-to by GSI using the
2093 operands in the expression tree EXPR.
2095 NOTE: The statement pointed-to by GSI may be reallocated if it
2096 did not have enough operand slots.
2098 This function is useful to convert an existing tree expression into
2099 the flat representation used for the RHS of a GIMPLE assignment.
2100 It will reallocate memory as needed to expand or shrink the number
2101 of operand slots needed to represent EXPR.
2103 NOTE: If you find yourself building a tree and then calling this
2104 function, you are most certainly doing it the slow way. It is much
2105 better to build a new assignment or to use the function
2106 gimple_assign_set_rhs_with_ops, which does not require an
2107 expression tree to be built. */
2110 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator
*gsi
, tree expr
)
2112 enum tree_code subcode
;
2115 extract_ops_from_tree_1 (expr
, &subcode
, &op1
, &op2
, &op3
);
2116 gimple_assign_set_rhs_with_ops_1 (gsi
, subcode
, op1
, op2
, op3
);
2120 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
2121 operands OP1, OP2 and OP3.
2123 NOTE: The statement pointed-to by GSI may be reallocated if it
2124 did not have enough operand slots. */
2127 gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator
*gsi
, enum tree_code code
,
2128 tree op1
, tree op2
, tree op3
)
2130 unsigned new_rhs_ops
= get_gimple_rhs_num_ops (code
);
2131 gimple stmt
= gsi_stmt (*gsi
);
2133 /* If the new CODE needs more operands, allocate a new statement. */
2134 if (gimple_num_ops (stmt
) < new_rhs_ops
+ 1)
2136 tree lhs
= gimple_assign_lhs (stmt
);
2137 gimple new_stmt
= gimple_alloc (gimple_code (stmt
), new_rhs_ops
+ 1);
2138 memcpy (new_stmt
, stmt
, gimple_size (gimple_code (stmt
)));
2139 gimple_init_singleton (new_stmt
);
2140 gsi_replace (gsi
, new_stmt
, true);
2143 /* The LHS needs to be reset as this also changes the SSA name
2145 gimple_assign_set_lhs (stmt
, lhs
);
2148 gimple_set_num_ops (stmt
, new_rhs_ops
+ 1);
2149 gimple_set_subcode (stmt
, code
);
2150 gimple_assign_set_rhs1 (stmt
, op1
);
2151 if (new_rhs_ops
> 1)
2152 gimple_assign_set_rhs2 (stmt
, op2
);
2153 if (new_rhs_ops
> 2)
2154 gimple_assign_set_rhs3 (stmt
, op3
);
2158 /* Return the LHS of a statement that performs an assignment,
2159 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2160 for a call to a function that returns no value, or for a
2161 statement other than an assignment or a call. */
2164 gimple_get_lhs (const_gimple stmt
)
2166 enum gimple_code code
= gimple_code (stmt
);
2168 if (code
== GIMPLE_ASSIGN
)
2169 return gimple_assign_lhs (stmt
);
2170 else if (code
== GIMPLE_CALL
)
2171 return gimple_call_lhs (stmt
);
2177 /* Set the LHS of a statement that performs an assignment,
2178 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2181 gimple_set_lhs (gimple stmt
, tree lhs
)
2183 enum gimple_code code
= gimple_code (stmt
);
2185 if (code
== GIMPLE_ASSIGN
)
2186 gimple_assign_set_lhs (stmt
, lhs
);
2187 else if (code
== GIMPLE_CALL
)
2188 gimple_call_set_lhs (stmt
, lhs
);
2193 /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
2194 GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
2195 expression with a different value.
2197 This will update any annotations (say debug bind stmts) referring
2198 to the original LHS, so that they use the RHS instead. This is
2199 done even if NLHS and LHS are the same, for it is understood that
2200 the RHS will be modified afterwards, and NLHS will not be assigned
2201 an equivalent value.
2203 Adjusting any non-annotation uses of the LHS, if needed, is a
2204 responsibility of the caller.
2206 The effect of this call should be pretty much the same as that of
2207 inserting a copy of STMT before STMT, and then removing the
2208 original stmt, at which time gsi_remove() would have update
2209 annotations, but using this function saves all the inserting,
2210 copying and removing. */
2213 gimple_replace_lhs (gimple stmt
, tree nlhs
)
2215 if (MAY_HAVE_DEBUG_STMTS
)
2217 tree lhs
= gimple_get_lhs (stmt
);
2219 gcc_assert (SSA_NAME_DEF_STMT (lhs
) == stmt
);
2221 insert_debug_temp_for_var_def (NULL
, lhs
);
2224 gimple_set_lhs (stmt
, nlhs
);
2227 /* Return a deep copy of statement STMT. All the operands from STMT
2228 are reallocated and copied using unshare_expr. The DEF, USE, VDEF
2229 and VUSE operand arrays are set to empty in the new copy. The new
2230 copy isn't part of any sequence. */
2233 gimple_copy (gimple stmt
)
2235 enum gimple_code code
= gimple_code (stmt
);
2236 unsigned num_ops
= gimple_num_ops (stmt
);
2237 gimple copy
= gimple_alloc (code
, num_ops
);
2240 /* Shallow copy all the fields from STMT. */
2241 memcpy (copy
, stmt
, gimple_size (code
));
2242 gimple_init_singleton (copy
);
2244 /* If STMT has sub-statements, deep-copy them as well. */
2245 if (gimple_has_substatements (stmt
))
2250 switch (gimple_code (stmt
))
2253 new_seq
= gimple_seq_copy (gimple_bind_body (stmt
));
2254 gimple_bind_set_body (copy
, new_seq
);
2255 gimple_bind_set_vars (copy
, unshare_expr (gimple_bind_vars (stmt
)));
2256 gimple_bind_set_block (copy
, gimple_bind_block (stmt
));
2260 new_seq
= gimple_seq_copy (gimple_catch_handler (stmt
));
2261 gimple_catch_set_handler (copy
, new_seq
);
2262 t
= unshare_expr (gimple_catch_types (stmt
));
2263 gimple_catch_set_types (copy
, t
);
2266 case GIMPLE_EH_FILTER
:
2267 new_seq
= gimple_seq_copy (gimple_eh_filter_failure (stmt
));
2268 gimple_eh_filter_set_failure (copy
, new_seq
);
2269 t
= unshare_expr (gimple_eh_filter_types (stmt
));
2270 gimple_eh_filter_set_types (copy
, t
);
2273 case GIMPLE_EH_ELSE
:
2274 new_seq
= gimple_seq_copy (gimple_eh_else_n_body (stmt
));
2275 gimple_eh_else_set_n_body (copy
, new_seq
);
2276 new_seq
= gimple_seq_copy (gimple_eh_else_e_body (stmt
));
2277 gimple_eh_else_set_e_body (copy
, new_seq
);
2281 new_seq
= gimple_seq_copy (gimple_try_eval (stmt
));
2282 gimple_try_set_eval (copy
, new_seq
);
2283 new_seq
= gimple_seq_copy (gimple_try_cleanup (stmt
));
2284 gimple_try_set_cleanup (copy
, new_seq
);
2287 case GIMPLE_OMP_FOR
:
2288 new_seq
= gimple_seq_copy (gimple_omp_for_pre_body (stmt
));
2289 gimple_omp_for_set_pre_body (copy
, new_seq
);
2290 t
= unshare_expr (gimple_omp_for_clauses (stmt
));
2291 gimple_omp_for_set_clauses (copy
, t
);
2292 copy
->gimple_omp_for
.iter
2293 = ggc_alloc_vec_gimple_omp_for_iter
2294 (gimple_omp_for_collapse (stmt
));
2295 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
2297 gimple_omp_for_set_cond (copy
, i
,
2298 gimple_omp_for_cond (stmt
, i
));
2299 gimple_omp_for_set_index (copy
, i
,
2300 gimple_omp_for_index (stmt
, i
));
2301 t
= unshare_expr (gimple_omp_for_initial (stmt
, i
));
2302 gimple_omp_for_set_initial (copy
, i
, t
);
2303 t
= unshare_expr (gimple_omp_for_final (stmt
, i
));
2304 gimple_omp_for_set_final (copy
, i
, t
);
2305 t
= unshare_expr (gimple_omp_for_incr (stmt
, i
));
2306 gimple_omp_for_set_incr (copy
, i
, t
);
2310 case GIMPLE_OMP_PARALLEL
:
2311 t
= unshare_expr (gimple_omp_parallel_clauses (stmt
));
2312 gimple_omp_parallel_set_clauses (copy
, t
);
2313 t
= unshare_expr (gimple_omp_parallel_child_fn (stmt
));
2314 gimple_omp_parallel_set_child_fn (copy
, t
);
2315 t
= unshare_expr (gimple_omp_parallel_data_arg (stmt
));
2316 gimple_omp_parallel_set_data_arg (copy
, t
);
2319 case GIMPLE_OMP_TASK
:
2320 t
= unshare_expr (gimple_omp_task_clauses (stmt
));
2321 gimple_omp_task_set_clauses (copy
, t
);
2322 t
= unshare_expr (gimple_omp_task_child_fn (stmt
));
2323 gimple_omp_task_set_child_fn (copy
, t
);
2324 t
= unshare_expr (gimple_omp_task_data_arg (stmt
));
2325 gimple_omp_task_set_data_arg (copy
, t
);
2326 t
= unshare_expr (gimple_omp_task_copy_fn (stmt
));
2327 gimple_omp_task_set_copy_fn (copy
, t
);
2328 t
= unshare_expr (gimple_omp_task_arg_size (stmt
));
2329 gimple_omp_task_set_arg_size (copy
, t
);
2330 t
= unshare_expr (gimple_omp_task_arg_align (stmt
));
2331 gimple_omp_task_set_arg_align (copy
, t
);
2334 case GIMPLE_OMP_CRITICAL
:
2335 t
= unshare_expr (gimple_omp_critical_name (stmt
));
2336 gimple_omp_critical_set_name (copy
, t
);
2339 case GIMPLE_OMP_SECTIONS
:
2340 t
= unshare_expr (gimple_omp_sections_clauses (stmt
));
2341 gimple_omp_sections_set_clauses (copy
, t
);
2342 t
= unshare_expr (gimple_omp_sections_control (stmt
));
2343 gimple_omp_sections_set_control (copy
, t
);
2346 case GIMPLE_OMP_SINGLE
:
2347 case GIMPLE_OMP_SECTION
:
2348 case GIMPLE_OMP_MASTER
:
2349 case GIMPLE_OMP_ORDERED
:
2351 new_seq
= gimple_seq_copy (gimple_omp_body (stmt
));
2352 gimple_omp_set_body (copy
, new_seq
);
2355 case GIMPLE_TRANSACTION
:
2356 new_seq
= gimple_seq_copy (gimple_transaction_body (stmt
));
2357 gimple_transaction_set_body (copy
, new_seq
);
2360 case GIMPLE_WITH_CLEANUP_EXPR
:
2361 new_seq
= gimple_seq_copy (gimple_wce_cleanup (stmt
));
2362 gimple_wce_set_cleanup (copy
, new_seq
);
2370 /* Make copy of operands. */
2373 for (i
= 0; i
< num_ops
; i
++)
2374 gimple_set_op (copy
, i
, unshare_expr (gimple_op (stmt
, i
)));
2376 /* Clear out SSA operand vectors on COPY. */
2377 if (gimple_has_ops (stmt
))
2379 gimple_set_def_ops (copy
, NULL
);
2380 gimple_set_use_ops (copy
, NULL
);
2383 if (gimple_has_mem_ops (stmt
))
2385 gimple_set_vdef (copy
, gimple_vdef (stmt
));
2386 gimple_set_vuse (copy
, gimple_vuse (stmt
));
2389 /* SSA operands need to be updated. */
2390 gimple_set_modified (copy
, true);
2397 /* Return true if statement S has side-effects. We consider a
2398 statement to have side effects if:
2400 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2401 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2404 gimple_has_side_effects (const_gimple s
)
2406 if (is_gimple_debug (s
))
2409 /* We don't have to scan the arguments to check for
2410 volatile arguments, though, at present, we still
2411 do a scan to check for TREE_SIDE_EFFECTS. */
2412 if (gimple_has_volatile_ops (s
))
2415 if (gimple_code (s
) == GIMPLE_ASM
2416 && gimple_asm_volatile_p (s
))
2419 if (is_gimple_call (s
))
2421 int flags
= gimple_call_flags (s
);
2423 /* An infinite loop is considered a side effect. */
2424 if (!(flags
& (ECF_CONST
| ECF_PURE
))
2425 || (flags
& ECF_LOOPING_CONST_OR_PURE
))
2434 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2435 Return true if S can trap. When INCLUDE_MEM is true, check whether
2436 the memory operations could trap. When INCLUDE_STORES is true and
2437 S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
2440 gimple_could_trap_p_1 (gimple s
, bool include_mem
, bool include_stores
)
2442 tree t
, div
= NULL_TREE
;
2447 unsigned i
, start
= (is_gimple_assign (s
) && !include_stores
) ? 1 : 0;
2449 for (i
= start
; i
< gimple_num_ops (s
); i
++)
2450 if (tree_could_trap_p (gimple_op (s
, i
)))
2454 switch (gimple_code (s
))
2457 return gimple_asm_volatile_p (s
);
2460 t
= gimple_call_fndecl (s
);
2461 /* Assume that calls to weak functions may trap. */
2462 if (!t
|| !DECL_P (t
) || DECL_WEAK (t
))
2467 t
= gimple_expr_type (s
);
2468 op
= gimple_assign_rhs_code (s
);
2469 if (get_gimple_rhs_class (op
) == GIMPLE_BINARY_RHS
)
2470 div
= gimple_assign_rhs2 (s
);
2471 return (operation_could_trap_p (op
, FLOAT_TYPE_P (t
),
2472 (INTEGRAL_TYPE_P (t
)
2473 && TYPE_OVERFLOW_TRAPS (t
)),
2483 /* Return true if statement S can trap. */
2486 gimple_could_trap_p (gimple s
)
2488 return gimple_could_trap_p_1 (s
, true, true);
2491 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2494 gimple_assign_rhs_could_trap_p (gimple s
)
2496 gcc_assert (is_gimple_assign (s
));
2497 return gimple_could_trap_p_1 (s
, true, false);
2501 /* Print debugging information for gimple stmts generated. */
2504 dump_gimple_statistics (void)
2506 #ifdef GATHER_STATISTICS
2507 int i
, total_tuples
= 0, total_bytes
= 0;
2509 fprintf (stderr
, "\nGIMPLE statements\n");
2510 fprintf (stderr
, "Kind Stmts Bytes\n");
2511 fprintf (stderr
, "---------------------------------------\n");
2512 for (i
= 0; i
< (int) gimple_alloc_kind_all
; ++i
)
2514 fprintf (stderr
, "%-20s %7d %10d\n", gimple_alloc_kind_names
[i
],
2515 gimple_alloc_counts
[i
], gimple_alloc_sizes
[i
]);
2516 total_tuples
+= gimple_alloc_counts
[i
];
2517 total_bytes
+= gimple_alloc_sizes
[i
];
2519 fprintf (stderr
, "---------------------------------------\n");
2520 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_tuples
, total_bytes
);
2521 fprintf (stderr
, "---------------------------------------\n");
2523 fprintf (stderr
, "No gimple statistics\n");
2528 /* Return the number of operands needed on the RHS of a GIMPLE
2529 assignment for an expression with tree code CODE. */
2532 get_gimple_rhs_num_ops (enum tree_code code
)
2534 enum gimple_rhs_class rhs_class
= get_gimple_rhs_class (code
);
2536 if (rhs_class
== GIMPLE_UNARY_RHS
|| rhs_class
== GIMPLE_SINGLE_RHS
)
2538 else if (rhs_class
== GIMPLE_BINARY_RHS
)
2540 else if (rhs_class
== GIMPLE_TERNARY_RHS
)
2546 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2548 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2549 : ((TYPE) == tcc_binary \
2550 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2551 : ((TYPE) == tcc_constant \
2552 || (TYPE) == tcc_declaration \
2553 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2554 : ((SYM) == TRUTH_AND_EXPR \
2555 || (SYM) == TRUTH_OR_EXPR \
2556 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2557 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2558 : ((SYM) == COND_EXPR \
2559 || (SYM) == WIDEN_MULT_PLUS_EXPR \
2560 || (SYM) == WIDEN_MULT_MINUS_EXPR \
2561 || (SYM) == DOT_PROD_EXPR \
2562 || (SYM) == REALIGN_LOAD_EXPR \
2563 || (SYM) == VEC_COND_EXPR \
2564 || (SYM) == VEC_PERM_EXPR \
2565 || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \
2566 : ((SYM) == CONSTRUCTOR \
2567 || (SYM) == OBJ_TYPE_REF \
2568 || (SYM) == ASSERT_EXPR \
2569 || (SYM) == ADDR_EXPR \
2570 || (SYM) == WITH_SIZE_EXPR \
2571 || (SYM) == SSA_NAME) ? GIMPLE_SINGLE_RHS \
2572 : GIMPLE_INVALID_RHS),
2573 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2575 const unsigned char gimple_rhs_class_table
[] = {
2576 #include "all-tree.def"
2580 #undef END_OF_BASE_TREE_CODES
2582 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2584 /* Validation of GIMPLE expressions. */
2586 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
2589 is_gimple_lvalue (tree t
)
2591 return (is_gimple_addressable (t
)
2592 || TREE_CODE (t
) == WITH_SIZE_EXPR
2593 /* These are complex lvalues, but don't have addresses, so they
2595 || TREE_CODE (t
) == BIT_FIELD_REF
);
2598 /* Return true if T is a GIMPLE condition. */
2601 is_gimple_condexpr (tree t
)
2603 return (is_gimple_val (t
) || (COMPARISON_CLASS_P (t
)
2604 && !tree_could_throw_p (t
)
2605 && is_gimple_val (TREE_OPERAND (t
, 0))
2606 && is_gimple_val (TREE_OPERAND (t
, 1))));
2609 /* Return true if T is something whose address can be taken. */
2612 is_gimple_addressable (tree t
)
2614 return (is_gimple_id (t
) || handled_component_p (t
)
2615 || TREE_CODE (t
) == MEM_REF
);
2618 /* Return true if T is a valid gimple constant. */
2621 is_gimple_constant (const_tree t
)
2623 switch (TREE_CODE (t
))
2633 /* Vector constant constructors are gimple invariant. */
2635 if (TREE_TYPE (t
) && TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2636 return TREE_CONSTANT (t
);
2645 /* Return true if T is a gimple address. */
2648 is_gimple_address (const_tree t
)
2652 if (TREE_CODE (t
) != ADDR_EXPR
)
2655 op
= TREE_OPERAND (t
, 0);
2656 while (handled_component_p (op
))
2658 if ((TREE_CODE (op
) == ARRAY_REF
2659 || TREE_CODE (op
) == ARRAY_RANGE_REF
)
2660 && !is_gimple_val (TREE_OPERAND (op
, 1)))
2663 op
= TREE_OPERAND (op
, 0);
2666 if (CONSTANT_CLASS_P (op
) || TREE_CODE (op
) == MEM_REF
)
2669 switch (TREE_CODE (op
))
2684 /* Return true if T is a gimple invariant address. */
2687 is_gimple_invariant_address (const_tree t
)
2691 if (TREE_CODE (t
) != ADDR_EXPR
)
2694 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2698 if (TREE_CODE (op
) == MEM_REF
)
2700 const_tree op0
= TREE_OPERAND (op
, 0);
2701 return (TREE_CODE (op0
) == ADDR_EXPR
2702 && (CONSTANT_CLASS_P (TREE_OPERAND (op0
, 0))
2703 || decl_address_invariant_p (TREE_OPERAND (op0
, 0))));
2706 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
2709 /* Return true if T is a gimple invariant address at IPA level
2710 (so addresses of variables on stack are not allowed). */
2713 is_gimple_ip_invariant_address (const_tree t
)
2717 if (TREE_CODE (t
) != ADDR_EXPR
)
2720 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2724 if (TREE_CODE (op
) == MEM_REF
)
2726 const_tree op0
= TREE_OPERAND (op
, 0);
2727 return (TREE_CODE (op0
) == ADDR_EXPR
2728 && (CONSTANT_CLASS_P (TREE_OPERAND (op0
, 0))
2729 || decl_address_ip_invariant_p (TREE_OPERAND (op0
, 0))));
2732 return CONSTANT_CLASS_P (op
) || decl_address_ip_invariant_p (op
);
2735 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
2736 form of function invariant. */
2739 is_gimple_min_invariant (const_tree t
)
2741 if (TREE_CODE (t
) == ADDR_EXPR
)
2742 return is_gimple_invariant_address (t
);
2744 return is_gimple_constant (t
);
2747 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
2748 form of gimple minimal invariant. */
2751 is_gimple_ip_invariant (const_tree t
)
2753 if (TREE_CODE (t
) == ADDR_EXPR
)
2754 return is_gimple_ip_invariant_address (t
);
2756 return is_gimple_constant (t
);
2759 /* Return true if T is a variable. */
2762 is_gimple_variable (tree t
)
2764 return (TREE_CODE (t
) == VAR_DECL
2765 || TREE_CODE (t
) == PARM_DECL
2766 || TREE_CODE (t
) == RESULT_DECL
2767 || TREE_CODE (t
) == SSA_NAME
);
2770 /* Return true if T is a GIMPLE identifier (something with an address). */
2773 is_gimple_id (tree t
)
2775 return (is_gimple_variable (t
)
2776 || TREE_CODE (t
) == FUNCTION_DECL
2777 || TREE_CODE (t
) == LABEL_DECL
2778 || TREE_CODE (t
) == CONST_DECL
2779 /* Allow string constants, since they are addressable. */
2780 || TREE_CODE (t
) == STRING_CST
);
2783 /* Return true if T is a non-aggregate register variable. */
2786 is_gimple_reg (tree t
)
2788 if (TREE_CODE (t
) == SSA_NAME
)
2790 t
= SSA_NAME_VAR (t
);
2791 if (TREE_CODE (t
) == VAR_DECL
2792 && VAR_DECL_IS_VIRTUAL_OPERAND (t
))
2797 if (TREE_CODE (t
) == VAR_DECL
2798 && VAR_DECL_IS_VIRTUAL_OPERAND (t
))
2801 if (!is_gimple_variable (t
))
2804 if (!is_gimple_reg_type (TREE_TYPE (t
)))
2807 /* A volatile decl is not acceptable because we can't reuse it as
2808 needed. We need to copy it into a temp first. */
2809 if (TREE_THIS_VOLATILE (t
))
2812 /* We define "registers" as things that can be renamed as needed,
2813 which with our infrastructure does not apply to memory. */
2814 if (needs_to_live_in_memory (t
))
2817 /* Hard register variables are an interesting case. For those that
2818 are call-clobbered, we don't know where all the calls are, since
2819 we don't (want to) take into account which operations will turn
2820 into libcalls at the rtl level. For those that are call-saved,
2821 we don't currently model the fact that calls may in fact change
2822 global hard registers, nor do we examine ASM_CLOBBERS at the tree
2823 level, and so miss variable changes that might imply. All around,
2824 it seems safest to not do too much optimization with these at the
2825 tree level at all. We'll have to rely on the rtl optimizers to
2826 clean this up, as there we've got all the appropriate bits exposed. */
2827 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2830 /* Complex and vector values must have been put into SSA-like form.
2831 That is, no assignments to the individual components. */
2832 if (TREE_CODE (TREE_TYPE (t
)) == COMPLEX_TYPE
2833 || TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2834 return DECL_GIMPLE_REG_P (t
);
2840 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
2843 is_gimple_val (tree t
)
2845 /* Make loads from volatiles and memory vars explicit. */
2846 if (is_gimple_variable (t
)
2847 && is_gimple_reg_type (TREE_TYPE (t
))
2848 && !is_gimple_reg (t
))
2851 return (is_gimple_variable (t
) || is_gimple_min_invariant (t
));
2854 /* Similarly, but accept hard registers as inputs to asm statements. */
2857 is_gimple_asm_val (tree t
)
2859 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2862 return is_gimple_val (t
);
2865 /* Return true if T is a GIMPLE minimal lvalue. */
2868 is_gimple_min_lval (tree t
)
2870 if (!(t
= CONST_CAST_TREE (strip_invariant_refs (t
))))
2872 return (is_gimple_id (t
) || TREE_CODE (t
) == MEM_REF
);
2875 /* Return true if T is a valid function operand of a CALL_EXPR. */
2878 is_gimple_call_addr (tree t
)
2880 return (TREE_CODE (t
) == OBJ_TYPE_REF
|| is_gimple_val (t
));
2883 /* Return true if T is a valid address operand of a MEM_REF. */
2886 is_gimple_mem_ref_addr (tree t
)
2888 return (is_gimple_reg (t
)
2889 || TREE_CODE (t
) == INTEGER_CST
2890 || (TREE_CODE (t
) == ADDR_EXPR
2891 && (CONSTANT_CLASS_P (TREE_OPERAND (t
, 0))
2892 || decl_address_invariant_p (TREE_OPERAND (t
, 0)))));
2896 /* Given a memory reference expression T, return its base address.
2897 The base address of a memory reference expression is the main
2898 object being referenced. For instance, the base address for
2899 'array[i].fld[j]' is 'array'. You can think of this as stripping
2900 away the offset part from a memory address.
2902 This function calls handled_component_p to strip away all the inner
2903 parts of the memory reference until it reaches the base object. */
2906 get_base_address (tree t
)
2908 while (handled_component_p (t
))
2909 t
= TREE_OPERAND (t
, 0);
2911 if ((TREE_CODE (t
) == MEM_REF
2912 || TREE_CODE (t
) == TARGET_MEM_REF
)
2913 && TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
2914 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
2916 if (TREE_CODE (t
) == SSA_NAME
2918 || TREE_CODE (t
) == STRING_CST
2919 || TREE_CODE (t
) == CONSTRUCTOR
2920 || INDIRECT_REF_P (t
)
2921 || TREE_CODE (t
) == MEM_REF
2922 || TREE_CODE (t
) == TARGET_MEM_REF
)
2929 recalculate_side_effects (tree t
)
2931 enum tree_code code
= TREE_CODE (t
);
2932 int len
= TREE_OPERAND_LENGTH (t
);
2935 switch (TREE_CODE_CLASS (code
))
2937 case tcc_expression
:
2943 case PREDECREMENT_EXPR
:
2944 case PREINCREMENT_EXPR
:
2945 case POSTDECREMENT_EXPR
:
2946 case POSTINCREMENT_EXPR
:
2947 /* All of these have side-effects, no matter what their
2956 case tcc_comparison
: /* a comparison expression */
2957 case tcc_unary
: /* a unary arithmetic expression */
2958 case tcc_binary
: /* a binary arithmetic expression */
2959 case tcc_reference
: /* a reference */
2960 case tcc_vl_exp
: /* a function call */
2961 TREE_SIDE_EFFECTS (t
) = TREE_THIS_VOLATILE (t
);
2962 for (i
= 0; i
< len
; ++i
)
2964 tree op
= TREE_OPERAND (t
, i
);
2965 if (op
&& TREE_SIDE_EFFECTS (op
))
2966 TREE_SIDE_EFFECTS (t
) = 1;
2971 /* No side-effects. */
2979 /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
2980 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
2981 we failed to create one. */
2984 canonicalize_cond_expr_cond (tree t
)
2986 /* Strip conversions around boolean operations. */
2987 if (CONVERT_EXPR_P (t
)
2988 && (truth_value_p (TREE_CODE (TREE_OPERAND (t
, 0)))
2989 || TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
2991 t
= TREE_OPERAND (t
, 0);
2993 /* For !x use x == 0. */
2994 if (TREE_CODE (t
) == TRUTH_NOT_EXPR
)
2996 tree top0
= TREE_OPERAND (t
, 0);
2997 t
= build2 (EQ_EXPR
, TREE_TYPE (t
),
2998 top0
, build_int_cst (TREE_TYPE (top0
), 0));
3000 /* For cmp ? 1 : 0 use cmp. */
3001 else if (TREE_CODE (t
) == COND_EXPR
3002 && COMPARISON_CLASS_P (TREE_OPERAND (t
, 0))
3003 && integer_onep (TREE_OPERAND (t
, 1))
3004 && integer_zerop (TREE_OPERAND (t
, 2)))
3006 tree top0
= TREE_OPERAND (t
, 0);
3007 t
= build2 (TREE_CODE (top0
), TREE_TYPE (t
),
3008 TREE_OPERAND (top0
, 0), TREE_OPERAND (top0
, 1));
3011 if (is_gimple_condexpr (t
))
3017 /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
3018 the positions marked by the set ARGS_TO_SKIP. */
3021 gimple_call_copy_skip_args (gimple stmt
, bitmap args_to_skip
)
3024 int nargs
= gimple_call_num_args (stmt
);
3025 VEC(tree
, heap
) *vargs
= VEC_alloc (tree
, heap
, nargs
);
3028 for (i
= 0; i
< nargs
; i
++)
3029 if (!bitmap_bit_p (args_to_skip
, i
))
3030 VEC_quick_push (tree
, vargs
, gimple_call_arg (stmt
, i
));
3032 if (gimple_call_internal_p (stmt
))
3033 new_stmt
= gimple_build_call_internal_vec (gimple_call_internal_fn (stmt
),
3036 new_stmt
= gimple_build_call_vec (gimple_call_fn (stmt
), vargs
);
3037 VEC_free (tree
, heap
, vargs
);
3038 if (gimple_call_lhs (stmt
))
3039 gimple_call_set_lhs (new_stmt
, gimple_call_lhs (stmt
));
3041 gimple_set_vuse (new_stmt
, gimple_vuse (stmt
));
3042 gimple_set_vdef (new_stmt
, gimple_vdef (stmt
));
3044 gimple_set_block (new_stmt
, gimple_block (stmt
));
3045 if (gimple_has_location (stmt
))
3046 gimple_set_location (new_stmt
, gimple_location (stmt
));
3047 gimple_call_copy_flags (new_stmt
, stmt
);
3048 gimple_call_set_chain (new_stmt
, gimple_call_chain (stmt
));
3050 gimple_set_modified (new_stmt
, true);
3056 enum gtc_mode
{ GTC_MERGE
= 0, GTC_DIAG
= 1 };
3058 static hashval_t
gimple_type_hash (const void *);
3060 /* Structure used to maintain a cache of some type pairs compared by
3061 gimple_types_compatible_p when comparing aggregate types. There are
3062 three possible values for SAME_P:
3064 -2: The pair (T1, T2) has just been inserted in the table.
3065 0: T1 and T2 are different types.
3066 1: T1 and T2 are the same type.
3068 The two elements in the SAME_P array are indexed by the comparison
3075 signed char same_p
[2];
3077 typedef struct type_pair_d
*type_pair_t
;
3078 DEF_VEC_P(type_pair_t
);
3079 DEF_VEC_ALLOC_P(type_pair_t
,heap
);
3081 #define GIMPLE_TYPE_PAIR_SIZE 16381
3082 struct type_pair_d
*type_pair_cache
;
3085 /* Lookup the pair of types T1 and T2 in *VISITED_P. Insert a new
3086 entry if none existed. */
3088 static inline type_pair_t
3089 lookup_type_pair (tree t1
, tree t2
)
3092 unsigned int uid1
, uid2
;
3094 if (type_pair_cache
== NULL
)
3095 type_pair_cache
= XCNEWVEC (struct type_pair_d
, GIMPLE_TYPE_PAIR_SIZE
);
3097 if (TYPE_UID (t1
) < TYPE_UID (t2
))
3099 uid1
= TYPE_UID (t1
);
3100 uid2
= TYPE_UID (t2
);
3104 uid1
= TYPE_UID (t2
);
3105 uid2
= TYPE_UID (t1
);
3107 gcc_checking_assert (uid1
!= uid2
);
3109 /* iterative_hash_hashval_t imply an function calls.
3110 We know that UIDS are in limited range. */
3111 index
= ((((unsigned HOST_WIDE_INT
)uid1
<< HOST_BITS_PER_WIDE_INT
/ 2) + uid2
)
3112 % GIMPLE_TYPE_PAIR_SIZE
);
3113 if (type_pair_cache
[index
].uid1
== uid1
3114 && type_pair_cache
[index
].uid2
== uid2
)
3115 return &type_pair_cache
[index
];
3117 type_pair_cache
[index
].uid1
= uid1
;
3118 type_pair_cache
[index
].uid2
= uid2
;
3119 type_pair_cache
[index
].same_p
[0] = -2;
3120 type_pair_cache
[index
].same_p
[1] = -2;
3122 return &type_pair_cache
[index
];
3125 /* Per pointer state for the SCC finding. The on_sccstack flag
3126 is not strictly required, it is true when there is no hash value
3127 recorded for the type and false otherwise. But querying that
3132 unsigned int dfsnum
;
3141 static unsigned int next_dfs_num
;
3142 static unsigned int gtc_next_dfs_num
;
3145 /* GIMPLE type merging cache. A direct-mapped cache based on TYPE_UID. */
3147 typedef struct GTY(()) gimple_type_leader_entry_s
{
3150 } gimple_type_leader_entry
;
3152 #define GIMPLE_TYPE_LEADER_SIZE 16381
3153 static GTY((deletable
, length("GIMPLE_TYPE_LEADER_SIZE")))
3154 gimple_type_leader_entry
*gimple_type_leader
;
3156 /* Lookup an existing leader for T and return it or NULL_TREE, if
3157 there is none in the cache. */
3160 gimple_lookup_type_leader (tree t
)
3162 gimple_type_leader_entry
*leader
;
3164 if (!gimple_type_leader
)
3167 leader
= &gimple_type_leader
[TYPE_UID (t
) % GIMPLE_TYPE_LEADER_SIZE
];
3168 if (leader
->type
!= t
)
3171 return leader
->leader
;
3174 /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is
3175 true then if any type has no name return false, otherwise return
3176 true if both types have no names. */
3179 compare_type_names_p (tree t1
, tree t2
)
3181 tree name1
= TYPE_NAME (t1
);
3182 tree name2
= TYPE_NAME (t2
);
3184 if ((name1
!= NULL_TREE
) != (name2
!= NULL_TREE
))
3187 if (name1
== NULL_TREE
)
3190 /* Either both should be a TYPE_DECL or both an IDENTIFIER_NODE. */
3191 if (TREE_CODE (name1
) != TREE_CODE (name2
))
3194 if (TREE_CODE (name1
) == TYPE_DECL
)
3195 name1
= DECL_NAME (name1
);
3196 gcc_checking_assert (!name1
|| TREE_CODE (name1
) == IDENTIFIER_NODE
);
3198 if (TREE_CODE (name2
) == TYPE_DECL
)
3199 name2
= DECL_NAME (name2
);
3200 gcc_checking_assert (!name2
|| TREE_CODE (name2
) == IDENTIFIER_NODE
);
3202 /* Identifiers can be compared with pointer equality rather
3203 than a string comparison. */
3210 /* Return true if the field decls F1 and F2 are at the same offset.
3212 This is intended to be used on GIMPLE types only. */
3215 gimple_compare_field_offset (tree f1
, tree f2
)
3217 if (DECL_OFFSET_ALIGN (f1
) == DECL_OFFSET_ALIGN (f2
))
3219 tree offset1
= DECL_FIELD_OFFSET (f1
);
3220 tree offset2
= DECL_FIELD_OFFSET (f2
);
3221 return ((offset1
== offset2
3222 /* Once gimplification is done, self-referential offsets are
3223 instantiated as operand #2 of the COMPONENT_REF built for
3224 each access and reset. Therefore, they are not relevant
3225 anymore and fields are interchangeable provided that they
3226 represent the same access. */
3227 || (TREE_CODE (offset1
) == PLACEHOLDER_EXPR
3228 && TREE_CODE (offset2
) == PLACEHOLDER_EXPR
3229 && (DECL_SIZE (f1
) == DECL_SIZE (f2
)
3230 || (TREE_CODE (DECL_SIZE (f1
)) == PLACEHOLDER_EXPR
3231 && TREE_CODE (DECL_SIZE (f2
)) == PLACEHOLDER_EXPR
)
3232 || operand_equal_p (DECL_SIZE (f1
), DECL_SIZE (f2
), 0))
3233 && DECL_ALIGN (f1
) == DECL_ALIGN (f2
))
3234 || operand_equal_p (offset1
, offset2
, 0))
3235 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1
),
3236 DECL_FIELD_BIT_OFFSET (f2
)));
3239 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
3240 should be, so handle differing ones specially by decomposing
3241 the offset into a byte and bit offset manually. */
3242 if (host_integerp (DECL_FIELD_OFFSET (f1
), 0)
3243 && host_integerp (DECL_FIELD_OFFSET (f2
), 0))
3245 unsigned HOST_WIDE_INT byte_offset1
, byte_offset2
;
3246 unsigned HOST_WIDE_INT bit_offset1
, bit_offset2
;
3247 bit_offset1
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1
));
3248 byte_offset1
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1
))
3249 + bit_offset1
/ BITS_PER_UNIT
);
3250 bit_offset2
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2
));
3251 byte_offset2
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2
))
3252 + bit_offset2
/ BITS_PER_UNIT
);
3253 if (byte_offset1
!= byte_offset2
)
3255 return bit_offset1
% BITS_PER_UNIT
== bit_offset2
% BITS_PER_UNIT
;
3262 gimple_types_compatible_p_1 (tree
, tree
, type_pair_t
,
3263 VEC(type_pair_t
, heap
) **,
3264 struct pointer_map_t
*, struct obstack
*);
3266 /* DFS visit the edge from the callers type pair with state *STATE to
3267 the pair T1, T2 while operating in FOR_MERGING_P mode.
3268 Update the merging status if it is not part of the SCC containing the
3269 callers pair and return it.
3270 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3273 gtc_visit (tree t1
, tree t2
,
3275 VEC(type_pair_t
, heap
) **sccstack
,
3276 struct pointer_map_t
*sccstate
,
3277 struct obstack
*sccstate_obstack
)
3279 struct sccs
*cstate
= NULL
;
3282 tree leader1
, leader2
;
3284 /* Check first for the obvious case of pointer identity. */
3288 /* Check that we have two types to compare. */
3289 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
3292 /* Can't be the same type if the types don't have the same code. */
3293 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3296 /* Can't be the same type if they have different CV qualifiers. */
3297 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
3300 if (TREE_ADDRESSABLE (t1
) != TREE_ADDRESSABLE (t2
))
3303 /* Void types and nullptr types are always the same. */
3304 if (TREE_CODE (t1
) == VOID_TYPE
3305 || TREE_CODE (t1
) == NULLPTR_TYPE
)
3308 /* Can't be the same type if they have different alignment or mode. */
3309 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3310 || TYPE_MODE (t1
) != TYPE_MODE (t2
))
3313 /* Do some simple checks before doing three hashtable queries. */
3314 if (INTEGRAL_TYPE_P (t1
)
3315 || SCALAR_FLOAT_TYPE_P (t1
)
3316 || FIXED_POINT_TYPE_P (t1
)
3317 || TREE_CODE (t1
) == VECTOR_TYPE
3318 || TREE_CODE (t1
) == COMPLEX_TYPE
3319 || TREE_CODE (t1
) == OFFSET_TYPE
3320 || POINTER_TYPE_P (t1
))
3322 /* Can't be the same type if they have different sign or precision. */
3323 if (TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
3324 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
3327 if (TREE_CODE (t1
) == INTEGER_TYPE
3328 && TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
))
3331 /* That's all we need to check for float and fixed-point types. */
3332 if (SCALAR_FLOAT_TYPE_P (t1
)
3333 || FIXED_POINT_TYPE_P (t1
))
3336 /* For other types fall through to more complex checks. */
3339 /* If the types have been previously registered and found equal
3341 leader1
= gimple_lookup_type_leader (t1
);
3342 leader2
= gimple_lookup_type_leader (t2
);
3345 || (leader1
&& leader1
== leader2
))
3348 /* If the hash values of t1 and t2 are different the types can't
3349 possibly be the same. This helps keeping the type-pair hashtable
3350 small, only tracking comparisons for hash collisions. */
3351 if (gimple_type_hash (t1
) != gimple_type_hash (t2
))
3354 /* Allocate a new cache entry for this comparison. */
3355 p
= lookup_type_pair (t1
, t2
);
3356 if (p
->same_p
[GTC_MERGE
] == 0 || p
->same_p
[GTC_MERGE
] == 1)
3358 /* We have already decided whether T1 and T2 are the
3359 same, return the cached result. */
3360 return p
->same_p
[GTC_MERGE
] == 1;
3363 if ((slot
= pointer_map_contains (sccstate
, p
)) != NULL
)
3364 cstate
= (struct sccs
*)*slot
;
3365 /* Not yet visited. DFS recurse. */
3368 gimple_types_compatible_p_1 (t1
, t2
, p
,
3369 sccstack
, sccstate
, sccstate_obstack
);
3370 cstate
= (struct sccs
*)* pointer_map_contains (sccstate
, p
);
3371 state
->low
= MIN (state
->low
, cstate
->low
);
3373 /* If the type is still on the SCC stack adjust the parents low. */
3374 if (cstate
->dfsnum
< state
->dfsnum
3375 && cstate
->on_sccstack
)
3376 state
->low
= MIN (cstate
->dfsnum
, state
->low
);
3378 /* Return the current lattice value. We start with an equality
3379 assumption so types part of a SCC will be optimistically
3380 treated equal unless proven otherwise. */
3381 return cstate
->u
.same_p
;
3384 /* Worker for gimple_types_compatible.
3385 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3388 gimple_types_compatible_p_1 (tree t1
, tree t2
, type_pair_t p
,
3389 VEC(type_pair_t
, heap
) **sccstack
,
3390 struct pointer_map_t
*sccstate
,
3391 struct obstack
*sccstate_obstack
)
3395 gcc_assert (p
->same_p
[GTC_MERGE
] == -2);
3397 state
= XOBNEW (sccstate_obstack
, struct sccs
);
3398 *pointer_map_insert (sccstate
, p
) = state
;
3400 VEC_safe_push (type_pair_t
, heap
, *sccstack
, p
);
3401 state
->dfsnum
= gtc_next_dfs_num
++;
3402 state
->low
= state
->dfsnum
;
3403 state
->on_sccstack
= true;
3404 /* Start with an equality assumption. As we DFS recurse into child
3405 SCCs this assumption may get revisited. */
3406 state
->u
.same_p
= 1;
3408 /* The struct tags shall compare equal. */
3409 if (!compare_type_names_p (t1
, t2
))
3410 goto different_types
;
3412 /* We may not merge typedef types to the same type in different
3415 && TREE_CODE (TYPE_NAME (t1
)) == TYPE_DECL
3416 && DECL_CONTEXT (TYPE_NAME (t1
))
3417 && TYPE_P (DECL_CONTEXT (TYPE_NAME (t1
))))
3419 if (!gtc_visit (DECL_CONTEXT (TYPE_NAME (t1
)),
3420 DECL_CONTEXT (TYPE_NAME (t2
)),
3421 state
, sccstack
, sccstate
, sccstate_obstack
))
3422 goto different_types
;
3425 /* If their attributes are not the same they can't be the same type. */
3426 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1
), TYPE_ATTRIBUTES (t2
)))
3427 goto different_types
;
3429 /* Do type-specific comparisons. */
3430 switch (TREE_CODE (t1
))
3434 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
),
3435 state
, sccstack
, sccstate
, sccstate_obstack
))
3436 goto different_types
;
3440 /* Array types are the same if the element types are the same and
3441 the number of elements are the same. */
3442 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
),
3443 state
, sccstack
, sccstate
, sccstate_obstack
)
3444 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)
3445 || TYPE_NONALIASED_COMPONENT (t1
) != TYPE_NONALIASED_COMPONENT (t2
))
3446 goto different_types
;
3449 tree i1
= TYPE_DOMAIN (t1
);
3450 tree i2
= TYPE_DOMAIN (t2
);
3452 /* For an incomplete external array, the type domain can be
3453 NULL_TREE. Check this condition also. */
3454 if (i1
== NULL_TREE
&& i2
== NULL_TREE
)
3456 else if (i1
== NULL_TREE
|| i2
== NULL_TREE
)
3457 goto different_types
;
3460 tree min1
= TYPE_MIN_VALUE (i1
);
3461 tree min2
= TYPE_MIN_VALUE (i2
);
3462 tree max1
= TYPE_MAX_VALUE (i1
);
3463 tree max2
= TYPE_MAX_VALUE (i2
);
3465 /* The minimum/maximum values have to be the same. */
3468 && ((TREE_CODE (min1
) == PLACEHOLDER_EXPR
3469 && TREE_CODE (min2
) == PLACEHOLDER_EXPR
)
3470 || operand_equal_p (min1
, min2
, 0))))
3473 && ((TREE_CODE (max1
) == PLACEHOLDER_EXPR
3474 && TREE_CODE (max2
) == PLACEHOLDER_EXPR
)
3475 || operand_equal_p (max1
, max2
, 0)))))
3478 goto different_types
;
3483 /* Method types should belong to the same class. */
3484 if (!gtc_visit (TYPE_METHOD_BASETYPE (t1
), TYPE_METHOD_BASETYPE (t2
),
3485 state
, sccstack
, sccstate
, sccstate_obstack
))
3486 goto different_types
;
3491 /* Function types are the same if the return type and arguments types
3493 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
),
3494 state
, sccstack
, sccstate
, sccstate_obstack
))
3495 goto different_types
;
3497 if (!comp_type_attributes (t1
, t2
))
3498 goto different_types
;
3500 if (TYPE_ARG_TYPES (t1
) == TYPE_ARG_TYPES (t2
))
3504 tree parms1
, parms2
;
3506 for (parms1
= TYPE_ARG_TYPES (t1
), parms2
= TYPE_ARG_TYPES (t2
);
3508 parms1
= TREE_CHAIN (parms1
), parms2
= TREE_CHAIN (parms2
))
3510 if (!gtc_visit (TREE_VALUE (parms1
), TREE_VALUE (parms2
),
3511 state
, sccstack
, sccstate
, sccstate_obstack
))
3512 goto different_types
;
3515 if (parms1
|| parms2
)
3516 goto different_types
;
3523 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
),
3524 state
, sccstack
, sccstate
, sccstate_obstack
)
3525 || !gtc_visit (TYPE_OFFSET_BASETYPE (t1
),
3526 TYPE_OFFSET_BASETYPE (t2
),
3527 state
, sccstack
, sccstate
, sccstate_obstack
))
3528 goto different_types
;
3534 case REFERENCE_TYPE
:
3536 /* If the two pointers have different ref-all attributes,
3537 they can't be the same type. */
3538 if (TYPE_REF_CAN_ALIAS_ALL (t1
) != TYPE_REF_CAN_ALIAS_ALL (t2
))
3539 goto different_types
;
3541 /* Otherwise, pointer and reference types are the same if the
3542 pointed-to types are the same. */
3543 if (gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
),
3544 state
, sccstack
, sccstate
, sccstate_obstack
))
3547 goto different_types
;
3553 tree min1
= TYPE_MIN_VALUE (t1
);
3554 tree max1
= TYPE_MAX_VALUE (t1
);
3555 tree min2
= TYPE_MIN_VALUE (t2
);
3556 tree max2
= TYPE_MAX_VALUE (t2
);
3557 bool min_equal_p
= false;
3558 bool max_equal_p
= false;
3560 /* If either type has a minimum value, the other type must
3562 if (min1
== NULL_TREE
&& min2
== NULL_TREE
)
3564 else if (min1
&& min2
&& operand_equal_p (min1
, min2
, 0))
3567 /* Likewise, if either type has a maximum value, the other
3568 type must have the same. */
3569 if (max1
== NULL_TREE
&& max2
== NULL_TREE
)
3571 else if (max1
&& max2
&& operand_equal_p (max1
, max2
, 0))
3574 if (!min_equal_p
|| !max_equal_p
)
3575 goto different_types
;
3582 /* FIXME lto, we cannot check bounds on enumeral types because
3583 different front ends will produce different values.
3584 In C, enumeral types are integers, while in C++ each element
3585 will have its own symbolic value. We should decide how enums
3586 are to be represented in GIMPLE and have each front end lower
3590 /* For enumeral types, all the values must be the same. */
3591 if (TYPE_VALUES (t1
) == TYPE_VALUES (t2
))
3594 for (v1
= TYPE_VALUES (t1
), v2
= TYPE_VALUES (t2
);
3596 v1
= TREE_CHAIN (v1
), v2
= TREE_CHAIN (v2
))
3598 tree c1
= TREE_VALUE (v1
);
3599 tree c2
= TREE_VALUE (v2
);
3601 if (TREE_CODE (c1
) == CONST_DECL
)
3602 c1
= DECL_INITIAL (c1
);
3604 if (TREE_CODE (c2
) == CONST_DECL
)
3605 c2
= DECL_INITIAL (c2
);
3607 if (tree_int_cst_equal (c1
, c2
) != 1)
3608 goto different_types
;
3610 if (TREE_PURPOSE (v1
) != TREE_PURPOSE (v2
))
3611 goto different_types
;
3614 /* If one enumeration has more values than the other, they
3615 are not the same. */
3617 goto different_types
;
3624 case QUAL_UNION_TYPE
:
3628 /* For aggregate types, all the fields must be the same. */
3629 for (f1
= TYPE_FIELDS (t1
), f2
= TYPE_FIELDS (t2
);
3631 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
3633 /* Different field kinds are not compatible. */
3634 if (TREE_CODE (f1
) != TREE_CODE (f2
))
3635 goto different_types
;
3636 /* Field decls must have the same name and offset. */
3637 if (TREE_CODE (f1
) == FIELD_DECL
3638 && (DECL_NONADDRESSABLE_P (f1
) != DECL_NONADDRESSABLE_P (f2
)
3639 || !gimple_compare_field_offset (f1
, f2
)))
3640 goto different_types
;
3641 /* All entities should have the same name and type. */
3642 if (DECL_NAME (f1
) != DECL_NAME (f2
)
3643 || !gtc_visit (TREE_TYPE (f1
), TREE_TYPE (f2
),
3644 state
, sccstack
, sccstate
, sccstate_obstack
))
3645 goto different_types
;
3648 /* If one aggregate has more fields than the other, they
3649 are not the same. */
3651 goto different_types
;
3660 /* Common exit path for types that are not compatible. */
3662 state
->u
.same_p
= 0;
3665 /* Common exit path for types that are compatible. */
3667 gcc_assert (state
->u
.same_p
== 1);
3670 if (state
->low
== state
->dfsnum
)
3674 /* Pop off the SCC and set its cache values to the final
3675 comparison result. */
3678 struct sccs
*cstate
;
3679 x
= VEC_pop (type_pair_t
, *sccstack
);
3680 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
3681 cstate
->on_sccstack
= false;
3682 x
->same_p
[GTC_MERGE
] = state
->u
.same_p
;
3687 return state
->u
.same_p
;
3690 /* Return true iff T1 and T2 are structurally identical. When
3691 FOR_MERGING_P is true the an incomplete type and a complete type
3692 are considered different, otherwise they are considered compatible. */
3695 gimple_types_compatible_p (tree t1
, tree t2
)
3697 VEC(type_pair_t
, heap
) *sccstack
= NULL
;
3698 struct pointer_map_t
*sccstate
;
3699 struct obstack sccstate_obstack
;
3700 type_pair_t p
= NULL
;
3702 tree leader1
, leader2
;
3704 /* Before starting to set up the SCC machinery handle simple cases. */
3706 /* Check first for the obvious case of pointer identity. */
3710 /* Check that we have two types to compare. */
3711 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
3714 /* Can't be the same type if the types don't have the same code. */
3715 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3718 /* Can't be the same type if they have different CV qualifiers. */
3719 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
3722 if (TREE_ADDRESSABLE (t1
) != TREE_ADDRESSABLE (t2
))
3725 /* Void types and nullptr types are always the same. */
3726 if (TREE_CODE (t1
) == VOID_TYPE
3727 || TREE_CODE (t1
) == NULLPTR_TYPE
)
3730 /* Can't be the same type if they have different alignment or mode. */
3731 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3732 || TYPE_MODE (t1
) != TYPE_MODE (t2
))
3735 /* Do some simple checks before doing three hashtable queries. */
3736 if (INTEGRAL_TYPE_P (t1
)
3737 || SCALAR_FLOAT_TYPE_P (t1
)
3738 || FIXED_POINT_TYPE_P (t1
)
3739 || TREE_CODE (t1
) == VECTOR_TYPE
3740 || TREE_CODE (t1
) == COMPLEX_TYPE
3741 || TREE_CODE (t1
) == OFFSET_TYPE
3742 || POINTER_TYPE_P (t1
))
3744 /* Can't be the same type if they have different sign or precision. */
3745 if (TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
3746 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
3749 if (TREE_CODE (t1
) == INTEGER_TYPE
3750 && TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
))
3753 /* That's all we need to check for float and fixed-point types. */
3754 if (SCALAR_FLOAT_TYPE_P (t1
)
3755 || FIXED_POINT_TYPE_P (t1
))
3758 /* For other types fall through to more complex checks. */
3761 /* If the types have been previously registered and found equal
3763 leader1
= gimple_lookup_type_leader (t1
);
3764 leader2
= gimple_lookup_type_leader (t2
);
3767 || (leader1
&& leader1
== leader2
))
3770 /* If the hash values of t1 and t2 are different the types can't
3771 possibly be the same. This helps keeping the type-pair hashtable
3772 small, only tracking comparisons for hash collisions. */
3773 if (gimple_type_hash (t1
) != gimple_type_hash (t2
))
3776 /* If we've visited this type pair before (in the case of aggregates
3777 with self-referential types), and we made a decision, return it. */
3778 p
= lookup_type_pair (t1
, t2
);
3779 if (p
->same_p
[GTC_MERGE
] == 0 || p
->same_p
[GTC_MERGE
] == 1)
3781 /* We have already decided whether T1 and T2 are the
3782 same, return the cached result. */
3783 return p
->same_p
[GTC_MERGE
] == 1;
3786 /* Now set up the SCC machinery for the comparison. */
3787 gtc_next_dfs_num
= 1;
3788 sccstate
= pointer_map_create ();
3789 gcc_obstack_init (&sccstate_obstack
);
3790 res
= gimple_types_compatible_p_1 (t1
, t2
, p
,
3791 &sccstack
, sccstate
, &sccstate_obstack
);
3792 VEC_free (type_pair_t
, heap
, sccstack
);
3793 pointer_map_destroy (sccstate
);
3794 obstack_free (&sccstate_obstack
, NULL
);
3801 iterative_hash_gimple_type (tree
, hashval_t
, VEC(tree
, heap
) **,
3802 struct pointer_map_t
*, struct obstack
*);
3804 /* DFS visit the edge from the callers type with state *STATE to T.
3805 Update the callers type hash V with the hash for T if it is not part
3806 of the SCC containing the callers type and return it.
3807 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3810 visit (tree t
, struct sccs
*state
, hashval_t v
,
3811 VEC (tree
, heap
) **sccstack
,
3812 struct pointer_map_t
*sccstate
,
3813 struct obstack
*sccstate_obstack
)
3815 struct sccs
*cstate
= NULL
;
3816 struct tree_int_map m
;
3819 /* If there is a hash value recorded for this type then it can't
3820 possibly be part of our parent SCC. Simply mix in its hash. */
3822 if ((slot
= htab_find_slot (type_hash_cache
, &m
, NO_INSERT
))
3824 return iterative_hash_hashval_t (((struct tree_int_map
*) *slot
)->to
, v
);
3826 if ((slot
= pointer_map_contains (sccstate
, t
)) != NULL
)
3827 cstate
= (struct sccs
*)*slot
;
3831 /* Not yet visited. DFS recurse. */
3832 tem
= iterative_hash_gimple_type (t
, v
,
3833 sccstack
, sccstate
, sccstate_obstack
);
3835 cstate
= (struct sccs
*)* pointer_map_contains (sccstate
, t
);
3836 state
->low
= MIN (state
->low
, cstate
->low
);
3837 /* If the type is no longer on the SCC stack and thus is not part
3838 of the parents SCC mix in its hash value. Otherwise we will
3839 ignore the type for hashing purposes and return the unaltered
3841 if (!cstate
->on_sccstack
)
3844 if (cstate
->dfsnum
< state
->dfsnum
3845 && cstate
->on_sccstack
)
3846 state
->low
= MIN (cstate
->dfsnum
, state
->low
);
3848 /* We are part of our parents SCC, skip this type during hashing
3849 and return the unaltered hash value. */
3853 /* Hash NAME with the previous hash value V and return it. */
3856 iterative_hash_name (tree name
, hashval_t v
)
3860 v
= iterative_hash_hashval_t (TREE_CODE (name
), v
);
3861 if (TREE_CODE (name
) == TYPE_DECL
)
3862 name
= DECL_NAME (name
);
3865 gcc_assert (TREE_CODE (name
) == IDENTIFIER_NODE
);
3866 return iterative_hash_object (IDENTIFIER_HASH_VALUE (name
), v
);
3869 /* A type, hashvalue pair for sorting SCC members. */
3871 struct type_hash_pair
{
3876 /* Compare two type, hashvalue pairs. */
3879 type_hash_pair_compare (const void *p1_
, const void *p2_
)
3881 const struct type_hash_pair
*p1
= (const struct type_hash_pair
*) p1_
;
3882 const struct type_hash_pair
*p2
= (const struct type_hash_pair
*) p2_
;
3883 if (p1
->hash
< p2
->hash
)
3885 else if (p1
->hash
> p2
->hash
)
3890 /* Returning a hash value for gimple type TYPE combined with VAL.
3891 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done.
3893 To hash a type we end up hashing in types that are reachable.
3894 Through pointers we can end up with cycles which messes up the
3895 required property that we need to compute the same hash value
3896 for structurally equivalent types. To avoid this we have to
3897 hash all types in a cycle (the SCC) in a commutative way. The
3898 easiest way is to not mix in the hashes of the SCC members at
3899 all. To make this work we have to delay setting the hash
3900 values of the SCC until it is complete. */
3903 iterative_hash_gimple_type (tree type
, hashval_t val
,
3904 VEC(tree
, heap
) **sccstack
,
3905 struct pointer_map_t
*sccstate
,
3906 struct obstack
*sccstate_obstack
)
3912 /* Not visited during this DFS walk. */
3913 gcc_checking_assert (!pointer_map_contains (sccstate
, type
));
3914 state
= XOBNEW (sccstate_obstack
, struct sccs
);
3915 *pointer_map_insert (sccstate
, type
) = state
;
3917 VEC_safe_push (tree
, heap
, *sccstack
, type
);
3918 state
->dfsnum
= next_dfs_num
++;
3919 state
->low
= state
->dfsnum
;
3920 state
->on_sccstack
= true;
3922 /* Combine a few common features of types so that types are grouped into
3923 smaller sets; when searching for existing matching types to merge,
3924 only existing types having the same features as the new type will be
3926 v
= iterative_hash_name (TYPE_NAME (type
), 0);
3927 if (TYPE_NAME (type
)
3928 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
3929 && DECL_CONTEXT (TYPE_NAME (type
))
3930 && TYPE_P (DECL_CONTEXT (TYPE_NAME (type
))))
3931 v
= visit (DECL_CONTEXT (TYPE_NAME (type
)), state
, v
,
3932 sccstack
, sccstate
, sccstate_obstack
);
3933 v
= iterative_hash_hashval_t (TREE_CODE (type
), v
);
3934 v
= iterative_hash_hashval_t (TYPE_QUALS (type
), v
);
3935 v
= iterative_hash_hashval_t (TREE_ADDRESSABLE (type
), v
);
3937 /* Do not hash the types size as this will cause differences in
3938 hash values for the complete vs. the incomplete type variant. */
3940 /* Incorporate common features of numerical types. */
3941 if (INTEGRAL_TYPE_P (type
)
3942 || SCALAR_FLOAT_TYPE_P (type
)
3943 || FIXED_POINT_TYPE_P (type
))
3945 v
= iterative_hash_hashval_t (TYPE_PRECISION (type
), v
);
3946 v
= iterative_hash_hashval_t (TYPE_MODE (type
), v
);
3947 v
= iterative_hash_hashval_t (TYPE_UNSIGNED (type
), v
);
3950 /* For pointer and reference types, fold in information about the type
3952 if (POINTER_TYPE_P (type
))
3953 v
= visit (TREE_TYPE (type
), state
, v
,
3954 sccstack
, sccstate
, sccstate_obstack
);
3956 /* For integer types hash the types min/max values and the string flag. */
3957 if (TREE_CODE (type
) == INTEGER_TYPE
)
3959 /* OMP lowering can introduce error_mark_node in place of
3960 random local decls in types. */
3961 if (TYPE_MIN_VALUE (type
) != error_mark_node
)
3962 v
= iterative_hash_expr (TYPE_MIN_VALUE (type
), v
);
3963 if (TYPE_MAX_VALUE (type
) != error_mark_node
)
3964 v
= iterative_hash_expr (TYPE_MAX_VALUE (type
), v
);
3965 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
3968 /* For array types hash the domain and the string flag. */
3969 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
))
3971 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
3972 v
= visit (TYPE_DOMAIN (type
), state
, v
,
3973 sccstack
, sccstate
, sccstate_obstack
);
3976 /* Recurse for aggregates with a single element type. */
3977 if (TREE_CODE (type
) == ARRAY_TYPE
3978 || TREE_CODE (type
) == COMPLEX_TYPE
3979 || TREE_CODE (type
) == VECTOR_TYPE
)
3980 v
= visit (TREE_TYPE (type
), state
, v
,
3981 sccstack
, sccstate
, sccstate_obstack
);
3983 /* Incorporate function return and argument types. */
3984 if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
3989 /* For method types also incorporate their parent class. */
3990 if (TREE_CODE (type
) == METHOD_TYPE
)
3991 v
= visit (TYPE_METHOD_BASETYPE (type
), state
, v
,
3992 sccstack
, sccstate
, sccstate_obstack
);
3994 /* Check result and argument types. */
3995 v
= visit (TREE_TYPE (type
), state
, v
,
3996 sccstack
, sccstate
, sccstate_obstack
);
3997 for (p
= TYPE_ARG_TYPES (type
), na
= 0; p
; p
= TREE_CHAIN (p
))
3999 v
= visit (TREE_VALUE (p
), state
, v
,
4000 sccstack
, sccstate
, sccstate_obstack
);
4004 v
= iterative_hash_hashval_t (na
, v
);
4007 if (RECORD_OR_UNION_TYPE_P (type
))
4012 for (f
= TYPE_FIELDS (type
), nf
= 0; f
; f
= TREE_CHAIN (f
))
4014 v
= iterative_hash_name (DECL_NAME (f
), v
);
4015 v
= visit (TREE_TYPE (f
), state
, v
,
4016 sccstack
, sccstate
, sccstate_obstack
);
4020 v
= iterative_hash_hashval_t (nf
, v
);
4023 /* Record hash for us. */
4026 /* See if we found an SCC. */
4027 if (state
->low
== state
->dfsnum
)
4030 struct tree_int_map
*m
;
4032 /* Pop off the SCC and set its hash values. */
4033 x
= VEC_pop (tree
, *sccstack
);
4034 /* Optimize SCC size one. */
4037 state
->on_sccstack
= false;
4038 m
= ggc_alloc_cleared_tree_int_map ();
4041 slot
= htab_find_slot (type_hash_cache
, m
, INSERT
);
4042 gcc_assert (!*slot
);
4047 struct sccs
*cstate
;
4048 unsigned first
, i
, size
, j
;
4049 struct type_hash_pair
*pairs
;
4050 /* Pop off the SCC and build an array of type, hash pairs. */
4051 first
= VEC_length (tree
, *sccstack
) - 1;
4052 while (VEC_index (tree
, *sccstack
, first
) != type
)
4054 size
= VEC_length (tree
, *sccstack
) - first
+ 1;
4055 pairs
= XALLOCAVEC (struct type_hash_pair
, size
);
4057 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
4058 cstate
->on_sccstack
= false;
4060 pairs
[i
].hash
= cstate
->u
.hash
;
4063 x
= VEC_pop (tree
, *sccstack
);
4064 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
4065 cstate
->on_sccstack
= false;
4068 pairs
[i
].hash
= cstate
->u
.hash
;
4071 gcc_assert (i
+ 1 == size
);
4072 /* Sort the arrays of type, hash pairs so that when we mix in
4073 all members of the SCC the hash value becomes independent on
4074 the order we visited the SCC. Disregard hashes equal to
4075 the hash of the type we mix into because we cannot guarantee
4076 a stable sort for those across different TUs. */
4077 qsort (pairs
, size
, sizeof (struct type_hash_pair
),
4078 type_hash_pair_compare
);
4079 for (i
= 0; i
< size
; ++i
)
4082 m
= ggc_alloc_cleared_tree_int_map ();
4083 m
->base
.from
= pairs
[i
].type
;
4084 hash
= pairs
[i
].hash
;
4085 /* Skip same hashes. */
4086 for (j
= i
+ 1; j
< size
&& pairs
[j
].hash
== pairs
[i
].hash
; ++j
)
4088 for (; j
< size
; ++j
)
4089 hash
= iterative_hash_hashval_t (pairs
[j
].hash
, hash
);
4090 for (j
= 0; pairs
[j
].hash
!= pairs
[i
].hash
; ++j
)
4091 hash
= iterative_hash_hashval_t (pairs
[j
].hash
, hash
);
4093 if (pairs
[i
].type
== type
)
4095 slot
= htab_find_slot (type_hash_cache
, m
, INSERT
);
4096 gcc_assert (!*slot
);
4102 return iterative_hash_hashval_t (v
, val
);
4106 /* Returns a hash value for P (assumed to be a type). The hash value
4107 is computed using some distinguishing features of the type. Note
4108 that we cannot use pointer hashing here as we may be dealing with
4109 two distinct instances of the same type.
4111 This function should produce the same hash value for two compatible
4112 types according to gimple_types_compatible_p. */
4115 gimple_type_hash (const void *p
)
4117 const_tree t
= (const_tree
) p
;
4118 VEC(tree
, heap
) *sccstack
= NULL
;
4119 struct pointer_map_t
*sccstate
;
4120 struct obstack sccstate_obstack
;
4123 struct tree_int_map m
;
4125 if (type_hash_cache
== NULL
)
4126 type_hash_cache
= htab_create_ggc (512, tree_int_map_hash
,
4127 tree_int_map_eq
, NULL
);
4129 m
.base
.from
= CONST_CAST_TREE (t
);
4130 if ((slot
= htab_find_slot (type_hash_cache
, &m
, NO_INSERT
))
4132 return iterative_hash_hashval_t (((struct tree_int_map
*) *slot
)->to
, 0);
4134 /* Perform a DFS walk and pre-hash all reachable types. */
4136 sccstate
= pointer_map_create ();
4137 gcc_obstack_init (&sccstate_obstack
);
4138 val
= iterative_hash_gimple_type (CONST_CAST_TREE (t
), 0,
4139 &sccstack
, sccstate
, &sccstate_obstack
);
4140 VEC_free (tree
, heap
, sccstack
);
4141 pointer_map_destroy (sccstate
);
4142 obstack_free (&sccstate_obstack
, NULL
);
4147 /* Returning a hash value for gimple type TYPE combined with VAL.
4149 The hash value returned is equal for types considered compatible
4150 by gimple_canonical_types_compatible_p. */
4153 iterative_hash_canonical_type (tree type
, hashval_t val
)
4157 struct tree_int_map
*mp
, m
;
4160 if ((slot
= htab_find_slot (canonical_type_hash_cache
, &m
, INSERT
))
4162 return iterative_hash_hashval_t (((struct tree_int_map
*) *slot
)->to
, val
);
4164 /* Combine a few common features of types so that types are grouped into
4165 smaller sets; when searching for existing matching types to merge,
4166 only existing types having the same features as the new type will be
4168 v
= iterative_hash_hashval_t (TREE_CODE (type
), 0);
4169 v
= iterative_hash_hashval_t (TREE_ADDRESSABLE (type
), v
);
4170 v
= iterative_hash_hashval_t (TYPE_ALIGN (type
), v
);
4171 v
= iterative_hash_hashval_t (TYPE_MODE (type
), v
);
4173 /* Incorporate common features of numerical types. */
4174 if (INTEGRAL_TYPE_P (type
)
4175 || SCALAR_FLOAT_TYPE_P (type
)
4176 || FIXED_POINT_TYPE_P (type
)
4177 || TREE_CODE (type
) == VECTOR_TYPE
4178 || TREE_CODE (type
) == COMPLEX_TYPE
4179 || TREE_CODE (type
) == OFFSET_TYPE
4180 || POINTER_TYPE_P (type
))
4182 v
= iterative_hash_hashval_t (TYPE_PRECISION (type
), v
);
4183 v
= iterative_hash_hashval_t (TYPE_UNSIGNED (type
), v
);
4186 /* For pointer and reference types, fold in information about the type
4187 pointed to but do not recurse to the pointed-to type. */
4188 if (POINTER_TYPE_P (type
))
4190 v
= iterative_hash_hashval_t (TYPE_REF_CAN_ALIAS_ALL (type
), v
);
4191 v
= iterative_hash_hashval_t (TYPE_ADDR_SPACE (TREE_TYPE (type
)), v
);
4192 v
= iterative_hash_hashval_t (TYPE_RESTRICT (type
), v
);
4193 v
= iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type
)), v
);
4196 /* For integer types hash only the string flag. */
4197 if (TREE_CODE (type
) == INTEGER_TYPE
)
4198 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
4200 /* For array types hash the domain bounds and the string flag. */
4201 if (TREE_CODE (type
) == ARRAY_TYPE
&& TYPE_DOMAIN (type
))
4203 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
4204 /* OMP lowering can introduce error_mark_node in place of
4205 random local decls in types. */
4206 if (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)) != error_mark_node
)
4207 v
= iterative_hash_expr (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), v
);
4208 if (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != error_mark_node
)
4209 v
= iterative_hash_expr (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)), v
);
4212 /* Recurse for aggregates with a single element type. */
4213 if (TREE_CODE (type
) == ARRAY_TYPE
4214 || TREE_CODE (type
) == COMPLEX_TYPE
4215 || TREE_CODE (type
) == VECTOR_TYPE
)
4216 v
= iterative_hash_canonical_type (TREE_TYPE (type
), v
);
4218 /* Incorporate function return and argument types. */
4219 if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
4224 /* For method types also incorporate their parent class. */
4225 if (TREE_CODE (type
) == METHOD_TYPE
)
4226 v
= iterative_hash_canonical_type (TYPE_METHOD_BASETYPE (type
), v
);
4228 v
= iterative_hash_canonical_type (TREE_TYPE (type
), v
);
4230 for (p
= TYPE_ARG_TYPES (type
), na
= 0; p
; p
= TREE_CHAIN (p
))
4232 v
= iterative_hash_canonical_type (TREE_VALUE (p
), v
);
4236 v
= iterative_hash_hashval_t (na
, v
);
4239 if (RECORD_OR_UNION_TYPE_P (type
))
4244 for (f
= TYPE_FIELDS (type
), nf
= 0; f
; f
= TREE_CHAIN (f
))
4245 if (TREE_CODE (f
) == FIELD_DECL
)
4247 v
= iterative_hash_canonical_type (TREE_TYPE (f
), v
);
4251 v
= iterative_hash_hashval_t (nf
, v
);
4254 /* Cache the just computed hash value. */
4255 mp
= ggc_alloc_cleared_tree_int_map ();
4256 mp
->base
.from
= type
;
4258 *slot
= (void *) mp
;
4260 return iterative_hash_hashval_t (v
, val
);
4264 gimple_canonical_type_hash (const void *p
)
4266 if (canonical_type_hash_cache
== NULL
)
4267 canonical_type_hash_cache
= htab_create_ggc (512, tree_int_map_hash
,
4268 tree_int_map_eq
, NULL
);
4270 return iterative_hash_canonical_type (CONST_CAST_TREE ((const_tree
) p
), 0);
4274 /* Returns nonzero if P1 and P2 are equal. */
4277 gimple_type_eq (const void *p1
, const void *p2
)
4279 const_tree t1
= (const_tree
) p1
;
4280 const_tree t2
= (const_tree
) p2
;
4281 return gimple_types_compatible_p (CONST_CAST_TREE (t1
),
4282 CONST_CAST_TREE (t2
));
4286 /* Worker for gimple_register_type.
4287 Register type T in the global type table gimple_types.
4288 When REGISTERING_MV is false first recurse for the main variant of T. */
4291 gimple_register_type_1 (tree t
, bool registering_mv
)
4294 gimple_type_leader_entry
*leader
;
4296 /* If we registered this type before return the cached result. */
4297 leader
= &gimple_type_leader
[TYPE_UID (t
) % GIMPLE_TYPE_LEADER_SIZE
];
4298 if (leader
->type
== t
)
4299 return leader
->leader
;
4301 /* Always register the main variant first. This is important so we
4302 pick up the non-typedef variants as canonical, otherwise we'll end
4303 up taking typedef ids for structure tags during comparison.
4304 It also makes sure that main variants will be merged to main variants.
4305 As we are operating on a possibly partially fixed up type graph
4306 do not bother to recurse more than once, otherwise we may end up
4308 If we are registering a main variant it will either remain its
4309 own main variant or it will be merged to something else in which
4310 case we do not care for the main variant leader. */
4312 && TYPE_MAIN_VARIANT (t
) != t
)
4313 gimple_register_type_1 (TYPE_MAIN_VARIANT (t
), true);
4315 /* See if we already have an equivalent type registered. */
4316 slot
= htab_find_slot (gimple_types
, t
, INSERT
);
4318 && *(tree
*)slot
!= t
)
4320 tree new_type
= (tree
) *((tree
*) slot
);
4322 leader
->leader
= new_type
;
4326 /* If not, insert it to the cache and the hash. */
4333 /* Register type T in the global type table gimple_types.
4334 If another type T', compatible with T, already existed in
4335 gimple_types then return T', otherwise return T. This is used by
4336 LTO to merge identical types read from different TUs. */
4339 gimple_register_type (tree t
)
4341 gcc_assert (TYPE_P (t
));
4343 if (!gimple_type_leader
)
4344 gimple_type_leader
= ggc_alloc_cleared_vec_gimple_type_leader_entry_s
4345 (GIMPLE_TYPE_LEADER_SIZE
);
4347 if (gimple_types
== NULL
)
4348 gimple_types
= htab_create_ggc (16381, gimple_type_hash
, gimple_type_eq
, 0);
4350 return gimple_register_type_1 (t
, false);
4353 /* The TYPE_CANONICAL merging machinery. It should closely resemble
4354 the middle-end types_compatible_p function. It needs to avoid
4355 claiming types are different for types that should be treated
4356 the same with respect to TBAA. Canonical types are also used
4357 for IL consistency checks via the useless_type_conversion_p
4358 predicate which does not handle all type kinds itself but falls
4359 back to pointer-comparison of TYPE_CANONICAL for aggregates
4362 /* Return true iff T1 and T2 are structurally identical for what
4363 TBAA is concerned. */
4366 gimple_canonical_types_compatible_p (tree t1
, tree t2
)
4368 /* Before starting to set up the SCC machinery handle simple cases. */
4370 /* Check first for the obvious case of pointer identity. */
4374 /* Check that we have two types to compare. */
4375 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
4378 /* If the types have been previously registered and found equal
4380 if (TYPE_CANONICAL (t1
)
4381 && TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
))
4384 /* Can't be the same type if the types don't have the same code. */
4385 if (TREE_CODE (t1
) != TREE_CODE (t2
))
4388 if (TREE_ADDRESSABLE (t1
) != TREE_ADDRESSABLE (t2
))
4391 /* Qualifiers do not matter for canonical type comparison purposes. */
4393 /* Void types and nullptr types are always the same. */
4394 if (TREE_CODE (t1
) == VOID_TYPE
4395 || TREE_CODE (t1
) == NULLPTR_TYPE
)
4398 /* Can't be the same type if they have different alignment, or mode. */
4399 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
4400 || TYPE_MODE (t1
) != TYPE_MODE (t2
))
4403 /* Non-aggregate types can be handled cheaply. */
4404 if (INTEGRAL_TYPE_P (t1
)
4405 || SCALAR_FLOAT_TYPE_P (t1
)
4406 || FIXED_POINT_TYPE_P (t1
)
4407 || TREE_CODE (t1
) == VECTOR_TYPE
4408 || TREE_CODE (t1
) == COMPLEX_TYPE
4409 || TREE_CODE (t1
) == OFFSET_TYPE
4410 || POINTER_TYPE_P (t1
))
4412 /* Can't be the same type if they have different sign or precision. */
4413 if (TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
4414 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
4417 if (TREE_CODE (t1
) == INTEGER_TYPE
4418 && TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
))
4421 /* For canonical type comparisons we do not want to build SCCs
4422 so we cannot compare pointed-to types. But we can, for now,
4423 require the same pointed-to type kind and match what
4424 useless_type_conversion_p would do. */
4425 if (POINTER_TYPE_P (t1
))
4427 /* If the two pointers have different ref-all attributes,
4428 they can't be the same type. */
4429 if (TYPE_REF_CAN_ALIAS_ALL (t1
) != TYPE_REF_CAN_ALIAS_ALL (t2
))
4432 if (TYPE_ADDR_SPACE (TREE_TYPE (t1
))
4433 != TYPE_ADDR_SPACE (TREE_TYPE (t2
)))
4436 if (TYPE_RESTRICT (t1
) != TYPE_RESTRICT (t2
))
4439 if (TREE_CODE (TREE_TYPE (t1
)) != TREE_CODE (TREE_TYPE (t2
)))
4443 /* Tail-recurse to components. */
4444 if (TREE_CODE (t1
) == VECTOR_TYPE
4445 || TREE_CODE (t1
) == COMPLEX_TYPE
)
4446 return gimple_canonical_types_compatible_p (TREE_TYPE (t1
),
4452 /* If their attributes are not the same they can't be the same type. */
4453 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1
), TYPE_ATTRIBUTES (t2
)))
4456 /* Do type-specific comparisons. */
4457 switch (TREE_CODE (t1
))
4460 /* Array types are the same if the element types are the same and
4461 the number of elements are the same. */
4462 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
4463 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)
4464 || TYPE_NONALIASED_COMPONENT (t1
) != TYPE_NONALIASED_COMPONENT (t2
))
4468 tree i1
= TYPE_DOMAIN (t1
);
4469 tree i2
= TYPE_DOMAIN (t2
);
4471 /* For an incomplete external array, the type domain can be
4472 NULL_TREE. Check this condition also. */
4473 if (i1
== NULL_TREE
&& i2
== NULL_TREE
)
4475 else if (i1
== NULL_TREE
|| i2
== NULL_TREE
)
4479 tree min1
= TYPE_MIN_VALUE (i1
);
4480 tree min2
= TYPE_MIN_VALUE (i2
);
4481 tree max1
= TYPE_MAX_VALUE (i1
);
4482 tree max2
= TYPE_MAX_VALUE (i2
);
4484 /* The minimum/maximum values have to be the same. */
4487 && ((TREE_CODE (min1
) == PLACEHOLDER_EXPR
4488 && TREE_CODE (min2
) == PLACEHOLDER_EXPR
)
4489 || operand_equal_p (min1
, min2
, 0))))
4492 && ((TREE_CODE (max1
) == PLACEHOLDER_EXPR
4493 && TREE_CODE (max2
) == PLACEHOLDER_EXPR
)
4494 || operand_equal_p (max1
, max2
, 0)))))
4502 /* Method types should belong to the same class. */
4503 if (!gimple_canonical_types_compatible_p
4504 (TYPE_METHOD_BASETYPE (t1
), TYPE_METHOD_BASETYPE (t2
)))
4510 /* Function types are the same if the return type and arguments types
4512 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
4515 if (!comp_type_attributes (t1
, t2
))
4518 if (TYPE_ARG_TYPES (t1
) == TYPE_ARG_TYPES (t2
))
4522 tree parms1
, parms2
;
4524 for (parms1
= TYPE_ARG_TYPES (t1
), parms2
= TYPE_ARG_TYPES (t2
);
4526 parms1
= TREE_CHAIN (parms1
), parms2
= TREE_CHAIN (parms2
))
4528 if (!gimple_canonical_types_compatible_p
4529 (TREE_VALUE (parms1
), TREE_VALUE (parms2
)))
4533 if (parms1
|| parms2
)
4541 case QUAL_UNION_TYPE
:
4545 /* For aggregate types, all the fields must be the same. */
4546 for (f1
= TYPE_FIELDS (t1
), f2
= TYPE_FIELDS (t2
);
4548 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
4550 /* Skip non-fields. */
4551 while (f1
&& TREE_CODE (f1
) != FIELD_DECL
)
4552 f1
= TREE_CHAIN (f1
);
4553 while (f2
&& TREE_CODE (f2
) != FIELD_DECL
)
4554 f2
= TREE_CHAIN (f2
);
4557 /* The fields must have the same name, offset and type. */
4558 if (DECL_NONADDRESSABLE_P (f1
) != DECL_NONADDRESSABLE_P (f2
)
4559 || !gimple_compare_field_offset (f1
, f2
)
4560 || !gimple_canonical_types_compatible_p
4561 (TREE_TYPE (f1
), TREE_TYPE (f2
)))
4565 /* If one aggregate has more fields than the other, they
4566 are not the same. */
4579 /* Returns nonzero if P1 and P2 are equal. */
4582 gimple_canonical_type_eq (const void *p1
, const void *p2
)
4584 const_tree t1
= (const_tree
) p1
;
4585 const_tree t2
= (const_tree
) p2
;
4586 return gimple_canonical_types_compatible_p (CONST_CAST_TREE (t1
),
4587 CONST_CAST_TREE (t2
));
4590 /* Register type T in the global type table gimple_types.
4591 If another type T', compatible with T, already existed in
4592 gimple_types then return T', otherwise return T. This is used by
4593 LTO to merge identical types read from different TUs.
4595 ??? This merging does not exactly match how the tree.c middle-end
4596 functions will assign TYPE_CANONICAL when new types are created
4597 during optimization (which at least happens for pointer and array
4601 gimple_register_canonical_type (tree t
)
4605 gcc_assert (TYPE_P (t
));
4607 if (TYPE_CANONICAL (t
))
4608 return TYPE_CANONICAL (t
);
4610 if (gimple_canonical_types
== NULL
)
4611 gimple_canonical_types
= htab_create_ggc (16381, gimple_canonical_type_hash
,
4612 gimple_canonical_type_eq
, 0);
4614 slot
= htab_find_slot (gimple_canonical_types
, t
, INSERT
);
4616 && *(tree
*)slot
!= t
)
4618 tree new_type
= (tree
) *((tree
*) slot
);
4620 TYPE_CANONICAL (t
) = new_type
;
4625 TYPE_CANONICAL (t
) = t
;
4633 /* Show statistics on references to the global type table gimple_types. */
4636 print_gimple_types_stats (void)
4639 fprintf (stderr
, "GIMPLE type table: size %ld, %ld elements, "
4640 "%ld searches, %ld collisions (ratio: %f)\n",
4641 (long) htab_size (gimple_types
),
4642 (long) htab_elements (gimple_types
),
4643 (long) gimple_types
->searches
,
4644 (long) gimple_types
->collisions
,
4645 htab_collisions (gimple_types
));
4647 fprintf (stderr
, "GIMPLE type table is empty\n");
4648 if (type_hash_cache
)
4649 fprintf (stderr
, "GIMPLE type hash table: size %ld, %ld elements, "
4650 "%ld searches, %ld collisions (ratio: %f)\n",
4651 (long) htab_size (type_hash_cache
),
4652 (long) htab_elements (type_hash_cache
),
4653 (long) type_hash_cache
->searches
,
4654 (long) type_hash_cache
->collisions
,
4655 htab_collisions (type_hash_cache
));
4657 fprintf (stderr
, "GIMPLE type hash table is empty\n");
4658 if (gimple_canonical_types
)
4659 fprintf (stderr
, "GIMPLE canonical type table: size %ld, %ld elements, "
4660 "%ld searches, %ld collisions (ratio: %f)\n",
4661 (long) htab_size (gimple_canonical_types
),
4662 (long) htab_elements (gimple_canonical_types
),
4663 (long) gimple_canonical_types
->searches
,
4664 (long) gimple_canonical_types
->collisions
,
4665 htab_collisions (gimple_canonical_types
));
4667 fprintf (stderr
, "GIMPLE canonical type table is empty\n");
4668 if (canonical_type_hash_cache
)
4669 fprintf (stderr
, "GIMPLE canonical type hash table: size %ld, %ld elements, "
4670 "%ld searches, %ld collisions (ratio: %f)\n",
4671 (long) htab_size (canonical_type_hash_cache
),
4672 (long) htab_elements (canonical_type_hash_cache
),
4673 (long) canonical_type_hash_cache
->searches
,
4674 (long) canonical_type_hash_cache
->collisions
,
4675 htab_collisions (canonical_type_hash_cache
));
4677 fprintf (stderr
, "GIMPLE canonical type hash table is empty\n");
4680 /* Free the gimple type hashtables used for LTO type merging. */
4683 free_gimple_type_tables (void)
4685 /* Last chance to print stats for the tables. */
4686 if (flag_lto_report
)
4687 print_gimple_types_stats ();
4691 htab_delete (gimple_types
);
4692 gimple_types
= NULL
;
4694 if (gimple_canonical_types
)
4696 htab_delete (gimple_canonical_types
);
4697 gimple_canonical_types
= NULL
;
4699 if (type_hash_cache
)
4701 htab_delete (type_hash_cache
);
4702 type_hash_cache
= NULL
;
4704 if (canonical_type_hash_cache
)
4706 htab_delete (canonical_type_hash_cache
);
4707 canonical_type_hash_cache
= NULL
;
4709 if (type_pair_cache
)
4711 free (type_pair_cache
);
4712 type_pair_cache
= NULL
;
4714 gimple_type_leader
= NULL
;
4718 /* Return a type the same as TYPE except unsigned or
4719 signed according to UNSIGNEDP. */
4722 gimple_signed_or_unsigned_type (bool unsignedp
, tree type
)
4726 type1
= TYPE_MAIN_VARIANT (type
);
4727 if (type1
== signed_char_type_node
4728 || type1
== char_type_node
4729 || type1
== unsigned_char_type_node
)
4730 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4731 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
4732 return unsignedp
? unsigned_type_node
: integer_type_node
;
4733 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
4734 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4735 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
4736 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4737 if (type1
== long_long_integer_type_node
4738 || type1
== long_long_unsigned_type_node
)
4740 ? long_long_unsigned_type_node
4741 : long_long_integer_type_node
;
4742 if (int128_integer_type_node
&& (type1
== int128_integer_type_node
|| type1
== int128_unsigned_type_node
))
4744 ? int128_unsigned_type_node
4745 : int128_integer_type_node
;
4746 #if HOST_BITS_PER_WIDE_INT >= 64
4747 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
4748 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4750 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
4751 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4752 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
4753 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4754 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
4755 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4756 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
4757 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4759 #define GIMPLE_FIXED_TYPES(NAME) \
4760 if (type1 == short_ ## NAME ## _type_node \
4761 || type1 == unsigned_short_ ## NAME ## _type_node) \
4762 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
4763 : short_ ## NAME ## _type_node; \
4764 if (type1 == NAME ## _type_node \
4765 || type1 == unsigned_ ## NAME ## _type_node) \
4766 return unsignedp ? unsigned_ ## NAME ## _type_node \
4767 : NAME ## _type_node; \
4768 if (type1 == long_ ## NAME ## _type_node \
4769 || type1 == unsigned_long_ ## NAME ## _type_node) \
4770 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
4771 : long_ ## NAME ## _type_node; \
4772 if (type1 == long_long_ ## NAME ## _type_node \
4773 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
4774 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
4775 : long_long_ ## NAME ## _type_node;
4777 #define GIMPLE_FIXED_MODE_TYPES(NAME) \
4778 if (type1 == NAME ## _type_node \
4779 || type1 == u ## NAME ## _type_node) \
4780 return unsignedp ? u ## NAME ## _type_node \
4781 : NAME ## _type_node;
4783 #define GIMPLE_FIXED_TYPES_SAT(NAME) \
4784 if (type1 == sat_ ## short_ ## NAME ## _type_node \
4785 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
4786 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
4787 : sat_ ## short_ ## NAME ## _type_node; \
4788 if (type1 == sat_ ## NAME ## _type_node \
4789 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
4790 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
4791 : sat_ ## NAME ## _type_node; \
4792 if (type1 == sat_ ## long_ ## NAME ## _type_node \
4793 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
4794 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
4795 : sat_ ## long_ ## NAME ## _type_node; \
4796 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
4797 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
4798 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
4799 : sat_ ## long_long_ ## NAME ## _type_node;
4801 #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
4802 if (type1 == sat_ ## NAME ## _type_node \
4803 || type1 == sat_ ## u ## NAME ## _type_node) \
4804 return unsignedp ? sat_ ## u ## NAME ## _type_node \
4805 : sat_ ## NAME ## _type_node;
4807 GIMPLE_FIXED_TYPES (fract
);
4808 GIMPLE_FIXED_TYPES_SAT (fract
);
4809 GIMPLE_FIXED_TYPES (accum
);
4810 GIMPLE_FIXED_TYPES_SAT (accum
);
4812 GIMPLE_FIXED_MODE_TYPES (qq
);
4813 GIMPLE_FIXED_MODE_TYPES (hq
);
4814 GIMPLE_FIXED_MODE_TYPES (sq
);
4815 GIMPLE_FIXED_MODE_TYPES (dq
);
4816 GIMPLE_FIXED_MODE_TYPES (tq
);
4817 GIMPLE_FIXED_MODE_TYPES_SAT (qq
);
4818 GIMPLE_FIXED_MODE_TYPES_SAT (hq
);
4819 GIMPLE_FIXED_MODE_TYPES_SAT (sq
);
4820 GIMPLE_FIXED_MODE_TYPES_SAT (dq
);
4821 GIMPLE_FIXED_MODE_TYPES_SAT (tq
);
4822 GIMPLE_FIXED_MODE_TYPES (ha
);
4823 GIMPLE_FIXED_MODE_TYPES (sa
);
4824 GIMPLE_FIXED_MODE_TYPES (da
);
4825 GIMPLE_FIXED_MODE_TYPES (ta
);
4826 GIMPLE_FIXED_MODE_TYPES_SAT (ha
);
4827 GIMPLE_FIXED_MODE_TYPES_SAT (sa
);
4828 GIMPLE_FIXED_MODE_TYPES_SAT (da
);
4829 GIMPLE_FIXED_MODE_TYPES_SAT (ta
);
4831 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
4832 the precision; they have precision set to match their range, but
4833 may use a wider mode to match an ABI. If we change modes, we may
4834 wind up with bad conversions. For INTEGER_TYPEs in C, must check
4835 the precision as well, so as to yield correct results for
4836 bit-field types. C++ does not have these separate bit-field
4837 types, and producing a signed or unsigned variant of an
4838 ENUMERAL_TYPE may cause other problems as well. */
4839 if (!INTEGRAL_TYPE_P (type
)
4840 || TYPE_UNSIGNED (type
) == unsignedp
)
4843 #define TYPE_OK(node) \
4844 (TYPE_MODE (type) == TYPE_MODE (node) \
4845 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
4846 if (TYPE_OK (signed_char_type_node
))
4847 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4848 if (TYPE_OK (integer_type_node
))
4849 return unsignedp
? unsigned_type_node
: integer_type_node
;
4850 if (TYPE_OK (short_integer_type_node
))
4851 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4852 if (TYPE_OK (long_integer_type_node
))
4853 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4854 if (TYPE_OK (long_long_integer_type_node
))
4856 ? long_long_unsigned_type_node
4857 : long_long_integer_type_node
);
4858 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
4860 ? int128_unsigned_type_node
4861 : int128_integer_type_node
);
4863 #if HOST_BITS_PER_WIDE_INT >= 64
4864 if (TYPE_OK (intTI_type_node
))
4865 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4867 if (TYPE_OK (intDI_type_node
))
4868 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4869 if (TYPE_OK (intSI_type_node
))
4870 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4871 if (TYPE_OK (intHI_type_node
))
4872 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4873 if (TYPE_OK (intQI_type_node
))
4874 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4876 #undef GIMPLE_FIXED_TYPES
4877 #undef GIMPLE_FIXED_MODE_TYPES
4878 #undef GIMPLE_FIXED_TYPES_SAT
4879 #undef GIMPLE_FIXED_MODE_TYPES_SAT
4882 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
4886 /* Return an unsigned type the same as TYPE in other respects. */
4889 gimple_unsigned_type (tree type
)
4891 return gimple_signed_or_unsigned_type (true, type
);
4895 /* Return a signed type the same as TYPE in other respects. */
4898 gimple_signed_type (tree type
)
4900 return gimple_signed_or_unsigned_type (false, type
);
4904 /* Return the typed-based alias set for T, which may be an expression
4905 or a type. Return -1 if we don't do anything special. */
4908 gimple_get_alias_set (tree t
)
4912 /* Permit type-punning when accessing a union, provided the access
4913 is directly through the union. For example, this code does not
4914 permit taking the address of a union member and then storing
4915 through it. Even the type-punning allowed here is a GCC
4916 extension, albeit a common and useful one; the C standard says
4917 that such accesses have implementation-defined behavior. */
4919 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4920 u
= TREE_OPERAND (u
, 0))
4921 if (TREE_CODE (u
) == COMPONENT_REF
4922 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4925 /* That's all the expressions we handle specially. */
4929 /* For convenience, follow the C standard when dealing with
4930 character types. Any object may be accessed via an lvalue that
4931 has character type. */
4932 if (t
== char_type_node
4933 || t
== signed_char_type_node
4934 || t
== unsigned_char_type_node
)
4937 /* Allow aliasing between signed and unsigned variants of the same
4938 type. We treat the signed variant as canonical. */
4939 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4941 tree t1
= gimple_signed_type (t
);
4943 /* t1 == t can happen for boolean nodes which are always unsigned. */
4945 return get_alias_set (t1
);
4952 /* Data structure used to count the number of dereferences to PTR
4953 inside an expression. */
4957 unsigned num_stores
;
4961 /* Helper for count_uses_and_derefs. Called by walk_tree to look for
4962 (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA. */
4965 count_ptr_derefs (tree
*tp
, int *walk_subtrees
, void *data
)
4967 struct walk_stmt_info
*wi_p
= (struct walk_stmt_info
*) data
;
4968 struct count_ptr_d
*count_p
= (struct count_ptr_d
*) wi_p
->info
;
4970 /* Do not walk inside ADDR_EXPR nodes. In the expression &ptr->fld,
4971 pointer 'ptr' is *not* dereferenced, it is simply used to compute
4972 the address of 'fld' as 'ptr + offsetof(fld)'. */
4973 if (TREE_CODE (*tp
) == ADDR_EXPR
)
4979 if (TREE_CODE (*tp
) == MEM_REF
&& TREE_OPERAND (*tp
, 0) == count_p
->ptr
)
4982 count_p
->num_stores
++;
4984 count_p
->num_loads
++;
4990 /* Count the number of direct and indirect uses for pointer PTR in
4991 statement STMT. The number of direct uses is stored in
4992 *NUM_USES_P. Indirect references are counted separately depending
4993 on whether they are store or load operations. The counts are
4994 stored in *NUM_STORES_P and *NUM_LOADS_P. */
4997 count_uses_and_derefs (tree ptr
, gimple stmt
, unsigned *num_uses_p
,
4998 unsigned *num_loads_p
, unsigned *num_stores_p
)
5007 /* Find out the total number of uses of PTR in STMT. */
5008 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, i
, SSA_OP_USE
)
5012 /* Now count the number of indirect references to PTR. This is
5013 truly awful, but we don't have much choice. There are no parent
5014 pointers inside INDIRECT_REFs, so an expression like
5015 '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to
5016 find all the indirect and direct uses of x_1 inside. The only
5017 shortcut we can take is the fact that GIMPLE only allows
5018 INDIRECT_REFs inside the expressions below. */
5019 if (is_gimple_assign (stmt
)
5020 || gimple_code (stmt
) == GIMPLE_RETURN
5021 || gimple_code (stmt
) == GIMPLE_ASM
5022 || is_gimple_call (stmt
))
5024 struct walk_stmt_info wi
;
5025 struct count_ptr_d count
;
5028 count
.num_stores
= 0;
5029 count
.num_loads
= 0;
5031 memset (&wi
, 0, sizeof (wi
));
5033 walk_gimple_op (stmt
, count_ptr_derefs
, &wi
);
5035 *num_stores_p
= count
.num_stores
;
5036 *num_loads_p
= count
.num_loads
;
5039 gcc_assert (*num_uses_p
>= *num_loads_p
+ *num_stores_p
);
5042 /* From a tree operand OP return the base of a load or store operation
5043 or NULL_TREE if OP is not a load or a store. */
5046 get_base_loadstore (tree op
)
5048 while (handled_component_p (op
))
5049 op
= TREE_OPERAND (op
, 0);
5051 || INDIRECT_REF_P (op
)
5052 || TREE_CODE (op
) == MEM_REF
5053 || TREE_CODE (op
) == TARGET_MEM_REF
)
5058 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
5059 VISIT_ADDR if non-NULL on loads, store and address-taken operands
5060 passing the STMT, the base of the operand and DATA to it. The base
5061 will be either a decl, an indirect reference (including TARGET_MEM_REF)
5062 or the argument of an address expression.
5063 Returns the results of these callbacks or'ed. */
5066 walk_stmt_load_store_addr_ops (gimple stmt
, void *data
,
5067 bool (*visit_load
)(gimple
, tree
, void *),
5068 bool (*visit_store
)(gimple
, tree
, void *),
5069 bool (*visit_addr
)(gimple
, tree
, void *))
5073 if (gimple_assign_single_p (stmt
))
5078 lhs
= get_base_loadstore (gimple_assign_lhs (stmt
));
5080 ret
|= visit_store (stmt
, lhs
, data
);
5082 rhs
= gimple_assign_rhs1 (stmt
);
5083 while (handled_component_p (rhs
))
5084 rhs
= TREE_OPERAND (rhs
, 0);
5087 if (TREE_CODE (rhs
) == ADDR_EXPR
)
5088 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
5089 else if (TREE_CODE (rhs
) == TARGET_MEM_REF
5090 && TREE_CODE (TMR_BASE (rhs
)) == ADDR_EXPR
)
5091 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (rhs
), 0), data
);
5092 else if (TREE_CODE (rhs
) == OBJ_TYPE_REF
5093 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs
)) == ADDR_EXPR
)
5094 ret
|= visit_addr (stmt
, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs
),
5096 else if (TREE_CODE (rhs
) == CONSTRUCTOR
)
5101 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs
), ix
, val
)
5102 if (TREE_CODE (val
) == ADDR_EXPR
)
5103 ret
|= visit_addr (stmt
, TREE_OPERAND (val
, 0), data
);
5104 else if (TREE_CODE (val
) == OBJ_TYPE_REF
5105 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val
)) == ADDR_EXPR
)
5106 ret
|= visit_addr (stmt
,
5107 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val
),
5110 lhs
= gimple_assign_lhs (stmt
);
5111 if (TREE_CODE (lhs
) == TARGET_MEM_REF
5112 && TREE_CODE (TMR_BASE (lhs
)) == ADDR_EXPR
)
5113 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (lhs
), 0), data
);
5117 rhs
= get_base_loadstore (rhs
);
5119 ret
|= visit_load (stmt
, rhs
, data
);
5123 && (is_gimple_assign (stmt
)
5124 || gimple_code (stmt
) == GIMPLE_COND
))
5126 for (i
= 0; i
< gimple_num_ops (stmt
); ++i
)
5128 tree op
= gimple_op (stmt
, i
);
5129 if (op
== NULL_TREE
)
5131 else if (TREE_CODE (op
) == ADDR_EXPR
)
5132 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5133 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
5134 tree with two operands. */
5135 else if (i
== 1 && COMPARISON_CLASS_P (op
))
5137 if (TREE_CODE (TREE_OPERAND (op
, 0)) == ADDR_EXPR
)
5138 ret
|= visit_addr (stmt
, TREE_OPERAND (TREE_OPERAND (op
, 0),
5140 if (TREE_CODE (TREE_OPERAND (op
, 1)) == ADDR_EXPR
)
5141 ret
|= visit_addr (stmt
, TREE_OPERAND (TREE_OPERAND (op
, 1),
5146 else if (is_gimple_call (stmt
))
5150 tree lhs
= gimple_call_lhs (stmt
);
5153 lhs
= get_base_loadstore (lhs
);
5155 ret
|= visit_store (stmt
, lhs
, data
);
5158 if (visit_load
|| visit_addr
)
5159 for (i
= 0; i
< gimple_call_num_args (stmt
); ++i
)
5161 tree rhs
= gimple_call_arg (stmt
, i
);
5163 && TREE_CODE (rhs
) == ADDR_EXPR
)
5164 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
5165 else if (visit_load
)
5167 rhs
= get_base_loadstore (rhs
);
5169 ret
|= visit_load (stmt
, rhs
, data
);
5173 && gimple_call_chain (stmt
)
5174 && TREE_CODE (gimple_call_chain (stmt
)) == ADDR_EXPR
)
5175 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_call_chain (stmt
), 0),
5178 && gimple_call_return_slot_opt_p (stmt
)
5179 && gimple_call_lhs (stmt
) != NULL_TREE
5180 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt
))))
5181 ret
|= visit_addr (stmt
, gimple_call_lhs (stmt
), data
);
5183 else if (gimple_code (stmt
) == GIMPLE_ASM
)
5186 const char *constraint
;
5187 const char **oconstraints
;
5188 bool allows_mem
, allows_reg
, is_inout
;
5189 noutputs
= gimple_asm_noutputs (stmt
);
5190 oconstraints
= XALLOCAVEC (const char *, noutputs
);
5191 if (visit_store
|| visit_addr
)
5192 for (i
= 0; i
< gimple_asm_noutputs (stmt
); ++i
)
5194 tree link
= gimple_asm_output_op (stmt
, i
);
5195 tree op
= get_base_loadstore (TREE_VALUE (link
));
5196 if (op
&& visit_store
)
5197 ret
|= visit_store (stmt
, op
, data
);
5200 constraint
= TREE_STRING_POINTER
5201 (TREE_VALUE (TREE_PURPOSE (link
)));
5202 oconstraints
[i
] = constraint
;
5203 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
,
5204 &allows_reg
, &is_inout
);
5205 if (op
&& !allows_reg
&& allows_mem
)
5206 ret
|= visit_addr (stmt
, op
, data
);
5209 if (visit_load
|| visit_addr
)
5210 for (i
= 0; i
< gimple_asm_ninputs (stmt
); ++i
)
5212 tree link
= gimple_asm_input_op (stmt
, i
);
5213 tree op
= TREE_VALUE (link
);
5215 && TREE_CODE (op
) == ADDR_EXPR
)
5216 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5217 else if (visit_load
|| visit_addr
)
5219 op
= get_base_loadstore (op
);
5223 ret
|= visit_load (stmt
, op
, data
);
5226 constraint
= TREE_STRING_POINTER
5227 (TREE_VALUE (TREE_PURPOSE (link
)));
5228 parse_input_constraint (&constraint
, 0, 0, noutputs
,
5230 &allows_mem
, &allows_reg
);
5231 if (!allows_reg
&& allows_mem
)
5232 ret
|= visit_addr (stmt
, op
, data
);
5238 else if (gimple_code (stmt
) == GIMPLE_RETURN
)
5240 tree op
= gimple_return_retval (stmt
);
5244 && TREE_CODE (op
) == ADDR_EXPR
)
5245 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5246 else if (visit_load
)
5248 op
= get_base_loadstore (op
);
5250 ret
|= visit_load (stmt
, op
, data
);
5255 && gimple_code (stmt
) == GIMPLE_PHI
)
5257 for (i
= 0; i
< gimple_phi_num_args (stmt
); ++i
)
5259 tree op
= PHI_ARG_DEF (stmt
, i
);
5260 if (TREE_CODE (op
) == ADDR_EXPR
)
5261 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5268 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
5269 should make a faster clone for this case. */
5272 walk_stmt_load_store_ops (gimple stmt
, void *data
,
5273 bool (*visit_load
)(gimple
, tree
, void *),
5274 bool (*visit_store
)(gimple
, tree
, void *))
5276 return walk_stmt_load_store_addr_ops (stmt
, data
,
5277 visit_load
, visit_store
, NULL
);
5280 /* Helper for gimple_ior_addresses_taken_1. */
5283 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED
,
5284 tree addr
, void *data
)
5286 bitmap addresses_taken
= (bitmap
)data
;
5287 addr
= get_base_address (addr
);
5291 bitmap_set_bit (addresses_taken
, DECL_UID (addr
));
5297 /* Set the bit for the uid of all decls that have their address taken
5298 in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
5299 were any in this stmt. */
5302 gimple_ior_addresses_taken (bitmap addresses_taken
, gimple stmt
)
5304 return walk_stmt_load_store_addr_ops (stmt
, addresses_taken
, NULL
, NULL
,
5305 gimple_ior_addresses_taken_1
);
5309 /* Return a printable name for symbol DECL. */
5312 gimple_decl_printable_name (tree decl
, int verbosity
)
5314 if (!DECL_NAME (decl
))
5317 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
5319 const char *str
, *mangled_str
;
5320 int dmgl_opts
= DMGL_NO_OPTS
;
5324 dmgl_opts
= DMGL_VERBOSE
5328 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5329 dmgl_opts
|= DMGL_PARAMS
;
5332 mangled_str
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5333 str
= cplus_demangle_v3 (mangled_str
, dmgl_opts
);
5334 return (str
) ? str
: mangled_str
;
5337 return IDENTIFIER_POINTER (DECL_NAME (decl
));
5340 /* Return true when STMT is builtins call to CODE. */
5343 gimple_call_builtin_p (gimple stmt
, enum built_in_function code
)
5346 return (is_gimple_call (stmt
)
5347 && (fndecl
= gimple_call_fndecl (stmt
)) != NULL
5348 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
5349 && DECL_FUNCTION_CODE (fndecl
) == code
);
5352 /* Return true if STMT clobbers memory. STMT is required to be a
5356 gimple_asm_clobbers_memory_p (const_gimple stmt
)
5360 for (i
= 0; i
< gimple_asm_nclobbers (stmt
); i
++)
5362 tree op
= gimple_asm_clobber_op (stmt
, i
);
5363 if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op
)), "memory") == 0)
5369 #include "gt-gimple.h"