1 /* Gimple IR support functions.
3 Copyright 2007, 2008, 2009, 2010 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
[] = {
97 #endif /* GATHER_STATISTICS */
99 /* A cache of gimple_seq objects. Sequences are created and destroyed
100 fairly often during gimplification. */
101 static GTY ((deletable
)) struct gimple_seq_d
*gimple_seq_cache
;
103 /* Private API manipulation functions shared only with some
105 extern void gimple_set_stored_syms (gimple
, bitmap
, bitmap_obstack
*);
106 extern void gimple_set_loaded_syms (gimple
, bitmap
, bitmap_obstack
*);
108 /* Gimple tuple constructors.
109 Note: Any constructor taking a ``gimple_seq'' as a parameter, can
110 be passed a NULL to start with an empty sequence. */
112 /* Set the code for statement G to CODE. */
115 gimple_set_code (gimple g
, enum gimple_code code
)
117 g
->gsbase
.code
= code
;
120 /* Return the number of bytes needed to hold a GIMPLE statement with
124 gimple_size (enum gimple_code code
)
126 return gsstruct_code_size
[gss_for_code (code
)];
129 /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
133 gimple_alloc_stat (enum gimple_code code
, unsigned num_ops MEM_STAT_DECL
)
138 size
= gimple_size (code
);
140 size
+= sizeof (tree
) * (num_ops
- 1);
142 #ifdef GATHER_STATISTICS
144 enum gimple_alloc_kind kind
= gimple_alloc_kind (code
);
145 gimple_alloc_counts
[(int) kind
]++;
146 gimple_alloc_sizes
[(int) kind
] += size
;
150 stmt
= ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT
);
151 gimple_set_code (stmt
, code
);
152 gimple_set_num_ops (stmt
, num_ops
);
154 /* Do not call gimple_set_modified here as it has other side
155 effects and this tuple is still not completely built. */
156 stmt
->gsbase
.modified
= 1;
161 /* Set SUBCODE to be the code of the expression computed by statement G. */
164 gimple_set_subcode (gimple g
, unsigned subcode
)
166 /* We only have 16 bits for the RHS code. Assert that we are not
168 gcc_assert (subcode
< (1 << 16));
169 g
->gsbase
.subcode
= subcode
;
174 /* Build a tuple with operands. CODE is the statement to build (which
175 must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the sub-code
176 for the new tuple. NUM_OPS is the number of operands to allocate. */
178 #define gimple_build_with_ops(c, s, n) \
179 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
182 gimple_build_with_ops_stat (enum gimple_code code
, unsigned subcode
,
183 unsigned num_ops MEM_STAT_DECL
)
185 gimple s
= gimple_alloc_stat (code
, num_ops PASS_MEM_STAT
);
186 gimple_set_subcode (s
, subcode
);
192 /* Build a GIMPLE_RETURN statement returning RETVAL. */
195 gimple_build_return (tree retval
)
197 gimple s
= gimple_build_with_ops (GIMPLE_RETURN
, ERROR_MARK
, 1);
199 gimple_return_set_retval (s
, retval
);
203 /* Reset alias information on call S. */
206 gimple_call_reset_alias_info (gimple s
)
208 if (gimple_call_flags (s
) & ECF_CONST
)
209 memset (gimple_call_use_set (s
), 0, sizeof (struct pt_solution
));
211 pt_solution_reset (gimple_call_use_set (s
));
212 if (gimple_call_flags (s
) & (ECF_CONST
|ECF_PURE
|ECF_NOVOPS
))
213 memset (gimple_call_clobber_set (s
), 0, sizeof (struct pt_solution
));
215 pt_solution_reset (gimple_call_clobber_set (s
));
218 /* Helper for gimple_build_call, gimple_build_call_vec and
219 gimple_build_call_from_tree. Build the basic components of a
220 GIMPLE_CALL statement to function FN with NARGS arguments. */
223 gimple_build_call_1 (tree fn
, unsigned nargs
)
225 gimple s
= gimple_build_with_ops (GIMPLE_CALL
, ERROR_MARK
, nargs
+ 3);
226 if (TREE_CODE (fn
) == FUNCTION_DECL
)
227 fn
= build_fold_addr_expr (fn
);
228 gimple_set_op (s
, 1, fn
);
229 gimple_call_set_fntype (s
, TREE_TYPE (TREE_TYPE (fn
)));
230 gimple_call_reset_alias_info (s
);
235 /* Build a GIMPLE_CALL statement to function FN with the arguments
236 specified in vector ARGS. */
239 gimple_build_call_vec (tree fn
, VEC(tree
, heap
) *args
)
242 unsigned nargs
= VEC_length (tree
, args
);
243 gimple call
= gimple_build_call_1 (fn
, nargs
);
245 for (i
= 0; i
< nargs
; i
++)
246 gimple_call_set_arg (call
, i
, VEC_index (tree
, args
, i
));
252 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
253 arguments. The ... are the arguments. */
256 gimple_build_call (tree fn
, unsigned nargs
, ...)
262 gcc_assert (TREE_CODE (fn
) == FUNCTION_DECL
|| is_gimple_call_addr (fn
));
264 call
= gimple_build_call_1 (fn
, nargs
);
266 va_start (ap
, nargs
);
267 for (i
= 0; i
< nargs
; i
++)
268 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
275 /* Helper for gimple_build_call_internal and gimple_build_call_internal_vec.
276 Build the basic components of a GIMPLE_CALL statement to internal
277 function FN with NARGS arguments. */
280 gimple_build_call_internal_1 (enum internal_fn fn
, unsigned nargs
)
282 gimple s
= gimple_build_with_ops (GIMPLE_CALL
, ERROR_MARK
, nargs
+ 3);
283 s
->gsbase
.subcode
|= GF_CALL_INTERNAL
;
284 gimple_call_set_internal_fn (s
, fn
);
285 gimple_call_reset_alias_info (s
);
290 /* Build a GIMPLE_CALL statement to internal function FN. NARGS is
291 the number of arguments. The ... are the arguments. */
294 gimple_build_call_internal (enum internal_fn fn
, unsigned nargs
, ...)
300 call
= gimple_build_call_internal_1 (fn
, nargs
);
301 va_start (ap
, nargs
);
302 for (i
= 0; i
< nargs
; i
++)
303 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
310 /* Build a GIMPLE_CALL statement to internal function FN with the arguments
311 specified in vector ARGS. */
314 gimple_build_call_internal_vec (enum internal_fn fn
, VEC(tree
, heap
) *args
)
319 nargs
= VEC_length (tree
, args
);
320 call
= gimple_build_call_internal_1 (fn
, nargs
);
321 for (i
= 0; i
< nargs
; i
++)
322 gimple_call_set_arg (call
, i
, VEC_index (tree
, args
, i
));
328 /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
329 assumed to be in GIMPLE form already. Minimal checking is done of
333 gimple_build_call_from_tree (tree t
)
337 tree fndecl
= get_callee_fndecl (t
);
339 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
341 nargs
= call_expr_nargs (t
);
342 call
= gimple_build_call_1 (fndecl
? fndecl
: CALL_EXPR_FN (t
), nargs
);
344 for (i
= 0; i
< nargs
; i
++)
345 gimple_call_set_arg (call
, i
, CALL_EXPR_ARG (t
, i
));
347 gimple_set_block (call
, TREE_BLOCK (t
));
349 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
350 gimple_call_set_chain (call
, CALL_EXPR_STATIC_CHAIN (t
));
351 gimple_call_set_tail (call
, CALL_EXPR_TAILCALL (t
));
352 gimple_call_set_cannot_inline (call
, CALL_CANNOT_INLINE_P (t
));
353 gimple_call_set_return_slot_opt (call
, CALL_EXPR_RETURN_SLOT_OPT (t
));
355 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
356 && DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_ALLOCA
)
357 gimple_call_set_alloca_for_var (call
, CALL_ALLOCA_FOR_VAR_P (t
));
359 gimple_call_set_from_thunk (call
, CALL_FROM_THUNK_P (t
));
360 gimple_call_set_va_arg_pack (call
, CALL_EXPR_VA_ARG_PACK (t
));
361 gimple_call_set_nothrow (call
, TREE_NOTHROW (t
));
362 gimple_set_no_warning (call
, TREE_NO_WARNING (t
));
368 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
369 *OP1_P, *OP2_P and *OP3_P respectively. */
372 extract_ops_from_tree_1 (tree expr
, enum tree_code
*subcode_p
, tree
*op1_p
,
373 tree
*op2_p
, tree
*op3_p
)
375 enum gimple_rhs_class grhs_class
;
377 *subcode_p
= TREE_CODE (expr
);
378 grhs_class
= get_gimple_rhs_class (*subcode_p
);
380 if (grhs_class
== GIMPLE_TERNARY_RHS
)
382 *op1_p
= TREE_OPERAND (expr
, 0);
383 *op2_p
= TREE_OPERAND (expr
, 1);
384 *op3_p
= TREE_OPERAND (expr
, 2);
386 else if (grhs_class
== GIMPLE_BINARY_RHS
)
388 *op1_p
= TREE_OPERAND (expr
, 0);
389 *op2_p
= TREE_OPERAND (expr
, 1);
392 else if (grhs_class
== GIMPLE_UNARY_RHS
)
394 *op1_p
= TREE_OPERAND (expr
, 0);
398 else if (grhs_class
== GIMPLE_SINGLE_RHS
)
409 /* Build a GIMPLE_ASSIGN statement.
411 LHS of the assignment.
412 RHS of the assignment which can be unary or binary. */
415 gimple_build_assign_stat (tree lhs
, tree rhs MEM_STAT_DECL
)
417 enum tree_code subcode
;
420 extract_ops_from_tree_1 (rhs
, &subcode
, &op1
, &op2
, &op3
);
421 return gimple_build_assign_with_ops_stat (subcode
, lhs
, op1
, op2
, op3
426 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands
427 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
428 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
431 gimple_build_assign_with_ops_stat (enum tree_code subcode
, tree lhs
, tree op1
,
432 tree op2
, tree op3 MEM_STAT_DECL
)
437 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
439 num_ops
= get_gimple_rhs_num_ops (subcode
) + 1;
441 p
= gimple_build_with_ops_stat (GIMPLE_ASSIGN
, (unsigned)subcode
, num_ops
443 gimple_assign_set_lhs (p
, lhs
);
444 gimple_assign_set_rhs1 (p
, op1
);
447 gcc_assert (num_ops
> 2);
448 gimple_assign_set_rhs2 (p
, op2
);
453 gcc_assert (num_ops
> 3);
454 gimple_assign_set_rhs3 (p
, op3
);
461 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
463 DST/SRC are the destination and source respectively. You can pass
464 ungimplified trees in DST or SRC, in which case they will be
465 converted to a gimple operand if necessary.
467 This function returns the newly created GIMPLE_ASSIGN tuple. */
470 gimplify_assign (tree dst
, tree src
, gimple_seq
*seq_p
)
472 tree t
= build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
473 gimplify_and_add (t
, seq_p
);
475 return gimple_seq_last_stmt (*seq_p
);
479 /* Build a GIMPLE_COND statement.
481 PRED is the condition used to compare LHS and the RHS.
482 T_LABEL is the label to jump to if the condition is true.
483 F_LABEL is the label to jump to otherwise. */
486 gimple_build_cond (enum tree_code pred_code
, tree lhs
, tree rhs
,
487 tree t_label
, tree f_label
)
491 gcc_assert (TREE_CODE_CLASS (pred_code
) == tcc_comparison
);
492 p
= gimple_build_with_ops (GIMPLE_COND
, pred_code
, 4);
493 gimple_cond_set_lhs (p
, lhs
);
494 gimple_cond_set_rhs (p
, rhs
);
495 gimple_cond_set_true_label (p
, t_label
);
496 gimple_cond_set_false_label (p
, f_label
);
501 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
504 gimple_cond_get_ops_from_tree (tree cond
, enum tree_code
*code_p
,
505 tree
*lhs_p
, tree
*rhs_p
)
507 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond
)) == tcc_comparison
508 || TREE_CODE (cond
) == TRUTH_NOT_EXPR
509 || is_gimple_min_invariant (cond
)
510 || SSA_VAR_P (cond
));
512 extract_ops_from_tree (cond
, code_p
, lhs_p
, rhs_p
);
514 /* Canonicalize conditionals of the form 'if (!VAL)'. */
515 if (*code_p
== TRUTH_NOT_EXPR
)
518 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
519 *rhs_p
= build_zero_cst (TREE_TYPE (*lhs_p
));
521 /* Canonicalize conditionals of the form 'if (VAL)' */
522 else if (TREE_CODE_CLASS (*code_p
) != tcc_comparison
)
525 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
526 *rhs_p
= build_zero_cst (TREE_TYPE (*lhs_p
));
531 /* Build a GIMPLE_COND statement from the conditional expression tree
532 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
535 gimple_build_cond_from_tree (tree cond
, tree t_label
, tree f_label
)
540 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
541 return gimple_build_cond (code
, lhs
, rhs
, t_label
, f_label
);
544 /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
545 boolean expression tree COND. */
548 gimple_cond_set_condition_from_tree (gimple stmt
, tree cond
)
553 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
554 gimple_cond_set_condition (stmt
, code
, lhs
, rhs
);
557 /* Build a GIMPLE_LABEL statement for LABEL. */
560 gimple_build_label (tree label
)
562 gimple p
= gimple_build_with_ops (GIMPLE_LABEL
, ERROR_MARK
, 1);
563 gimple_label_set_label (p
, label
);
567 /* Build a GIMPLE_GOTO statement to label DEST. */
570 gimple_build_goto (tree dest
)
572 gimple p
= gimple_build_with_ops (GIMPLE_GOTO
, ERROR_MARK
, 1);
573 gimple_goto_set_dest (p
, dest
);
578 /* Build a GIMPLE_NOP statement. */
581 gimple_build_nop (void)
583 return gimple_alloc (GIMPLE_NOP
, 0);
587 /* Build a GIMPLE_BIND statement.
588 VARS are the variables in BODY.
589 BLOCK is the containing block. */
592 gimple_build_bind (tree vars
, gimple_seq body
, tree block
)
594 gimple p
= gimple_alloc (GIMPLE_BIND
, 0);
595 gimple_bind_set_vars (p
, vars
);
597 gimple_bind_set_body (p
, body
);
599 gimple_bind_set_block (p
, block
);
603 /* Helper function to set the simple fields of a asm stmt.
605 STRING is a pointer to a string that is the asm blocks assembly code.
606 NINPUT is the number of register inputs.
607 NOUTPUT is the number of register outputs.
608 NCLOBBERS is the number of clobbered registers.
612 gimple_build_asm_1 (const char *string
, unsigned ninputs
, unsigned noutputs
,
613 unsigned nclobbers
, unsigned nlabels
)
616 int size
= strlen (string
);
618 /* ASMs with labels cannot have outputs. This should have been
619 enforced by the front end. */
620 gcc_assert (nlabels
== 0 || noutputs
== 0);
622 p
= gimple_build_with_ops (GIMPLE_ASM
, ERROR_MARK
,
623 ninputs
+ noutputs
+ nclobbers
+ nlabels
);
625 p
->gimple_asm
.ni
= ninputs
;
626 p
->gimple_asm
.no
= noutputs
;
627 p
->gimple_asm
.nc
= nclobbers
;
628 p
->gimple_asm
.nl
= nlabels
;
629 p
->gimple_asm
.string
= ggc_alloc_string (string
, size
);
631 #ifdef GATHER_STATISTICS
632 gimple_alloc_sizes
[(int) gimple_alloc_kind (GIMPLE_ASM
)] += size
;
638 /* Build a GIMPLE_ASM statement.
640 STRING is the assembly code.
641 NINPUT is the number of register inputs.
642 NOUTPUT is the number of register outputs.
643 NCLOBBERS is the number of clobbered registers.
644 INPUTS is a vector of the input register parameters.
645 OUTPUTS is a vector of the output register parameters.
646 CLOBBERS is a vector of the clobbered register parameters.
647 LABELS is a vector of destination labels. */
650 gimple_build_asm_vec (const char *string
, VEC(tree
,gc
)* inputs
,
651 VEC(tree
,gc
)* outputs
, VEC(tree
,gc
)* clobbers
,
652 VEC(tree
,gc
)* labels
)
657 p
= gimple_build_asm_1 (string
,
658 VEC_length (tree
, inputs
),
659 VEC_length (tree
, outputs
),
660 VEC_length (tree
, clobbers
),
661 VEC_length (tree
, labels
));
663 for (i
= 0; i
< VEC_length (tree
, inputs
); i
++)
664 gimple_asm_set_input_op (p
, i
, VEC_index (tree
, inputs
, i
));
666 for (i
= 0; i
< VEC_length (tree
, outputs
); i
++)
667 gimple_asm_set_output_op (p
, i
, VEC_index (tree
, outputs
, i
));
669 for (i
= 0; i
< VEC_length (tree
, clobbers
); i
++)
670 gimple_asm_set_clobber_op (p
, i
, VEC_index (tree
, clobbers
, i
));
672 for (i
= 0; i
< VEC_length (tree
, labels
); i
++)
673 gimple_asm_set_label_op (p
, i
, VEC_index (tree
, labels
, i
));
678 /* Build a GIMPLE_CATCH statement.
680 TYPES are the catch types.
681 HANDLER is the exception handler. */
684 gimple_build_catch (tree types
, gimple_seq handler
)
686 gimple p
= gimple_alloc (GIMPLE_CATCH
, 0);
687 gimple_catch_set_types (p
, types
);
689 gimple_catch_set_handler (p
, handler
);
694 /* Build a GIMPLE_EH_FILTER statement.
696 TYPES are the filter's types.
697 FAILURE is the filter's failure action. */
700 gimple_build_eh_filter (tree types
, gimple_seq failure
)
702 gimple p
= gimple_alloc (GIMPLE_EH_FILTER
, 0);
703 gimple_eh_filter_set_types (p
, types
);
705 gimple_eh_filter_set_failure (p
, failure
);
710 /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
713 gimple_build_eh_must_not_throw (tree decl
)
715 gimple p
= gimple_alloc (GIMPLE_EH_MUST_NOT_THROW
, 0);
717 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
718 gcc_assert (flags_from_decl_or_type (decl
) & ECF_NORETURN
);
719 gimple_eh_must_not_throw_set_fndecl (p
, decl
);
724 /* Build a GIMPLE_TRY statement.
726 EVAL is the expression to evaluate.
727 CLEANUP is the cleanup expression.
728 KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
729 whether this is a try/catch or a try/finally respectively. */
732 gimple_build_try (gimple_seq eval
, gimple_seq cleanup
,
733 enum gimple_try_flags kind
)
737 gcc_assert (kind
== GIMPLE_TRY_CATCH
|| kind
== GIMPLE_TRY_FINALLY
);
738 p
= gimple_alloc (GIMPLE_TRY
, 0);
739 gimple_set_subcode (p
, kind
);
741 gimple_try_set_eval (p
, eval
);
743 gimple_try_set_cleanup (p
, cleanup
);
748 /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
750 CLEANUP is the cleanup expression. */
753 gimple_build_wce (gimple_seq cleanup
)
755 gimple p
= gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR
, 0);
757 gimple_wce_set_cleanup (p
, cleanup
);
763 /* Build a GIMPLE_RESX statement. */
766 gimple_build_resx (int region
)
768 gimple p
= gimple_build_with_ops (GIMPLE_RESX
, ERROR_MARK
, 0);
769 p
->gimple_eh_ctrl
.region
= region
;
774 /* The helper for constructing a gimple switch statement.
775 INDEX is the switch's index.
776 NLABELS is the number of labels in the switch excluding the default.
777 DEFAULT_LABEL is the default label for the switch statement. */
780 gimple_build_switch_nlabels (unsigned nlabels
, tree index
, tree default_label
)
782 /* nlabels + 1 default label + 1 index. */
783 gimple p
= gimple_build_with_ops (GIMPLE_SWITCH
, ERROR_MARK
,
784 1 + (default_label
!= NULL
) + nlabels
);
785 gimple_switch_set_index (p
, index
);
787 gimple_switch_set_default_label (p
, default_label
);
792 /* Build a GIMPLE_SWITCH statement.
794 INDEX is the switch's index.
795 NLABELS is the number of labels in the switch excluding the DEFAULT_LABEL.
796 ... are the labels excluding the default. */
799 gimple_build_switch (unsigned nlabels
, tree index
, tree default_label
, ...)
803 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
805 /* Store the rest of the labels. */
806 va_start (al
, default_label
);
807 offset
= (default_label
!= NULL
);
808 for (i
= 0; i
< nlabels
; i
++)
809 gimple_switch_set_label (p
, i
+ offset
, va_arg (al
, tree
));
816 /* Build a GIMPLE_SWITCH statement.
818 INDEX is the switch's index.
819 DEFAULT_LABEL is the default label
820 ARGS is a vector of labels excluding the default. */
823 gimple_build_switch_vec (tree index
, tree default_label
, VEC(tree
, heap
) *args
)
825 unsigned i
, offset
, nlabels
= VEC_length (tree
, args
);
826 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
828 /* Copy the labels from the vector to the switch statement. */
829 offset
= (default_label
!= NULL
);
830 for (i
= 0; i
< nlabels
; i
++)
831 gimple_switch_set_label (p
, i
+ offset
, VEC_index (tree
, args
, i
));
836 /* Build a GIMPLE_EH_DISPATCH statement. */
839 gimple_build_eh_dispatch (int region
)
841 gimple p
= gimple_build_with_ops (GIMPLE_EH_DISPATCH
, ERROR_MARK
, 0);
842 p
->gimple_eh_ctrl
.region
= region
;
846 /* Build a new GIMPLE_DEBUG_BIND statement.
848 VAR is bound to VALUE; block and location are taken from STMT. */
851 gimple_build_debug_bind_stat (tree var
, tree value
, gimple stmt MEM_STAT_DECL
)
853 gimple p
= gimple_build_with_ops_stat (GIMPLE_DEBUG
,
854 (unsigned)GIMPLE_DEBUG_BIND
, 2
857 gimple_debug_bind_set_var (p
, var
);
858 gimple_debug_bind_set_value (p
, value
);
861 gimple_set_block (p
, gimple_block (stmt
));
862 gimple_set_location (p
, gimple_location (stmt
));
869 /* Build a GIMPLE_OMP_CRITICAL statement.
871 BODY is the sequence of statements for which only one thread can execute.
872 NAME is optional identifier for this critical block. */
875 gimple_build_omp_critical (gimple_seq body
, tree name
)
877 gimple p
= gimple_alloc (GIMPLE_OMP_CRITICAL
, 0);
878 gimple_omp_critical_set_name (p
, name
);
880 gimple_omp_set_body (p
, body
);
885 /* Build a GIMPLE_OMP_FOR statement.
887 BODY is sequence of statements inside the for loop.
888 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate,
889 lastprivate, reductions, ordered, schedule, and nowait.
890 COLLAPSE is the collapse count.
891 PRE_BODY is the sequence of statements that are loop invariant. */
894 gimple_build_omp_for (gimple_seq body
, tree clauses
, size_t collapse
,
897 gimple p
= gimple_alloc (GIMPLE_OMP_FOR
, 0);
899 gimple_omp_set_body (p
, body
);
900 gimple_omp_for_set_clauses (p
, clauses
);
901 p
->gimple_omp_for
.collapse
= collapse
;
902 p
->gimple_omp_for
.iter
903 = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse
);
905 gimple_omp_for_set_pre_body (p
, pre_body
);
911 /* Build a GIMPLE_OMP_PARALLEL statement.
913 BODY is sequence of statements which are executed in parallel.
914 CLAUSES, are the OMP parallel construct's clauses.
915 CHILD_FN is the function created for the parallel threads to execute.
916 DATA_ARG are the shared data argument(s). */
919 gimple_build_omp_parallel (gimple_seq body
, tree clauses
, tree child_fn
,
922 gimple p
= gimple_alloc (GIMPLE_OMP_PARALLEL
, 0);
924 gimple_omp_set_body (p
, body
);
925 gimple_omp_parallel_set_clauses (p
, clauses
);
926 gimple_omp_parallel_set_child_fn (p
, child_fn
);
927 gimple_omp_parallel_set_data_arg (p
, data_arg
);
933 /* Build a GIMPLE_OMP_TASK statement.
935 BODY is sequence of statements which are executed by the explicit task.
936 CLAUSES, are the OMP parallel construct's clauses.
937 CHILD_FN is the function created for the parallel threads to execute.
938 DATA_ARG are the shared data argument(s).
939 COPY_FN is the optional function for firstprivate initialization.
940 ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
943 gimple_build_omp_task (gimple_seq body
, tree clauses
, tree child_fn
,
944 tree data_arg
, tree copy_fn
, tree arg_size
,
947 gimple p
= gimple_alloc (GIMPLE_OMP_TASK
, 0);
949 gimple_omp_set_body (p
, body
);
950 gimple_omp_task_set_clauses (p
, clauses
);
951 gimple_omp_task_set_child_fn (p
, child_fn
);
952 gimple_omp_task_set_data_arg (p
, data_arg
);
953 gimple_omp_task_set_copy_fn (p
, copy_fn
);
954 gimple_omp_task_set_arg_size (p
, arg_size
);
955 gimple_omp_task_set_arg_align (p
, arg_align
);
961 /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
963 BODY is the sequence of statements in the section. */
966 gimple_build_omp_section (gimple_seq body
)
968 gimple p
= gimple_alloc (GIMPLE_OMP_SECTION
, 0);
970 gimple_omp_set_body (p
, body
);
976 /* Build a GIMPLE_OMP_MASTER statement.
978 BODY is the sequence of statements to be executed by just the master. */
981 gimple_build_omp_master (gimple_seq body
)
983 gimple p
= gimple_alloc (GIMPLE_OMP_MASTER
, 0);
985 gimple_omp_set_body (p
, body
);
991 /* Build a GIMPLE_OMP_CONTINUE statement.
993 CONTROL_DEF is the definition of the control variable.
994 CONTROL_USE is the use of the control variable. */
997 gimple_build_omp_continue (tree control_def
, tree control_use
)
999 gimple p
= gimple_alloc (GIMPLE_OMP_CONTINUE
, 0);
1000 gimple_omp_continue_set_control_def (p
, control_def
);
1001 gimple_omp_continue_set_control_use (p
, control_use
);
1005 /* Build a GIMPLE_OMP_ORDERED statement.
1007 BODY is the sequence of statements inside a loop that will executed in
1011 gimple_build_omp_ordered (gimple_seq body
)
1013 gimple p
= gimple_alloc (GIMPLE_OMP_ORDERED
, 0);
1015 gimple_omp_set_body (p
, body
);
1021 /* Build a GIMPLE_OMP_RETURN statement.
1022 WAIT_P is true if this is a non-waiting return. */
1025 gimple_build_omp_return (bool wait_p
)
1027 gimple p
= gimple_alloc (GIMPLE_OMP_RETURN
, 0);
1029 gimple_omp_return_set_nowait (p
);
1035 /* Build a GIMPLE_OMP_SECTIONS statement.
1037 BODY is a sequence of section statements.
1038 CLAUSES are any of the OMP sections contsruct's clauses: private,
1039 firstprivate, lastprivate, reduction, and nowait. */
1042 gimple_build_omp_sections (gimple_seq body
, tree clauses
)
1044 gimple p
= gimple_alloc (GIMPLE_OMP_SECTIONS
, 0);
1046 gimple_omp_set_body (p
, body
);
1047 gimple_omp_sections_set_clauses (p
, clauses
);
1053 /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
1056 gimple_build_omp_sections_switch (void)
1058 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH
, 0);
1062 /* Build a GIMPLE_OMP_SINGLE statement.
1064 BODY is the sequence of statements that will be executed once.
1065 CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
1066 copyprivate, nowait. */
1069 gimple_build_omp_single (gimple_seq body
, tree clauses
)
1071 gimple p
= gimple_alloc (GIMPLE_OMP_SINGLE
, 0);
1073 gimple_omp_set_body (p
, body
);
1074 gimple_omp_single_set_clauses (p
, clauses
);
1080 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1083 gimple_build_omp_atomic_load (tree lhs
, tree rhs
)
1085 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD
, 0);
1086 gimple_omp_atomic_load_set_lhs (p
, lhs
);
1087 gimple_omp_atomic_load_set_rhs (p
, rhs
);
1091 /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1093 VAL is the value we are storing. */
1096 gimple_build_omp_atomic_store (tree val
)
1098 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_STORE
, 0);
1099 gimple_omp_atomic_store_set_val (p
, val
);
1103 /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
1104 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
1107 gimple_build_predict (enum br_predictor predictor
, enum prediction outcome
)
1109 gimple p
= gimple_alloc (GIMPLE_PREDICT
, 0);
1110 /* Ensure all the predictors fit into the lower bits of the subcode. */
1111 gcc_assert ((int) END_PREDICTORS
<= GF_PREDICT_TAKEN
);
1112 gimple_predict_set_predictor (p
, predictor
);
1113 gimple_predict_set_outcome (p
, outcome
);
1117 #if defined ENABLE_GIMPLE_CHECKING
1118 /* Complain of a gimple type mismatch and die. */
1121 gimple_check_failed (const_gimple gs
, const char *file
, int line
,
1122 const char *function
, enum gimple_code code
,
1123 enum tree_code subcode
)
1125 internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1126 gimple_code_name
[code
],
1127 tree_code_name
[subcode
],
1128 gimple_code_name
[gimple_code (gs
)],
1129 gs
->gsbase
.subcode
> 0
1130 ? tree_code_name
[gs
->gsbase
.subcode
]
1132 function
, trim_filename (file
), line
);
1134 #endif /* ENABLE_GIMPLE_CHECKING */
1137 /* Allocate a new GIMPLE sequence in GC memory and return it. If
1138 there are free sequences in GIMPLE_SEQ_CACHE return one of those
1142 gimple_seq_alloc (void)
1144 gimple_seq seq
= gimple_seq_cache
;
1147 gimple_seq_cache
= gimple_seq_cache
->next_free
;
1148 gcc_assert (gimple_seq_cache
!= seq
);
1149 memset (seq
, 0, sizeof (*seq
));
1153 seq
= ggc_alloc_cleared_gimple_seq_d ();
1154 #ifdef GATHER_STATISTICS
1155 gimple_alloc_counts
[(int) gimple_alloc_kind_seq
]++;
1156 gimple_alloc_sizes
[(int) gimple_alloc_kind_seq
] += sizeof (*seq
);
1163 /* Return SEQ to the free pool of GIMPLE sequences. */
1166 gimple_seq_free (gimple_seq seq
)
1171 gcc_assert (gimple_seq_first (seq
) == NULL
);
1172 gcc_assert (gimple_seq_last (seq
) == NULL
);
1174 /* If this triggers, it's a sign that the same list is being freed
1176 gcc_assert (seq
!= gimple_seq_cache
|| gimple_seq_cache
== NULL
);
1178 /* Add SEQ to the pool of free sequences. */
1179 seq
->next_free
= gimple_seq_cache
;
1180 gimple_seq_cache
= seq
;
1184 /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1185 *SEQ_P is NULL, a new sequence is allocated. */
1188 gimple_seq_add_stmt (gimple_seq
*seq_p
, gimple gs
)
1190 gimple_stmt_iterator si
;
1196 *seq_p
= gimple_seq_alloc ();
1198 si
= gsi_last (*seq_p
);
1199 gsi_insert_after (&si
, gs
, GSI_NEW_STMT
);
1203 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1204 NULL, a new sequence is allocated. */
1207 gimple_seq_add_seq (gimple_seq
*dst_p
, gimple_seq src
)
1209 gimple_stmt_iterator si
;
1215 *dst_p
= gimple_seq_alloc ();
1217 si
= gsi_last (*dst_p
);
1218 gsi_insert_seq_after (&si
, src
, GSI_NEW_STMT
);
1222 /* Helper function of empty_body_p. Return true if STMT is an empty
1226 empty_stmt_p (gimple stmt
)
1228 if (gimple_code (stmt
) == GIMPLE_NOP
)
1230 if (gimple_code (stmt
) == GIMPLE_BIND
)
1231 return empty_body_p (gimple_bind_body (stmt
));
1236 /* Return true if BODY contains nothing but empty statements. */
1239 empty_body_p (gimple_seq body
)
1241 gimple_stmt_iterator i
;
1243 if (gimple_seq_empty_p (body
))
1245 for (i
= gsi_start (body
); !gsi_end_p (i
); gsi_next (&i
))
1246 if (!empty_stmt_p (gsi_stmt (i
))
1247 && !is_gimple_debug (gsi_stmt (i
)))
1254 /* Perform a deep copy of sequence SRC and return the result. */
1257 gimple_seq_copy (gimple_seq src
)
1259 gimple_stmt_iterator gsi
;
1260 gimple_seq new_seq
= gimple_seq_alloc ();
1263 for (gsi
= gsi_start (src
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1265 stmt
= gimple_copy (gsi_stmt (gsi
));
1266 gimple_seq_add_stmt (&new_seq
, stmt
);
1273 /* Walk all the statements in the sequence SEQ calling walk_gimple_stmt
1274 on each one. WI is as in walk_gimple_stmt.
1276 If walk_gimple_stmt returns non-NULL, the walk is stopped, the
1277 value is stored in WI->CALLBACK_RESULT and the statement that
1278 produced the value is returned.
1280 Otherwise, all the statements are walked and NULL returned. */
1283 walk_gimple_seq (gimple_seq seq
, walk_stmt_fn callback_stmt
,
1284 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1286 gimple_stmt_iterator gsi
;
1288 for (gsi
= gsi_start (seq
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1290 tree ret
= walk_gimple_stmt (&gsi
, callback_stmt
, callback_op
, wi
);
1293 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
1296 wi
->callback_result
= ret
;
1297 return gsi_stmt (gsi
);
1302 wi
->callback_result
= NULL_TREE
;
1308 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
1311 walk_gimple_asm (gimple stmt
, walk_tree_fn callback_op
,
1312 struct walk_stmt_info
*wi
)
1316 const char **oconstraints
;
1318 const char *constraint
;
1319 bool allows_mem
, allows_reg
, is_inout
;
1321 noutputs
= gimple_asm_noutputs (stmt
);
1322 oconstraints
= (const char **) alloca ((noutputs
) * sizeof (const char *));
1327 for (i
= 0; i
< noutputs
; i
++)
1329 op
= gimple_asm_output_op (stmt
, i
);
1330 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1331 oconstraints
[i
] = constraint
;
1332 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
, &allows_reg
,
1335 wi
->val_only
= (allows_reg
|| !allows_mem
);
1336 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1341 n
= gimple_asm_ninputs (stmt
);
1342 for (i
= 0; i
< n
; i
++)
1344 op
= gimple_asm_input_op (stmt
, i
);
1345 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1346 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
1347 oconstraints
, &allows_mem
, &allows_reg
);
1350 wi
->val_only
= (allows_reg
|| !allows_mem
);
1351 /* Although input "m" is not really a LHS, we need a lvalue. */
1352 wi
->is_lhs
= !wi
->val_only
;
1354 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1362 wi
->val_only
= true;
1365 n
= gimple_asm_nlabels (stmt
);
1366 for (i
= 0; i
< n
; i
++)
1368 op
= gimple_asm_label_op (stmt
, i
);
1369 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1378 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
1379 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
1381 CALLBACK_OP is called on each operand of STMT via walk_tree.
1382 Additional parameters to walk_tree must be stored in WI. For each operand
1383 OP, walk_tree is called as:
1385 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
1387 If CALLBACK_OP returns non-NULL for an operand, the remaining
1388 operands are not scanned.
1390 The return value is that returned by the last call to walk_tree, or
1391 NULL_TREE if no CALLBACK_OP is specified. */
1394 walk_gimple_op (gimple stmt
, walk_tree_fn callback_op
,
1395 struct walk_stmt_info
*wi
)
1397 struct pointer_set_t
*pset
= (wi
) ? wi
->pset
: NULL
;
1399 tree ret
= NULL_TREE
;
1401 switch (gimple_code (stmt
))
1404 /* Walk the RHS operands. If the LHS is of a non-renamable type or
1405 is a register variable, we may use a COMPONENT_REF on the RHS. */
1408 tree lhs
= gimple_assign_lhs (stmt
);
1410 = (is_gimple_reg_type (TREE_TYPE (lhs
)) && !is_gimple_reg (lhs
))
1411 || !gimple_assign_single_p (stmt
);
1414 for (i
= 1; i
< gimple_num_ops (stmt
); i
++)
1416 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
,
1422 /* Walk the LHS. If the RHS is appropriate for a memory, we
1423 may use a COMPONENT_REF on the LHS. */
1426 /* If the RHS has more than 1 operand, it is not appropriate
1428 wi
->val_only
= !is_gimple_mem_rhs (gimple_assign_rhs1 (stmt
))
1429 || !gimple_assign_single_p (stmt
);
1433 ret
= walk_tree (gimple_op_ptr (stmt
, 0), callback_op
, wi
, pset
);
1439 wi
->val_only
= true;
1448 wi
->val_only
= true;
1451 ret
= walk_tree (gimple_call_chain_ptr (stmt
), callback_op
, wi
, pset
);
1455 ret
= walk_tree (gimple_call_fn_ptr (stmt
), callback_op
, wi
, pset
);
1459 for (i
= 0; i
< gimple_call_num_args (stmt
); i
++)
1463 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt
, i
)));
1464 ret
= walk_tree (gimple_call_arg_ptr (stmt
, i
), callback_op
, wi
,
1470 if (gimple_call_lhs (stmt
))
1476 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt
)));
1479 ret
= walk_tree (gimple_call_lhs_ptr (stmt
), callback_op
, wi
, pset
);
1487 wi
->val_only
= true;
1492 ret
= walk_tree (gimple_catch_types_ptr (stmt
), callback_op
, wi
,
1498 case GIMPLE_EH_FILTER
:
1499 ret
= walk_tree (gimple_eh_filter_types_ptr (stmt
), callback_op
, wi
,
1506 ret
= walk_gimple_asm (stmt
, callback_op
, wi
);
1511 case GIMPLE_OMP_CONTINUE
:
1512 ret
= walk_tree (gimple_omp_continue_control_def_ptr (stmt
),
1513 callback_op
, wi
, pset
);
1517 ret
= walk_tree (gimple_omp_continue_control_use_ptr (stmt
),
1518 callback_op
, wi
, pset
);
1523 case GIMPLE_OMP_CRITICAL
:
1524 ret
= walk_tree (gimple_omp_critical_name_ptr (stmt
), callback_op
, wi
,
1530 case GIMPLE_OMP_FOR
:
1531 ret
= walk_tree (gimple_omp_for_clauses_ptr (stmt
), callback_op
, wi
,
1535 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
1537 ret
= walk_tree (gimple_omp_for_index_ptr (stmt
, i
), callback_op
,
1541 ret
= walk_tree (gimple_omp_for_initial_ptr (stmt
, i
), callback_op
,
1545 ret
= walk_tree (gimple_omp_for_final_ptr (stmt
, i
), callback_op
,
1549 ret
= walk_tree (gimple_omp_for_incr_ptr (stmt
, i
), callback_op
,
1556 case GIMPLE_OMP_PARALLEL
:
1557 ret
= walk_tree (gimple_omp_parallel_clauses_ptr (stmt
), callback_op
,
1561 ret
= walk_tree (gimple_omp_parallel_child_fn_ptr (stmt
), callback_op
,
1565 ret
= walk_tree (gimple_omp_parallel_data_arg_ptr (stmt
), callback_op
,
1571 case GIMPLE_OMP_TASK
:
1572 ret
= walk_tree (gimple_omp_task_clauses_ptr (stmt
), callback_op
,
1576 ret
= walk_tree (gimple_omp_task_child_fn_ptr (stmt
), callback_op
,
1580 ret
= walk_tree (gimple_omp_task_data_arg_ptr (stmt
), callback_op
,
1584 ret
= walk_tree (gimple_omp_task_copy_fn_ptr (stmt
), callback_op
,
1588 ret
= walk_tree (gimple_omp_task_arg_size_ptr (stmt
), callback_op
,
1592 ret
= walk_tree (gimple_omp_task_arg_align_ptr (stmt
), callback_op
,
1598 case GIMPLE_OMP_SECTIONS
:
1599 ret
= walk_tree (gimple_omp_sections_clauses_ptr (stmt
), callback_op
,
1604 ret
= walk_tree (gimple_omp_sections_control_ptr (stmt
), callback_op
,
1611 case GIMPLE_OMP_SINGLE
:
1612 ret
= walk_tree (gimple_omp_single_clauses_ptr (stmt
), callback_op
, wi
,
1618 case GIMPLE_OMP_ATOMIC_LOAD
:
1619 ret
= walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt
), callback_op
, wi
,
1624 ret
= walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt
), callback_op
, wi
,
1630 case GIMPLE_OMP_ATOMIC_STORE
:
1631 ret
= walk_tree (gimple_omp_atomic_store_val_ptr (stmt
), callback_op
,
1637 /* Tuples that do not have operands. */
1640 case GIMPLE_OMP_RETURN
:
1641 case GIMPLE_PREDICT
:
1646 enum gimple_statement_structure_enum gss
;
1647 gss
= gimple_statement_structure (stmt
);
1648 if (gss
== GSS_WITH_OPS
|| gss
== GSS_WITH_MEM_OPS
)
1649 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
1651 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
, pset
);
1663 /* Walk the current statement in GSI (optionally using traversal state
1664 stored in WI). If WI is NULL, no state is kept during traversal.
1665 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
1666 that it has handled all the operands of the statement, its return
1667 value is returned. Otherwise, the return value from CALLBACK_STMT
1668 is discarded and its operands are scanned.
1670 If CALLBACK_STMT is NULL or it didn't handle the operands,
1671 CALLBACK_OP is called on each operand of the statement via
1672 walk_gimple_op. If walk_gimple_op returns non-NULL for any
1673 operand, the remaining operands are not scanned. In this case, the
1674 return value from CALLBACK_OP is returned.
1676 In any other case, NULL_TREE is returned. */
1679 walk_gimple_stmt (gimple_stmt_iterator
*gsi
, walk_stmt_fn callback_stmt
,
1680 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1684 gimple stmt
= gsi_stmt (*gsi
);
1689 if (wi
&& wi
->want_locations
&& gimple_has_location (stmt
))
1690 input_location
= gimple_location (stmt
);
1694 /* Invoke the statement callback. Return if the callback handled
1695 all of STMT operands by itself. */
1698 bool handled_ops
= false;
1699 tree_ret
= callback_stmt (gsi
, &handled_ops
, wi
);
1703 /* If CALLBACK_STMT did not handle operands, it should not have
1704 a value to return. */
1705 gcc_assert (tree_ret
== NULL
);
1707 /* Re-read stmt in case the callback changed it. */
1708 stmt
= gsi_stmt (*gsi
);
1711 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
1714 tree_ret
= walk_gimple_op (stmt
, callback_op
, wi
);
1719 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
1720 switch (gimple_code (stmt
))
1723 ret
= walk_gimple_seq (gimple_bind_body (stmt
), callback_stmt
,
1726 return wi
->callback_result
;
1730 ret
= walk_gimple_seq (gimple_catch_handler (stmt
), callback_stmt
,
1733 return wi
->callback_result
;
1736 case GIMPLE_EH_FILTER
:
1737 ret
= walk_gimple_seq (gimple_eh_filter_failure (stmt
), callback_stmt
,
1740 return wi
->callback_result
;
1744 ret
= walk_gimple_seq (gimple_try_eval (stmt
), callback_stmt
, callback_op
,
1747 return wi
->callback_result
;
1749 ret
= walk_gimple_seq (gimple_try_cleanup (stmt
), callback_stmt
,
1752 return wi
->callback_result
;
1755 case GIMPLE_OMP_FOR
:
1756 ret
= walk_gimple_seq (gimple_omp_for_pre_body (stmt
), callback_stmt
,
1759 return wi
->callback_result
;
1762 case GIMPLE_OMP_CRITICAL
:
1763 case GIMPLE_OMP_MASTER
:
1764 case GIMPLE_OMP_ORDERED
:
1765 case GIMPLE_OMP_SECTION
:
1766 case GIMPLE_OMP_PARALLEL
:
1767 case GIMPLE_OMP_TASK
:
1768 case GIMPLE_OMP_SECTIONS
:
1769 case GIMPLE_OMP_SINGLE
:
1770 ret
= walk_gimple_seq (gimple_omp_body (stmt
), callback_stmt
, callback_op
,
1773 return wi
->callback_result
;
1776 case GIMPLE_WITH_CLEANUP_EXPR
:
1777 ret
= walk_gimple_seq (gimple_wce_cleanup (stmt
), callback_stmt
,
1780 return wi
->callback_result
;
1784 gcc_assert (!gimple_has_substatements (stmt
));
1792 /* Set sequence SEQ to be the GIMPLE body for function FN. */
1795 gimple_set_body (tree fndecl
, gimple_seq seq
)
1797 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1800 /* If FNDECL still does not have a function structure associated
1801 with it, then it does not make sense for it to receive a
1803 gcc_assert (seq
== NULL
);
1806 fn
->gimple_body
= seq
;
1810 /* Return the body of GIMPLE statements for function FN. After the
1811 CFG pass, the function body doesn't exist anymore because it has
1812 been split up into basic blocks. In this case, it returns
1816 gimple_body (tree fndecl
)
1818 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1819 return fn
? fn
->gimple_body
: NULL
;
1822 /* Return true when FNDECL has Gimple body either in unlowered
1825 gimple_has_body_p (tree fndecl
)
1827 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1828 return (gimple_body (fndecl
) || (fn
&& fn
->cfg
));
1831 /* Return true if calls C1 and C2 are known to go to the same function. */
1834 gimple_call_same_target_p (const_gimple c1
, const_gimple c2
)
1836 if (gimple_call_internal_p (c1
))
1837 return (gimple_call_internal_p (c2
)
1838 && gimple_call_internal_fn (c1
) == gimple_call_internal_fn (c2
));
1840 return (gimple_call_fn (c1
) == gimple_call_fn (c2
)
1841 || (gimple_call_fndecl (c1
)
1842 && gimple_call_fndecl (c1
) == gimple_call_fndecl (c2
)));
1845 /* Detect flags from a GIMPLE_CALL. This is just like
1846 call_expr_flags, but for gimple tuples. */
1849 gimple_call_flags (const_gimple stmt
)
1852 tree decl
= gimple_call_fndecl (stmt
);
1855 flags
= flags_from_decl_or_type (decl
);
1856 else if (gimple_call_internal_p (stmt
))
1857 flags
= internal_fn_flags (gimple_call_internal_fn (stmt
));
1859 flags
= flags_from_decl_or_type (gimple_call_fntype (stmt
));
1861 if (stmt
->gsbase
.subcode
& GF_CALL_NOTHROW
)
1862 flags
|= ECF_NOTHROW
;
1867 /* Return the "fn spec" string for call STMT. */
1870 gimple_call_fnspec (const_gimple stmt
)
1874 type
= gimple_call_fntype (stmt
);
1878 attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
1882 return TREE_VALUE (TREE_VALUE (attr
));
1885 /* Detects argument flags for argument number ARG on call STMT. */
1888 gimple_call_arg_flags (const_gimple stmt
, unsigned arg
)
1890 tree attr
= gimple_call_fnspec (stmt
);
1892 if (!attr
|| 1 + arg
>= (unsigned) TREE_STRING_LENGTH (attr
))
1895 switch (TREE_STRING_POINTER (attr
)[1 + arg
])
1902 return EAF_DIRECT
| EAF_NOCLOBBER
| EAF_NOESCAPE
;
1905 return EAF_NOCLOBBER
| EAF_NOESCAPE
;
1908 return EAF_DIRECT
| EAF_NOESCAPE
;
1911 return EAF_NOESCAPE
;
1919 /* Detects return flags for the call STMT. */
1922 gimple_call_return_flags (const_gimple stmt
)
1926 if (gimple_call_flags (stmt
) & ECF_MALLOC
)
1929 attr
= gimple_call_fnspec (stmt
);
1930 if (!attr
|| TREE_STRING_LENGTH (attr
) < 1)
1933 switch (TREE_STRING_POINTER (attr
)[0])
1939 return ERF_RETURNS_ARG
| (TREE_STRING_POINTER (attr
)[0] - '1');
1951 /* Return true if GS is a copy assignment. */
1954 gimple_assign_copy_p (gimple gs
)
1956 return (gimple_assign_single_p (gs
)
1957 && is_gimple_val (gimple_op (gs
, 1)));
1961 /* Return true if GS is a SSA_NAME copy assignment. */
1964 gimple_assign_ssa_name_copy_p (gimple gs
)
1966 return (gimple_assign_single_p (gs
)
1967 && TREE_CODE (gimple_assign_lhs (gs
)) == SSA_NAME
1968 && TREE_CODE (gimple_assign_rhs1 (gs
)) == SSA_NAME
);
1972 /* Return true if GS is an assignment with a unary RHS, but the
1973 operator has no effect on the assigned value. The logic is adapted
1974 from STRIP_NOPS. This predicate is intended to be used in tuplifying
1975 instances in which STRIP_NOPS was previously applied to the RHS of
1978 NOTE: In the use cases that led to the creation of this function
1979 and of gimple_assign_single_p, it is typical to test for either
1980 condition and to proceed in the same manner. In each case, the
1981 assigned value is represented by the single RHS operand of the
1982 assignment. I suspect there may be cases where gimple_assign_copy_p,
1983 gimple_assign_single_p, or equivalent logic is used where a similar
1984 treatment of unary NOPs is appropriate. */
1987 gimple_assign_unary_nop_p (gimple gs
)
1989 return (is_gimple_assign (gs
)
1990 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs
))
1991 || gimple_assign_rhs_code (gs
) == NON_LVALUE_EXPR
)
1992 && gimple_assign_rhs1 (gs
) != error_mark_node
1993 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs
)))
1994 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs
)))));
1997 /* Set BB to be the basic block holding G. */
2000 gimple_set_bb (gimple stmt
, basic_block bb
)
2002 stmt
->gsbase
.bb
= bb
;
2004 /* If the statement is a label, add the label to block-to-labels map
2005 so that we can speed up edge creation for GIMPLE_GOTOs. */
2006 if (cfun
->cfg
&& gimple_code (stmt
) == GIMPLE_LABEL
)
2011 t
= gimple_label_label (stmt
);
2012 uid
= LABEL_DECL_UID (t
);
2015 unsigned old_len
= VEC_length (basic_block
, label_to_block_map
);
2016 LABEL_DECL_UID (t
) = uid
= cfun
->cfg
->last_label_uid
++;
2017 if (old_len
<= (unsigned) uid
)
2019 unsigned new_len
= 3 * uid
/ 2 + 1;
2021 VEC_safe_grow_cleared (basic_block
, gc
, label_to_block_map
,
2026 VEC_replace (basic_block
, label_to_block_map
, uid
, bb
);
2031 /* Modify the RHS of the assignment pointed-to by GSI using the
2032 operands in the expression tree EXPR.
2034 NOTE: The statement pointed-to by GSI may be reallocated if it
2035 did not have enough operand slots.
2037 This function is useful to convert an existing tree expression into
2038 the flat representation used for the RHS of a GIMPLE assignment.
2039 It will reallocate memory as needed to expand or shrink the number
2040 of operand slots needed to represent EXPR.
2042 NOTE: If you find yourself building a tree and then calling this
2043 function, you are most certainly doing it the slow way. It is much
2044 better to build a new assignment or to use the function
2045 gimple_assign_set_rhs_with_ops, which does not require an
2046 expression tree to be built. */
2049 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator
*gsi
, tree expr
)
2051 enum tree_code subcode
;
2054 extract_ops_from_tree_1 (expr
, &subcode
, &op1
, &op2
, &op3
);
2055 gimple_assign_set_rhs_with_ops_1 (gsi
, subcode
, op1
, op2
, op3
);
2059 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
2060 operands OP1, OP2 and OP3.
2062 NOTE: The statement pointed-to by GSI may be reallocated if it
2063 did not have enough operand slots. */
2066 gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator
*gsi
, enum tree_code code
,
2067 tree op1
, tree op2
, tree op3
)
2069 unsigned new_rhs_ops
= get_gimple_rhs_num_ops (code
);
2070 gimple stmt
= gsi_stmt (*gsi
);
2072 /* If the new CODE needs more operands, allocate a new statement. */
2073 if (gimple_num_ops (stmt
) < new_rhs_ops
+ 1)
2075 tree lhs
= gimple_assign_lhs (stmt
);
2076 gimple new_stmt
= gimple_alloc (gimple_code (stmt
), new_rhs_ops
+ 1);
2077 memcpy (new_stmt
, stmt
, gimple_size (gimple_code (stmt
)));
2078 gsi_replace (gsi
, new_stmt
, true);
2081 /* The LHS needs to be reset as this also changes the SSA name
2083 gimple_assign_set_lhs (stmt
, lhs
);
2086 gimple_set_num_ops (stmt
, new_rhs_ops
+ 1);
2087 gimple_set_subcode (stmt
, code
);
2088 gimple_assign_set_rhs1 (stmt
, op1
);
2089 if (new_rhs_ops
> 1)
2090 gimple_assign_set_rhs2 (stmt
, op2
);
2091 if (new_rhs_ops
> 2)
2092 gimple_assign_set_rhs3 (stmt
, op3
);
2096 /* Return the LHS of a statement that performs an assignment,
2097 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2098 for a call to a function that returns no value, or for a
2099 statement other than an assignment or a call. */
2102 gimple_get_lhs (const_gimple stmt
)
2104 enum gimple_code code
= gimple_code (stmt
);
2106 if (code
== GIMPLE_ASSIGN
)
2107 return gimple_assign_lhs (stmt
);
2108 else if (code
== GIMPLE_CALL
)
2109 return gimple_call_lhs (stmt
);
2115 /* Set the LHS of a statement that performs an assignment,
2116 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2119 gimple_set_lhs (gimple stmt
, tree lhs
)
2121 enum gimple_code code
= gimple_code (stmt
);
2123 if (code
== GIMPLE_ASSIGN
)
2124 gimple_assign_set_lhs (stmt
, lhs
);
2125 else if (code
== GIMPLE_CALL
)
2126 gimple_call_set_lhs (stmt
, lhs
);
2131 /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
2132 GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
2133 expression with a different value.
2135 This will update any annotations (say debug bind stmts) referring
2136 to the original LHS, so that they use the RHS instead. This is
2137 done even if NLHS and LHS are the same, for it is understood that
2138 the RHS will be modified afterwards, and NLHS will not be assigned
2139 an equivalent value.
2141 Adjusting any non-annotation uses of the LHS, if needed, is a
2142 responsibility of the caller.
2144 The effect of this call should be pretty much the same as that of
2145 inserting a copy of STMT before STMT, and then removing the
2146 original stmt, at which time gsi_remove() would have update
2147 annotations, but using this function saves all the inserting,
2148 copying and removing. */
2151 gimple_replace_lhs (gimple stmt
, tree nlhs
)
2153 if (MAY_HAVE_DEBUG_STMTS
)
2155 tree lhs
= gimple_get_lhs (stmt
);
2157 gcc_assert (SSA_NAME_DEF_STMT (lhs
) == stmt
);
2159 insert_debug_temp_for_var_def (NULL
, lhs
);
2162 gimple_set_lhs (stmt
, nlhs
);
2165 /* Return a deep copy of statement STMT. All the operands from STMT
2166 are reallocated and copied using unshare_expr. The DEF, USE, VDEF
2167 and VUSE operand arrays are set to empty in the new copy. */
2170 gimple_copy (gimple stmt
)
2172 enum gimple_code code
= gimple_code (stmt
);
2173 unsigned num_ops
= gimple_num_ops (stmt
);
2174 gimple copy
= gimple_alloc (code
, num_ops
);
2177 /* Shallow copy all the fields from STMT. */
2178 memcpy (copy
, stmt
, gimple_size (code
));
2180 /* If STMT has sub-statements, deep-copy them as well. */
2181 if (gimple_has_substatements (stmt
))
2186 switch (gimple_code (stmt
))
2189 new_seq
= gimple_seq_copy (gimple_bind_body (stmt
));
2190 gimple_bind_set_body (copy
, new_seq
);
2191 gimple_bind_set_vars (copy
, unshare_expr (gimple_bind_vars (stmt
)));
2192 gimple_bind_set_block (copy
, gimple_bind_block (stmt
));
2196 new_seq
= gimple_seq_copy (gimple_catch_handler (stmt
));
2197 gimple_catch_set_handler (copy
, new_seq
);
2198 t
= unshare_expr (gimple_catch_types (stmt
));
2199 gimple_catch_set_types (copy
, t
);
2202 case GIMPLE_EH_FILTER
:
2203 new_seq
= gimple_seq_copy (gimple_eh_filter_failure (stmt
));
2204 gimple_eh_filter_set_failure (copy
, new_seq
);
2205 t
= unshare_expr (gimple_eh_filter_types (stmt
));
2206 gimple_eh_filter_set_types (copy
, t
);
2210 new_seq
= gimple_seq_copy (gimple_try_eval (stmt
));
2211 gimple_try_set_eval (copy
, new_seq
);
2212 new_seq
= gimple_seq_copy (gimple_try_cleanup (stmt
));
2213 gimple_try_set_cleanup (copy
, new_seq
);
2216 case GIMPLE_OMP_FOR
:
2217 new_seq
= gimple_seq_copy (gimple_omp_for_pre_body (stmt
));
2218 gimple_omp_for_set_pre_body (copy
, new_seq
);
2219 t
= unshare_expr (gimple_omp_for_clauses (stmt
));
2220 gimple_omp_for_set_clauses (copy
, t
);
2221 copy
->gimple_omp_for
.iter
2222 = ggc_alloc_vec_gimple_omp_for_iter
2223 (gimple_omp_for_collapse (stmt
));
2224 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
2226 gimple_omp_for_set_cond (copy
, i
,
2227 gimple_omp_for_cond (stmt
, i
));
2228 gimple_omp_for_set_index (copy
, i
,
2229 gimple_omp_for_index (stmt
, i
));
2230 t
= unshare_expr (gimple_omp_for_initial (stmt
, i
));
2231 gimple_omp_for_set_initial (copy
, i
, t
);
2232 t
= unshare_expr (gimple_omp_for_final (stmt
, i
));
2233 gimple_omp_for_set_final (copy
, i
, t
);
2234 t
= unshare_expr (gimple_omp_for_incr (stmt
, i
));
2235 gimple_omp_for_set_incr (copy
, i
, t
);
2239 case GIMPLE_OMP_PARALLEL
:
2240 t
= unshare_expr (gimple_omp_parallel_clauses (stmt
));
2241 gimple_omp_parallel_set_clauses (copy
, t
);
2242 t
= unshare_expr (gimple_omp_parallel_child_fn (stmt
));
2243 gimple_omp_parallel_set_child_fn (copy
, t
);
2244 t
= unshare_expr (gimple_omp_parallel_data_arg (stmt
));
2245 gimple_omp_parallel_set_data_arg (copy
, t
);
2248 case GIMPLE_OMP_TASK
:
2249 t
= unshare_expr (gimple_omp_task_clauses (stmt
));
2250 gimple_omp_task_set_clauses (copy
, t
);
2251 t
= unshare_expr (gimple_omp_task_child_fn (stmt
));
2252 gimple_omp_task_set_child_fn (copy
, t
);
2253 t
= unshare_expr (gimple_omp_task_data_arg (stmt
));
2254 gimple_omp_task_set_data_arg (copy
, t
);
2255 t
= unshare_expr (gimple_omp_task_copy_fn (stmt
));
2256 gimple_omp_task_set_copy_fn (copy
, t
);
2257 t
= unshare_expr (gimple_omp_task_arg_size (stmt
));
2258 gimple_omp_task_set_arg_size (copy
, t
);
2259 t
= unshare_expr (gimple_omp_task_arg_align (stmt
));
2260 gimple_omp_task_set_arg_align (copy
, t
);
2263 case GIMPLE_OMP_CRITICAL
:
2264 t
= unshare_expr (gimple_omp_critical_name (stmt
));
2265 gimple_omp_critical_set_name (copy
, t
);
2268 case GIMPLE_OMP_SECTIONS
:
2269 t
= unshare_expr (gimple_omp_sections_clauses (stmt
));
2270 gimple_omp_sections_set_clauses (copy
, t
);
2271 t
= unshare_expr (gimple_omp_sections_control (stmt
));
2272 gimple_omp_sections_set_control (copy
, t
);
2275 case GIMPLE_OMP_SINGLE
:
2276 case GIMPLE_OMP_SECTION
:
2277 case GIMPLE_OMP_MASTER
:
2278 case GIMPLE_OMP_ORDERED
:
2280 new_seq
= gimple_seq_copy (gimple_omp_body (stmt
));
2281 gimple_omp_set_body (copy
, new_seq
);
2284 case GIMPLE_WITH_CLEANUP_EXPR
:
2285 new_seq
= gimple_seq_copy (gimple_wce_cleanup (stmt
));
2286 gimple_wce_set_cleanup (copy
, new_seq
);
2294 /* Make copy of operands. */
2297 for (i
= 0; i
< num_ops
; i
++)
2298 gimple_set_op (copy
, i
, unshare_expr (gimple_op (stmt
, i
)));
2300 /* Clear out SSA operand vectors on COPY. */
2301 if (gimple_has_ops (stmt
))
2303 gimple_set_def_ops (copy
, NULL
);
2304 gimple_set_use_ops (copy
, NULL
);
2307 if (gimple_has_mem_ops (stmt
))
2309 gimple_set_vdef (copy
, gimple_vdef (stmt
));
2310 gimple_set_vuse (copy
, gimple_vuse (stmt
));
2313 /* SSA operands need to be updated. */
2314 gimple_set_modified (copy
, true);
2321 /* Set the MODIFIED flag to MODIFIEDP, iff the gimple statement G has
2322 a MODIFIED field. */
2325 gimple_set_modified (gimple s
, bool modifiedp
)
2327 if (gimple_has_ops (s
))
2328 s
->gsbase
.modified
= (unsigned) modifiedp
;
2332 /* Return true if statement S has side-effects. We consider a
2333 statement to have side effects if:
2335 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2336 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2339 gimple_has_side_effects (const_gimple s
)
2343 if (is_gimple_debug (s
))
2346 /* We don't have to scan the arguments to check for
2347 volatile arguments, though, at present, we still
2348 do a scan to check for TREE_SIDE_EFFECTS. */
2349 if (gimple_has_volatile_ops (s
))
2352 if (gimple_code (s
) == GIMPLE_ASM
2353 && gimple_asm_volatile_p (s
))
2356 if (is_gimple_call (s
))
2358 unsigned nargs
= gimple_call_num_args (s
);
2361 if (!(gimple_call_flags (s
) & (ECF_CONST
| ECF_PURE
)))
2363 else if (gimple_call_flags (s
) & ECF_LOOPING_CONST_OR_PURE
)
2364 /* An infinite loop is considered a side effect. */
2367 if (gimple_call_lhs (s
)
2368 && TREE_SIDE_EFFECTS (gimple_call_lhs (s
)))
2370 gcc_checking_assert (gimple_has_volatile_ops (s
));
2374 fn
= gimple_call_fn (s
);
2375 if (fn
&& TREE_SIDE_EFFECTS (fn
))
2378 for (i
= 0; i
< nargs
; i
++)
2379 if (TREE_SIDE_EFFECTS (gimple_call_arg (s
, i
)))
2381 gcc_checking_assert (gimple_has_volatile_ops (s
));
2389 for (i
= 0; i
< gimple_num_ops (s
); i
++)
2391 tree op
= gimple_op (s
, i
);
2392 if (op
&& TREE_SIDE_EFFECTS (op
))
2394 gcc_checking_assert (gimple_has_volatile_ops (s
));
2403 /* Return true if the RHS of statement S has side effects.
2404 We may use it to determine if it is admissable to replace
2405 an assignment or call with a copy of a previously-computed
2406 value. In such cases, side-effects due to the LHS are
2410 gimple_rhs_has_side_effects (const_gimple s
)
2414 if (is_gimple_call (s
))
2416 unsigned nargs
= gimple_call_num_args (s
);
2419 if (!(gimple_call_flags (s
) & (ECF_CONST
| ECF_PURE
)))
2422 /* We cannot use gimple_has_volatile_ops here,
2423 because we must ignore a volatile LHS. */
2424 fn
= gimple_call_fn (s
);
2425 if (fn
&& (TREE_SIDE_EFFECTS (fn
) || TREE_THIS_VOLATILE (fn
)))
2427 gcc_assert (gimple_has_volatile_ops (s
));
2431 for (i
= 0; i
< nargs
; i
++)
2432 if (TREE_SIDE_EFFECTS (gimple_call_arg (s
, i
))
2433 || TREE_THIS_VOLATILE (gimple_call_arg (s
, i
)))
2438 else if (is_gimple_assign (s
))
2440 /* Skip the first operand, the LHS. */
2441 for (i
= 1; i
< gimple_num_ops (s
); i
++)
2442 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
))
2443 || TREE_THIS_VOLATILE (gimple_op (s
, i
)))
2445 gcc_assert (gimple_has_volatile_ops (s
));
2449 else if (is_gimple_debug (s
))
2453 /* For statements without an LHS, examine all arguments. */
2454 for (i
= 0; i
< gimple_num_ops (s
); i
++)
2455 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
))
2456 || TREE_THIS_VOLATILE (gimple_op (s
, i
)))
2458 gcc_assert (gimple_has_volatile_ops (s
));
2466 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2467 Return true if S can trap. When INCLUDE_MEM is true, check whether
2468 the memory operations could trap. When INCLUDE_STORES is true and
2469 S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
2472 gimple_could_trap_p_1 (gimple s
, bool include_mem
, bool include_stores
)
2474 tree t
, div
= NULL_TREE
;
2479 unsigned i
, start
= (is_gimple_assign (s
) && !include_stores
) ? 1 : 0;
2481 for (i
= start
; i
< gimple_num_ops (s
); i
++)
2482 if (tree_could_trap_p (gimple_op (s
, i
)))
2486 switch (gimple_code (s
))
2489 return gimple_asm_volatile_p (s
);
2492 t
= gimple_call_fndecl (s
);
2493 /* Assume that calls to weak functions may trap. */
2494 if (!t
|| !DECL_P (t
) || DECL_WEAK (t
))
2499 t
= gimple_expr_type (s
);
2500 op
= gimple_assign_rhs_code (s
);
2501 if (get_gimple_rhs_class (op
) == GIMPLE_BINARY_RHS
)
2502 div
= gimple_assign_rhs2 (s
);
2503 return (operation_could_trap_p (op
, FLOAT_TYPE_P (t
),
2504 (INTEGRAL_TYPE_P (t
)
2505 && TYPE_OVERFLOW_TRAPS (t
)),
2515 /* Return true if statement S can trap. */
2518 gimple_could_trap_p (gimple s
)
2520 return gimple_could_trap_p_1 (s
, true, true);
2523 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2526 gimple_assign_rhs_could_trap_p (gimple s
)
2528 gcc_assert (is_gimple_assign (s
));
2529 return gimple_could_trap_p_1 (s
, true, false);
2533 /* Print debugging information for gimple stmts generated. */
2536 dump_gimple_statistics (void)
2538 #ifdef GATHER_STATISTICS
2539 int i
, total_tuples
= 0, total_bytes
= 0;
2541 fprintf (stderr
, "\nGIMPLE statements\n");
2542 fprintf (stderr
, "Kind Stmts Bytes\n");
2543 fprintf (stderr
, "---------------------------------------\n");
2544 for (i
= 0; i
< (int) gimple_alloc_kind_all
; ++i
)
2546 fprintf (stderr
, "%-20s %7d %10d\n", gimple_alloc_kind_names
[i
],
2547 gimple_alloc_counts
[i
], gimple_alloc_sizes
[i
]);
2548 total_tuples
+= gimple_alloc_counts
[i
];
2549 total_bytes
+= gimple_alloc_sizes
[i
];
2551 fprintf (stderr
, "---------------------------------------\n");
2552 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_tuples
, total_bytes
);
2553 fprintf (stderr
, "---------------------------------------\n");
2555 fprintf (stderr
, "No gimple statistics\n");
2560 /* Return the number of operands needed on the RHS of a GIMPLE
2561 assignment for an expression with tree code CODE. */
2564 get_gimple_rhs_num_ops (enum tree_code code
)
2566 enum gimple_rhs_class rhs_class
= get_gimple_rhs_class (code
);
2568 if (rhs_class
== GIMPLE_UNARY_RHS
|| rhs_class
== GIMPLE_SINGLE_RHS
)
2570 else if (rhs_class
== GIMPLE_BINARY_RHS
)
2572 else if (rhs_class
== GIMPLE_TERNARY_RHS
)
2578 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2580 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2581 : ((TYPE) == tcc_binary \
2582 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2583 : ((TYPE) == tcc_constant \
2584 || (TYPE) == tcc_declaration \
2585 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2586 : ((SYM) == TRUTH_AND_EXPR \
2587 || (SYM) == TRUTH_OR_EXPR \
2588 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2589 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2590 : ((SYM) == WIDEN_MULT_PLUS_EXPR \
2591 || (SYM) == WIDEN_MULT_MINUS_EXPR \
2592 || (SYM) == DOT_PROD_EXPR \
2593 || (SYM) == REALIGN_LOAD_EXPR \
2594 || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \
2595 : ((SYM) == COND_EXPR \
2596 || (SYM) == CONSTRUCTOR \
2597 || (SYM) == OBJ_TYPE_REF \
2598 || (SYM) == ASSERT_EXPR \
2599 || (SYM) == ADDR_EXPR \
2600 || (SYM) == WITH_SIZE_EXPR \
2601 || (SYM) == SSA_NAME \
2602 || (SYM) == VEC_COND_EXPR) ? GIMPLE_SINGLE_RHS \
2603 : GIMPLE_INVALID_RHS),
2604 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2606 const unsigned char gimple_rhs_class_table
[] = {
2607 #include "all-tree.def"
2611 #undef END_OF_BASE_TREE_CODES
2613 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2615 /* Validation of GIMPLE expressions. */
2617 /* Returns true iff T is a valid RHS for an assignment to a renamed
2618 user -- or front-end generated artificial -- variable. */
2621 is_gimple_reg_rhs (tree t
)
2623 return get_gimple_rhs_class (TREE_CODE (t
)) != GIMPLE_INVALID_RHS
;
2626 /* Returns true iff T is a valid RHS for an assignment to an un-renamed
2627 LHS, or for a call argument. */
2630 is_gimple_mem_rhs (tree t
)
2632 /* If we're dealing with a renamable type, either source or dest must be
2633 a renamed variable. */
2634 if (is_gimple_reg_type (TREE_TYPE (t
)))
2635 return is_gimple_val (t
);
2637 return is_gimple_val (t
) || is_gimple_lvalue (t
);
2640 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
2643 is_gimple_lvalue (tree t
)
2645 return (is_gimple_addressable (t
)
2646 || TREE_CODE (t
) == WITH_SIZE_EXPR
2647 /* These are complex lvalues, but don't have addresses, so they
2649 || TREE_CODE (t
) == BIT_FIELD_REF
);
2652 /* Return true if T is a GIMPLE condition. */
2655 is_gimple_condexpr (tree t
)
2657 return (is_gimple_val (t
) || (COMPARISON_CLASS_P (t
)
2658 && !tree_could_throw_p (t
)
2659 && is_gimple_val (TREE_OPERAND (t
, 0))
2660 && is_gimple_val (TREE_OPERAND (t
, 1))));
2663 /* Return true if T is something whose address can be taken. */
2666 is_gimple_addressable (tree t
)
2668 return (is_gimple_id (t
) || handled_component_p (t
)
2669 || TREE_CODE (t
) == MEM_REF
);
2672 /* Return true if T is a valid gimple constant. */
2675 is_gimple_constant (const_tree t
)
2677 switch (TREE_CODE (t
))
2687 /* Vector constant constructors are gimple invariant. */
2689 if (TREE_TYPE (t
) && TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2690 return TREE_CONSTANT (t
);
2699 /* Return true if T is a gimple address. */
2702 is_gimple_address (const_tree t
)
2706 if (TREE_CODE (t
) != ADDR_EXPR
)
2709 op
= TREE_OPERAND (t
, 0);
2710 while (handled_component_p (op
))
2712 if ((TREE_CODE (op
) == ARRAY_REF
2713 || TREE_CODE (op
) == ARRAY_RANGE_REF
)
2714 && !is_gimple_val (TREE_OPERAND (op
, 1)))
2717 op
= TREE_OPERAND (op
, 0);
2720 if (CONSTANT_CLASS_P (op
) || TREE_CODE (op
) == MEM_REF
)
2723 switch (TREE_CODE (op
))
2738 /* Strip out all handled components that produce invariant
2742 strip_invariant_refs (const_tree op
)
2744 while (handled_component_p (op
))
2746 switch (TREE_CODE (op
))
2749 case ARRAY_RANGE_REF
:
2750 if (!is_gimple_constant (TREE_OPERAND (op
, 1))
2751 || TREE_OPERAND (op
, 2) != NULL_TREE
2752 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2757 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2763 op
= TREE_OPERAND (op
, 0);
2769 /* Return true if T is a gimple invariant address. */
2772 is_gimple_invariant_address (const_tree t
)
2776 if (TREE_CODE (t
) != ADDR_EXPR
)
2779 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2783 if (TREE_CODE (op
) == MEM_REF
)
2785 const_tree op0
= TREE_OPERAND (op
, 0);
2786 return (TREE_CODE (op0
) == ADDR_EXPR
2787 && (CONSTANT_CLASS_P (TREE_OPERAND (op0
, 0))
2788 || decl_address_invariant_p (TREE_OPERAND (op0
, 0))));
2791 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
2794 /* Return true if T is a gimple invariant address at IPA level
2795 (so addresses of variables on stack are not allowed). */
2798 is_gimple_ip_invariant_address (const_tree t
)
2802 if (TREE_CODE (t
) != ADDR_EXPR
)
2805 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2807 return op
&& (CONSTANT_CLASS_P (op
) || decl_address_ip_invariant_p (op
));
2810 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
2811 form of function invariant. */
2814 is_gimple_min_invariant (const_tree t
)
2816 if (TREE_CODE (t
) == ADDR_EXPR
)
2817 return is_gimple_invariant_address (t
);
2819 return is_gimple_constant (t
);
2822 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
2823 form of gimple minimal invariant. */
2826 is_gimple_ip_invariant (const_tree t
)
2828 if (TREE_CODE (t
) == ADDR_EXPR
)
2829 return is_gimple_ip_invariant_address (t
);
2831 return is_gimple_constant (t
);
2834 /* Return true if T looks like a valid GIMPLE statement. */
2837 is_gimple_stmt (tree t
)
2839 const enum tree_code code
= TREE_CODE (t
);
2844 /* The only valid NOP_EXPR is the empty statement. */
2845 return IS_EMPTY_STMT (t
);
2849 /* These are only valid if they're void. */
2850 return TREE_TYPE (t
) == NULL
|| VOID_TYPE_P (TREE_TYPE (t
));
2856 case CASE_LABEL_EXPR
:
2857 case TRY_CATCH_EXPR
:
2858 case TRY_FINALLY_EXPR
:
2859 case EH_FILTER_EXPR
:
2862 case STATEMENT_LIST
:
2872 /* These are always void. */
2878 /* These are valid regardless of their type. */
2886 /* Return true if T is a variable. */
2889 is_gimple_variable (tree t
)
2891 return (TREE_CODE (t
) == VAR_DECL
2892 || TREE_CODE (t
) == PARM_DECL
2893 || TREE_CODE (t
) == RESULT_DECL
2894 || TREE_CODE (t
) == SSA_NAME
);
2897 /* Return true if T is a GIMPLE identifier (something with an address). */
2900 is_gimple_id (tree t
)
2902 return (is_gimple_variable (t
)
2903 || TREE_CODE (t
) == FUNCTION_DECL
2904 || TREE_CODE (t
) == LABEL_DECL
2905 || TREE_CODE (t
) == CONST_DECL
2906 /* Allow string constants, since they are addressable. */
2907 || TREE_CODE (t
) == STRING_CST
);
2910 /* Return true if TYPE is a suitable type for a scalar register variable. */
2913 is_gimple_reg_type (tree type
)
2915 return !AGGREGATE_TYPE_P (type
);
2918 /* Return true if T is a non-aggregate register variable. */
2921 is_gimple_reg (tree t
)
2923 if (TREE_CODE (t
) == SSA_NAME
)
2924 t
= SSA_NAME_VAR (t
);
2926 if (!is_gimple_variable (t
))
2929 if (!is_gimple_reg_type (TREE_TYPE (t
)))
2932 /* A volatile decl is not acceptable because we can't reuse it as
2933 needed. We need to copy it into a temp first. */
2934 if (TREE_THIS_VOLATILE (t
))
2937 /* We define "registers" as things that can be renamed as needed,
2938 which with our infrastructure does not apply to memory. */
2939 if (needs_to_live_in_memory (t
))
2942 /* Hard register variables are an interesting case. For those that
2943 are call-clobbered, we don't know where all the calls are, since
2944 we don't (want to) take into account which operations will turn
2945 into libcalls at the rtl level. For those that are call-saved,
2946 we don't currently model the fact that calls may in fact change
2947 global hard registers, nor do we examine ASM_CLOBBERS at the tree
2948 level, and so miss variable changes that might imply. All around,
2949 it seems safest to not do too much optimization with these at the
2950 tree level at all. We'll have to rely on the rtl optimizers to
2951 clean this up, as there we've got all the appropriate bits exposed. */
2952 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2955 /* Complex and vector values must have been put into SSA-like form.
2956 That is, no assignments to the individual components. */
2957 if (TREE_CODE (TREE_TYPE (t
)) == COMPLEX_TYPE
2958 || TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2959 return DECL_GIMPLE_REG_P (t
);
2965 /* Return true if T is a GIMPLE variable whose address is not needed. */
2968 is_gimple_non_addressable (tree t
)
2970 if (TREE_CODE (t
) == SSA_NAME
)
2971 t
= SSA_NAME_VAR (t
);
2973 return (is_gimple_variable (t
) && ! needs_to_live_in_memory (t
));
2976 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
2979 is_gimple_val (tree t
)
2981 /* Make loads from volatiles and memory vars explicit. */
2982 if (is_gimple_variable (t
)
2983 && is_gimple_reg_type (TREE_TYPE (t
))
2984 && !is_gimple_reg (t
))
2987 return (is_gimple_variable (t
) || is_gimple_min_invariant (t
));
2990 /* Similarly, but accept hard registers as inputs to asm statements. */
2993 is_gimple_asm_val (tree t
)
2995 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2998 return is_gimple_val (t
);
3001 /* Return true if T is a GIMPLE minimal lvalue. */
3004 is_gimple_min_lval (tree t
)
3006 if (!(t
= CONST_CAST_TREE (strip_invariant_refs (t
))))
3008 return (is_gimple_id (t
) || TREE_CODE (t
) == MEM_REF
);
3011 /* Return true if T is a valid function operand of a CALL_EXPR. */
3014 is_gimple_call_addr (tree t
)
3016 return (TREE_CODE (t
) == OBJ_TYPE_REF
|| is_gimple_val (t
));
3019 /* Return true if T is a valid address operand of a MEM_REF. */
3022 is_gimple_mem_ref_addr (tree t
)
3024 return (is_gimple_reg (t
)
3025 || TREE_CODE (t
) == INTEGER_CST
3026 || (TREE_CODE (t
) == ADDR_EXPR
3027 && (CONSTANT_CLASS_P (TREE_OPERAND (t
, 0))
3028 || decl_address_invariant_p (TREE_OPERAND (t
, 0)))));
3031 /* If T makes a function call, return the corresponding CALL_EXPR operand.
3032 Otherwise, return NULL_TREE. */
3035 get_call_expr_in (tree t
)
3037 if (TREE_CODE (t
) == MODIFY_EXPR
)
3038 t
= TREE_OPERAND (t
, 1);
3039 if (TREE_CODE (t
) == WITH_SIZE_EXPR
)
3040 t
= TREE_OPERAND (t
, 0);
3041 if (TREE_CODE (t
) == CALL_EXPR
)
3047 /* Given a memory reference expression T, return its base address.
3048 The base address of a memory reference expression is the main
3049 object being referenced. For instance, the base address for
3050 'array[i].fld[j]' is 'array'. You can think of this as stripping
3051 away the offset part from a memory address.
3053 This function calls handled_component_p to strip away all the inner
3054 parts of the memory reference until it reaches the base object. */
3057 get_base_address (tree t
)
3059 while (handled_component_p (t
))
3060 t
= TREE_OPERAND (t
, 0);
3062 if ((TREE_CODE (t
) == MEM_REF
3063 || TREE_CODE (t
) == TARGET_MEM_REF
)
3064 && TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
3065 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
3067 if (TREE_CODE (t
) == SSA_NAME
3069 || TREE_CODE (t
) == STRING_CST
3070 || TREE_CODE (t
) == CONSTRUCTOR
3071 || INDIRECT_REF_P (t
)
3072 || TREE_CODE (t
) == MEM_REF
3073 || TREE_CODE (t
) == TARGET_MEM_REF
)
3080 recalculate_side_effects (tree t
)
3082 enum tree_code code
= TREE_CODE (t
);
3083 int len
= TREE_OPERAND_LENGTH (t
);
3086 switch (TREE_CODE_CLASS (code
))
3088 case tcc_expression
:
3094 case PREDECREMENT_EXPR
:
3095 case PREINCREMENT_EXPR
:
3096 case POSTDECREMENT_EXPR
:
3097 case POSTINCREMENT_EXPR
:
3098 /* All of these have side-effects, no matter what their
3107 case tcc_comparison
: /* a comparison expression */
3108 case tcc_unary
: /* a unary arithmetic expression */
3109 case tcc_binary
: /* a binary arithmetic expression */
3110 case tcc_reference
: /* a reference */
3111 case tcc_vl_exp
: /* a function call */
3112 TREE_SIDE_EFFECTS (t
) = TREE_THIS_VOLATILE (t
);
3113 for (i
= 0; i
< len
; ++i
)
3115 tree op
= TREE_OPERAND (t
, i
);
3116 if (op
&& TREE_SIDE_EFFECTS (op
))
3117 TREE_SIDE_EFFECTS (t
) = 1;
3122 /* No side-effects. */
3130 /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
3131 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
3132 we failed to create one. */
3135 canonicalize_cond_expr_cond (tree t
)
3137 /* Strip conversions around boolean operations. */
3138 if (CONVERT_EXPR_P (t
)
3139 && truth_value_p (TREE_CODE (TREE_OPERAND (t
, 0))))
3140 t
= TREE_OPERAND (t
, 0);
3142 /* For (bool)x use x != 0. */
3143 if (CONVERT_EXPR_P (t
)
3144 && TREE_CODE (TREE_TYPE (t
)) == BOOLEAN_TYPE
)
3146 tree top0
= TREE_OPERAND (t
, 0);
3147 t
= build2 (NE_EXPR
, TREE_TYPE (t
),
3148 top0
, build_int_cst (TREE_TYPE (top0
), 0));
3150 /* For !x use x == 0. */
3151 else if (TREE_CODE (t
) == TRUTH_NOT_EXPR
)
3153 tree top0
= TREE_OPERAND (t
, 0);
3154 t
= build2 (EQ_EXPR
, TREE_TYPE (t
),
3155 top0
, build_int_cst (TREE_TYPE (top0
), 0));
3157 /* For cmp ? 1 : 0 use cmp. */
3158 else if (TREE_CODE (t
) == COND_EXPR
3159 && COMPARISON_CLASS_P (TREE_OPERAND (t
, 0))
3160 && integer_onep (TREE_OPERAND (t
, 1))
3161 && integer_zerop (TREE_OPERAND (t
, 2)))
3163 tree top0
= TREE_OPERAND (t
, 0);
3164 t
= build2 (TREE_CODE (top0
), TREE_TYPE (t
),
3165 TREE_OPERAND (top0
, 0), TREE_OPERAND (top0
, 1));
3168 if (is_gimple_condexpr (t
))
3174 /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
3175 the positions marked by the set ARGS_TO_SKIP. */
3178 gimple_call_copy_skip_args (gimple stmt
, bitmap args_to_skip
)
3181 int nargs
= gimple_call_num_args (stmt
);
3182 VEC(tree
, heap
) *vargs
= VEC_alloc (tree
, heap
, nargs
);
3185 for (i
= 0; i
< nargs
; i
++)
3186 if (!bitmap_bit_p (args_to_skip
, i
))
3187 VEC_quick_push (tree
, vargs
, gimple_call_arg (stmt
, i
));
3189 if (gimple_call_internal_p (stmt
))
3190 new_stmt
= gimple_build_call_internal_vec (gimple_call_internal_fn (stmt
),
3193 new_stmt
= gimple_build_call_vec (gimple_call_fn (stmt
), vargs
);
3194 VEC_free (tree
, heap
, vargs
);
3195 if (gimple_call_lhs (stmt
))
3196 gimple_call_set_lhs (new_stmt
, gimple_call_lhs (stmt
));
3198 gimple_set_vuse (new_stmt
, gimple_vuse (stmt
));
3199 gimple_set_vdef (new_stmt
, gimple_vdef (stmt
));
3201 gimple_set_block (new_stmt
, gimple_block (stmt
));
3202 if (gimple_has_location (stmt
))
3203 gimple_set_location (new_stmt
, gimple_location (stmt
));
3204 gimple_call_copy_flags (new_stmt
, stmt
);
3205 gimple_call_set_chain (new_stmt
, gimple_call_chain (stmt
));
3207 gimple_set_modified (new_stmt
, true);
3213 enum gtc_mode
{ GTC_MERGE
= 0, GTC_DIAG
= 1 };
3215 static hashval_t
gimple_type_hash (const void *);
3217 /* Structure used to maintain a cache of some type pairs compared by
3218 gimple_types_compatible_p when comparing aggregate types. There are
3219 three possible values for SAME_P:
3221 -2: The pair (T1, T2) has just been inserted in the table.
3222 0: T1 and T2 are different types.
3223 1: T1 and T2 are the same type.
3225 The two elements in the SAME_P array are indexed by the comparison
3232 signed char same_p
[2];
3234 typedef struct type_pair_d
*type_pair_t
;
3235 DEF_VEC_P(type_pair_t
);
3236 DEF_VEC_ALLOC_P(type_pair_t
,heap
);
3238 #define GIMPLE_TYPE_PAIR_SIZE 16381
3239 struct type_pair_d
*type_pair_cache
;
3242 /* Lookup the pair of types T1 and T2 in *VISITED_P. Insert a new
3243 entry if none existed. */
3245 static inline type_pair_t
3246 lookup_type_pair (tree t1
, tree t2
)
3249 unsigned int uid1
, uid2
;
3251 if (type_pair_cache
== NULL
)
3252 type_pair_cache
= XCNEWVEC (struct type_pair_d
, GIMPLE_TYPE_PAIR_SIZE
);
3254 if (TYPE_UID (t1
) < TYPE_UID (t2
))
3256 uid1
= TYPE_UID (t1
);
3257 uid2
= TYPE_UID (t2
);
3261 uid1
= TYPE_UID (t2
);
3262 uid2
= TYPE_UID (t1
);
3264 gcc_checking_assert (uid1
!= uid2
);
3266 /* iterative_hash_hashval_t imply an function calls.
3267 We know that UIDS are in limited range. */
3268 index
= ((((unsigned HOST_WIDE_INT
)uid1
<< HOST_BITS_PER_WIDE_INT
/ 2) + uid2
)
3269 % GIMPLE_TYPE_PAIR_SIZE
);
3270 if (type_pair_cache
[index
].uid1
== uid1
3271 && type_pair_cache
[index
].uid2
== uid2
)
3272 return &type_pair_cache
[index
];
3274 type_pair_cache
[index
].uid1
= uid1
;
3275 type_pair_cache
[index
].uid2
= uid2
;
3276 type_pair_cache
[index
].same_p
[0] = -2;
3277 type_pair_cache
[index
].same_p
[1] = -2;
3279 return &type_pair_cache
[index
];
3282 /* Per pointer state for the SCC finding. The on_sccstack flag
3283 is not strictly required, it is true when there is no hash value
3284 recorded for the type and false otherwise. But querying that
3289 unsigned int dfsnum
;
3298 static unsigned int next_dfs_num
;
3299 static unsigned int gtc_next_dfs_num
;
3302 /* GIMPLE type merging cache. A direct-mapped cache based on TYPE_UID. */
3304 typedef struct GTY(()) gimple_type_leader_entry_s
{
3307 } gimple_type_leader_entry
;
3309 #define GIMPLE_TYPE_LEADER_SIZE 16381
3310 static GTY((deletable
, length("GIMPLE_TYPE_LEADER_SIZE")))
3311 gimple_type_leader_entry
*gimple_type_leader
;
3313 /* Lookup an existing leader for T and return it or NULL_TREE, if
3314 there is none in the cache. */
3317 gimple_lookup_type_leader (tree t
)
3319 gimple_type_leader_entry
*leader
;
3321 if (!gimple_type_leader
)
3324 leader
= &gimple_type_leader
[TYPE_UID (t
) % GIMPLE_TYPE_LEADER_SIZE
];
3325 if (leader
->type
!= t
)
3328 return leader
->leader
;
3331 /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is
3332 true then if any type has no name return false, otherwise return
3333 true if both types have no names. */
3336 compare_type_names_p (tree t1
, tree t2
)
3338 tree name1
= TYPE_NAME (t1
);
3339 tree name2
= TYPE_NAME (t2
);
3341 if (name1
&& TREE_CODE (name1
) == TYPE_DECL
)
3342 name1
= DECL_NAME (name1
);
3343 gcc_checking_assert (!name1
|| TREE_CODE (name1
) == IDENTIFIER_NODE
);
3345 if (name2
&& TREE_CODE (name2
) == TYPE_DECL
)
3346 name2
= DECL_NAME (name2
);
3347 gcc_checking_assert (!name2
|| TREE_CODE (name2
) == IDENTIFIER_NODE
);
3349 /* Identifiers can be compared with pointer equality rather
3350 than a string comparison. */
3357 /* Return true if the field decls F1 and F2 are at the same offset.
3359 This is intended to be used on GIMPLE types only. */
3362 gimple_compare_field_offset (tree f1
, tree f2
)
3364 if (DECL_OFFSET_ALIGN (f1
) == DECL_OFFSET_ALIGN (f2
))
3366 tree offset1
= DECL_FIELD_OFFSET (f1
);
3367 tree offset2
= DECL_FIELD_OFFSET (f2
);
3368 return ((offset1
== offset2
3369 /* Once gimplification is done, self-referential offsets are
3370 instantiated as operand #2 of the COMPONENT_REF built for
3371 each access and reset. Therefore, they are not relevant
3372 anymore and fields are interchangeable provided that they
3373 represent the same access. */
3374 || (TREE_CODE (offset1
) == PLACEHOLDER_EXPR
3375 && TREE_CODE (offset2
) == PLACEHOLDER_EXPR
3376 && (DECL_SIZE (f1
) == DECL_SIZE (f2
)
3377 || (TREE_CODE (DECL_SIZE (f1
)) == PLACEHOLDER_EXPR
3378 && TREE_CODE (DECL_SIZE (f2
)) == PLACEHOLDER_EXPR
)
3379 || operand_equal_p (DECL_SIZE (f1
), DECL_SIZE (f2
), 0))
3380 && DECL_ALIGN (f1
) == DECL_ALIGN (f2
))
3381 || operand_equal_p (offset1
, offset2
, 0))
3382 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1
),
3383 DECL_FIELD_BIT_OFFSET (f2
)));
3386 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
3387 should be, so handle differing ones specially by decomposing
3388 the offset into a byte and bit offset manually. */
3389 if (host_integerp (DECL_FIELD_OFFSET (f1
), 0)
3390 && host_integerp (DECL_FIELD_OFFSET (f2
), 0))
3392 unsigned HOST_WIDE_INT byte_offset1
, byte_offset2
;
3393 unsigned HOST_WIDE_INT bit_offset1
, bit_offset2
;
3394 bit_offset1
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1
));
3395 byte_offset1
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1
))
3396 + bit_offset1
/ BITS_PER_UNIT
);
3397 bit_offset2
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2
));
3398 byte_offset2
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2
))
3399 + bit_offset2
/ BITS_PER_UNIT
);
3400 if (byte_offset1
!= byte_offset2
)
3402 return bit_offset1
% BITS_PER_UNIT
== bit_offset2
% BITS_PER_UNIT
;
3409 gimple_types_compatible_p_1 (tree
, tree
, type_pair_t
,
3410 VEC(type_pair_t
, heap
) **,
3411 struct pointer_map_t
*, struct obstack
*);
3413 /* DFS visit the edge from the callers type pair with state *STATE to
3414 the pair T1, T2 while operating in FOR_MERGING_P mode.
3415 Update the merging status if it is not part of the SCC containing the
3416 callers pair and return it.
3417 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3420 gtc_visit (tree t1
, tree t2
,
3422 VEC(type_pair_t
, heap
) **sccstack
,
3423 struct pointer_map_t
*sccstate
,
3424 struct obstack
*sccstate_obstack
)
3426 struct sccs
*cstate
= NULL
;
3429 tree leader1
, leader2
;
3431 /* Check first for the obvious case of pointer identity. */
3435 /* Check that we have two types to compare. */
3436 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
3439 /* Can't be the same type if the types don't have the same code. */
3440 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3443 /* Can't be the same type if they have different CV qualifiers. */
3444 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
3447 if (TREE_ADDRESSABLE (t1
) != TREE_ADDRESSABLE (t2
))
3450 /* Void types and nullptr types are always the same. */
3451 if (TREE_CODE (t1
) == VOID_TYPE
3452 || TREE_CODE (t1
) == NULLPTR_TYPE
)
3455 /* Can't be the same type if they have different alignment or mode. */
3456 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3457 || TYPE_MODE (t1
) != TYPE_MODE (t2
))
3460 /* Do some simple checks before doing three hashtable queries. */
3461 if (INTEGRAL_TYPE_P (t1
)
3462 || SCALAR_FLOAT_TYPE_P (t1
)
3463 || FIXED_POINT_TYPE_P (t1
)
3464 || TREE_CODE (t1
) == VECTOR_TYPE
3465 || TREE_CODE (t1
) == COMPLEX_TYPE
3466 || TREE_CODE (t1
) == OFFSET_TYPE
3467 || POINTER_TYPE_P (t1
))
3469 /* Can't be the same type if they have different sign or precision. */
3470 if (TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
3471 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
3474 if (TREE_CODE (t1
) == INTEGER_TYPE
3475 && (TYPE_IS_SIZETYPE (t1
) != TYPE_IS_SIZETYPE (t2
)
3476 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)))
3479 /* That's all we need to check for float and fixed-point types. */
3480 if (SCALAR_FLOAT_TYPE_P (t1
)
3481 || FIXED_POINT_TYPE_P (t1
))
3484 /* For other types fall thru to more complex checks. */
3487 /* If the types have been previously registered and found equal
3489 leader1
= gimple_lookup_type_leader (t1
);
3490 leader2
= gimple_lookup_type_leader (t2
);
3493 || (leader1
&& leader1
== leader2
))
3496 /* If the hash values of t1 and t2 are different the types can't
3497 possibly be the same. This helps keeping the type-pair hashtable
3498 small, only tracking comparisons for hash collisions. */
3499 if (gimple_type_hash (t1
) != gimple_type_hash (t2
))
3502 /* Allocate a new cache entry for this comparison. */
3503 p
= lookup_type_pair (t1
, t2
);
3504 if (p
->same_p
[GTC_MERGE
] == 0 || p
->same_p
[GTC_MERGE
] == 1)
3506 /* We have already decided whether T1 and T2 are the
3507 same, return the cached result. */
3508 return p
->same_p
[GTC_MERGE
] == 1;
3511 if ((slot
= pointer_map_contains (sccstate
, p
)) != NULL
)
3512 cstate
= (struct sccs
*)*slot
;
3513 /* Not yet visited. DFS recurse. */
3516 gimple_types_compatible_p_1 (t1
, t2
, p
,
3517 sccstack
, sccstate
, sccstate_obstack
);
3518 cstate
= (struct sccs
*)* pointer_map_contains (sccstate
, p
);
3519 state
->low
= MIN (state
->low
, cstate
->low
);
3521 /* If the type is still on the SCC stack adjust the parents low. */
3522 if (cstate
->dfsnum
< state
->dfsnum
3523 && cstate
->on_sccstack
)
3524 state
->low
= MIN (cstate
->dfsnum
, state
->low
);
3526 /* Return the current lattice value. We start with an equality
3527 assumption so types part of a SCC will be optimistically
3528 treated equal unless proven otherwise. */
3529 return cstate
->u
.same_p
;
3532 /* Worker for gimple_types_compatible.
3533 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3536 gimple_types_compatible_p_1 (tree t1
, tree t2
, type_pair_t p
,
3537 VEC(type_pair_t
, heap
) **sccstack
,
3538 struct pointer_map_t
*sccstate
,
3539 struct obstack
*sccstate_obstack
)
3543 gcc_assert (p
->same_p
[GTC_MERGE
] == -2);
3545 state
= XOBNEW (sccstate_obstack
, struct sccs
);
3546 *pointer_map_insert (sccstate
, p
) = state
;
3548 VEC_safe_push (type_pair_t
, heap
, *sccstack
, p
);
3549 state
->dfsnum
= gtc_next_dfs_num
++;
3550 state
->low
= state
->dfsnum
;
3551 state
->on_sccstack
= true;
3552 /* Start with an equality assumption. As we DFS recurse into child
3553 SCCs this assumption may get revisited. */
3554 state
->u
.same_p
= 1;
3556 /* The struct tags shall compare equal. */
3557 if (!compare_type_names_p (t1
, t2
))
3558 goto different_types
;
3560 /* If their attributes are not the same they can't be the same type. */
3561 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1
), TYPE_ATTRIBUTES (t2
)))
3562 goto different_types
;
3564 /* Do type-specific comparisons. */
3565 switch (TREE_CODE (t1
))
3569 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
),
3570 state
, sccstack
, sccstate
, sccstate_obstack
))
3571 goto different_types
;
3575 /* Array types are the same if the element types are the same and
3576 the number of elements are the same. */
3577 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
),
3578 state
, sccstack
, sccstate
, sccstate_obstack
)
3579 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)
3580 || TYPE_NONALIASED_COMPONENT (t1
) != TYPE_NONALIASED_COMPONENT (t2
))
3581 goto different_types
;
3584 tree i1
= TYPE_DOMAIN (t1
);
3585 tree i2
= TYPE_DOMAIN (t2
);
3587 /* For an incomplete external array, the type domain can be
3588 NULL_TREE. Check this condition also. */
3589 if (i1
== NULL_TREE
&& i2
== NULL_TREE
)
3591 else if (i1
== NULL_TREE
|| i2
== NULL_TREE
)
3592 goto different_types
;
3593 /* If for a complete array type the possibly gimplified sizes
3594 are different the types are different. */
3595 else if (((TYPE_SIZE (i1
) != NULL
) ^ (TYPE_SIZE (i2
) != NULL
))
3598 && !operand_equal_p (TYPE_SIZE (i1
), TYPE_SIZE (i2
), 0)))
3599 goto different_types
;
3602 tree min1
= TYPE_MIN_VALUE (i1
);
3603 tree min2
= TYPE_MIN_VALUE (i2
);
3604 tree max1
= TYPE_MAX_VALUE (i1
);
3605 tree max2
= TYPE_MAX_VALUE (i2
);
3607 /* The minimum/maximum values have to be the same. */
3610 && ((TREE_CODE (min1
) == PLACEHOLDER_EXPR
3611 && TREE_CODE (min2
) == PLACEHOLDER_EXPR
)
3612 || operand_equal_p (min1
, min2
, 0))))
3615 && ((TREE_CODE (max1
) == PLACEHOLDER_EXPR
3616 && TREE_CODE (max2
) == PLACEHOLDER_EXPR
)
3617 || operand_equal_p (max1
, max2
, 0)))))
3620 goto different_types
;
3625 /* Method types should belong to the same class. */
3626 if (!gtc_visit (TYPE_METHOD_BASETYPE (t1
), TYPE_METHOD_BASETYPE (t2
),
3627 state
, sccstack
, sccstate
, sccstate_obstack
))
3628 goto different_types
;
3633 /* Function types are the same if the return type and arguments types
3635 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
),
3636 state
, sccstack
, sccstate
, sccstate_obstack
))
3637 goto different_types
;
3639 if (!comp_type_attributes (t1
, t2
))
3640 goto different_types
;
3642 if (TYPE_ARG_TYPES (t1
) == TYPE_ARG_TYPES (t2
))
3646 tree parms1
, parms2
;
3648 for (parms1
= TYPE_ARG_TYPES (t1
), parms2
= TYPE_ARG_TYPES (t2
);
3650 parms1
= TREE_CHAIN (parms1
), parms2
= TREE_CHAIN (parms2
))
3652 if (!gtc_visit (TREE_VALUE (parms1
), TREE_VALUE (parms2
),
3653 state
, sccstack
, sccstate
, sccstate_obstack
))
3654 goto different_types
;
3657 if (parms1
|| parms2
)
3658 goto different_types
;
3665 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
),
3666 state
, sccstack
, sccstate
, sccstate_obstack
)
3667 || !gtc_visit (TYPE_OFFSET_BASETYPE (t1
),
3668 TYPE_OFFSET_BASETYPE (t2
),
3669 state
, sccstack
, sccstate
, sccstate_obstack
))
3670 goto different_types
;
3676 case REFERENCE_TYPE
:
3678 /* If the two pointers have different ref-all attributes,
3679 they can't be the same type. */
3680 if (TYPE_REF_CAN_ALIAS_ALL (t1
) != TYPE_REF_CAN_ALIAS_ALL (t2
))
3681 goto different_types
;
3683 /* Otherwise, pointer and reference types are the same if the
3684 pointed-to types are the same. */
3685 if (gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
),
3686 state
, sccstack
, sccstate
, sccstate_obstack
))
3689 goto different_types
;
3695 tree min1
= TYPE_MIN_VALUE (t1
);
3696 tree max1
= TYPE_MAX_VALUE (t1
);
3697 tree min2
= TYPE_MIN_VALUE (t2
);
3698 tree max2
= TYPE_MAX_VALUE (t2
);
3699 bool min_equal_p
= false;
3700 bool max_equal_p
= false;
3702 /* If either type has a minimum value, the other type must
3704 if (min1
== NULL_TREE
&& min2
== NULL_TREE
)
3706 else if (min1
&& min2
&& operand_equal_p (min1
, min2
, 0))
3709 /* Likewise, if either type has a maximum value, the other
3710 type must have the same. */
3711 if (max1
== NULL_TREE
&& max2
== NULL_TREE
)
3713 else if (max1
&& max2
&& operand_equal_p (max1
, max2
, 0))
3716 if (!min_equal_p
|| !max_equal_p
)
3717 goto different_types
;
3724 /* FIXME lto, we cannot check bounds on enumeral types because
3725 different front ends will produce different values.
3726 In C, enumeral types are integers, while in C++ each element
3727 will have its own symbolic value. We should decide how enums
3728 are to be represented in GIMPLE and have each front end lower
3732 /* For enumeral types, all the values must be the same. */
3733 if (TYPE_VALUES (t1
) == TYPE_VALUES (t2
))
3736 for (v1
= TYPE_VALUES (t1
), v2
= TYPE_VALUES (t2
);
3738 v1
= TREE_CHAIN (v1
), v2
= TREE_CHAIN (v2
))
3740 tree c1
= TREE_VALUE (v1
);
3741 tree c2
= TREE_VALUE (v2
);
3743 if (TREE_CODE (c1
) == CONST_DECL
)
3744 c1
= DECL_INITIAL (c1
);
3746 if (TREE_CODE (c2
) == CONST_DECL
)
3747 c2
= DECL_INITIAL (c2
);
3749 if (tree_int_cst_equal (c1
, c2
) != 1)
3750 goto different_types
;
3752 if (TREE_PURPOSE (v1
) != TREE_PURPOSE (v2
))
3753 goto different_types
;
3756 /* If one enumeration has more values than the other, they
3757 are not the same. */
3759 goto different_types
;
3766 case QUAL_UNION_TYPE
:
3770 /* For aggregate types, all the fields must be the same. */
3771 for (f1
= TYPE_FIELDS (t1
), f2
= TYPE_FIELDS (t2
);
3773 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
3775 /* Different field kinds are not compatible. */
3776 if (TREE_CODE (f1
) != TREE_CODE (f2
))
3777 goto different_types
;
3778 /* Field decls must have the same name and offset. */
3779 if (TREE_CODE (f1
) == FIELD_DECL
3780 && (DECL_NONADDRESSABLE_P (f1
) != DECL_NONADDRESSABLE_P (f2
)
3781 || !gimple_compare_field_offset (f1
, f2
)))
3782 goto different_types
;
3783 /* All entities should have the same name and type. */
3784 if (DECL_NAME (f1
) != DECL_NAME (f2
)
3785 || !gtc_visit (TREE_TYPE (f1
), TREE_TYPE (f2
),
3786 state
, sccstack
, sccstate
, sccstate_obstack
))
3787 goto different_types
;
3790 /* If one aggregate has more fields than the other, they
3791 are not the same. */
3793 goto different_types
;
3802 /* Common exit path for types that are not compatible. */
3804 state
->u
.same_p
= 0;
3807 /* Common exit path for types that are compatible. */
3809 gcc_assert (state
->u
.same_p
== 1);
3812 if (state
->low
== state
->dfsnum
)
3816 /* Pop off the SCC and set its cache values to the final
3817 comparison result. */
3820 struct sccs
*cstate
;
3821 x
= VEC_pop (type_pair_t
, *sccstack
);
3822 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
3823 cstate
->on_sccstack
= false;
3824 x
->same_p
[GTC_MERGE
] = state
->u
.same_p
;
3829 return state
->u
.same_p
;
3832 /* Return true iff T1 and T2 are structurally identical. When
3833 FOR_MERGING_P is true the an incomplete type and a complete type
3834 are considered different, otherwise they are considered compatible. */
3837 gimple_types_compatible_p (tree t1
, tree t2
)
3839 VEC(type_pair_t
, heap
) *sccstack
= NULL
;
3840 struct pointer_map_t
*sccstate
;
3841 struct obstack sccstate_obstack
;
3842 type_pair_t p
= NULL
;
3844 tree leader1
, leader2
;
3846 /* Before starting to set up the SCC machinery handle simple cases. */
3848 /* Check first for the obvious case of pointer identity. */
3852 /* Check that we have two types to compare. */
3853 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
3856 /* Can't be the same type if the types don't have the same code. */
3857 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3860 /* Can't be the same type if they have different CV qualifiers. */
3861 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
3864 if (TREE_ADDRESSABLE (t1
) != TREE_ADDRESSABLE (t2
))
3867 /* Void types and nullptr types are always the same. */
3868 if (TREE_CODE (t1
) == VOID_TYPE
3869 || TREE_CODE (t1
) == NULLPTR_TYPE
)
3872 /* Can't be the same type if they have different alignment or mode. */
3873 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3874 || TYPE_MODE (t1
) != TYPE_MODE (t2
))
3877 /* Do some simple checks before doing three hashtable queries. */
3878 if (INTEGRAL_TYPE_P (t1
)
3879 || SCALAR_FLOAT_TYPE_P (t1
)
3880 || FIXED_POINT_TYPE_P (t1
)
3881 || TREE_CODE (t1
) == VECTOR_TYPE
3882 || TREE_CODE (t1
) == COMPLEX_TYPE
3883 || TREE_CODE (t1
) == OFFSET_TYPE
3884 || POINTER_TYPE_P (t1
))
3886 /* Can't be the same type if they have different sign or precision. */
3887 if (TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
3888 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
3891 if (TREE_CODE (t1
) == INTEGER_TYPE
3892 && (TYPE_IS_SIZETYPE (t1
) != TYPE_IS_SIZETYPE (t2
)
3893 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)))
3896 /* That's all we need to check for float and fixed-point types. */
3897 if (SCALAR_FLOAT_TYPE_P (t1
)
3898 || FIXED_POINT_TYPE_P (t1
))
3901 /* For other types fall thru to more complex checks. */
3904 /* If the types have been previously registered and found equal
3906 leader1
= gimple_lookup_type_leader (t1
);
3907 leader2
= gimple_lookup_type_leader (t2
);
3910 || (leader1
&& leader1
== leader2
))
3913 /* If the hash values of t1 and t2 are different the types can't
3914 possibly be the same. This helps keeping the type-pair hashtable
3915 small, only tracking comparisons for hash collisions. */
3916 if (gimple_type_hash (t1
) != gimple_type_hash (t2
))
3919 /* If we've visited this type pair before (in the case of aggregates
3920 with self-referential types), and we made a decision, return it. */
3921 p
= lookup_type_pair (t1
, t2
);
3922 if (p
->same_p
[GTC_MERGE
] == 0 || p
->same_p
[GTC_MERGE
] == 1)
3924 /* We have already decided whether T1 and T2 are the
3925 same, return the cached result. */
3926 return p
->same_p
[GTC_MERGE
] == 1;
3929 /* Now set up the SCC machinery for the comparison. */
3930 gtc_next_dfs_num
= 1;
3931 sccstate
= pointer_map_create ();
3932 gcc_obstack_init (&sccstate_obstack
);
3933 res
= gimple_types_compatible_p_1 (t1
, t2
, p
,
3934 &sccstack
, sccstate
, &sccstate_obstack
);
3935 VEC_free (type_pair_t
, heap
, sccstack
);
3936 pointer_map_destroy (sccstate
);
3937 obstack_free (&sccstate_obstack
, NULL
);
3944 iterative_hash_gimple_type (tree
, hashval_t
, VEC(tree
, heap
) **,
3945 struct pointer_map_t
*, struct obstack
*);
3947 /* DFS visit the edge from the callers type with state *STATE to T.
3948 Update the callers type hash V with the hash for T if it is not part
3949 of the SCC containing the callers type and return it.
3950 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3953 visit (tree t
, struct sccs
*state
, hashval_t v
,
3954 VEC (tree
, heap
) **sccstack
,
3955 struct pointer_map_t
*sccstate
,
3956 struct obstack
*sccstate_obstack
)
3958 struct sccs
*cstate
= NULL
;
3959 struct tree_int_map m
;
3962 /* If there is a hash value recorded for this type then it can't
3963 possibly be part of our parent SCC. Simply mix in its hash. */
3965 if ((slot
= htab_find_slot (type_hash_cache
, &m
, NO_INSERT
))
3967 return iterative_hash_hashval_t (((struct tree_int_map
*) *slot
)->to
, v
);
3969 if ((slot
= pointer_map_contains (sccstate
, t
)) != NULL
)
3970 cstate
= (struct sccs
*)*slot
;
3974 /* Not yet visited. DFS recurse. */
3975 tem
= iterative_hash_gimple_type (t
, v
,
3976 sccstack
, sccstate
, sccstate_obstack
);
3978 cstate
= (struct sccs
*)* pointer_map_contains (sccstate
, t
);
3979 state
->low
= MIN (state
->low
, cstate
->low
);
3980 /* If the type is no longer on the SCC stack and thus is not part
3981 of the parents SCC mix in its hash value. Otherwise we will
3982 ignore the type for hashing purposes and return the unaltered
3984 if (!cstate
->on_sccstack
)
3987 if (cstate
->dfsnum
< state
->dfsnum
3988 && cstate
->on_sccstack
)
3989 state
->low
= MIN (cstate
->dfsnum
, state
->low
);
3991 /* We are part of our parents SCC, skip this type during hashing
3992 and return the unaltered hash value. */
3996 /* Hash NAME with the previous hash value V and return it. */
3999 iterative_hash_name (tree name
, hashval_t v
)
4003 if (TREE_CODE (name
) == TYPE_DECL
)
4004 name
= DECL_NAME (name
);
4007 gcc_assert (TREE_CODE (name
) == IDENTIFIER_NODE
);
4008 return iterative_hash_object (IDENTIFIER_HASH_VALUE (name
), v
);
4011 /* A type, hashvalue pair for sorting SCC members. */
4013 struct type_hash_pair
{
4018 /* Compare two type, hashvalue pairs. */
4021 type_hash_pair_compare (const void *p1_
, const void *p2_
)
4023 const struct type_hash_pair
*p1
= (const struct type_hash_pair
*) p1_
;
4024 const struct type_hash_pair
*p2
= (const struct type_hash_pair
*) p2_
;
4025 if (p1
->hash
< p2
->hash
)
4027 else if (p1
->hash
> p2
->hash
)
4032 /* Returning a hash value for gimple type TYPE combined with VAL.
4033 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done.
4035 To hash a type we end up hashing in types that are reachable.
4036 Through pointers we can end up with cycles which messes up the
4037 required property that we need to compute the same hash value
4038 for structurally equivalent types. To avoid this we have to
4039 hash all types in a cycle (the SCC) in a commutative way. The
4040 easiest way is to not mix in the hashes of the SCC members at
4041 all. To make this work we have to delay setting the hash
4042 values of the SCC until it is complete. */
4045 iterative_hash_gimple_type (tree type
, hashval_t val
,
4046 VEC(tree
, heap
) **sccstack
,
4047 struct pointer_map_t
*sccstate
,
4048 struct obstack
*sccstate_obstack
)
4054 /* Not visited during this DFS walk. */
4055 gcc_checking_assert (!pointer_map_contains (sccstate
, type
));
4056 state
= XOBNEW (sccstate_obstack
, struct sccs
);
4057 *pointer_map_insert (sccstate
, type
) = state
;
4059 VEC_safe_push (tree
, heap
, *sccstack
, type
);
4060 state
->dfsnum
= next_dfs_num
++;
4061 state
->low
= state
->dfsnum
;
4062 state
->on_sccstack
= true;
4064 /* Combine a few common features of types so that types are grouped into
4065 smaller sets; when searching for existing matching types to merge,
4066 only existing types having the same features as the new type will be
4068 v
= iterative_hash_name (TYPE_NAME (type
), 0);
4069 v
= iterative_hash_hashval_t (TREE_CODE (type
), v
);
4070 v
= iterative_hash_hashval_t (TYPE_QUALS (type
), v
);
4071 v
= iterative_hash_hashval_t (TREE_ADDRESSABLE (type
), v
);
4073 /* Do not hash the types size as this will cause differences in
4074 hash values for the complete vs. the incomplete type variant. */
4076 /* Incorporate common features of numerical types. */
4077 if (INTEGRAL_TYPE_P (type
)
4078 || SCALAR_FLOAT_TYPE_P (type
)
4079 || FIXED_POINT_TYPE_P (type
))
4081 v
= iterative_hash_hashval_t (TYPE_PRECISION (type
), v
);
4082 v
= iterative_hash_hashval_t (TYPE_MODE (type
), v
);
4083 v
= iterative_hash_hashval_t (TYPE_UNSIGNED (type
), v
);
4086 /* For pointer and reference types, fold in information about the type
4088 if (POINTER_TYPE_P (type
))
4089 v
= visit (TREE_TYPE (type
), state
, v
,
4090 sccstack
, sccstate
, sccstate_obstack
);
4092 /* For integer types hash the types min/max values and the string flag. */
4093 if (TREE_CODE (type
) == INTEGER_TYPE
)
4095 /* OMP lowering can introduce error_mark_node in place of
4096 random local decls in types. */
4097 if (TYPE_MIN_VALUE (type
) != error_mark_node
)
4098 v
= iterative_hash_expr (TYPE_MIN_VALUE (type
), v
);
4099 if (TYPE_MAX_VALUE (type
) != error_mark_node
)
4100 v
= iterative_hash_expr (TYPE_MAX_VALUE (type
), v
);
4101 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
4104 /* For array types hash their domain and the string flag. */
4105 if (TREE_CODE (type
) == ARRAY_TYPE
4106 && TYPE_DOMAIN (type
))
4108 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
4109 v
= visit (TYPE_DOMAIN (type
), state
, v
,
4110 sccstack
, sccstate
, sccstate_obstack
);
4113 /* Recurse for aggregates with a single element type. */
4114 if (TREE_CODE (type
) == ARRAY_TYPE
4115 || TREE_CODE (type
) == COMPLEX_TYPE
4116 || TREE_CODE (type
) == VECTOR_TYPE
)
4117 v
= visit (TREE_TYPE (type
), state
, v
,
4118 sccstack
, sccstate
, sccstate_obstack
);
4120 /* Incorporate function return and argument types. */
4121 if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
4126 /* For method types also incorporate their parent class. */
4127 if (TREE_CODE (type
) == METHOD_TYPE
)
4128 v
= visit (TYPE_METHOD_BASETYPE (type
), state
, v
,
4129 sccstack
, sccstate
, sccstate_obstack
);
4131 /* Check result and argument types. */
4132 v
= visit (TREE_TYPE (type
), state
, v
,
4133 sccstack
, sccstate
, sccstate_obstack
);
4134 for (p
= TYPE_ARG_TYPES (type
), na
= 0; p
; p
= TREE_CHAIN (p
))
4136 v
= visit (TREE_VALUE (p
), state
, v
,
4137 sccstack
, sccstate
, sccstate_obstack
);
4141 v
= iterative_hash_hashval_t (na
, v
);
4144 if (TREE_CODE (type
) == RECORD_TYPE
4145 || TREE_CODE (type
) == UNION_TYPE
4146 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
4151 for (f
= TYPE_FIELDS (type
), nf
= 0; f
; f
= TREE_CHAIN (f
))
4153 v
= iterative_hash_name (DECL_NAME (f
), v
);
4154 v
= visit (TREE_TYPE (f
), state
, v
,
4155 sccstack
, sccstate
, sccstate_obstack
);
4159 v
= iterative_hash_hashval_t (nf
, v
);
4162 /* Record hash for us. */
4165 /* See if we found an SCC. */
4166 if (state
->low
== state
->dfsnum
)
4169 struct tree_int_map
*m
;
4171 /* Pop off the SCC and set its hash values. */
4172 x
= VEC_pop (tree
, *sccstack
);
4173 /* Optimize SCC size one. */
4176 state
->on_sccstack
= false;
4177 m
= ggc_alloc_cleared_tree_int_map ();
4180 slot
= htab_find_slot (type_hash_cache
, m
, INSERT
);
4181 gcc_assert (!*slot
);
4186 struct sccs
*cstate
;
4187 unsigned first
, i
, size
, j
;
4188 struct type_hash_pair
*pairs
;
4189 /* Pop off the SCC and build an array of type, hash pairs. */
4190 first
= VEC_length (tree
, *sccstack
) - 1;
4191 while (VEC_index (tree
, *sccstack
, first
) != type
)
4193 size
= VEC_length (tree
, *sccstack
) - first
+ 1;
4194 pairs
= XALLOCAVEC (struct type_hash_pair
, size
);
4196 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
4197 cstate
->on_sccstack
= false;
4199 pairs
[i
].hash
= cstate
->u
.hash
;
4202 x
= VEC_pop (tree
, *sccstack
);
4203 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
4204 cstate
->on_sccstack
= false;
4207 pairs
[i
].hash
= cstate
->u
.hash
;
4210 gcc_assert (i
+ 1 == size
);
4211 /* Sort the arrays of type, hash pairs so that when we mix in
4212 all members of the SCC the hash value becomes independent on
4213 the order we visited the SCC. Disregard hashes equal to
4214 the hash of the type we mix into because we cannot guarantee
4215 a stable sort for those across different TUs. */
4216 qsort (pairs
, size
, sizeof (struct type_hash_pair
),
4217 type_hash_pair_compare
);
4218 for (i
= 0; i
< size
; ++i
)
4221 m
= ggc_alloc_cleared_tree_int_map ();
4222 m
->base
.from
= pairs
[i
].type
;
4223 hash
= pairs
[i
].hash
;
4224 /* Skip same hashes. */
4225 for (j
= i
+ 1; j
< size
&& pairs
[j
].hash
== pairs
[i
].hash
; ++j
)
4227 for (; j
< size
; ++j
)
4228 hash
= iterative_hash_hashval_t (pairs
[j
].hash
, hash
);
4229 for (j
= 0; pairs
[j
].hash
!= pairs
[i
].hash
; ++j
)
4230 hash
= iterative_hash_hashval_t (pairs
[j
].hash
, hash
);
4232 if (pairs
[i
].type
== type
)
4234 slot
= htab_find_slot (type_hash_cache
, m
, INSERT
);
4235 gcc_assert (!*slot
);
4241 return iterative_hash_hashval_t (v
, val
);
4245 /* Returns a hash value for P (assumed to be a type). The hash value
4246 is computed using some distinguishing features of the type. Note
4247 that we cannot use pointer hashing here as we may be dealing with
4248 two distinct instances of the same type.
4250 This function should produce the same hash value for two compatible
4251 types according to gimple_types_compatible_p. */
4254 gimple_type_hash (const void *p
)
4256 const_tree t
= (const_tree
) p
;
4257 VEC(tree
, heap
) *sccstack
= NULL
;
4258 struct pointer_map_t
*sccstate
;
4259 struct obstack sccstate_obstack
;
4262 struct tree_int_map m
;
4264 if (type_hash_cache
== NULL
)
4265 type_hash_cache
= htab_create_ggc (512, tree_int_map_hash
,
4266 tree_int_map_eq
, NULL
);
4268 m
.base
.from
= CONST_CAST_TREE (t
);
4269 if ((slot
= htab_find_slot (type_hash_cache
, &m
, NO_INSERT
))
4271 return iterative_hash_hashval_t (((struct tree_int_map
*) *slot
)->to
, 0);
4273 /* Perform a DFS walk and pre-hash all reachable types. */
4275 sccstate
= pointer_map_create ();
4276 gcc_obstack_init (&sccstate_obstack
);
4277 val
= iterative_hash_gimple_type (CONST_CAST_TREE (t
), 0,
4278 &sccstack
, sccstate
, &sccstate_obstack
);
4279 VEC_free (tree
, heap
, sccstack
);
4280 pointer_map_destroy (sccstate
);
4281 obstack_free (&sccstate_obstack
, NULL
);
4286 /* Returning a hash value for gimple type TYPE combined with VAL.
4288 The hash value returned is equal for types considered compatible
4289 by gimple_canonical_types_compatible_p. */
4292 iterative_hash_canonical_type (tree type
, hashval_t val
)
4296 struct tree_int_map
*mp
, m
;
4299 if ((slot
= htab_find_slot (canonical_type_hash_cache
, &m
, INSERT
))
4301 return iterative_hash_hashval_t (((struct tree_int_map
*) *slot
)->to
, val
);
4303 /* Combine a few common features of types so that types are grouped into
4304 smaller sets; when searching for existing matching types to merge,
4305 only existing types having the same features as the new type will be
4307 v
= iterative_hash_hashval_t (TREE_CODE (type
), 0);
4308 v
= iterative_hash_hashval_t (TREE_ADDRESSABLE (type
), v
);
4309 v
= iterative_hash_hashval_t (TYPE_ALIGN (type
), v
);
4310 v
= iterative_hash_hashval_t (TYPE_MODE (type
), v
);
4312 /* Incorporate common features of numerical types. */
4313 if (INTEGRAL_TYPE_P (type
)
4314 || SCALAR_FLOAT_TYPE_P (type
)
4315 || FIXED_POINT_TYPE_P (type
)
4316 || TREE_CODE (type
) == VECTOR_TYPE
4317 || TREE_CODE (type
) == COMPLEX_TYPE
4318 || TREE_CODE (type
) == OFFSET_TYPE
4319 || POINTER_TYPE_P (type
))
4321 v
= iterative_hash_hashval_t (TYPE_PRECISION (type
), v
);
4322 v
= iterative_hash_hashval_t (TYPE_UNSIGNED (type
), v
);
4325 /* For pointer and reference types, fold in information about the type
4326 pointed to but do not recurse to the pointed-to type. */
4327 if (POINTER_TYPE_P (type
))
4329 v
= iterative_hash_hashval_t (TYPE_REF_CAN_ALIAS_ALL (type
), v
);
4330 v
= iterative_hash_hashval_t (TYPE_ADDR_SPACE (TREE_TYPE (type
)), v
);
4331 v
= iterative_hash_hashval_t (TYPE_RESTRICT (type
), v
);
4332 v
= iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type
)), v
);
4335 /* For integer types hash the types min/max values and the string flag. */
4336 if (TREE_CODE (type
) == INTEGER_TYPE
)
4338 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
4339 v
= iterative_hash_hashval_t (TYPE_IS_SIZETYPE (type
), v
);
4342 /* For array types hash their domain and the string flag. */
4343 if (TREE_CODE (type
) == ARRAY_TYPE
4344 && TYPE_DOMAIN (type
))
4346 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
4347 v
= iterative_hash_canonical_type (TYPE_DOMAIN (type
), v
);
4350 /* Recurse for aggregates with a single element type. */
4351 if (TREE_CODE (type
) == ARRAY_TYPE
4352 || TREE_CODE (type
) == COMPLEX_TYPE
4353 || TREE_CODE (type
) == VECTOR_TYPE
)
4354 v
= iterative_hash_canonical_type (TREE_TYPE (type
), v
);
4356 /* Incorporate function return and argument types. */
4357 if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
4362 /* For method types also incorporate their parent class. */
4363 if (TREE_CODE (type
) == METHOD_TYPE
)
4364 v
= iterative_hash_canonical_type (TYPE_METHOD_BASETYPE (type
), v
);
4366 v
= iterative_hash_canonical_type (TREE_TYPE (type
), v
);
4368 for (p
= TYPE_ARG_TYPES (type
), na
= 0; p
; p
= TREE_CHAIN (p
))
4370 v
= iterative_hash_canonical_type (TREE_VALUE (p
), v
);
4374 v
= iterative_hash_hashval_t (na
, v
);
4377 if (TREE_CODE (type
) == RECORD_TYPE
4378 || TREE_CODE (type
) == UNION_TYPE
4379 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
4384 for (f
= TYPE_FIELDS (type
), nf
= 0; f
; f
= TREE_CHAIN (f
))
4385 if (TREE_CODE (f
) == FIELD_DECL
)
4387 v
= iterative_hash_canonical_type (TREE_TYPE (f
), v
);
4391 v
= iterative_hash_hashval_t (nf
, v
);
4394 /* Cache the just computed hash value. */
4395 mp
= ggc_alloc_cleared_tree_int_map ();
4396 mp
->base
.from
= type
;
4398 *slot
= (void *) mp
;
4400 return iterative_hash_hashval_t (v
, val
);
4404 gimple_canonical_type_hash (const void *p
)
4406 if (canonical_type_hash_cache
== NULL
)
4407 canonical_type_hash_cache
= htab_create_ggc (512, tree_int_map_hash
,
4408 tree_int_map_eq
, NULL
);
4410 return iterative_hash_canonical_type (CONST_CAST_TREE ((const_tree
) p
), 0);
4414 /* Returns nonzero if P1 and P2 are equal. */
4417 gimple_type_eq (const void *p1
, const void *p2
)
4419 const_tree t1
= (const_tree
) p1
;
4420 const_tree t2
= (const_tree
) p2
;
4421 return gimple_types_compatible_p (CONST_CAST_TREE (t1
),
4422 CONST_CAST_TREE (t2
));
4426 /* Worker for gimple_register_type.
4427 Register type T in the global type table gimple_types.
4428 When REGISTERING_MV is false first recurse for the main variant of T. */
4431 gimple_register_type_1 (tree t
, bool registering_mv
)
4434 gimple_type_leader_entry
*leader
;
4436 /* If we registered this type before return the cached result. */
4437 leader
= &gimple_type_leader
[TYPE_UID (t
) % GIMPLE_TYPE_LEADER_SIZE
];
4438 if (leader
->type
== t
)
4439 return leader
->leader
;
4441 /* Always register the main variant first. This is important so we
4442 pick up the non-typedef variants as canonical, otherwise we'll end
4443 up taking typedef ids for structure tags during comparison.
4444 It also makes sure that main variants will be merged to main variants.
4445 As we are operating on a possibly partially fixed up type graph
4446 do not bother to recurse more than once, otherwise we may end up
4448 If we are registering a main variant it will either remain its
4449 own main variant or it will be merged to something else in which
4450 case we do not care for the main variant leader. */
4452 && TYPE_MAIN_VARIANT (t
) != t
)
4453 gimple_register_type_1 (TYPE_MAIN_VARIANT (t
), true);
4455 /* See if we already have an equivalent type registered. */
4456 slot
= htab_find_slot (gimple_types
, t
, INSERT
);
4458 && *(tree
*)slot
!= t
)
4460 tree new_type
= (tree
) *((tree
*) slot
);
4462 leader
->leader
= new_type
;
4466 /* If not, insert it to the cache and the hash. */
4473 /* Register type T in the global type table gimple_types.
4474 If another type T', compatible with T, already existed in
4475 gimple_types then return T', otherwise return T. This is used by
4476 LTO to merge identical types read from different TUs. */
4479 gimple_register_type (tree t
)
4481 gcc_assert (TYPE_P (t
));
4483 if (!gimple_type_leader
)
4484 gimple_type_leader
= ggc_alloc_cleared_vec_gimple_type_leader_entry_s
4485 (GIMPLE_TYPE_LEADER_SIZE
);
4487 if (gimple_types
== NULL
)
4488 gimple_types
= htab_create_ggc (16381, gimple_type_hash
, gimple_type_eq
, 0);
4490 return gimple_register_type_1 (t
, false);
4493 /* The TYPE_CANONICAL merging machinery. It should closely resemble
4494 the middle-end types_compatible_p function. It needs to avoid
4495 claiming types are different for types that should be treated
4496 the same with respect to TBAA. Canonical types are also used
4497 for IL consistency checks via the useless_type_conversion_p
4498 predicate which does not handle all type kinds itself but falls
4499 back to pointer-comparison of TYPE_CANONICAL for aggregates
4502 /* Return true iff T1 and T2 are structurally identical for what
4503 TBAA is concerned. */
4506 gimple_canonical_types_compatible_p (tree t1
, tree t2
)
4508 /* Before starting to set up the SCC machinery handle simple cases. */
4510 /* Check first for the obvious case of pointer identity. */
4514 /* Check that we have two types to compare. */
4515 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
4518 /* If the types have been previously registered and found equal
4520 if (TYPE_CANONICAL (t1
)
4521 && TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
))
4524 /* Can't be the same type if the types don't have the same code. */
4525 if (TREE_CODE (t1
) != TREE_CODE (t2
))
4528 if (TREE_ADDRESSABLE (t1
) != TREE_ADDRESSABLE (t2
))
4531 /* Qualifiers do not matter for canonical type comparison purposes. */
4533 /* Void types and nullptr types are always the same. */
4534 if (TREE_CODE (t1
) == VOID_TYPE
4535 || TREE_CODE (t1
) == NULLPTR_TYPE
)
4538 /* Can't be the same type if they have different alignment, or mode. */
4539 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
4540 || TYPE_MODE (t1
) != TYPE_MODE (t2
))
4543 /* Non-aggregate types can be handled cheaply. */
4544 if (INTEGRAL_TYPE_P (t1
)
4545 || SCALAR_FLOAT_TYPE_P (t1
)
4546 || FIXED_POINT_TYPE_P (t1
)
4547 || TREE_CODE (t1
) == VECTOR_TYPE
4548 || TREE_CODE (t1
) == COMPLEX_TYPE
4549 || TREE_CODE (t1
) == OFFSET_TYPE
4550 || POINTER_TYPE_P (t1
))
4552 /* Can't be the same type if they have different sign or precision. */
4553 if (TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
4554 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
4557 if (TREE_CODE (t1
) == INTEGER_TYPE
4558 && (TYPE_IS_SIZETYPE (t1
) != TYPE_IS_SIZETYPE (t2
)
4559 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)))
4562 /* For canonical type comparisons we do not want to build SCCs
4563 so we cannot compare pointed-to types. But we can, for now,
4564 require the same pointed-to type kind and match what
4565 useless_type_conversion_p would do. */
4566 if (POINTER_TYPE_P (t1
))
4568 /* If the two pointers have different ref-all attributes,
4569 they can't be the same type. */
4570 if (TYPE_REF_CAN_ALIAS_ALL (t1
) != TYPE_REF_CAN_ALIAS_ALL (t2
))
4573 if (TYPE_ADDR_SPACE (TREE_TYPE (t1
))
4574 != TYPE_ADDR_SPACE (TREE_TYPE (t2
)))
4577 if (TYPE_RESTRICT (t1
) != TYPE_RESTRICT (t2
))
4580 if (TREE_CODE (TREE_TYPE (t1
)) != TREE_CODE (TREE_TYPE (t2
)))
4584 /* Tail-recurse to components. */
4585 if (TREE_CODE (t1
) == VECTOR_TYPE
4586 || TREE_CODE (t1
) == COMPLEX_TYPE
)
4587 return gimple_canonical_types_compatible_p (TREE_TYPE (t1
),
4593 /* If their attributes are not the same they can't be the same type. */
4594 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1
), TYPE_ATTRIBUTES (t2
)))
4597 /* Do type-specific comparisons. */
4598 switch (TREE_CODE (t1
))
4601 /* Array types are the same if the element types are the same and
4602 the number of elements are the same. */
4603 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
4604 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)
4605 || TYPE_NONALIASED_COMPONENT (t1
) != TYPE_NONALIASED_COMPONENT (t2
))
4609 tree i1
= TYPE_DOMAIN (t1
);
4610 tree i2
= TYPE_DOMAIN (t2
);
4612 /* For an incomplete external array, the type domain can be
4613 NULL_TREE. Check this condition also. */
4614 if (i1
== NULL_TREE
&& i2
== NULL_TREE
)
4616 else if (i1
== NULL_TREE
|| i2
== NULL_TREE
)
4618 /* If for a complete array type the possibly gimplified sizes
4619 are different the types are different. */
4620 else if (((TYPE_SIZE (i1
) != NULL
) ^ (TYPE_SIZE (i2
) != NULL
))
4623 && !operand_equal_p (TYPE_SIZE (i1
), TYPE_SIZE (i2
), 0)))
4627 tree min1
= TYPE_MIN_VALUE (i1
);
4628 tree min2
= TYPE_MIN_VALUE (i2
);
4629 tree max1
= TYPE_MAX_VALUE (i1
);
4630 tree max2
= TYPE_MAX_VALUE (i2
);
4632 /* The minimum/maximum values have to be the same. */
4635 && ((TREE_CODE (min1
) == PLACEHOLDER_EXPR
4636 && TREE_CODE (min2
) == PLACEHOLDER_EXPR
)
4637 || operand_equal_p (min1
, min2
, 0))))
4640 && ((TREE_CODE (max1
) == PLACEHOLDER_EXPR
4641 && TREE_CODE (max2
) == PLACEHOLDER_EXPR
)
4642 || operand_equal_p (max1
, max2
, 0)))))
4650 /* Method types should belong to the same class. */
4651 if (!gimple_canonical_types_compatible_p
4652 (TYPE_METHOD_BASETYPE (t1
), TYPE_METHOD_BASETYPE (t2
)))
4658 /* Function types are the same if the return type and arguments types
4660 if (!gimple_canonical_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
4663 if (!comp_type_attributes (t1
, t2
))
4666 if (TYPE_ARG_TYPES (t1
) == TYPE_ARG_TYPES (t2
))
4670 tree parms1
, parms2
;
4672 for (parms1
= TYPE_ARG_TYPES (t1
), parms2
= TYPE_ARG_TYPES (t2
);
4674 parms1
= TREE_CHAIN (parms1
), parms2
= TREE_CHAIN (parms2
))
4676 if (!gimple_canonical_types_compatible_p
4677 (TREE_VALUE (parms1
), TREE_VALUE (parms2
)))
4681 if (parms1
|| parms2
)
4689 case QUAL_UNION_TYPE
:
4693 /* For aggregate types, all the fields must be the same. */
4694 for (f1
= TYPE_FIELDS (t1
), f2
= TYPE_FIELDS (t2
);
4696 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
4698 /* Skip non-fields. */
4699 while (f1
&& TREE_CODE (f1
) != FIELD_DECL
)
4700 f1
= TREE_CHAIN (f1
);
4701 while (f2
&& TREE_CODE (f2
) != FIELD_DECL
)
4702 f2
= TREE_CHAIN (f2
);
4705 /* The fields must have the same name, offset and type. */
4706 if (DECL_NONADDRESSABLE_P (f1
) != DECL_NONADDRESSABLE_P (f2
)
4707 || !gimple_compare_field_offset (f1
, f2
)
4708 || !gimple_canonical_types_compatible_p
4709 (TREE_TYPE (f1
), TREE_TYPE (f2
)))
4713 /* If one aggregate has more fields than the other, they
4714 are not the same. */
4727 /* Returns nonzero if P1 and P2 are equal. */
4730 gimple_canonical_type_eq (const void *p1
, const void *p2
)
4732 const_tree t1
= (const_tree
) p1
;
4733 const_tree t2
= (const_tree
) p2
;
4734 return gimple_canonical_types_compatible_p (CONST_CAST_TREE (t1
),
4735 CONST_CAST_TREE (t2
));
4738 /* Register type T in the global type table gimple_types.
4739 If another type T', compatible with T, already existed in
4740 gimple_types then return T', otherwise return T. This is used by
4741 LTO to merge identical types read from different TUs.
4743 ??? This merging does not exactly match how the tree.c middle-end
4744 functions will assign TYPE_CANONICAL when new types are created
4745 during optimization (which at least happens for pointer and array
4749 gimple_register_canonical_type (tree t
)
4753 gcc_assert (TYPE_P (t
));
4755 if (TYPE_CANONICAL (t
))
4756 return TYPE_CANONICAL (t
);
4758 if (gimple_canonical_types
== NULL
)
4759 gimple_canonical_types
= htab_create_ggc (16381, gimple_canonical_type_hash
,
4760 gimple_canonical_type_eq
, 0);
4762 slot
= htab_find_slot (gimple_canonical_types
, t
, INSERT
);
4764 && *(tree
*)slot
!= t
)
4766 tree new_type
= (tree
) *((tree
*) slot
);
4768 TYPE_CANONICAL (t
) = new_type
;
4773 TYPE_CANONICAL (t
) = t
;
4781 /* Show statistics on references to the global type table gimple_types. */
4784 print_gimple_types_stats (void)
4787 fprintf (stderr
, "GIMPLE type table: size %ld, %ld elements, "
4788 "%ld searches, %ld collisions (ratio: %f)\n",
4789 (long) htab_size (gimple_types
),
4790 (long) htab_elements (gimple_types
),
4791 (long) gimple_types
->searches
,
4792 (long) gimple_types
->collisions
,
4793 htab_collisions (gimple_types
));
4795 fprintf (stderr
, "GIMPLE type table is empty\n");
4796 if (type_hash_cache
)
4797 fprintf (stderr
, "GIMPLE type hash table: size %ld, %ld elements, "
4798 "%ld searches, %ld collisions (ratio: %f)\n",
4799 (long) htab_size (type_hash_cache
),
4800 (long) htab_elements (type_hash_cache
),
4801 (long) type_hash_cache
->searches
,
4802 (long) type_hash_cache
->collisions
,
4803 htab_collisions (type_hash_cache
));
4805 fprintf (stderr
, "GIMPLE type hash table is empty\n");
4806 if (gimple_canonical_types
)
4807 fprintf (stderr
, "GIMPLE canonical type table: size %ld, %ld elements, "
4808 "%ld searches, %ld collisions (ratio: %f)\n",
4809 (long) htab_size (gimple_canonical_types
),
4810 (long) htab_elements (gimple_canonical_types
),
4811 (long) gimple_canonical_types
->searches
,
4812 (long) gimple_canonical_types
->collisions
,
4813 htab_collisions (gimple_canonical_types
));
4815 fprintf (stderr
, "GIMPLE canonical type table is empty\n");
4816 if (canonical_type_hash_cache
)
4817 fprintf (stderr
, "GIMPLE canonical type hash table: size %ld, %ld elements, "
4818 "%ld searches, %ld collisions (ratio: %f)\n",
4819 (long) htab_size (canonical_type_hash_cache
),
4820 (long) htab_elements (canonical_type_hash_cache
),
4821 (long) canonical_type_hash_cache
->searches
,
4822 (long) canonical_type_hash_cache
->collisions
,
4823 htab_collisions (canonical_type_hash_cache
));
4825 fprintf (stderr
, "GIMPLE canonical type hash table is empty\n");
4828 /* Free the gimple type hashtables used for LTO type merging. */
4831 free_gimple_type_tables (void)
4833 /* Last chance to print stats for the tables. */
4834 if (flag_lto_report
)
4835 print_gimple_types_stats ();
4839 htab_delete (gimple_types
);
4840 gimple_types
= NULL
;
4842 if (gimple_canonical_types
)
4844 htab_delete (gimple_canonical_types
);
4845 gimple_canonical_types
= NULL
;
4847 if (type_hash_cache
)
4849 htab_delete (type_hash_cache
);
4850 type_hash_cache
= NULL
;
4852 if (canonical_type_hash_cache
)
4854 htab_delete (canonical_type_hash_cache
);
4855 canonical_type_hash_cache
= NULL
;
4857 if (type_pair_cache
)
4859 free (type_pair_cache
);
4860 type_pair_cache
= NULL
;
4862 gimple_type_leader
= NULL
;
4866 /* Return a type the same as TYPE except unsigned or
4867 signed according to UNSIGNEDP. */
4870 gimple_signed_or_unsigned_type (bool unsignedp
, tree type
)
4874 type1
= TYPE_MAIN_VARIANT (type
);
4875 if (type1
== signed_char_type_node
4876 || type1
== char_type_node
4877 || type1
== unsigned_char_type_node
)
4878 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4879 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
4880 return unsignedp
? unsigned_type_node
: integer_type_node
;
4881 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
4882 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4883 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
4884 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4885 if (type1
== long_long_integer_type_node
4886 || type1
== long_long_unsigned_type_node
)
4888 ? long_long_unsigned_type_node
4889 : long_long_integer_type_node
;
4890 if (int128_integer_type_node
&& (type1
== int128_integer_type_node
|| type1
== int128_unsigned_type_node
))
4892 ? int128_unsigned_type_node
4893 : int128_integer_type_node
;
4894 #if HOST_BITS_PER_WIDE_INT >= 64
4895 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
4896 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4898 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
4899 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4900 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
4901 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4902 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
4903 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4904 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
4905 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4907 #define GIMPLE_FIXED_TYPES(NAME) \
4908 if (type1 == short_ ## NAME ## _type_node \
4909 || type1 == unsigned_short_ ## NAME ## _type_node) \
4910 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
4911 : short_ ## NAME ## _type_node; \
4912 if (type1 == NAME ## _type_node \
4913 || type1 == unsigned_ ## NAME ## _type_node) \
4914 return unsignedp ? unsigned_ ## NAME ## _type_node \
4915 : NAME ## _type_node; \
4916 if (type1 == long_ ## NAME ## _type_node \
4917 || type1 == unsigned_long_ ## NAME ## _type_node) \
4918 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
4919 : long_ ## NAME ## _type_node; \
4920 if (type1 == long_long_ ## NAME ## _type_node \
4921 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
4922 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
4923 : long_long_ ## NAME ## _type_node;
4925 #define GIMPLE_FIXED_MODE_TYPES(NAME) \
4926 if (type1 == NAME ## _type_node \
4927 || type1 == u ## NAME ## _type_node) \
4928 return unsignedp ? u ## NAME ## _type_node \
4929 : NAME ## _type_node;
4931 #define GIMPLE_FIXED_TYPES_SAT(NAME) \
4932 if (type1 == sat_ ## short_ ## NAME ## _type_node \
4933 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
4934 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
4935 : sat_ ## short_ ## NAME ## _type_node; \
4936 if (type1 == sat_ ## NAME ## _type_node \
4937 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
4938 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
4939 : sat_ ## NAME ## _type_node; \
4940 if (type1 == sat_ ## long_ ## NAME ## _type_node \
4941 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
4942 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
4943 : sat_ ## long_ ## NAME ## _type_node; \
4944 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
4945 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
4946 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
4947 : sat_ ## long_long_ ## NAME ## _type_node;
4949 #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
4950 if (type1 == sat_ ## NAME ## _type_node \
4951 || type1 == sat_ ## u ## NAME ## _type_node) \
4952 return unsignedp ? sat_ ## u ## NAME ## _type_node \
4953 : sat_ ## NAME ## _type_node;
4955 GIMPLE_FIXED_TYPES (fract
);
4956 GIMPLE_FIXED_TYPES_SAT (fract
);
4957 GIMPLE_FIXED_TYPES (accum
);
4958 GIMPLE_FIXED_TYPES_SAT (accum
);
4960 GIMPLE_FIXED_MODE_TYPES (qq
);
4961 GIMPLE_FIXED_MODE_TYPES (hq
);
4962 GIMPLE_FIXED_MODE_TYPES (sq
);
4963 GIMPLE_FIXED_MODE_TYPES (dq
);
4964 GIMPLE_FIXED_MODE_TYPES (tq
);
4965 GIMPLE_FIXED_MODE_TYPES_SAT (qq
);
4966 GIMPLE_FIXED_MODE_TYPES_SAT (hq
);
4967 GIMPLE_FIXED_MODE_TYPES_SAT (sq
);
4968 GIMPLE_FIXED_MODE_TYPES_SAT (dq
);
4969 GIMPLE_FIXED_MODE_TYPES_SAT (tq
);
4970 GIMPLE_FIXED_MODE_TYPES (ha
);
4971 GIMPLE_FIXED_MODE_TYPES (sa
);
4972 GIMPLE_FIXED_MODE_TYPES (da
);
4973 GIMPLE_FIXED_MODE_TYPES (ta
);
4974 GIMPLE_FIXED_MODE_TYPES_SAT (ha
);
4975 GIMPLE_FIXED_MODE_TYPES_SAT (sa
);
4976 GIMPLE_FIXED_MODE_TYPES_SAT (da
);
4977 GIMPLE_FIXED_MODE_TYPES_SAT (ta
);
4979 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
4980 the precision; they have precision set to match their range, but
4981 may use a wider mode to match an ABI. If we change modes, we may
4982 wind up with bad conversions. For INTEGER_TYPEs in C, must check
4983 the precision as well, so as to yield correct results for
4984 bit-field types. C++ does not have these separate bit-field
4985 types, and producing a signed or unsigned variant of an
4986 ENUMERAL_TYPE may cause other problems as well. */
4987 if (!INTEGRAL_TYPE_P (type
)
4988 || TYPE_UNSIGNED (type
) == unsignedp
)
4991 #define TYPE_OK(node) \
4992 (TYPE_MODE (type) == TYPE_MODE (node) \
4993 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
4994 if (TYPE_OK (signed_char_type_node
))
4995 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4996 if (TYPE_OK (integer_type_node
))
4997 return unsignedp
? unsigned_type_node
: integer_type_node
;
4998 if (TYPE_OK (short_integer_type_node
))
4999 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
5000 if (TYPE_OK (long_integer_type_node
))
5001 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
5002 if (TYPE_OK (long_long_integer_type_node
))
5004 ? long_long_unsigned_type_node
5005 : long_long_integer_type_node
);
5006 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
5008 ? int128_unsigned_type_node
5009 : int128_integer_type_node
);
5011 #if HOST_BITS_PER_WIDE_INT >= 64
5012 if (TYPE_OK (intTI_type_node
))
5013 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
5015 if (TYPE_OK (intDI_type_node
))
5016 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
5017 if (TYPE_OK (intSI_type_node
))
5018 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
5019 if (TYPE_OK (intHI_type_node
))
5020 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
5021 if (TYPE_OK (intQI_type_node
))
5022 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
5024 #undef GIMPLE_FIXED_TYPES
5025 #undef GIMPLE_FIXED_MODE_TYPES
5026 #undef GIMPLE_FIXED_TYPES_SAT
5027 #undef GIMPLE_FIXED_MODE_TYPES_SAT
5030 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
5034 /* Return an unsigned type the same as TYPE in other respects. */
5037 gimple_unsigned_type (tree type
)
5039 return gimple_signed_or_unsigned_type (true, type
);
5043 /* Return a signed type the same as TYPE in other respects. */
5046 gimple_signed_type (tree type
)
5048 return gimple_signed_or_unsigned_type (false, type
);
5052 /* Return the typed-based alias set for T, which may be an expression
5053 or a type. Return -1 if we don't do anything special. */
5056 gimple_get_alias_set (tree t
)
5060 /* Permit type-punning when accessing a union, provided the access
5061 is directly through the union. For example, this code does not
5062 permit taking the address of a union member and then storing
5063 through it. Even the type-punning allowed here is a GCC
5064 extension, albeit a common and useful one; the C standard says
5065 that such accesses have implementation-defined behavior. */
5067 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
5068 u
= TREE_OPERAND (u
, 0))
5069 if (TREE_CODE (u
) == COMPONENT_REF
5070 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
5073 /* That's all the expressions we handle specially. */
5077 /* For convenience, follow the C standard when dealing with
5078 character types. Any object may be accessed via an lvalue that
5079 has character type. */
5080 if (t
== char_type_node
5081 || t
== signed_char_type_node
5082 || t
== unsigned_char_type_node
)
5085 /* Allow aliasing between signed and unsigned variants of the same
5086 type. We treat the signed variant as canonical. */
5087 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
5089 tree t1
= gimple_signed_type (t
);
5091 /* t1 == t can happen for boolean nodes which are always unsigned. */
5093 return get_alias_set (t1
);
5100 /* Data structure used to count the number of dereferences to PTR
5101 inside an expression. */
5105 unsigned num_stores
;
5109 /* Helper for count_uses_and_derefs. Called by walk_tree to look for
5110 (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA. */
5113 count_ptr_derefs (tree
*tp
, int *walk_subtrees
, void *data
)
5115 struct walk_stmt_info
*wi_p
= (struct walk_stmt_info
*) data
;
5116 struct count_ptr_d
*count_p
= (struct count_ptr_d
*) wi_p
->info
;
5118 /* Do not walk inside ADDR_EXPR nodes. In the expression &ptr->fld,
5119 pointer 'ptr' is *not* dereferenced, it is simply used to compute
5120 the address of 'fld' as 'ptr + offsetof(fld)'. */
5121 if (TREE_CODE (*tp
) == ADDR_EXPR
)
5127 if (TREE_CODE (*tp
) == MEM_REF
&& TREE_OPERAND (*tp
, 0) == count_p
->ptr
)
5130 count_p
->num_stores
++;
5132 count_p
->num_loads
++;
5138 /* Count the number of direct and indirect uses for pointer PTR in
5139 statement STMT. The number of direct uses is stored in
5140 *NUM_USES_P. Indirect references are counted separately depending
5141 on whether they are store or load operations. The counts are
5142 stored in *NUM_STORES_P and *NUM_LOADS_P. */
5145 count_uses_and_derefs (tree ptr
, gimple stmt
, unsigned *num_uses_p
,
5146 unsigned *num_loads_p
, unsigned *num_stores_p
)
5155 /* Find out the total number of uses of PTR in STMT. */
5156 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, i
, SSA_OP_USE
)
5160 /* Now count the number of indirect references to PTR. This is
5161 truly awful, but we don't have much choice. There are no parent
5162 pointers inside INDIRECT_REFs, so an expression like
5163 '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to
5164 find all the indirect and direct uses of x_1 inside. The only
5165 shortcut we can take is the fact that GIMPLE only allows
5166 INDIRECT_REFs inside the expressions below. */
5167 if (is_gimple_assign (stmt
)
5168 || gimple_code (stmt
) == GIMPLE_RETURN
5169 || gimple_code (stmt
) == GIMPLE_ASM
5170 || is_gimple_call (stmt
))
5172 struct walk_stmt_info wi
;
5173 struct count_ptr_d count
;
5176 count
.num_stores
= 0;
5177 count
.num_loads
= 0;
5179 memset (&wi
, 0, sizeof (wi
));
5181 walk_gimple_op (stmt
, count_ptr_derefs
, &wi
);
5183 *num_stores_p
= count
.num_stores
;
5184 *num_loads_p
= count
.num_loads
;
5187 gcc_assert (*num_uses_p
>= *num_loads_p
+ *num_stores_p
);
5190 /* From a tree operand OP return the base of a load or store operation
5191 or NULL_TREE if OP is not a load or a store. */
5194 get_base_loadstore (tree op
)
5196 while (handled_component_p (op
))
5197 op
= TREE_OPERAND (op
, 0);
5199 || INDIRECT_REF_P (op
)
5200 || TREE_CODE (op
) == MEM_REF
5201 || TREE_CODE (op
) == TARGET_MEM_REF
)
5206 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
5207 VISIT_ADDR if non-NULL on loads, store and address-taken operands
5208 passing the STMT, the base of the operand and DATA to it. The base
5209 will be either a decl, an indirect reference (including TARGET_MEM_REF)
5210 or the argument of an address expression.
5211 Returns the results of these callbacks or'ed. */
5214 walk_stmt_load_store_addr_ops (gimple stmt
, void *data
,
5215 bool (*visit_load
)(gimple
, tree
, void *),
5216 bool (*visit_store
)(gimple
, tree
, void *),
5217 bool (*visit_addr
)(gimple
, tree
, void *))
5221 if (gimple_assign_single_p (stmt
))
5226 lhs
= get_base_loadstore (gimple_assign_lhs (stmt
));
5228 ret
|= visit_store (stmt
, lhs
, data
);
5230 rhs
= gimple_assign_rhs1 (stmt
);
5231 while (handled_component_p (rhs
))
5232 rhs
= TREE_OPERAND (rhs
, 0);
5235 if (TREE_CODE (rhs
) == ADDR_EXPR
)
5236 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
5237 else if (TREE_CODE (rhs
) == TARGET_MEM_REF
5238 && TREE_CODE (TMR_BASE (rhs
)) == ADDR_EXPR
)
5239 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (rhs
), 0), data
);
5240 else if (TREE_CODE (rhs
) == OBJ_TYPE_REF
5241 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs
)) == ADDR_EXPR
)
5242 ret
|= visit_addr (stmt
, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs
),
5244 lhs
= gimple_assign_lhs (stmt
);
5245 if (TREE_CODE (lhs
) == TARGET_MEM_REF
5246 && TREE_CODE (TMR_BASE (lhs
)) == ADDR_EXPR
)
5247 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (lhs
), 0), data
);
5251 rhs
= get_base_loadstore (rhs
);
5253 ret
|= visit_load (stmt
, rhs
, data
);
5257 && (is_gimple_assign (stmt
)
5258 || gimple_code (stmt
) == GIMPLE_COND
))
5260 for (i
= 0; i
< gimple_num_ops (stmt
); ++i
)
5261 if (gimple_op (stmt
, i
)
5262 && TREE_CODE (gimple_op (stmt
, i
)) == ADDR_EXPR
)
5263 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_op (stmt
, i
), 0), data
);
5265 else if (is_gimple_call (stmt
))
5269 tree lhs
= gimple_call_lhs (stmt
);
5272 lhs
= get_base_loadstore (lhs
);
5274 ret
|= visit_store (stmt
, lhs
, data
);
5277 if (visit_load
|| visit_addr
)
5278 for (i
= 0; i
< gimple_call_num_args (stmt
); ++i
)
5280 tree rhs
= gimple_call_arg (stmt
, i
);
5282 && TREE_CODE (rhs
) == ADDR_EXPR
)
5283 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
5284 else if (visit_load
)
5286 rhs
= get_base_loadstore (rhs
);
5288 ret
|= visit_load (stmt
, rhs
, data
);
5292 && gimple_call_chain (stmt
)
5293 && TREE_CODE (gimple_call_chain (stmt
)) == ADDR_EXPR
)
5294 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_call_chain (stmt
), 0),
5297 && gimple_call_return_slot_opt_p (stmt
)
5298 && gimple_call_lhs (stmt
) != NULL_TREE
5299 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt
))))
5300 ret
|= visit_addr (stmt
, gimple_call_lhs (stmt
), data
);
5302 else if (gimple_code (stmt
) == GIMPLE_ASM
)
5305 const char *constraint
;
5306 const char **oconstraints
;
5307 bool allows_mem
, allows_reg
, is_inout
;
5308 noutputs
= gimple_asm_noutputs (stmt
);
5309 oconstraints
= XALLOCAVEC (const char *, noutputs
);
5310 if (visit_store
|| visit_addr
)
5311 for (i
= 0; i
< gimple_asm_noutputs (stmt
); ++i
)
5313 tree link
= gimple_asm_output_op (stmt
, i
);
5314 tree op
= get_base_loadstore (TREE_VALUE (link
));
5315 if (op
&& visit_store
)
5316 ret
|= visit_store (stmt
, op
, data
);
5319 constraint
= TREE_STRING_POINTER
5320 (TREE_VALUE (TREE_PURPOSE (link
)));
5321 oconstraints
[i
] = constraint
;
5322 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
,
5323 &allows_reg
, &is_inout
);
5324 if (op
&& !allows_reg
&& allows_mem
)
5325 ret
|= visit_addr (stmt
, op
, data
);
5328 if (visit_load
|| visit_addr
)
5329 for (i
= 0; i
< gimple_asm_ninputs (stmt
); ++i
)
5331 tree link
= gimple_asm_input_op (stmt
, i
);
5332 tree op
= TREE_VALUE (link
);
5334 && TREE_CODE (op
) == ADDR_EXPR
)
5335 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5336 else if (visit_load
|| visit_addr
)
5338 op
= get_base_loadstore (op
);
5342 ret
|= visit_load (stmt
, op
, data
);
5345 constraint
= TREE_STRING_POINTER
5346 (TREE_VALUE (TREE_PURPOSE (link
)));
5347 parse_input_constraint (&constraint
, 0, 0, noutputs
,
5349 &allows_mem
, &allows_reg
);
5350 if (!allows_reg
&& allows_mem
)
5351 ret
|= visit_addr (stmt
, op
, data
);
5357 else if (gimple_code (stmt
) == GIMPLE_RETURN
)
5359 tree op
= gimple_return_retval (stmt
);
5363 && TREE_CODE (op
) == ADDR_EXPR
)
5364 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5365 else if (visit_load
)
5367 op
= get_base_loadstore (op
);
5369 ret
|= visit_load (stmt
, op
, data
);
5374 && gimple_code (stmt
) == GIMPLE_PHI
)
5376 for (i
= 0; i
< gimple_phi_num_args (stmt
); ++i
)
5378 tree op
= PHI_ARG_DEF (stmt
, i
);
5379 if (TREE_CODE (op
) == ADDR_EXPR
)
5380 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5387 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
5388 should make a faster clone for this case. */
5391 walk_stmt_load_store_ops (gimple stmt
, void *data
,
5392 bool (*visit_load
)(gimple
, tree
, void *),
5393 bool (*visit_store
)(gimple
, tree
, void *))
5395 return walk_stmt_load_store_addr_ops (stmt
, data
,
5396 visit_load
, visit_store
, NULL
);
5399 /* Helper for gimple_ior_addresses_taken_1. */
5402 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED
,
5403 tree addr
, void *data
)
5405 bitmap addresses_taken
= (bitmap
)data
;
5406 addr
= get_base_address (addr
);
5410 bitmap_set_bit (addresses_taken
, DECL_UID (addr
));
5416 /* Set the bit for the uid of all decls that have their address taken
5417 in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
5418 were any in this stmt. */
5421 gimple_ior_addresses_taken (bitmap addresses_taken
, gimple stmt
)
5423 return walk_stmt_load_store_addr_ops (stmt
, addresses_taken
, NULL
, NULL
,
5424 gimple_ior_addresses_taken_1
);
5428 /* Return a printable name for symbol DECL. */
5431 gimple_decl_printable_name (tree decl
, int verbosity
)
5433 if (!DECL_NAME (decl
))
5436 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
5438 const char *str
, *mangled_str
;
5439 int dmgl_opts
= DMGL_NO_OPTS
;
5443 dmgl_opts
= DMGL_VERBOSE
5447 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5448 dmgl_opts
|= DMGL_PARAMS
;
5451 mangled_str
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5452 str
= cplus_demangle_v3 (mangled_str
, dmgl_opts
);
5453 return (str
) ? str
: mangled_str
;
5456 return IDENTIFIER_POINTER (DECL_NAME (decl
));
5459 /* Return true when STMT is builtins call to CODE. */
5462 gimple_call_builtin_p (gimple stmt
, enum built_in_function code
)
5465 return (is_gimple_call (stmt
)
5466 && (fndecl
= gimple_call_fndecl (stmt
)) != NULL
5467 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
5468 && DECL_FUNCTION_CODE (fndecl
) == code
);
5471 /* Return true if STMT clobbers memory. STMT is required to be a
5475 gimple_asm_clobbers_memory_p (const_gimple stmt
)
5479 for (i
= 0; i
< gimple_asm_nclobbers (stmt
); i
++)
5481 tree op
= gimple_asm_clobber_op (stmt
, i
);
5482 if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op
)), "memory") == 0)
5488 #include "gt-gimple.h"