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 /* Global type comparison cache. This is by TYPE_UID for space efficiency
54 and thus cannot use and does not need GC. */
55 static htab_t gtc_visited
;
56 static struct obstack gtc_ob
;
58 /* All the tuples have their operand vector (if present) at the very bottom
59 of the structure. Therefore, the offset required to find the
60 operands vector the size of the structure minus the size of the 1
61 element tree array at the end (see gimple_ops). */
62 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \
63 (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0),
64 EXPORTED_CONST
size_t gimple_ops_offset_
[] = {
65 #include "gsstruct.def"
69 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof(struct STRUCT),
70 static const size_t gsstruct_code_size
[] = {
71 #include "gsstruct.def"
75 #define DEFGSCODE(SYM, NAME, GSSCODE) NAME,
76 const char *const gimple_code_name
[] = {
81 #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE,
82 EXPORTED_CONST
enum gimple_statement_structure_enum gss_for_code_
[] = {
87 #ifdef GATHER_STATISTICS
90 int gimple_alloc_counts
[(int) gimple_alloc_kind_all
];
91 int gimple_alloc_sizes
[(int) gimple_alloc_kind_all
];
93 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */
94 static const char * const gimple_alloc_kind_names
[] = {
102 #endif /* GATHER_STATISTICS */
104 /* A cache of gimple_seq objects. Sequences are created and destroyed
105 fairly often during gimplification. */
106 static GTY ((deletable
)) struct gimple_seq_d
*gimple_seq_cache
;
108 /* Private API manipulation functions shared only with some
110 extern void gimple_set_stored_syms (gimple
, bitmap
, bitmap_obstack
*);
111 extern void gimple_set_loaded_syms (gimple
, bitmap
, bitmap_obstack
*);
113 /* Gimple tuple constructors.
114 Note: Any constructor taking a ``gimple_seq'' as a parameter, can
115 be passed a NULL to start with an empty sequence. */
117 /* Set the code for statement G to CODE. */
120 gimple_set_code (gimple g
, enum gimple_code code
)
122 g
->gsbase
.code
= code
;
125 /* Return the number of bytes needed to hold a GIMPLE statement with
129 gimple_size (enum gimple_code code
)
131 return gsstruct_code_size
[gss_for_code (code
)];
134 /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
138 gimple_alloc_stat (enum gimple_code code
, unsigned num_ops MEM_STAT_DECL
)
143 size
= gimple_size (code
);
145 size
+= sizeof (tree
) * (num_ops
- 1);
147 #ifdef GATHER_STATISTICS
149 enum gimple_alloc_kind kind
= gimple_alloc_kind (code
);
150 gimple_alloc_counts
[(int) kind
]++;
151 gimple_alloc_sizes
[(int) kind
] += size
;
155 stmt
= ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT
);
156 gimple_set_code (stmt
, code
);
157 gimple_set_num_ops (stmt
, num_ops
);
159 /* Do not call gimple_set_modified here as it has other side
160 effects and this tuple is still not completely built. */
161 stmt
->gsbase
.modified
= 1;
166 /* Set SUBCODE to be the code of the expression computed by statement G. */
169 gimple_set_subcode (gimple g
, unsigned subcode
)
171 /* We only have 16 bits for the RHS code. Assert that we are not
173 gcc_assert (subcode
< (1 << 16));
174 g
->gsbase
.subcode
= subcode
;
179 /* Build a tuple with operands. CODE is the statement to build (which
180 must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the sub-code
181 for the new tuple. NUM_OPS is the number of operands to allocate. */
183 #define gimple_build_with_ops(c, s, n) \
184 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
187 gimple_build_with_ops_stat (enum gimple_code code
, unsigned subcode
,
188 unsigned num_ops MEM_STAT_DECL
)
190 gimple s
= gimple_alloc_stat (code
, num_ops PASS_MEM_STAT
);
191 gimple_set_subcode (s
, subcode
);
197 /* Build a GIMPLE_RETURN statement returning RETVAL. */
200 gimple_build_return (tree retval
)
202 gimple s
= gimple_build_with_ops (GIMPLE_RETURN
, ERROR_MARK
, 1);
204 gimple_return_set_retval (s
, retval
);
208 /* Reset alias information on call S. */
211 gimple_call_reset_alias_info (gimple s
)
213 if (gimple_call_flags (s
) & ECF_CONST
)
214 memset (gimple_call_use_set (s
), 0, sizeof (struct pt_solution
));
216 pt_solution_reset (gimple_call_use_set (s
));
217 if (gimple_call_flags (s
) & (ECF_CONST
|ECF_PURE
|ECF_NOVOPS
))
218 memset (gimple_call_clobber_set (s
), 0, sizeof (struct pt_solution
));
220 pt_solution_reset (gimple_call_clobber_set (s
));
223 /* Helper for gimple_build_call, gimple_build_call_vec and
224 gimple_build_call_from_tree. Build the basic components of a
225 GIMPLE_CALL statement to function FN with NARGS arguments. */
228 gimple_build_call_1 (tree fn
, unsigned nargs
)
230 gimple s
= gimple_build_with_ops (GIMPLE_CALL
, ERROR_MARK
, nargs
+ 3);
231 if (TREE_CODE (fn
) == FUNCTION_DECL
)
232 fn
= build_fold_addr_expr (fn
);
233 gimple_set_op (s
, 1, fn
);
234 gimple_call_set_fntype (s
, TREE_TYPE (TREE_TYPE (fn
)));
235 gimple_call_reset_alias_info (s
);
240 /* Build a GIMPLE_CALL statement to function FN with the arguments
241 specified in vector ARGS. */
244 gimple_build_call_vec (tree fn
, VEC(tree
, heap
) *args
)
247 unsigned nargs
= VEC_length (tree
, args
);
248 gimple call
= gimple_build_call_1 (fn
, nargs
);
250 for (i
= 0; i
< nargs
; i
++)
251 gimple_call_set_arg (call
, i
, VEC_index (tree
, args
, i
));
257 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
258 arguments. The ... are the arguments. */
261 gimple_build_call (tree fn
, unsigned nargs
, ...)
267 gcc_assert (TREE_CODE (fn
) == FUNCTION_DECL
|| is_gimple_call_addr (fn
));
269 call
= gimple_build_call_1 (fn
, nargs
);
271 va_start (ap
, nargs
);
272 for (i
= 0; i
< nargs
; i
++)
273 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
280 /* Helper for gimple_build_call_internal and gimple_build_call_internal_vec.
281 Build the basic components of a GIMPLE_CALL statement to internal
282 function FN with NARGS arguments. */
285 gimple_build_call_internal_1 (enum internal_fn fn
, unsigned nargs
)
287 gimple s
= gimple_build_with_ops (GIMPLE_CALL
, ERROR_MARK
, nargs
+ 3);
288 s
->gsbase
.subcode
|= GF_CALL_INTERNAL
;
289 gimple_call_set_internal_fn (s
, fn
);
290 gimple_call_reset_alias_info (s
);
295 /* Build a GIMPLE_CALL statement to internal function FN. NARGS is
296 the number of arguments. The ... are the arguments. */
299 gimple_build_call_internal (enum internal_fn fn
, unsigned nargs
, ...)
305 call
= gimple_build_call_internal_1 (fn
, nargs
);
306 va_start (ap
, nargs
);
307 for (i
= 0; i
< nargs
; i
++)
308 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
315 /* Build a GIMPLE_CALL statement to internal function FN with the arguments
316 specified in vector ARGS. */
319 gimple_build_call_internal_vec (enum internal_fn fn
, VEC(tree
, heap
) *args
)
324 nargs
= VEC_length (tree
, args
);
325 call
= gimple_build_call_internal_1 (fn
, nargs
);
326 for (i
= 0; i
< nargs
; i
++)
327 gimple_call_set_arg (call
, i
, VEC_index (tree
, args
, i
));
333 /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
334 assumed to be in GIMPLE form already. Minimal checking is done of
338 gimple_build_call_from_tree (tree t
)
342 tree fndecl
= get_callee_fndecl (t
);
344 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
346 nargs
= call_expr_nargs (t
);
347 call
= gimple_build_call_1 (fndecl
? fndecl
: CALL_EXPR_FN (t
), nargs
);
349 for (i
= 0; i
< nargs
; i
++)
350 gimple_call_set_arg (call
, i
, CALL_EXPR_ARG (t
, i
));
352 gimple_set_block (call
, TREE_BLOCK (t
));
354 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
355 gimple_call_set_chain (call
, CALL_EXPR_STATIC_CHAIN (t
));
356 gimple_call_set_tail (call
, CALL_EXPR_TAILCALL (t
));
357 gimple_call_set_cannot_inline (call
, CALL_CANNOT_INLINE_P (t
));
358 gimple_call_set_return_slot_opt (call
, CALL_EXPR_RETURN_SLOT_OPT (t
));
360 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
361 && DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_ALLOCA
)
362 gimple_call_set_alloca_for_var (call
, CALL_ALLOCA_FOR_VAR_P (t
));
364 gimple_call_set_from_thunk (call
, CALL_FROM_THUNK_P (t
));
365 gimple_call_set_va_arg_pack (call
, CALL_EXPR_VA_ARG_PACK (t
));
366 gimple_call_set_nothrow (call
, TREE_NOTHROW (t
));
367 gimple_set_no_warning (call
, TREE_NO_WARNING (t
));
373 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
374 *OP1_P, *OP2_P and *OP3_P respectively. */
377 extract_ops_from_tree_1 (tree expr
, enum tree_code
*subcode_p
, tree
*op1_p
,
378 tree
*op2_p
, tree
*op3_p
)
380 enum gimple_rhs_class grhs_class
;
382 *subcode_p
= TREE_CODE (expr
);
383 grhs_class
= get_gimple_rhs_class (*subcode_p
);
385 if (grhs_class
== GIMPLE_TERNARY_RHS
)
387 *op1_p
= TREE_OPERAND (expr
, 0);
388 *op2_p
= TREE_OPERAND (expr
, 1);
389 *op3_p
= TREE_OPERAND (expr
, 2);
391 else if (grhs_class
== GIMPLE_BINARY_RHS
)
393 *op1_p
= TREE_OPERAND (expr
, 0);
394 *op2_p
= TREE_OPERAND (expr
, 1);
397 else if (grhs_class
== GIMPLE_UNARY_RHS
)
399 *op1_p
= TREE_OPERAND (expr
, 0);
403 else if (grhs_class
== GIMPLE_SINGLE_RHS
)
414 /* Build a GIMPLE_ASSIGN statement.
416 LHS of the assignment.
417 RHS of the assignment which can be unary or binary. */
420 gimple_build_assign_stat (tree lhs
, tree rhs MEM_STAT_DECL
)
422 enum tree_code subcode
;
425 extract_ops_from_tree_1 (rhs
, &subcode
, &op1
, &op2
, &op3
);
426 return gimple_build_assign_with_ops_stat (subcode
, lhs
, op1
, op2
, op3
431 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands
432 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
433 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
436 gimple_build_assign_with_ops_stat (enum tree_code subcode
, tree lhs
, tree op1
,
437 tree op2
, tree op3 MEM_STAT_DECL
)
442 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
444 num_ops
= get_gimple_rhs_num_ops (subcode
) + 1;
446 p
= gimple_build_with_ops_stat (GIMPLE_ASSIGN
, (unsigned)subcode
, num_ops
448 gimple_assign_set_lhs (p
, lhs
);
449 gimple_assign_set_rhs1 (p
, op1
);
452 gcc_assert (num_ops
> 2);
453 gimple_assign_set_rhs2 (p
, op2
);
458 gcc_assert (num_ops
> 3);
459 gimple_assign_set_rhs3 (p
, op3
);
466 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
468 DST/SRC are the destination and source respectively. You can pass
469 ungimplified trees in DST or SRC, in which case they will be
470 converted to a gimple operand if necessary.
472 This function returns the newly created GIMPLE_ASSIGN tuple. */
475 gimplify_assign (tree dst
, tree src
, gimple_seq
*seq_p
)
477 tree t
= build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
478 gimplify_and_add (t
, seq_p
);
480 return gimple_seq_last_stmt (*seq_p
);
484 /* Build a GIMPLE_COND statement.
486 PRED is the condition used to compare LHS and the RHS.
487 T_LABEL is the label to jump to if the condition is true.
488 F_LABEL is the label to jump to otherwise. */
491 gimple_build_cond (enum tree_code pred_code
, tree lhs
, tree rhs
,
492 tree t_label
, tree f_label
)
496 gcc_assert (TREE_CODE_CLASS (pred_code
) == tcc_comparison
);
497 p
= gimple_build_with_ops (GIMPLE_COND
, pred_code
, 4);
498 gimple_cond_set_lhs (p
, lhs
);
499 gimple_cond_set_rhs (p
, rhs
);
500 gimple_cond_set_true_label (p
, t_label
);
501 gimple_cond_set_false_label (p
, f_label
);
506 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
509 gimple_cond_get_ops_from_tree (tree cond
, enum tree_code
*code_p
,
510 tree
*lhs_p
, tree
*rhs_p
)
512 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond
)) == tcc_comparison
513 || TREE_CODE (cond
) == TRUTH_NOT_EXPR
514 || is_gimple_min_invariant (cond
)
515 || SSA_VAR_P (cond
));
517 extract_ops_from_tree (cond
, code_p
, lhs_p
, rhs_p
);
519 /* Canonicalize conditionals of the form 'if (!VAL)'. */
520 if (*code_p
== TRUTH_NOT_EXPR
)
523 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
524 *rhs_p
= build_zero_cst (TREE_TYPE (*lhs_p
));
526 /* Canonicalize conditionals of the form 'if (VAL)' */
527 else if (TREE_CODE_CLASS (*code_p
) != tcc_comparison
)
530 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
531 *rhs_p
= build_zero_cst (TREE_TYPE (*lhs_p
));
536 /* Build a GIMPLE_COND statement from the conditional expression tree
537 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
540 gimple_build_cond_from_tree (tree cond
, tree t_label
, tree f_label
)
545 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
546 return gimple_build_cond (code
, lhs
, rhs
, t_label
, f_label
);
549 /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
550 boolean expression tree COND. */
553 gimple_cond_set_condition_from_tree (gimple stmt
, tree cond
)
558 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
559 gimple_cond_set_condition (stmt
, code
, lhs
, rhs
);
562 /* Build a GIMPLE_LABEL statement for LABEL. */
565 gimple_build_label (tree label
)
567 gimple p
= gimple_build_with_ops (GIMPLE_LABEL
, ERROR_MARK
, 1);
568 gimple_label_set_label (p
, label
);
572 /* Build a GIMPLE_GOTO statement to label DEST. */
575 gimple_build_goto (tree dest
)
577 gimple p
= gimple_build_with_ops (GIMPLE_GOTO
, ERROR_MARK
, 1);
578 gimple_goto_set_dest (p
, dest
);
583 /* Build a GIMPLE_NOP statement. */
586 gimple_build_nop (void)
588 return gimple_alloc (GIMPLE_NOP
, 0);
592 /* Build a GIMPLE_BIND statement.
593 VARS are the variables in BODY.
594 BLOCK is the containing block. */
597 gimple_build_bind (tree vars
, gimple_seq body
, tree block
)
599 gimple p
= gimple_alloc (GIMPLE_BIND
, 0);
600 gimple_bind_set_vars (p
, vars
);
602 gimple_bind_set_body (p
, body
);
604 gimple_bind_set_block (p
, block
);
608 /* Helper function to set the simple fields of a asm stmt.
610 STRING is a pointer to a string that is the asm blocks assembly code.
611 NINPUT is the number of register inputs.
612 NOUTPUT is the number of register outputs.
613 NCLOBBERS is the number of clobbered registers.
617 gimple_build_asm_1 (const char *string
, unsigned ninputs
, unsigned noutputs
,
618 unsigned nclobbers
, unsigned nlabels
)
621 int size
= strlen (string
);
623 /* ASMs with labels cannot have outputs. This should have been
624 enforced by the front end. */
625 gcc_assert (nlabels
== 0 || noutputs
== 0);
627 p
= gimple_build_with_ops (GIMPLE_ASM
, ERROR_MARK
,
628 ninputs
+ noutputs
+ nclobbers
+ nlabels
);
630 p
->gimple_asm
.ni
= ninputs
;
631 p
->gimple_asm
.no
= noutputs
;
632 p
->gimple_asm
.nc
= nclobbers
;
633 p
->gimple_asm
.nl
= nlabels
;
634 p
->gimple_asm
.string
= ggc_alloc_string (string
, size
);
636 #ifdef GATHER_STATISTICS
637 gimple_alloc_sizes
[(int) gimple_alloc_kind (GIMPLE_ASM
)] += size
;
643 /* Build a GIMPLE_ASM statement.
645 STRING is the assembly code.
646 NINPUT is the number of register inputs.
647 NOUTPUT is the number of register outputs.
648 NCLOBBERS is the number of clobbered registers.
649 INPUTS is a vector of the input register parameters.
650 OUTPUTS is a vector of the output register parameters.
651 CLOBBERS is a vector of the clobbered register parameters.
652 LABELS is a vector of destination labels. */
655 gimple_build_asm_vec (const char *string
, VEC(tree
,gc
)* inputs
,
656 VEC(tree
,gc
)* outputs
, VEC(tree
,gc
)* clobbers
,
657 VEC(tree
,gc
)* labels
)
662 p
= gimple_build_asm_1 (string
,
663 VEC_length (tree
, inputs
),
664 VEC_length (tree
, outputs
),
665 VEC_length (tree
, clobbers
),
666 VEC_length (tree
, labels
));
668 for (i
= 0; i
< VEC_length (tree
, inputs
); i
++)
669 gimple_asm_set_input_op (p
, i
, VEC_index (tree
, inputs
, i
));
671 for (i
= 0; i
< VEC_length (tree
, outputs
); i
++)
672 gimple_asm_set_output_op (p
, i
, VEC_index (tree
, outputs
, i
));
674 for (i
= 0; i
< VEC_length (tree
, clobbers
); i
++)
675 gimple_asm_set_clobber_op (p
, i
, VEC_index (tree
, clobbers
, i
));
677 for (i
= 0; i
< VEC_length (tree
, labels
); i
++)
678 gimple_asm_set_label_op (p
, i
, VEC_index (tree
, labels
, i
));
683 /* Build a GIMPLE_CATCH statement.
685 TYPES are the catch types.
686 HANDLER is the exception handler. */
689 gimple_build_catch (tree types
, gimple_seq handler
)
691 gimple p
= gimple_alloc (GIMPLE_CATCH
, 0);
692 gimple_catch_set_types (p
, types
);
694 gimple_catch_set_handler (p
, handler
);
699 /* Build a GIMPLE_EH_FILTER statement.
701 TYPES are the filter's types.
702 FAILURE is the filter's failure action. */
705 gimple_build_eh_filter (tree types
, gimple_seq failure
)
707 gimple p
= gimple_alloc (GIMPLE_EH_FILTER
, 0);
708 gimple_eh_filter_set_types (p
, types
);
710 gimple_eh_filter_set_failure (p
, failure
);
715 /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
718 gimple_build_eh_must_not_throw (tree decl
)
720 gimple p
= gimple_alloc (GIMPLE_EH_MUST_NOT_THROW
, 0);
722 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
723 gcc_assert (flags_from_decl_or_type (decl
) & ECF_NORETURN
);
724 gimple_eh_must_not_throw_set_fndecl (p
, decl
);
729 /* Build a GIMPLE_TRY statement.
731 EVAL is the expression to evaluate.
732 CLEANUP is the cleanup expression.
733 KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
734 whether this is a try/catch or a try/finally respectively. */
737 gimple_build_try (gimple_seq eval
, gimple_seq cleanup
,
738 enum gimple_try_flags kind
)
742 gcc_assert (kind
== GIMPLE_TRY_CATCH
|| kind
== GIMPLE_TRY_FINALLY
);
743 p
= gimple_alloc (GIMPLE_TRY
, 0);
744 gimple_set_subcode (p
, kind
);
746 gimple_try_set_eval (p
, eval
);
748 gimple_try_set_cleanup (p
, cleanup
);
753 /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
755 CLEANUP is the cleanup expression. */
758 gimple_build_wce (gimple_seq cleanup
)
760 gimple p
= gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR
, 0);
762 gimple_wce_set_cleanup (p
, cleanup
);
768 /* Build a GIMPLE_RESX statement. */
771 gimple_build_resx (int region
)
773 gimple p
= gimple_build_with_ops (GIMPLE_RESX
, ERROR_MARK
, 0);
774 p
->gimple_eh_ctrl
.region
= region
;
779 /* The helper for constructing a gimple switch statement.
780 INDEX is the switch's index.
781 NLABELS is the number of labels in the switch excluding the default.
782 DEFAULT_LABEL is the default label for the switch statement. */
785 gimple_build_switch_nlabels (unsigned nlabels
, tree index
, tree default_label
)
787 /* nlabels + 1 default label + 1 index. */
788 gimple p
= gimple_build_with_ops (GIMPLE_SWITCH
, ERROR_MARK
,
789 1 + (default_label
!= NULL
) + nlabels
);
790 gimple_switch_set_index (p
, index
);
792 gimple_switch_set_default_label (p
, default_label
);
797 /* Build a GIMPLE_SWITCH statement.
799 INDEX is the switch's index.
800 NLABELS is the number of labels in the switch excluding the DEFAULT_LABEL.
801 ... are the labels excluding the default. */
804 gimple_build_switch (unsigned nlabels
, tree index
, tree default_label
, ...)
808 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
810 /* Store the rest of the labels. */
811 va_start (al
, default_label
);
812 offset
= (default_label
!= NULL
);
813 for (i
= 0; i
< nlabels
; i
++)
814 gimple_switch_set_label (p
, i
+ offset
, va_arg (al
, tree
));
821 /* Build a GIMPLE_SWITCH statement.
823 INDEX is the switch's index.
824 DEFAULT_LABEL is the default label
825 ARGS is a vector of labels excluding the default. */
828 gimple_build_switch_vec (tree index
, tree default_label
, VEC(tree
, heap
) *args
)
830 unsigned i
, offset
, nlabels
= VEC_length (tree
, args
);
831 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
833 /* Copy the labels from the vector to the switch statement. */
834 offset
= (default_label
!= NULL
);
835 for (i
= 0; i
< nlabels
; i
++)
836 gimple_switch_set_label (p
, i
+ offset
, VEC_index (tree
, args
, i
));
841 /* Build a GIMPLE_EH_DISPATCH statement. */
844 gimple_build_eh_dispatch (int region
)
846 gimple p
= gimple_build_with_ops (GIMPLE_EH_DISPATCH
, ERROR_MARK
, 0);
847 p
->gimple_eh_ctrl
.region
= region
;
851 /* Build a new GIMPLE_DEBUG_BIND statement.
853 VAR is bound to VALUE; block and location are taken from STMT. */
856 gimple_build_debug_bind_stat (tree var
, tree value
, gimple stmt MEM_STAT_DECL
)
858 gimple p
= gimple_build_with_ops_stat (GIMPLE_DEBUG
,
859 (unsigned)GIMPLE_DEBUG_BIND
, 2
862 gimple_debug_bind_set_var (p
, var
);
863 gimple_debug_bind_set_value (p
, value
);
866 gimple_set_block (p
, gimple_block (stmt
));
867 gimple_set_location (p
, gimple_location (stmt
));
874 /* Build a GIMPLE_OMP_CRITICAL statement.
876 BODY is the sequence of statements for which only one thread can execute.
877 NAME is optional identifier for this critical block. */
880 gimple_build_omp_critical (gimple_seq body
, tree name
)
882 gimple p
= gimple_alloc (GIMPLE_OMP_CRITICAL
, 0);
883 gimple_omp_critical_set_name (p
, name
);
885 gimple_omp_set_body (p
, body
);
890 /* Build a GIMPLE_OMP_FOR statement.
892 BODY is sequence of statements inside the for loop.
893 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate,
894 lastprivate, reductions, ordered, schedule, and nowait.
895 COLLAPSE is the collapse count.
896 PRE_BODY is the sequence of statements that are loop invariant. */
899 gimple_build_omp_for (gimple_seq body
, tree clauses
, size_t collapse
,
902 gimple p
= gimple_alloc (GIMPLE_OMP_FOR
, 0);
904 gimple_omp_set_body (p
, body
);
905 gimple_omp_for_set_clauses (p
, clauses
);
906 p
->gimple_omp_for
.collapse
= collapse
;
907 p
->gimple_omp_for
.iter
908 = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse
);
910 gimple_omp_for_set_pre_body (p
, pre_body
);
916 /* Build a GIMPLE_OMP_PARALLEL statement.
918 BODY is sequence of statements which are executed in parallel.
919 CLAUSES, are the OMP parallel construct's clauses.
920 CHILD_FN is the function created for the parallel threads to execute.
921 DATA_ARG are the shared data argument(s). */
924 gimple_build_omp_parallel (gimple_seq body
, tree clauses
, tree child_fn
,
927 gimple p
= gimple_alloc (GIMPLE_OMP_PARALLEL
, 0);
929 gimple_omp_set_body (p
, body
);
930 gimple_omp_parallel_set_clauses (p
, clauses
);
931 gimple_omp_parallel_set_child_fn (p
, child_fn
);
932 gimple_omp_parallel_set_data_arg (p
, data_arg
);
938 /* Build a GIMPLE_OMP_TASK statement.
940 BODY is sequence of statements which are executed by the explicit task.
941 CLAUSES, are the OMP parallel construct's clauses.
942 CHILD_FN is the function created for the parallel threads to execute.
943 DATA_ARG are the shared data argument(s).
944 COPY_FN is the optional function for firstprivate initialization.
945 ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
948 gimple_build_omp_task (gimple_seq body
, tree clauses
, tree child_fn
,
949 tree data_arg
, tree copy_fn
, tree arg_size
,
952 gimple p
= gimple_alloc (GIMPLE_OMP_TASK
, 0);
954 gimple_omp_set_body (p
, body
);
955 gimple_omp_task_set_clauses (p
, clauses
);
956 gimple_omp_task_set_child_fn (p
, child_fn
);
957 gimple_omp_task_set_data_arg (p
, data_arg
);
958 gimple_omp_task_set_copy_fn (p
, copy_fn
);
959 gimple_omp_task_set_arg_size (p
, arg_size
);
960 gimple_omp_task_set_arg_align (p
, arg_align
);
966 /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
968 BODY is the sequence of statements in the section. */
971 gimple_build_omp_section (gimple_seq body
)
973 gimple p
= gimple_alloc (GIMPLE_OMP_SECTION
, 0);
975 gimple_omp_set_body (p
, body
);
981 /* Build a GIMPLE_OMP_MASTER statement.
983 BODY is the sequence of statements to be executed by just the master. */
986 gimple_build_omp_master (gimple_seq body
)
988 gimple p
= gimple_alloc (GIMPLE_OMP_MASTER
, 0);
990 gimple_omp_set_body (p
, body
);
996 /* Build a GIMPLE_OMP_CONTINUE statement.
998 CONTROL_DEF is the definition of the control variable.
999 CONTROL_USE is the use of the control variable. */
1002 gimple_build_omp_continue (tree control_def
, tree control_use
)
1004 gimple p
= gimple_alloc (GIMPLE_OMP_CONTINUE
, 0);
1005 gimple_omp_continue_set_control_def (p
, control_def
);
1006 gimple_omp_continue_set_control_use (p
, control_use
);
1010 /* Build a GIMPLE_OMP_ORDERED statement.
1012 BODY is the sequence of statements inside a loop that will executed in
1016 gimple_build_omp_ordered (gimple_seq body
)
1018 gimple p
= gimple_alloc (GIMPLE_OMP_ORDERED
, 0);
1020 gimple_omp_set_body (p
, body
);
1026 /* Build a GIMPLE_OMP_RETURN statement.
1027 WAIT_P is true if this is a non-waiting return. */
1030 gimple_build_omp_return (bool wait_p
)
1032 gimple p
= gimple_alloc (GIMPLE_OMP_RETURN
, 0);
1034 gimple_omp_return_set_nowait (p
);
1040 /* Build a GIMPLE_OMP_SECTIONS statement.
1042 BODY is a sequence of section statements.
1043 CLAUSES are any of the OMP sections contsruct's clauses: private,
1044 firstprivate, lastprivate, reduction, and nowait. */
1047 gimple_build_omp_sections (gimple_seq body
, tree clauses
)
1049 gimple p
= gimple_alloc (GIMPLE_OMP_SECTIONS
, 0);
1051 gimple_omp_set_body (p
, body
);
1052 gimple_omp_sections_set_clauses (p
, clauses
);
1058 /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
1061 gimple_build_omp_sections_switch (void)
1063 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH
, 0);
1067 /* Build a GIMPLE_OMP_SINGLE statement.
1069 BODY is the sequence of statements that will be executed once.
1070 CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
1071 copyprivate, nowait. */
1074 gimple_build_omp_single (gimple_seq body
, tree clauses
)
1076 gimple p
= gimple_alloc (GIMPLE_OMP_SINGLE
, 0);
1078 gimple_omp_set_body (p
, body
);
1079 gimple_omp_single_set_clauses (p
, clauses
);
1085 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1088 gimple_build_omp_atomic_load (tree lhs
, tree rhs
)
1090 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD
, 0);
1091 gimple_omp_atomic_load_set_lhs (p
, lhs
);
1092 gimple_omp_atomic_load_set_rhs (p
, rhs
);
1096 /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1098 VAL is the value we are storing. */
1101 gimple_build_omp_atomic_store (tree val
)
1103 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_STORE
, 0);
1104 gimple_omp_atomic_store_set_val (p
, val
);
1108 /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
1109 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
1112 gimple_build_predict (enum br_predictor predictor
, enum prediction outcome
)
1114 gimple p
= gimple_alloc (GIMPLE_PREDICT
, 0);
1115 /* Ensure all the predictors fit into the lower bits of the subcode. */
1116 gcc_assert ((int) END_PREDICTORS
<= GF_PREDICT_TAKEN
);
1117 gimple_predict_set_predictor (p
, predictor
);
1118 gimple_predict_set_outcome (p
, outcome
);
1122 #if defined ENABLE_GIMPLE_CHECKING
1123 /* Complain of a gimple type mismatch and die. */
1126 gimple_check_failed (const_gimple gs
, const char *file
, int line
,
1127 const char *function
, enum gimple_code code
,
1128 enum tree_code subcode
)
1130 internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1131 gimple_code_name
[code
],
1132 tree_code_name
[subcode
],
1133 gimple_code_name
[gimple_code (gs
)],
1134 gs
->gsbase
.subcode
> 0
1135 ? tree_code_name
[gs
->gsbase
.subcode
]
1137 function
, trim_filename (file
), line
);
1139 #endif /* ENABLE_GIMPLE_CHECKING */
1142 /* Allocate a new GIMPLE sequence in GC memory and return it. If
1143 there are free sequences in GIMPLE_SEQ_CACHE return one of those
1147 gimple_seq_alloc (void)
1149 gimple_seq seq
= gimple_seq_cache
;
1152 gimple_seq_cache
= gimple_seq_cache
->next_free
;
1153 gcc_assert (gimple_seq_cache
!= seq
);
1154 memset (seq
, 0, sizeof (*seq
));
1158 seq
= ggc_alloc_cleared_gimple_seq_d ();
1159 #ifdef GATHER_STATISTICS
1160 gimple_alloc_counts
[(int) gimple_alloc_kind_seq
]++;
1161 gimple_alloc_sizes
[(int) gimple_alloc_kind_seq
] += sizeof (*seq
);
1168 /* Return SEQ to the free pool of GIMPLE sequences. */
1171 gimple_seq_free (gimple_seq seq
)
1176 gcc_assert (gimple_seq_first (seq
) == NULL
);
1177 gcc_assert (gimple_seq_last (seq
) == NULL
);
1179 /* If this triggers, it's a sign that the same list is being freed
1181 gcc_assert (seq
!= gimple_seq_cache
|| gimple_seq_cache
== NULL
);
1183 /* Add SEQ to the pool of free sequences. */
1184 seq
->next_free
= gimple_seq_cache
;
1185 gimple_seq_cache
= seq
;
1189 /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1190 *SEQ_P is NULL, a new sequence is allocated. */
1193 gimple_seq_add_stmt (gimple_seq
*seq_p
, gimple gs
)
1195 gimple_stmt_iterator si
;
1201 *seq_p
= gimple_seq_alloc ();
1203 si
= gsi_last (*seq_p
);
1204 gsi_insert_after (&si
, gs
, GSI_NEW_STMT
);
1208 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1209 NULL, a new sequence is allocated. */
1212 gimple_seq_add_seq (gimple_seq
*dst_p
, gimple_seq src
)
1214 gimple_stmt_iterator si
;
1220 *dst_p
= gimple_seq_alloc ();
1222 si
= gsi_last (*dst_p
);
1223 gsi_insert_seq_after (&si
, src
, GSI_NEW_STMT
);
1227 /* Helper function of empty_body_p. Return true if STMT is an empty
1231 empty_stmt_p (gimple stmt
)
1233 if (gimple_code (stmt
) == GIMPLE_NOP
)
1235 if (gimple_code (stmt
) == GIMPLE_BIND
)
1236 return empty_body_p (gimple_bind_body (stmt
));
1241 /* Return true if BODY contains nothing but empty statements. */
1244 empty_body_p (gimple_seq body
)
1246 gimple_stmt_iterator i
;
1248 if (gimple_seq_empty_p (body
))
1250 for (i
= gsi_start (body
); !gsi_end_p (i
); gsi_next (&i
))
1251 if (!empty_stmt_p (gsi_stmt (i
))
1252 && !is_gimple_debug (gsi_stmt (i
)))
1259 /* Perform a deep copy of sequence SRC and return the result. */
1262 gimple_seq_copy (gimple_seq src
)
1264 gimple_stmt_iterator gsi
;
1265 gimple_seq new_seq
= gimple_seq_alloc ();
1268 for (gsi
= gsi_start (src
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1270 stmt
= gimple_copy (gsi_stmt (gsi
));
1271 gimple_seq_add_stmt (&new_seq
, stmt
);
1278 /* Walk all the statements in the sequence SEQ calling walk_gimple_stmt
1279 on each one. WI is as in walk_gimple_stmt.
1281 If walk_gimple_stmt returns non-NULL, the walk is stopped, the
1282 value is stored in WI->CALLBACK_RESULT and the statement that
1283 produced the value is returned.
1285 Otherwise, all the statements are walked and NULL returned. */
1288 walk_gimple_seq (gimple_seq seq
, walk_stmt_fn callback_stmt
,
1289 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1291 gimple_stmt_iterator gsi
;
1293 for (gsi
= gsi_start (seq
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1295 tree ret
= walk_gimple_stmt (&gsi
, callback_stmt
, callback_op
, wi
);
1298 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
1301 wi
->callback_result
= ret
;
1302 return gsi_stmt (gsi
);
1307 wi
->callback_result
= NULL_TREE
;
1313 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
1316 walk_gimple_asm (gimple stmt
, walk_tree_fn callback_op
,
1317 struct walk_stmt_info
*wi
)
1321 const char **oconstraints
;
1323 const char *constraint
;
1324 bool allows_mem
, allows_reg
, is_inout
;
1326 noutputs
= gimple_asm_noutputs (stmt
);
1327 oconstraints
= (const char **) alloca ((noutputs
) * sizeof (const char *));
1332 for (i
= 0; i
< noutputs
; i
++)
1334 op
= gimple_asm_output_op (stmt
, i
);
1335 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1336 oconstraints
[i
] = constraint
;
1337 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
, &allows_reg
,
1340 wi
->val_only
= (allows_reg
|| !allows_mem
);
1341 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1346 n
= gimple_asm_ninputs (stmt
);
1347 for (i
= 0; i
< n
; i
++)
1349 op
= gimple_asm_input_op (stmt
, i
);
1350 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1351 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
1352 oconstraints
, &allows_mem
, &allows_reg
);
1355 wi
->val_only
= (allows_reg
|| !allows_mem
);
1356 /* Although input "m" is not really a LHS, we need a lvalue. */
1357 wi
->is_lhs
= !wi
->val_only
;
1359 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1367 wi
->val_only
= true;
1370 n
= gimple_asm_nlabels (stmt
);
1371 for (i
= 0; i
< n
; i
++)
1373 op
= gimple_asm_label_op (stmt
, i
);
1374 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1383 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
1384 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
1386 CALLBACK_OP is called on each operand of STMT via walk_tree.
1387 Additional parameters to walk_tree must be stored in WI. For each operand
1388 OP, walk_tree is called as:
1390 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
1392 If CALLBACK_OP returns non-NULL for an operand, the remaining
1393 operands are not scanned.
1395 The return value is that returned by the last call to walk_tree, or
1396 NULL_TREE if no CALLBACK_OP is specified. */
1399 walk_gimple_op (gimple stmt
, walk_tree_fn callback_op
,
1400 struct walk_stmt_info
*wi
)
1402 struct pointer_set_t
*pset
= (wi
) ? wi
->pset
: NULL
;
1404 tree ret
= NULL_TREE
;
1406 switch (gimple_code (stmt
))
1409 /* Walk the RHS operands. If the LHS is of a non-renamable type or
1410 is a register variable, we may use a COMPONENT_REF on the RHS. */
1413 tree lhs
= gimple_assign_lhs (stmt
);
1415 = (is_gimple_reg_type (TREE_TYPE (lhs
)) && !is_gimple_reg (lhs
))
1416 || !gimple_assign_single_p (stmt
);
1419 for (i
= 1; i
< gimple_num_ops (stmt
); i
++)
1421 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
,
1427 /* Walk the LHS. If the RHS is appropriate for a memory, we
1428 may use a COMPONENT_REF on the LHS. */
1431 /* If the RHS has more than 1 operand, it is not appropriate
1433 wi
->val_only
= !is_gimple_mem_rhs (gimple_assign_rhs1 (stmt
))
1434 || !gimple_assign_single_p (stmt
);
1438 ret
= walk_tree (gimple_op_ptr (stmt
, 0), callback_op
, wi
, pset
);
1444 wi
->val_only
= true;
1453 wi
->val_only
= true;
1456 ret
= walk_tree (gimple_call_chain_ptr (stmt
), callback_op
, wi
, pset
);
1460 ret
= walk_tree (gimple_call_fn_ptr (stmt
), callback_op
, wi
, pset
);
1464 for (i
= 0; i
< gimple_call_num_args (stmt
); i
++)
1467 wi
->val_only
= is_gimple_reg_type (gimple_call_arg (stmt
, i
));
1468 ret
= walk_tree (gimple_call_arg_ptr (stmt
, i
), callback_op
, wi
,
1474 if (gimple_call_lhs (stmt
))
1479 wi
->val_only
= is_gimple_reg_type (gimple_call_lhs (stmt
));
1482 ret
= walk_tree (gimple_call_lhs_ptr (stmt
), callback_op
, wi
, pset
);
1490 wi
->val_only
= true;
1495 ret
= walk_tree (gimple_catch_types_ptr (stmt
), callback_op
, wi
,
1501 case GIMPLE_EH_FILTER
:
1502 ret
= walk_tree (gimple_eh_filter_types_ptr (stmt
), callback_op
, wi
,
1509 ret
= walk_gimple_asm (stmt
, callback_op
, wi
);
1514 case GIMPLE_OMP_CONTINUE
:
1515 ret
= walk_tree (gimple_omp_continue_control_def_ptr (stmt
),
1516 callback_op
, wi
, pset
);
1520 ret
= walk_tree (gimple_omp_continue_control_use_ptr (stmt
),
1521 callback_op
, wi
, pset
);
1526 case GIMPLE_OMP_CRITICAL
:
1527 ret
= walk_tree (gimple_omp_critical_name_ptr (stmt
), callback_op
, wi
,
1533 case GIMPLE_OMP_FOR
:
1534 ret
= walk_tree (gimple_omp_for_clauses_ptr (stmt
), callback_op
, wi
,
1538 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
1540 ret
= walk_tree (gimple_omp_for_index_ptr (stmt
, i
), callback_op
,
1544 ret
= walk_tree (gimple_omp_for_initial_ptr (stmt
, i
), callback_op
,
1548 ret
= walk_tree (gimple_omp_for_final_ptr (stmt
, i
), callback_op
,
1552 ret
= walk_tree (gimple_omp_for_incr_ptr (stmt
, i
), callback_op
,
1559 case GIMPLE_OMP_PARALLEL
:
1560 ret
= walk_tree (gimple_omp_parallel_clauses_ptr (stmt
), callback_op
,
1564 ret
= walk_tree (gimple_omp_parallel_child_fn_ptr (stmt
), callback_op
,
1568 ret
= walk_tree (gimple_omp_parallel_data_arg_ptr (stmt
), callback_op
,
1574 case GIMPLE_OMP_TASK
:
1575 ret
= walk_tree (gimple_omp_task_clauses_ptr (stmt
), callback_op
,
1579 ret
= walk_tree (gimple_omp_task_child_fn_ptr (stmt
), callback_op
,
1583 ret
= walk_tree (gimple_omp_task_data_arg_ptr (stmt
), callback_op
,
1587 ret
= walk_tree (gimple_omp_task_copy_fn_ptr (stmt
), callback_op
,
1591 ret
= walk_tree (gimple_omp_task_arg_size_ptr (stmt
), callback_op
,
1595 ret
= walk_tree (gimple_omp_task_arg_align_ptr (stmt
), callback_op
,
1601 case GIMPLE_OMP_SECTIONS
:
1602 ret
= walk_tree (gimple_omp_sections_clauses_ptr (stmt
), callback_op
,
1607 ret
= walk_tree (gimple_omp_sections_control_ptr (stmt
), callback_op
,
1614 case GIMPLE_OMP_SINGLE
:
1615 ret
= walk_tree (gimple_omp_single_clauses_ptr (stmt
), callback_op
, wi
,
1621 case GIMPLE_OMP_ATOMIC_LOAD
:
1622 ret
= walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt
), callback_op
, wi
,
1627 ret
= walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt
), callback_op
, wi
,
1633 case GIMPLE_OMP_ATOMIC_STORE
:
1634 ret
= walk_tree (gimple_omp_atomic_store_val_ptr (stmt
), callback_op
,
1640 /* Tuples that do not have operands. */
1643 case GIMPLE_OMP_RETURN
:
1644 case GIMPLE_PREDICT
:
1649 enum gimple_statement_structure_enum gss
;
1650 gss
= gimple_statement_structure (stmt
);
1651 if (gss
== GSS_WITH_OPS
|| gss
== GSS_WITH_MEM_OPS
)
1652 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
1654 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
, pset
);
1666 /* Walk the current statement in GSI (optionally using traversal state
1667 stored in WI). If WI is NULL, no state is kept during traversal.
1668 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
1669 that it has handled all the operands of the statement, its return
1670 value is returned. Otherwise, the return value from CALLBACK_STMT
1671 is discarded and its operands are scanned.
1673 If CALLBACK_STMT is NULL or it didn't handle the operands,
1674 CALLBACK_OP is called on each operand of the statement via
1675 walk_gimple_op. If walk_gimple_op returns non-NULL for any
1676 operand, the remaining operands are not scanned. In this case, the
1677 return value from CALLBACK_OP is returned.
1679 In any other case, NULL_TREE is returned. */
1682 walk_gimple_stmt (gimple_stmt_iterator
*gsi
, walk_stmt_fn callback_stmt
,
1683 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1687 gimple stmt
= gsi_stmt (*gsi
);
1692 if (wi
&& wi
->want_locations
&& gimple_has_location (stmt
))
1693 input_location
= gimple_location (stmt
);
1697 /* Invoke the statement callback. Return if the callback handled
1698 all of STMT operands by itself. */
1701 bool handled_ops
= false;
1702 tree_ret
= callback_stmt (gsi
, &handled_ops
, wi
);
1706 /* If CALLBACK_STMT did not handle operands, it should not have
1707 a value to return. */
1708 gcc_assert (tree_ret
== NULL
);
1710 /* Re-read stmt in case the callback changed it. */
1711 stmt
= gsi_stmt (*gsi
);
1714 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
1717 tree_ret
= walk_gimple_op (stmt
, callback_op
, wi
);
1722 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
1723 switch (gimple_code (stmt
))
1726 ret
= walk_gimple_seq (gimple_bind_body (stmt
), callback_stmt
,
1729 return wi
->callback_result
;
1733 ret
= walk_gimple_seq (gimple_catch_handler (stmt
), callback_stmt
,
1736 return wi
->callback_result
;
1739 case GIMPLE_EH_FILTER
:
1740 ret
= walk_gimple_seq (gimple_eh_filter_failure (stmt
), callback_stmt
,
1743 return wi
->callback_result
;
1747 ret
= walk_gimple_seq (gimple_try_eval (stmt
), callback_stmt
, callback_op
,
1750 return wi
->callback_result
;
1752 ret
= walk_gimple_seq (gimple_try_cleanup (stmt
), callback_stmt
,
1755 return wi
->callback_result
;
1758 case GIMPLE_OMP_FOR
:
1759 ret
= walk_gimple_seq (gimple_omp_for_pre_body (stmt
), callback_stmt
,
1762 return wi
->callback_result
;
1765 case GIMPLE_OMP_CRITICAL
:
1766 case GIMPLE_OMP_MASTER
:
1767 case GIMPLE_OMP_ORDERED
:
1768 case GIMPLE_OMP_SECTION
:
1769 case GIMPLE_OMP_PARALLEL
:
1770 case GIMPLE_OMP_TASK
:
1771 case GIMPLE_OMP_SECTIONS
:
1772 case GIMPLE_OMP_SINGLE
:
1773 ret
= walk_gimple_seq (gimple_omp_body (stmt
), callback_stmt
, callback_op
,
1776 return wi
->callback_result
;
1779 case GIMPLE_WITH_CLEANUP_EXPR
:
1780 ret
= walk_gimple_seq (gimple_wce_cleanup (stmt
), callback_stmt
,
1783 return wi
->callback_result
;
1787 gcc_assert (!gimple_has_substatements (stmt
));
1795 /* Set sequence SEQ to be the GIMPLE body for function FN. */
1798 gimple_set_body (tree fndecl
, gimple_seq seq
)
1800 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1803 /* If FNDECL still does not have a function structure associated
1804 with it, then it does not make sense for it to receive a
1806 gcc_assert (seq
== NULL
);
1809 fn
->gimple_body
= seq
;
1813 /* Return the body of GIMPLE statements for function FN. After the
1814 CFG pass, the function body doesn't exist anymore because it has
1815 been split up into basic blocks. In this case, it returns
1819 gimple_body (tree fndecl
)
1821 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1822 return fn
? fn
->gimple_body
: NULL
;
1825 /* Return true when FNDECL has Gimple body either in unlowered
1828 gimple_has_body_p (tree fndecl
)
1830 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1831 return (gimple_body (fndecl
) || (fn
&& fn
->cfg
));
1834 /* Return true if calls C1 and C2 are known to go to the same function. */
1837 gimple_call_same_target_p (const_gimple c1
, const_gimple c2
)
1839 if (gimple_call_internal_p (c1
))
1840 return (gimple_call_internal_p (c2
)
1841 && gimple_call_internal_fn (c1
) == gimple_call_internal_fn (c2
));
1843 return (gimple_call_fn (c1
) == gimple_call_fn (c2
)
1844 || (gimple_call_fndecl (c1
)
1845 && gimple_call_fndecl (c1
) == gimple_call_fndecl (c2
)));
1848 /* Detect flags from a GIMPLE_CALL. This is just like
1849 call_expr_flags, but for gimple tuples. */
1852 gimple_call_flags (const_gimple stmt
)
1855 tree decl
= gimple_call_fndecl (stmt
);
1858 flags
= flags_from_decl_or_type (decl
);
1859 else if (gimple_call_internal_p (stmt
))
1860 flags
= internal_fn_flags (gimple_call_internal_fn (stmt
));
1862 flags
= flags_from_decl_or_type (gimple_call_fntype (stmt
));
1864 if (stmt
->gsbase
.subcode
& GF_CALL_NOTHROW
)
1865 flags
|= ECF_NOTHROW
;
1870 /* Return the "fn spec" string for call STMT. */
1873 gimple_call_fnspec (const_gimple stmt
)
1877 type
= gimple_call_fntype (stmt
);
1881 attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
1885 return TREE_VALUE (TREE_VALUE (attr
));
1888 /* Detects argument flags for argument number ARG on call STMT. */
1891 gimple_call_arg_flags (const_gimple stmt
, unsigned arg
)
1893 tree attr
= gimple_call_fnspec (stmt
);
1895 if (!attr
|| 1 + arg
>= (unsigned) TREE_STRING_LENGTH (attr
))
1898 switch (TREE_STRING_POINTER (attr
)[1 + arg
])
1905 return EAF_DIRECT
| EAF_NOCLOBBER
| EAF_NOESCAPE
;
1908 return EAF_NOCLOBBER
| EAF_NOESCAPE
;
1911 return EAF_DIRECT
| EAF_NOESCAPE
;
1914 return EAF_NOESCAPE
;
1922 /* Detects return flags for the call STMT. */
1925 gimple_call_return_flags (const_gimple stmt
)
1929 if (gimple_call_flags (stmt
) & ECF_MALLOC
)
1932 attr
= gimple_call_fnspec (stmt
);
1933 if (!attr
|| TREE_STRING_LENGTH (attr
) < 1)
1936 switch (TREE_STRING_POINTER (attr
)[0])
1942 return ERF_RETURNS_ARG
| (TREE_STRING_POINTER (attr
)[0] - '1');
1954 /* Return true if GS is a copy assignment. */
1957 gimple_assign_copy_p (gimple gs
)
1959 return (gimple_assign_single_p (gs
)
1960 && is_gimple_val (gimple_op (gs
, 1)));
1964 /* Return true if GS is a SSA_NAME copy assignment. */
1967 gimple_assign_ssa_name_copy_p (gimple gs
)
1969 return (gimple_assign_single_p (gs
)
1970 && TREE_CODE (gimple_assign_lhs (gs
)) == SSA_NAME
1971 && TREE_CODE (gimple_assign_rhs1 (gs
)) == SSA_NAME
);
1975 /* Return true if GS is an assignment with a unary RHS, but the
1976 operator has no effect on the assigned value. The logic is adapted
1977 from STRIP_NOPS. This predicate is intended to be used in tuplifying
1978 instances in which STRIP_NOPS was previously applied to the RHS of
1981 NOTE: In the use cases that led to the creation of this function
1982 and of gimple_assign_single_p, it is typical to test for either
1983 condition and to proceed in the same manner. In each case, the
1984 assigned value is represented by the single RHS operand of the
1985 assignment. I suspect there may be cases where gimple_assign_copy_p,
1986 gimple_assign_single_p, or equivalent logic is used where a similar
1987 treatment of unary NOPs is appropriate. */
1990 gimple_assign_unary_nop_p (gimple gs
)
1992 return (is_gimple_assign (gs
)
1993 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs
))
1994 || gimple_assign_rhs_code (gs
) == NON_LVALUE_EXPR
)
1995 && gimple_assign_rhs1 (gs
) != error_mark_node
1996 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs
)))
1997 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs
)))));
2000 /* Set BB to be the basic block holding G. */
2003 gimple_set_bb (gimple stmt
, basic_block bb
)
2005 stmt
->gsbase
.bb
= bb
;
2007 /* If the statement is a label, add the label to block-to-labels map
2008 so that we can speed up edge creation for GIMPLE_GOTOs. */
2009 if (cfun
->cfg
&& gimple_code (stmt
) == GIMPLE_LABEL
)
2014 t
= gimple_label_label (stmt
);
2015 uid
= LABEL_DECL_UID (t
);
2018 unsigned old_len
= VEC_length (basic_block
, label_to_block_map
);
2019 LABEL_DECL_UID (t
) = uid
= cfun
->cfg
->last_label_uid
++;
2020 if (old_len
<= (unsigned) uid
)
2022 unsigned new_len
= 3 * uid
/ 2 + 1;
2024 VEC_safe_grow_cleared (basic_block
, gc
, label_to_block_map
,
2029 VEC_replace (basic_block
, label_to_block_map
, uid
, bb
);
2034 /* Modify the RHS of the assignment pointed-to by GSI using the
2035 operands in the expression tree EXPR.
2037 NOTE: The statement pointed-to by GSI may be reallocated if it
2038 did not have enough operand slots.
2040 This function is useful to convert an existing tree expression into
2041 the flat representation used for the RHS of a GIMPLE assignment.
2042 It will reallocate memory as needed to expand or shrink the number
2043 of operand slots needed to represent EXPR.
2045 NOTE: If you find yourself building a tree and then calling this
2046 function, you are most certainly doing it the slow way. It is much
2047 better to build a new assignment or to use the function
2048 gimple_assign_set_rhs_with_ops, which does not require an
2049 expression tree to be built. */
2052 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator
*gsi
, tree expr
)
2054 enum tree_code subcode
;
2057 extract_ops_from_tree_1 (expr
, &subcode
, &op1
, &op2
, &op3
);
2058 gimple_assign_set_rhs_with_ops_1 (gsi
, subcode
, op1
, op2
, op3
);
2062 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
2063 operands OP1, OP2 and OP3.
2065 NOTE: The statement pointed-to by GSI may be reallocated if it
2066 did not have enough operand slots. */
2069 gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator
*gsi
, enum tree_code code
,
2070 tree op1
, tree op2
, tree op3
)
2072 unsigned new_rhs_ops
= get_gimple_rhs_num_ops (code
);
2073 gimple stmt
= gsi_stmt (*gsi
);
2075 /* If the new CODE needs more operands, allocate a new statement. */
2076 if (gimple_num_ops (stmt
) < new_rhs_ops
+ 1)
2078 tree lhs
= gimple_assign_lhs (stmt
);
2079 gimple new_stmt
= gimple_alloc (gimple_code (stmt
), new_rhs_ops
+ 1);
2080 memcpy (new_stmt
, stmt
, gimple_size (gimple_code (stmt
)));
2081 gsi_replace (gsi
, new_stmt
, true);
2084 /* The LHS needs to be reset as this also changes the SSA name
2086 gimple_assign_set_lhs (stmt
, lhs
);
2089 gimple_set_num_ops (stmt
, new_rhs_ops
+ 1);
2090 gimple_set_subcode (stmt
, code
);
2091 gimple_assign_set_rhs1 (stmt
, op1
);
2092 if (new_rhs_ops
> 1)
2093 gimple_assign_set_rhs2 (stmt
, op2
);
2094 if (new_rhs_ops
> 2)
2095 gimple_assign_set_rhs3 (stmt
, op3
);
2099 /* Return the LHS of a statement that performs an assignment,
2100 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2101 for a call to a function that returns no value, or for a
2102 statement other than an assignment or a call. */
2105 gimple_get_lhs (const_gimple stmt
)
2107 enum gimple_code code
= gimple_code (stmt
);
2109 if (code
== GIMPLE_ASSIGN
)
2110 return gimple_assign_lhs (stmt
);
2111 else if (code
== GIMPLE_CALL
)
2112 return gimple_call_lhs (stmt
);
2118 /* Set the LHS of a statement that performs an assignment,
2119 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2122 gimple_set_lhs (gimple stmt
, tree lhs
)
2124 enum gimple_code code
= gimple_code (stmt
);
2126 if (code
== GIMPLE_ASSIGN
)
2127 gimple_assign_set_lhs (stmt
, lhs
);
2128 else if (code
== GIMPLE_CALL
)
2129 gimple_call_set_lhs (stmt
, lhs
);
2134 /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
2135 GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
2136 expression with a different value.
2138 This will update any annotations (say debug bind stmts) referring
2139 to the original LHS, so that they use the RHS instead. This is
2140 done even if NLHS and LHS are the same, for it is understood that
2141 the RHS will be modified afterwards, and NLHS will not be assigned
2142 an equivalent value.
2144 Adjusting any non-annotation uses of the LHS, if needed, is a
2145 responsibility of the caller.
2147 The effect of this call should be pretty much the same as that of
2148 inserting a copy of STMT before STMT, and then removing the
2149 original stmt, at which time gsi_remove() would have update
2150 annotations, but using this function saves all the inserting,
2151 copying and removing. */
2154 gimple_replace_lhs (gimple stmt
, tree nlhs
)
2156 if (MAY_HAVE_DEBUG_STMTS
)
2158 tree lhs
= gimple_get_lhs (stmt
);
2160 gcc_assert (SSA_NAME_DEF_STMT (lhs
) == stmt
);
2162 insert_debug_temp_for_var_def (NULL
, lhs
);
2165 gimple_set_lhs (stmt
, nlhs
);
2168 /* Return a deep copy of statement STMT. All the operands from STMT
2169 are reallocated and copied using unshare_expr. The DEF, USE, VDEF
2170 and VUSE operand arrays are set to empty in the new copy. */
2173 gimple_copy (gimple stmt
)
2175 enum gimple_code code
= gimple_code (stmt
);
2176 unsigned num_ops
= gimple_num_ops (stmt
);
2177 gimple copy
= gimple_alloc (code
, num_ops
);
2180 /* Shallow copy all the fields from STMT. */
2181 memcpy (copy
, stmt
, gimple_size (code
));
2183 /* If STMT has sub-statements, deep-copy them as well. */
2184 if (gimple_has_substatements (stmt
))
2189 switch (gimple_code (stmt
))
2192 new_seq
= gimple_seq_copy (gimple_bind_body (stmt
));
2193 gimple_bind_set_body (copy
, new_seq
);
2194 gimple_bind_set_vars (copy
, unshare_expr (gimple_bind_vars (stmt
)));
2195 gimple_bind_set_block (copy
, gimple_bind_block (stmt
));
2199 new_seq
= gimple_seq_copy (gimple_catch_handler (stmt
));
2200 gimple_catch_set_handler (copy
, new_seq
);
2201 t
= unshare_expr (gimple_catch_types (stmt
));
2202 gimple_catch_set_types (copy
, t
);
2205 case GIMPLE_EH_FILTER
:
2206 new_seq
= gimple_seq_copy (gimple_eh_filter_failure (stmt
));
2207 gimple_eh_filter_set_failure (copy
, new_seq
);
2208 t
= unshare_expr (gimple_eh_filter_types (stmt
));
2209 gimple_eh_filter_set_types (copy
, t
);
2213 new_seq
= gimple_seq_copy (gimple_try_eval (stmt
));
2214 gimple_try_set_eval (copy
, new_seq
);
2215 new_seq
= gimple_seq_copy (gimple_try_cleanup (stmt
));
2216 gimple_try_set_cleanup (copy
, new_seq
);
2219 case GIMPLE_OMP_FOR
:
2220 new_seq
= gimple_seq_copy (gimple_omp_for_pre_body (stmt
));
2221 gimple_omp_for_set_pre_body (copy
, new_seq
);
2222 t
= unshare_expr (gimple_omp_for_clauses (stmt
));
2223 gimple_omp_for_set_clauses (copy
, t
);
2224 copy
->gimple_omp_for
.iter
2225 = ggc_alloc_vec_gimple_omp_for_iter
2226 (gimple_omp_for_collapse (stmt
));
2227 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
2229 gimple_omp_for_set_cond (copy
, i
,
2230 gimple_omp_for_cond (stmt
, i
));
2231 gimple_omp_for_set_index (copy
, i
,
2232 gimple_omp_for_index (stmt
, i
));
2233 t
= unshare_expr (gimple_omp_for_initial (stmt
, i
));
2234 gimple_omp_for_set_initial (copy
, i
, t
);
2235 t
= unshare_expr (gimple_omp_for_final (stmt
, i
));
2236 gimple_omp_for_set_final (copy
, i
, t
);
2237 t
= unshare_expr (gimple_omp_for_incr (stmt
, i
));
2238 gimple_omp_for_set_incr (copy
, i
, t
);
2242 case GIMPLE_OMP_PARALLEL
:
2243 t
= unshare_expr (gimple_omp_parallel_clauses (stmt
));
2244 gimple_omp_parallel_set_clauses (copy
, t
);
2245 t
= unshare_expr (gimple_omp_parallel_child_fn (stmt
));
2246 gimple_omp_parallel_set_child_fn (copy
, t
);
2247 t
= unshare_expr (gimple_omp_parallel_data_arg (stmt
));
2248 gimple_omp_parallel_set_data_arg (copy
, t
);
2251 case GIMPLE_OMP_TASK
:
2252 t
= unshare_expr (gimple_omp_task_clauses (stmt
));
2253 gimple_omp_task_set_clauses (copy
, t
);
2254 t
= unshare_expr (gimple_omp_task_child_fn (stmt
));
2255 gimple_omp_task_set_child_fn (copy
, t
);
2256 t
= unshare_expr (gimple_omp_task_data_arg (stmt
));
2257 gimple_omp_task_set_data_arg (copy
, t
);
2258 t
= unshare_expr (gimple_omp_task_copy_fn (stmt
));
2259 gimple_omp_task_set_copy_fn (copy
, t
);
2260 t
= unshare_expr (gimple_omp_task_arg_size (stmt
));
2261 gimple_omp_task_set_arg_size (copy
, t
);
2262 t
= unshare_expr (gimple_omp_task_arg_align (stmt
));
2263 gimple_omp_task_set_arg_align (copy
, t
);
2266 case GIMPLE_OMP_CRITICAL
:
2267 t
= unshare_expr (gimple_omp_critical_name (stmt
));
2268 gimple_omp_critical_set_name (copy
, t
);
2271 case GIMPLE_OMP_SECTIONS
:
2272 t
= unshare_expr (gimple_omp_sections_clauses (stmt
));
2273 gimple_omp_sections_set_clauses (copy
, t
);
2274 t
= unshare_expr (gimple_omp_sections_control (stmt
));
2275 gimple_omp_sections_set_control (copy
, t
);
2278 case GIMPLE_OMP_SINGLE
:
2279 case GIMPLE_OMP_SECTION
:
2280 case GIMPLE_OMP_MASTER
:
2281 case GIMPLE_OMP_ORDERED
:
2283 new_seq
= gimple_seq_copy (gimple_omp_body (stmt
));
2284 gimple_omp_set_body (copy
, new_seq
);
2287 case GIMPLE_WITH_CLEANUP_EXPR
:
2288 new_seq
= gimple_seq_copy (gimple_wce_cleanup (stmt
));
2289 gimple_wce_set_cleanup (copy
, new_seq
);
2297 /* Make copy of operands. */
2300 for (i
= 0; i
< num_ops
; i
++)
2301 gimple_set_op (copy
, i
, unshare_expr (gimple_op (stmt
, i
)));
2303 /* Clear out SSA operand vectors on COPY. */
2304 if (gimple_has_ops (stmt
))
2306 gimple_set_def_ops (copy
, NULL
);
2307 gimple_set_use_ops (copy
, NULL
);
2310 if (gimple_has_mem_ops (stmt
))
2312 gimple_set_vdef (copy
, gimple_vdef (stmt
));
2313 gimple_set_vuse (copy
, gimple_vuse (stmt
));
2316 /* SSA operands need to be updated. */
2317 gimple_set_modified (copy
, true);
2324 /* Set the MODIFIED flag to MODIFIEDP, iff the gimple statement G has
2325 a MODIFIED field. */
2328 gimple_set_modified (gimple s
, bool modifiedp
)
2330 if (gimple_has_ops (s
))
2331 s
->gsbase
.modified
= (unsigned) modifiedp
;
2335 /* Return true if statement S has side-effects. We consider a
2336 statement to have side effects if:
2338 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2339 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2342 gimple_has_side_effects (const_gimple s
)
2346 if (is_gimple_debug (s
))
2349 /* We don't have to scan the arguments to check for
2350 volatile arguments, though, at present, we still
2351 do a scan to check for TREE_SIDE_EFFECTS. */
2352 if (gimple_has_volatile_ops (s
))
2355 if (is_gimple_call (s
))
2357 unsigned nargs
= gimple_call_num_args (s
);
2360 if (!(gimple_call_flags (s
) & (ECF_CONST
| ECF_PURE
)))
2362 else if (gimple_call_flags (s
) & ECF_LOOPING_CONST_OR_PURE
)
2363 /* An infinite loop is considered a side effect. */
2366 if (gimple_call_lhs (s
)
2367 && TREE_SIDE_EFFECTS (gimple_call_lhs (s
)))
2369 gcc_assert (gimple_has_volatile_ops (s
));
2373 fn
= gimple_call_fn (s
);
2374 if (fn
&& TREE_SIDE_EFFECTS (fn
))
2377 for (i
= 0; i
< nargs
; i
++)
2378 if (TREE_SIDE_EFFECTS (gimple_call_arg (s
, i
)))
2380 gcc_assert (gimple_has_volatile_ops (s
));
2388 for (i
= 0; i
< gimple_num_ops (s
); i
++)
2389 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
)))
2391 gcc_assert (gimple_has_volatile_ops (s
));
2399 /* Return true if the RHS of statement S has side effects.
2400 We may use it to determine if it is admissable to replace
2401 an assignment or call with a copy of a previously-computed
2402 value. In such cases, side-effects due to the LHS are
2406 gimple_rhs_has_side_effects (const_gimple s
)
2410 if (is_gimple_call (s
))
2412 unsigned nargs
= gimple_call_num_args (s
);
2415 if (!(gimple_call_flags (s
) & (ECF_CONST
| ECF_PURE
)))
2418 /* We cannot use gimple_has_volatile_ops here,
2419 because we must ignore a volatile LHS. */
2420 fn
= gimple_call_fn (s
);
2421 if (fn
&& (TREE_SIDE_EFFECTS (fn
) || TREE_THIS_VOLATILE (fn
)))
2423 gcc_assert (gimple_has_volatile_ops (s
));
2427 for (i
= 0; i
< nargs
; i
++)
2428 if (TREE_SIDE_EFFECTS (gimple_call_arg (s
, i
))
2429 || TREE_THIS_VOLATILE (gimple_call_arg (s
, i
)))
2434 else if (is_gimple_assign (s
))
2436 /* Skip the first operand, the LHS. */
2437 for (i
= 1; i
< gimple_num_ops (s
); i
++)
2438 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
))
2439 || TREE_THIS_VOLATILE (gimple_op (s
, i
)))
2441 gcc_assert (gimple_has_volatile_ops (s
));
2445 else if (is_gimple_debug (s
))
2449 /* For statements without an LHS, examine all arguments. */
2450 for (i
= 0; i
< gimple_num_ops (s
); i
++)
2451 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
))
2452 || TREE_THIS_VOLATILE (gimple_op (s
, i
)))
2454 gcc_assert (gimple_has_volatile_ops (s
));
2462 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2463 Return true if S can trap. When INCLUDE_MEM is true, check whether
2464 the memory operations could trap. When INCLUDE_STORES is true and
2465 S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
2468 gimple_could_trap_p_1 (gimple s
, bool include_mem
, bool include_stores
)
2470 tree t
, div
= NULL_TREE
;
2475 unsigned i
, start
= (is_gimple_assign (s
) && !include_stores
) ? 1 : 0;
2477 for (i
= start
; i
< gimple_num_ops (s
); i
++)
2478 if (tree_could_trap_p (gimple_op (s
, i
)))
2482 switch (gimple_code (s
))
2485 return gimple_asm_volatile_p (s
);
2488 t
= gimple_call_fndecl (s
);
2489 /* Assume that calls to weak functions may trap. */
2490 if (!t
|| !DECL_P (t
) || DECL_WEAK (t
))
2495 t
= gimple_expr_type (s
);
2496 op
= gimple_assign_rhs_code (s
);
2497 if (get_gimple_rhs_class (op
) == GIMPLE_BINARY_RHS
)
2498 div
= gimple_assign_rhs2 (s
);
2499 return (operation_could_trap_p (op
, FLOAT_TYPE_P (t
),
2500 (INTEGRAL_TYPE_P (t
)
2501 && TYPE_OVERFLOW_TRAPS (t
)),
2511 /* Return true if statement S can trap. */
2514 gimple_could_trap_p (gimple s
)
2516 return gimple_could_trap_p_1 (s
, true, true);
2519 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2522 gimple_assign_rhs_could_trap_p (gimple s
)
2524 gcc_assert (is_gimple_assign (s
));
2525 return gimple_could_trap_p_1 (s
, true, false);
2529 /* Print debugging information for gimple stmts generated. */
2532 dump_gimple_statistics (void)
2534 #ifdef GATHER_STATISTICS
2535 int i
, total_tuples
= 0, total_bytes
= 0;
2537 fprintf (stderr
, "\nGIMPLE statements\n");
2538 fprintf (stderr
, "Kind Stmts Bytes\n");
2539 fprintf (stderr
, "---------------------------------------\n");
2540 for (i
= 0; i
< (int) gimple_alloc_kind_all
; ++i
)
2542 fprintf (stderr
, "%-20s %7d %10d\n", gimple_alloc_kind_names
[i
],
2543 gimple_alloc_counts
[i
], gimple_alloc_sizes
[i
]);
2544 total_tuples
+= gimple_alloc_counts
[i
];
2545 total_bytes
+= gimple_alloc_sizes
[i
];
2547 fprintf (stderr
, "---------------------------------------\n");
2548 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_tuples
, total_bytes
);
2549 fprintf (stderr
, "---------------------------------------\n");
2551 fprintf (stderr
, "No gimple statistics\n");
2556 /* Return the number of operands needed on the RHS of a GIMPLE
2557 assignment for an expression with tree code CODE. */
2560 get_gimple_rhs_num_ops (enum tree_code code
)
2562 enum gimple_rhs_class rhs_class
= get_gimple_rhs_class (code
);
2564 if (rhs_class
== GIMPLE_UNARY_RHS
|| rhs_class
== GIMPLE_SINGLE_RHS
)
2566 else if (rhs_class
== GIMPLE_BINARY_RHS
)
2568 else if (rhs_class
== GIMPLE_TERNARY_RHS
)
2574 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2576 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2577 : ((TYPE) == tcc_binary \
2578 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2579 : ((TYPE) == tcc_constant \
2580 || (TYPE) == tcc_declaration \
2581 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2582 : ((SYM) == TRUTH_AND_EXPR \
2583 || (SYM) == TRUTH_OR_EXPR \
2584 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2585 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2586 : ((SYM) == WIDEN_MULT_PLUS_EXPR \
2587 || (SYM) == WIDEN_MULT_MINUS_EXPR \
2588 || (SYM) == DOT_PROD_EXPR \
2589 || (SYM) == REALIGN_LOAD_EXPR \
2590 || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \
2591 : ((SYM) == COND_EXPR \
2592 || (SYM) == CONSTRUCTOR \
2593 || (SYM) == OBJ_TYPE_REF \
2594 || (SYM) == ASSERT_EXPR \
2595 || (SYM) == ADDR_EXPR \
2596 || (SYM) == WITH_SIZE_EXPR \
2597 || (SYM) == SSA_NAME \
2598 || (SYM) == VEC_COND_EXPR) ? GIMPLE_SINGLE_RHS \
2599 : GIMPLE_INVALID_RHS),
2600 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2602 const unsigned char gimple_rhs_class_table
[] = {
2603 #include "all-tree.def"
2607 #undef END_OF_BASE_TREE_CODES
2609 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2611 /* Validation of GIMPLE expressions. */
2613 /* Returns true iff T is a valid RHS for an assignment to a renamed
2614 user -- or front-end generated artificial -- variable. */
2617 is_gimple_reg_rhs (tree t
)
2619 return get_gimple_rhs_class (TREE_CODE (t
)) != GIMPLE_INVALID_RHS
;
2622 /* Returns true iff T is a valid RHS for an assignment to an un-renamed
2623 LHS, or for a call argument. */
2626 is_gimple_mem_rhs (tree t
)
2628 /* If we're dealing with a renamable type, either source or dest must be
2629 a renamed variable. */
2630 if (is_gimple_reg_type (TREE_TYPE (t
)))
2631 return is_gimple_val (t
);
2633 return is_gimple_val (t
) || is_gimple_lvalue (t
);
2636 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
2639 is_gimple_lvalue (tree t
)
2641 return (is_gimple_addressable (t
)
2642 || TREE_CODE (t
) == WITH_SIZE_EXPR
2643 /* These are complex lvalues, but don't have addresses, so they
2645 || TREE_CODE (t
) == BIT_FIELD_REF
);
2648 /* Return true if T is a GIMPLE condition. */
2651 is_gimple_condexpr (tree t
)
2653 return (is_gimple_val (t
) || (COMPARISON_CLASS_P (t
)
2654 && !tree_could_throw_p (t
)
2655 && is_gimple_val (TREE_OPERAND (t
, 0))
2656 && is_gimple_val (TREE_OPERAND (t
, 1))));
2659 /* Return true if T is something whose address can be taken. */
2662 is_gimple_addressable (tree t
)
2664 return (is_gimple_id (t
) || handled_component_p (t
)
2665 || TREE_CODE (t
) == MEM_REF
);
2668 /* Return true if T is a valid gimple constant. */
2671 is_gimple_constant (const_tree t
)
2673 switch (TREE_CODE (t
))
2683 /* Vector constant constructors are gimple invariant. */
2685 if (TREE_TYPE (t
) && TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2686 return TREE_CONSTANT (t
);
2695 /* Return true if T is a gimple address. */
2698 is_gimple_address (const_tree t
)
2702 if (TREE_CODE (t
) != ADDR_EXPR
)
2705 op
= TREE_OPERAND (t
, 0);
2706 while (handled_component_p (op
))
2708 if ((TREE_CODE (op
) == ARRAY_REF
2709 || TREE_CODE (op
) == ARRAY_RANGE_REF
)
2710 && !is_gimple_val (TREE_OPERAND (op
, 1)))
2713 op
= TREE_OPERAND (op
, 0);
2716 if (CONSTANT_CLASS_P (op
) || TREE_CODE (op
) == MEM_REF
)
2719 switch (TREE_CODE (op
))
2734 /* Strip out all handled components that produce invariant
2738 strip_invariant_refs (const_tree op
)
2740 while (handled_component_p (op
))
2742 switch (TREE_CODE (op
))
2745 case ARRAY_RANGE_REF
:
2746 if (!is_gimple_constant (TREE_OPERAND (op
, 1))
2747 || TREE_OPERAND (op
, 2) != NULL_TREE
2748 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2753 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2759 op
= TREE_OPERAND (op
, 0);
2765 /* Return true if T is a gimple invariant address. */
2768 is_gimple_invariant_address (const_tree t
)
2772 if (TREE_CODE (t
) != ADDR_EXPR
)
2775 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2779 if (TREE_CODE (op
) == MEM_REF
)
2781 const_tree op0
= TREE_OPERAND (op
, 0);
2782 return (TREE_CODE (op0
) == ADDR_EXPR
2783 && (CONSTANT_CLASS_P (TREE_OPERAND (op0
, 0))
2784 || decl_address_invariant_p (TREE_OPERAND (op0
, 0))));
2787 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
2790 /* Return true if T is a gimple invariant address at IPA level
2791 (so addresses of variables on stack are not allowed). */
2794 is_gimple_ip_invariant_address (const_tree t
)
2798 if (TREE_CODE (t
) != ADDR_EXPR
)
2801 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2803 return op
&& (CONSTANT_CLASS_P (op
) || decl_address_ip_invariant_p (op
));
2806 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
2807 form of function invariant. */
2810 is_gimple_min_invariant (const_tree t
)
2812 if (TREE_CODE (t
) == ADDR_EXPR
)
2813 return is_gimple_invariant_address (t
);
2815 return is_gimple_constant (t
);
2818 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
2819 form of gimple minimal invariant. */
2822 is_gimple_ip_invariant (const_tree t
)
2824 if (TREE_CODE (t
) == ADDR_EXPR
)
2825 return is_gimple_ip_invariant_address (t
);
2827 return is_gimple_constant (t
);
2830 /* Return true if T looks like a valid GIMPLE statement. */
2833 is_gimple_stmt (tree t
)
2835 const enum tree_code code
= TREE_CODE (t
);
2840 /* The only valid NOP_EXPR is the empty statement. */
2841 return IS_EMPTY_STMT (t
);
2845 /* These are only valid if they're void. */
2846 return TREE_TYPE (t
) == NULL
|| VOID_TYPE_P (TREE_TYPE (t
));
2852 case CASE_LABEL_EXPR
:
2853 case TRY_CATCH_EXPR
:
2854 case TRY_FINALLY_EXPR
:
2855 case EH_FILTER_EXPR
:
2858 case STATEMENT_LIST
:
2868 /* These are always void. */
2874 /* These are valid regardless of their type. */
2882 /* Return true if T is a variable. */
2885 is_gimple_variable (tree t
)
2887 return (TREE_CODE (t
) == VAR_DECL
2888 || TREE_CODE (t
) == PARM_DECL
2889 || TREE_CODE (t
) == RESULT_DECL
2890 || TREE_CODE (t
) == SSA_NAME
);
2893 /* Return true if T is a GIMPLE identifier (something with an address). */
2896 is_gimple_id (tree t
)
2898 return (is_gimple_variable (t
)
2899 || TREE_CODE (t
) == FUNCTION_DECL
2900 || TREE_CODE (t
) == LABEL_DECL
2901 || TREE_CODE (t
) == CONST_DECL
2902 /* Allow string constants, since they are addressable. */
2903 || TREE_CODE (t
) == STRING_CST
);
2906 /* Return true if TYPE is a suitable type for a scalar register variable. */
2909 is_gimple_reg_type (tree type
)
2911 return !AGGREGATE_TYPE_P (type
);
2914 /* Return true if T is a non-aggregate register variable. */
2917 is_gimple_reg (tree t
)
2919 if (TREE_CODE (t
) == SSA_NAME
)
2920 t
= SSA_NAME_VAR (t
);
2922 if (!is_gimple_variable (t
))
2925 if (!is_gimple_reg_type (TREE_TYPE (t
)))
2928 /* A volatile decl is not acceptable because we can't reuse it as
2929 needed. We need to copy it into a temp first. */
2930 if (TREE_THIS_VOLATILE (t
))
2933 /* We define "registers" as things that can be renamed as needed,
2934 which with our infrastructure does not apply to memory. */
2935 if (needs_to_live_in_memory (t
))
2938 /* Hard register variables are an interesting case. For those that
2939 are call-clobbered, we don't know where all the calls are, since
2940 we don't (want to) take into account which operations will turn
2941 into libcalls at the rtl level. For those that are call-saved,
2942 we don't currently model the fact that calls may in fact change
2943 global hard registers, nor do we examine ASM_CLOBBERS at the tree
2944 level, and so miss variable changes that might imply. All around,
2945 it seems safest to not do too much optimization with these at the
2946 tree level at all. We'll have to rely on the rtl optimizers to
2947 clean this up, as there we've got all the appropriate bits exposed. */
2948 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2951 /* Complex and vector values must have been put into SSA-like form.
2952 That is, no assignments to the individual components. */
2953 if (TREE_CODE (TREE_TYPE (t
)) == COMPLEX_TYPE
2954 || TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2955 return DECL_GIMPLE_REG_P (t
);
2961 /* Return true if T is a GIMPLE variable whose address is not needed. */
2964 is_gimple_non_addressable (tree t
)
2966 if (TREE_CODE (t
) == SSA_NAME
)
2967 t
= SSA_NAME_VAR (t
);
2969 return (is_gimple_variable (t
) && ! needs_to_live_in_memory (t
));
2972 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
2975 is_gimple_val (tree t
)
2977 /* Make loads from volatiles and memory vars explicit. */
2978 if (is_gimple_variable (t
)
2979 && is_gimple_reg_type (TREE_TYPE (t
))
2980 && !is_gimple_reg (t
))
2983 return (is_gimple_variable (t
) || is_gimple_min_invariant (t
));
2986 /* Similarly, but accept hard registers as inputs to asm statements. */
2989 is_gimple_asm_val (tree t
)
2991 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2994 return is_gimple_val (t
);
2997 /* Return true if T is a GIMPLE minimal lvalue. */
3000 is_gimple_min_lval (tree t
)
3002 if (!(t
= CONST_CAST_TREE (strip_invariant_refs (t
))))
3004 return (is_gimple_id (t
) || TREE_CODE (t
) == MEM_REF
);
3007 /* Return true if T is a valid function operand of a CALL_EXPR. */
3010 is_gimple_call_addr (tree t
)
3012 return (TREE_CODE (t
) == OBJ_TYPE_REF
|| is_gimple_val (t
));
3015 /* Return true if T is a valid address operand of a MEM_REF. */
3018 is_gimple_mem_ref_addr (tree t
)
3020 return (is_gimple_reg (t
)
3021 || TREE_CODE (t
) == INTEGER_CST
3022 || (TREE_CODE (t
) == ADDR_EXPR
3023 && (CONSTANT_CLASS_P (TREE_OPERAND (t
, 0))
3024 || decl_address_invariant_p (TREE_OPERAND (t
, 0)))));
3027 /* If T makes a function call, return the corresponding CALL_EXPR operand.
3028 Otherwise, return NULL_TREE. */
3031 get_call_expr_in (tree t
)
3033 if (TREE_CODE (t
) == MODIFY_EXPR
)
3034 t
= TREE_OPERAND (t
, 1);
3035 if (TREE_CODE (t
) == WITH_SIZE_EXPR
)
3036 t
= TREE_OPERAND (t
, 0);
3037 if (TREE_CODE (t
) == CALL_EXPR
)
3043 /* Given a memory reference expression T, return its base address.
3044 The base address of a memory reference expression is the main
3045 object being referenced. For instance, the base address for
3046 'array[i].fld[j]' is 'array'. You can think of this as stripping
3047 away the offset part from a memory address.
3049 This function calls handled_component_p to strip away all the inner
3050 parts of the memory reference until it reaches the base object. */
3053 get_base_address (tree t
)
3055 while (handled_component_p (t
))
3056 t
= TREE_OPERAND (t
, 0);
3058 if ((TREE_CODE (t
) == MEM_REF
3059 || TREE_CODE (t
) == TARGET_MEM_REF
)
3060 && TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
3061 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
3063 if (TREE_CODE (t
) == SSA_NAME
3065 || TREE_CODE (t
) == STRING_CST
3066 || TREE_CODE (t
) == CONSTRUCTOR
3067 || INDIRECT_REF_P (t
)
3068 || TREE_CODE (t
) == MEM_REF
3069 || TREE_CODE (t
) == TARGET_MEM_REF
)
3076 recalculate_side_effects (tree t
)
3078 enum tree_code code
= TREE_CODE (t
);
3079 int len
= TREE_OPERAND_LENGTH (t
);
3082 switch (TREE_CODE_CLASS (code
))
3084 case tcc_expression
:
3090 case PREDECREMENT_EXPR
:
3091 case PREINCREMENT_EXPR
:
3092 case POSTDECREMENT_EXPR
:
3093 case POSTINCREMENT_EXPR
:
3094 /* All of these have side-effects, no matter what their
3103 case tcc_comparison
: /* a comparison expression */
3104 case tcc_unary
: /* a unary arithmetic expression */
3105 case tcc_binary
: /* a binary arithmetic expression */
3106 case tcc_reference
: /* a reference */
3107 case tcc_vl_exp
: /* a function call */
3108 TREE_SIDE_EFFECTS (t
) = TREE_THIS_VOLATILE (t
);
3109 for (i
= 0; i
< len
; ++i
)
3111 tree op
= TREE_OPERAND (t
, i
);
3112 if (op
&& TREE_SIDE_EFFECTS (op
))
3113 TREE_SIDE_EFFECTS (t
) = 1;
3118 /* No side-effects. */
3126 /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
3127 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
3128 we failed to create one. */
3131 canonicalize_cond_expr_cond (tree t
)
3133 /* Strip conversions around boolean operations. */
3134 if (CONVERT_EXPR_P (t
)
3135 && truth_value_p (TREE_CODE (TREE_OPERAND (t
, 0))))
3136 t
= TREE_OPERAND (t
, 0);
3138 /* For (bool)x use x != 0. */
3139 if (CONVERT_EXPR_P (t
)
3140 && TREE_CODE (TREE_TYPE (t
)) == BOOLEAN_TYPE
)
3142 tree top0
= TREE_OPERAND (t
, 0);
3143 t
= build2 (NE_EXPR
, TREE_TYPE (t
),
3144 top0
, build_int_cst (TREE_TYPE (top0
), 0));
3146 /* For !x use x == 0. */
3147 else if (TREE_CODE (t
) == TRUTH_NOT_EXPR
)
3149 tree top0
= TREE_OPERAND (t
, 0);
3150 t
= build2 (EQ_EXPR
, TREE_TYPE (t
),
3151 top0
, build_int_cst (TREE_TYPE (top0
), 0));
3153 /* For cmp ? 1 : 0 use cmp. */
3154 else if (TREE_CODE (t
) == COND_EXPR
3155 && COMPARISON_CLASS_P (TREE_OPERAND (t
, 0))
3156 && integer_onep (TREE_OPERAND (t
, 1))
3157 && integer_zerop (TREE_OPERAND (t
, 2)))
3159 tree top0
= TREE_OPERAND (t
, 0);
3160 t
= build2 (TREE_CODE (top0
), TREE_TYPE (t
),
3161 TREE_OPERAND (top0
, 0), TREE_OPERAND (top0
, 1));
3164 if (is_gimple_condexpr (t
))
3170 /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
3171 the positions marked by the set ARGS_TO_SKIP. */
3174 gimple_call_copy_skip_args (gimple stmt
, bitmap args_to_skip
)
3177 int nargs
= gimple_call_num_args (stmt
);
3178 VEC(tree
, heap
) *vargs
= VEC_alloc (tree
, heap
, nargs
);
3181 for (i
= 0; i
< nargs
; i
++)
3182 if (!bitmap_bit_p (args_to_skip
, i
))
3183 VEC_quick_push (tree
, vargs
, gimple_call_arg (stmt
, i
));
3185 if (gimple_call_internal_p (stmt
))
3186 new_stmt
= gimple_build_call_internal_vec (gimple_call_internal_fn (stmt
),
3189 new_stmt
= gimple_build_call_vec (gimple_call_fn (stmt
), vargs
);
3190 VEC_free (tree
, heap
, vargs
);
3191 if (gimple_call_lhs (stmt
))
3192 gimple_call_set_lhs (new_stmt
, gimple_call_lhs (stmt
));
3194 gimple_set_vuse (new_stmt
, gimple_vuse (stmt
));
3195 gimple_set_vdef (new_stmt
, gimple_vdef (stmt
));
3197 gimple_set_block (new_stmt
, gimple_block (stmt
));
3198 if (gimple_has_location (stmt
))
3199 gimple_set_location (new_stmt
, gimple_location (stmt
));
3200 gimple_call_copy_flags (new_stmt
, stmt
);
3201 gimple_call_set_chain (new_stmt
, gimple_call_chain (stmt
));
3203 gimple_set_modified (new_stmt
, true);
3209 static hashval_t
gimple_type_hash_1 (const void *, enum gtc_mode
);
3211 /* Structure used to maintain a cache of some type pairs compared by
3212 gimple_types_compatible_p when comparing aggregate types. There are
3213 three possible values for SAME_P:
3215 -2: The pair (T1, T2) has just been inserted in the table.
3216 0: T1 and T2 are different types.
3217 1: T1 and T2 are the same type.
3219 The two elements in the SAME_P array are indexed by the comparison
3226 signed char same_p
[2];
3228 typedef struct type_pair_d
*type_pair_t
;
3230 DEF_VEC_P(type_pair_t
);
3231 DEF_VEC_ALLOC_P(type_pair_t
,heap
);
3233 /* Return a hash value for the type pair pointed-to by P. */
3236 type_pair_hash (const void *p
)
3238 const struct type_pair_d
*pair
= (const struct type_pair_d
*) p
;
3239 hashval_t val1
= pair
->uid1
;
3240 hashval_t val2
= pair
->uid2
;
3241 return (iterative_hash_hashval_t (val2
, val1
)
3242 ^ iterative_hash_hashval_t (val1
, val2
));
3245 /* Compare two type pairs pointed-to by P1 and P2. */
3248 type_pair_eq (const void *p1
, const void *p2
)
3250 const struct type_pair_d
*pair1
= (const struct type_pair_d
*) p1
;
3251 const struct type_pair_d
*pair2
= (const struct type_pair_d
*) p2
;
3252 return ((pair1
->uid1
== pair2
->uid1
&& pair1
->uid2
== pair2
->uid2
)
3253 || (pair1
->uid1
== pair2
->uid2
&& pair1
->uid2
== pair2
->uid1
));
3256 /* Lookup the pair of types T1 and T2 in *VISITED_P. Insert a new
3257 entry if none existed. */
3260 lookup_type_pair (tree t1
, tree t2
, htab_t
*visited_p
, struct obstack
*ob_p
)
3262 struct type_pair_d pair
;
3266 if (*visited_p
== NULL
)
3268 *visited_p
= htab_create (251, type_pair_hash
, type_pair_eq
, NULL
);
3269 gcc_obstack_init (ob_p
);
3272 pair
.uid1
= TYPE_UID (t1
);
3273 pair
.uid2
= TYPE_UID (t2
);
3274 slot
= htab_find_slot (*visited_p
, &pair
, INSERT
);
3277 p
= *((type_pair_t
*) slot
);
3280 p
= XOBNEW (ob_p
, struct type_pair_d
);
3281 p
->uid1
= TYPE_UID (t1
);
3282 p
->uid2
= TYPE_UID (t2
);
3291 /* Per pointer state for the SCC finding. The on_sccstack flag
3292 is not strictly required, it is true when there is no hash value
3293 recorded for the type and false otherwise. But querying that
3298 unsigned int dfsnum
;
3307 static unsigned int next_dfs_num
;
3308 static unsigned int gtc_next_dfs_num
;
3311 /* GIMPLE type merging cache. A direct-mapped cache based on TYPE_UID. */
3313 typedef struct GTY(()) gimple_type_leader_entry_s
{
3316 } gimple_type_leader_entry
;
3318 #define GIMPLE_TYPE_LEADER_SIZE 16381
3319 static GTY((deletable
, length("GIMPLE_TYPE_LEADER_SIZE")))
3320 gimple_type_leader_entry
*gimple_type_leader
;
3322 /* Lookup an existing leader for T and return it or NULL_TREE, if
3323 there is none in the cache. */
3326 gimple_lookup_type_leader (tree t
)
3328 gimple_type_leader_entry
*leader
;
3330 if (!gimple_type_leader
)
3333 leader
= &gimple_type_leader
[TYPE_UID (t
) % GIMPLE_TYPE_LEADER_SIZE
];
3334 if (leader
->type
!= t
)
3337 return leader
->leader
;
3340 /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is
3341 true then if any type has no name return false, otherwise return
3342 true if both types have no names. */
3345 compare_type_names_p (tree t1
, tree t2
, bool for_completion_p
)
3347 tree name1
= TYPE_NAME (t1
);
3348 tree name2
= TYPE_NAME (t2
);
3350 /* Consider anonymous types all unique for completion. */
3351 if (for_completion_p
3352 && (!name1
|| !name2
))
3355 if (name1
&& TREE_CODE (name1
) == TYPE_DECL
)
3357 name1
= DECL_NAME (name1
);
3358 if (for_completion_p
3362 gcc_assert (!name1
|| TREE_CODE (name1
) == IDENTIFIER_NODE
);
3364 if (name2
&& TREE_CODE (name2
) == TYPE_DECL
)
3366 name2
= DECL_NAME (name2
);
3367 if (for_completion_p
3371 gcc_assert (!name2
|| TREE_CODE (name2
) == IDENTIFIER_NODE
);
3373 /* Identifiers can be compared with pointer equality rather
3374 than a string comparison. */
3381 /* Return true if the field decls F1 and F2 are at the same offset.
3383 This is intended to be used on GIMPLE types only. */
3386 gimple_compare_field_offset (tree f1
, tree f2
)
3388 if (DECL_OFFSET_ALIGN (f1
) == DECL_OFFSET_ALIGN (f2
))
3390 tree offset1
= DECL_FIELD_OFFSET (f1
);
3391 tree offset2
= DECL_FIELD_OFFSET (f2
);
3392 return ((offset1
== offset2
3393 /* Once gimplification is done, self-referential offsets are
3394 instantiated as operand #2 of the COMPONENT_REF built for
3395 each access and reset. Therefore, they are not relevant
3396 anymore and fields are interchangeable provided that they
3397 represent the same access. */
3398 || (TREE_CODE (offset1
) == PLACEHOLDER_EXPR
3399 && TREE_CODE (offset2
) == PLACEHOLDER_EXPR
3400 && (DECL_SIZE (f1
) == DECL_SIZE (f2
)
3401 || (TREE_CODE (DECL_SIZE (f1
)) == PLACEHOLDER_EXPR
3402 && TREE_CODE (DECL_SIZE (f2
)) == PLACEHOLDER_EXPR
)
3403 || operand_equal_p (DECL_SIZE (f1
), DECL_SIZE (f2
), 0))
3404 && DECL_ALIGN (f1
) == DECL_ALIGN (f2
))
3405 || operand_equal_p (offset1
, offset2
, 0))
3406 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1
),
3407 DECL_FIELD_BIT_OFFSET (f2
)));
3410 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
3411 should be, so handle differing ones specially by decomposing
3412 the offset into a byte and bit offset manually. */
3413 if (host_integerp (DECL_FIELD_OFFSET (f1
), 0)
3414 && host_integerp (DECL_FIELD_OFFSET (f2
), 0))
3416 unsigned HOST_WIDE_INT byte_offset1
, byte_offset2
;
3417 unsigned HOST_WIDE_INT bit_offset1
, bit_offset2
;
3418 bit_offset1
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1
));
3419 byte_offset1
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1
))
3420 + bit_offset1
/ BITS_PER_UNIT
);
3421 bit_offset2
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2
));
3422 byte_offset2
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2
))
3423 + bit_offset2
/ BITS_PER_UNIT
);
3424 if (byte_offset1
!= byte_offset2
)
3426 return bit_offset1
% BITS_PER_UNIT
== bit_offset2
% BITS_PER_UNIT
;
3432 /* If the type T1 and the type T2 are a complete and an incomplete
3433 variant of the same type return true. */
3436 gimple_compatible_complete_and_incomplete_subtype_p (tree t1
, tree t2
)
3438 /* If one pointer points to an incomplete type variant of
3439 the other pointed-to type they are the same. */
3440 if (TREE_CODE (t1
) == TREE_CODE (t2
)
3441 && RECORD_OR_UNION_TYPE_P (t1
)
3442 && (!COMPLETE_TYPE_P (t1
)
3443 || !COMPLETE_TYPE_P (t2
))
3444 && TYPE_QUALS (t1
) == TYPE_QUALS (t2
)
3445 && compare_type_names_p (TYPE_MAIN_VARIANT (t1
),
3446 TYPE_MAIN_VARIANT (t2
), true))
3452 gimple_types_compatible_p_1 (tree
, tree
, enum gtc_mode
, type_pair_t
,
3453 VEC(type_pair_t
, heap
) **,
3454 struct pointer_map_t
*, struct obstack
*);
3456 /* DFS visit the edge from the callers type pair with state *STATE to
3457 the pair T1, T2 while operating in FOR_MERGING_P mode.
3458 Update the merging status if it is not part of the SCC containing the
3459 callers pair and return it.
3460 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3463 gtc_visit (tree t1
, tree t2
, enum gtc_mode mode
,
3465 VEC(type_pair_t
, heap
) **sccstack
,
3466 struct pointer_map_t
*sccstate
,
3467 struct obstack
*sccstate_obstack
)
3469 struct sccs
*cstate
= NULL
;
3473 /* Check first for the obvious case of pointer identity. */
3477 /* Check that we have two types to compare. */
3478 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
3481 /* If the types have been previously registered and found equal
3483 if (mode
== GTC_MERGE
)
3485 tree leader1
= gimple_lookup_type_leader (t1
);
3486 tree leader2
= gimple_lookup_type_leader (t2
);
3489 || (leader1
&& leader1
== leader2
))
3492 else if (mode
== GTC_DIAG
)
3494 if (TYPE_CANONICAL (t1
)
3495 && TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
))
3499 /* Can't be the same type if the types don't have the same code. */
3500 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3503 /* Can't be the same type if they have different CV qualifiers. */
3504 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
3507 /* Void types are always the same. */
3508 if (TREE_CODE (t1
) == VOID_TYPE
)
3511 /* Do some simple checks before doing three hashtable queries. */
3512 if (INTEGRAL_TYPE_P (t1
)
3513 || SCALAR_FLOAT_TYPE_P (t1
)
3514 || FIXED_POINT_TYPE_P (t1
)
3515 || TREE_CODE (t1
) == VECTOR_TYPE
3516 || TREE_CODE (t1
) == COMPLEX_TYPE
3517 || TREE_CODE (t1
) == OFFSET_TYPE
)
3519 /* Can't be the same type if they have different alignment,
3520 sign, precision or mode. */
3521 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3522 || TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
3523 || TYPE_MODE (t1
) != TYPE_MODE (t2
)
3524 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
3527 if (TREE_CODE (t1
) == INTEGER_TYPE
3528 && (TYPE_IS_SIZETYPE (t1
) != TYPE_IS_SIZETYPE (t2
)
3529 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)))
3532 /* That's all we need to check for float and fixed-point types. */
3533 if (SCALAR_FLOAT_TYPE_P (t1
)
3534 || FIXED_POINT_TYPE_P (t1
))
3537 /* For integral types fall thru to more complex checks. */
3540 else if (AGGREGATE_TYPE_P (t1
) || POINTER_TYPE_P (t1
))
3542 /* Can't be the same type if they have different alignment or mode. */
3543 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3544 || TYPE_MODE (t1
) != TYPE_MODE (t2
))
3548 /* If the hash values of t1 and t2 are different the types can't
3549 possibly be the same. This helps keeping the type-pair hashtable
3550 small, only tracking comparisons for hash collisions. */
3551 if (gimple_type_hash_1 (t1
, mode
) != gimple_type_hash_1 (t2
, mode
))
3554 /* Allocate a new cache entry for this comparison. */
3555 p
= lookup_type_pair (t1
, t2
, >c_visited
, >c_ob
);
3556 if (p
->same_p
[mode
] == 0 || p
->same_p
[mode
] == 1)
3558 /* We have already decided whether T1 and T2 are the
3559 same, return the cached result. */
3560 return p
->same_p
[mode
] == 1;
3563 if ((slot
= pointer_map_contains (sccstate
, p
)) != NULL
)
3564 cstate
= (struct sccs
*)*slot
;
3565 /* Not yet visited. DFS recurse. */
3568 gimple_types_compatible_p_1 (t1
, t2
, mode
, p
,
3569 sccstack
, sccstate
, sccstate_obstack
);
3570 cstate
= (struct sccs
*)* pointer_map_contains (sccstate
, p
);
3571 state
->low
= MIN (state
->low
, cstate
->low
);
3573 /* If the type is still on the SCC stack adjust the parents low. */
3574 if (cstate
->dfsnum
< state
->dfsnum
3575 && cstate
->on_sccstack
)
3576 state
->low
= MIN (cstate
->dfsnum
, state
->low
);
3578 /* Return the current lattice value. We start with an equality
3579 assumption so types part of a SCC will be optimistically
3580 treated equal unless proven otherwise. */
3581 return cstate
->u
.same_p
;
3584 /* Worker for gimple_types_compatible.
3585 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3588 gimple_types_compatible_p_1 (tree t1
, tree t2
, enum gtc_mode mode
,
3590 VEC(type_pair_t
, heap
) **sccstack
,
3591 struct pointer_map_t
*sccstate
,
3592 struct obstack
*sccstate_obstack
)
3596 gcc_assert (p
->same_p
[mode
] == -2);
3598 state
= XOBNEW (sccstate_obstack
, struct sccs
);
3599 *pointer_map_insert (sccstate
, p
) = state
;
3601 VEC_safe_push (type_pair_t
, heap
, *sccstack
, p
);
3602 state
->dfsnum
= gtc_next_dfs_num
++;
3603 state
->low
= state
->dfsnum
;
3604 state
->on_sccstack
= true;
3605 /* Start with an equality assumption. As we DFS recurse into child
3606 SCCs this assumption may get revisited. */
3607 state
->u
.same_p
= 1;
3609 /* If their attributes are not the same they can't be the same type. */
3610 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1
), TYPE_ATTRIBUTES (t2
)))
3611 goto different_types
;
3613 /* Do type-specific comparisons. */
3614 switch (TREE_CODE (t1
))
3618 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
), mode
,
3619 state
, sccstack
, sccstate
, sccstate_obstack
))
3620 goto different_types
;
3624 /* Array types are the same if the element types are the same and
3625 the number of elements are the same. */
3626 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
), mode
,
3627 state
, sccstack
, sccstate
, sccstate_obstack
)
3628 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)
3629 || TYPE_NONALIASED_COMPONENT (t1
) != TYPE_NONALIASED_COMPONENT (t2
))
3630 goto different_types
;
3633 tree i1
= TYPE_DOMAIN (t1
);
3634 tree i2
= TYPE_DOMAIN (t2
);
3636 /* For an incomplete external array, the type domain can be
3637 NULL_TREE. Check this condition also. */
3638 if (i1
== NULL_TREE
&& i2
== NULL_TREE
)
3640 else if (i1
== NULL_TREE
|| i2
== NULL_TREE
)
3641 goto different_types
;
3642 /* If for a complete array type the possibly gimplified sizes
3643 are different the types are different. */
3644 else if (((TYPE_SIZE (i1
) != NULL
) ^ (TYPE_SIZE (i2
) != NULL
))
3647 && !operand_equal_p (TYPE_SIZE (i1
), TYPE_SIZE (i2
), 0)))
3648 goto different_types
;
3651 tree min1
= TYPE_MIN_VALUE (i1
);
3652 tree min2
= TYPE_MIN_VALUE (i2
);
3653 tree max1
= TYPE_MAX_VALUE (i1
);
3654 tree max2
= TYPE_MAX_VALUE (i2
);
3656 /* The minimum/maximum values have to be the same. */
3659 && ((TREE_CODE (min1
) == PLACEHOLDER_EXPR
3660 && TREE_CODE (min2
) == PLACEHOLDER_EXPR
)
3661 || operand_equal_p (min1
, min2
, 0))))
3664 && ((TREE_CODE (max1
) == PLACEHOLDER_EXPR
3665 && TREE_CODE (max2
) == PLACEHOLDER_EXPR
)
3666 || operand_equal_p (max1
, max2
, 0)))))
3669 goto different_types
;
3674 /* Method types should belong to the same class. */
3675 if (!gtc_visit (TYPE_METHOD_BASETYPE (t1
), TYPE_METHOD_BASETYPE (t2
),
3676 mode
, state
, sccstack
, sccstate
, sccstate_obstack
))
3677 goto different_types
;
3682 /* Function types are the same if the return type and arguments types
3684 if ((mode
!= GTC_DIAG
3685 || !gimple_compatible_complete_and_incomplete_subtype_p
3686 (TREE_TYPE (t1
), TREE_TYPE (t2
)))
3687 && !gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
), mode
,
3688 state
, sccstack
, sccstate
, sccstate_obstack
))
3689 goto different_types
;
3691 if (!comp_type_attributes (t1
, t2
))
3692 goto different_types
;
3694 if (TYPE_ARG_TYPES (t1
) == TYPE_ARG_TYPES (t2
))
3698 tree parms1
, parms2
;
3700 for (parms1
= TYPE_ARG_TYPES (t1
), parms2
= TYPE_ARG_TYPES (t2
);
3702 parms1
= TREE_CHAIN (parms1
), parms2
= TREE_CHAIN (parms2
))
3704 if ((mode
== GTC_MERGE
3705 || !gimple_compatible_complete_and_incomplete_subtype_p
3706 (TREE_VALUE (parms1
), TREE_VALUE (parms2
)))
3707 && !gtc_visit (TREE_VALUE (parms1
), TREE_VALUE (parms2
), mode
,
3708 state
, sccstack
, sccstate
, sccstate_obstack
))
3709 goto different_types
;
3712 if (parms1
|| parms2
)
3713 goto different_types
;
3720 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
), mode
,
3721 state
, sccstack
, sccstate
, sccstate_obstack
)
3722 || !gtc_visit (TYPE_OFFSET_BASETYPE (t1
),
3723 TYPE_OFFSET_BASETYPE (t2
), mode
,
3724 state
, sccstack
, sccstate
, sccstate_obstack
))
3725 goto different_types
;
3731 case REFERENCE_TYPE
:
3733 /* If the two pointers have different ref-all attributes,
3734 they can't be the same type. */
3735 if (TYPE_REF_CAN_ALIAS_ALL (t1
) != TYPE_REF_CAN_ALIAS_ALL (t2
))
3736 goto different_types
;
3738 /* If one pointer points to an incomplete type variant of
3739 the other pointed-to type they are the same. */
3740 if (mode
== GTC_DIAG
3741 && gimple_compatible_complete_and_incomplete_subtype_p
3742 (TREE_TYPE (t1
), TREE_TYPE (t2
)))
3745 /* Otherwise, pointer and reference types are the same if the
3746 pointed-to types are the same. */
3747 if (gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
), mode
,
3748 state
, sccstack
, sccstate
, sccstate_obstack
))
3751 goto different_types
;
3755 /* There is only one decltype(nullptr). */
3761 tree min1
= TYPE_MIN_VALUE (t1
);
3762 tree max1
= TYPE_MAX_VALUE (t1
);
3763 tree min2
= TYPE_MIN_VALUE (t2
);
3764 tree max2
= TYPE_MAX_VALUE (t2
);
3765 bool min_equal_p
= false;
3766 bool max_equal_p
= false;
3768 /* If either type has a minimum value, the other type must
3770 if (min1
== NULL_TREE
&& min2
== NULL_TREE
)
3772 else if (min1
&& min2
&& operand_equal_p (min1
, min2
, 0))
3775 /* Likewise, if either type has a maximum value, the other
3776 type must have the same. */
3777 if (max1
== NULL_TREE
&& max2
== NULL_TREE
)
3779 else if (max1
&& max2
&& operand_equal_p (max1
, max2
, 0))
3782 if (!min_equal_p
|| !max_equal_p
)
3783 goto different_types
;
3790 /* FIXME lto, we cannot check bounds on enumeral types because
3791 different front ends will produce different values.
3792 In C, enumeral types are integers, while in C++ each element
3793 will have its own symbolic value. We should decide how enums
3794 are to be represented in GIMPLE and have each front end lower
3798 /* For enumeral types, all the values must be the same. */
3799 if (TYPE_VALUES (t1
) == TYPE_VALUES (t2
))
3802 for (v1
= TYPE_VALUES (t1
), v2
= TYPE_VALUES (t2
);
3804 v1
= TREE_CHAIN (v1
), v2
= TREE_CHAIN (v2
))
3806 tree c1
= TREE_VALUE (v1
);
3807 tree c2
= TREE_VALUE (v2
);
3809 if (TREE_CODE (c1
) == CONST_DECL
)
3810 c1
= DECL_INITIAL (c1
);
3812 if (TREE_CODE (c2
) == CONST_DECL
)
3813 c2
= DECL_INITIAL (c2
);
3815 if (tree_int_cst_equal (c1
, c2
) != 1)
3816 goto different_types
;
3818 if (mode
== GTC_MERGE
&& TREE_PURPOSE (v1
) != TREE_PURPOSE (v2
))
3819 goto different_types
;
3822 /* If one enumeration has more values than the other, they
3823 are not the same. */
3825 goto different_types
;
3832 case QUAL_UNION_TYPE
:
3836 /* The struct tags shall compare equal. */
3837 if (mode
== GTC_MERGE
3838 && !compare_type_names_p (TYPE_MAIN_VARIANT (t1
),
3839 TYPE_MAIN_VARIANT (t2
), false))
3840 goto different_types
;
3842 /* For aggregate types, all the fields must be the same. */
3843 for (f1
= TYPE_FIELDS (t1
), f2
= TYPE_FIELDS (t2
);
3845 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
3847 /* The fields must have the same name, offset and type. */
3848 if ((mode
== GTC_MERGE
3849 && DECL_NAME (f1
) != DECL_NAME (f2
))
3850 || DECL_NONADDRESSABLE_P (f1
) != DECL_NONADDRESSABLE_P (f2
)
3851 || !gimple_compare_field_offset (f1
, f2
)
3852 || !gtc_visit (TREE_TYPE (f1
), TREE_TYPE (f2
), mode
,
3853 state
, sccstack
, sccstate
, sccstate_obstack
))
3854 goto different_types
;
3857 /* If one aggregate has more fields than the other, they
3858 are not the same. */
3860 goto different_types
;
3869 /* Common exit path for types that are not compatible. */
3871 state
->u
.same_p
= 0;
3874 /* Common exit path for types that are compatible. */
3876 gcc_assert (state
->u
.same_p
== 1);
3879 if (state
->low
== state
->dfsnum
)
3883 /* Pop off the SCC and set its cache values to the final
3884 comparison result. */
3887 struct sccs
*cstate
;
3888 x
= VEC_pop (type_pair_t
, *sccstack
);
3889 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
3890 cstate
->on_sccstack
= false;
3891 x
->same_p
[mode
] = state
->u
.same_p
;
3896 return state
->u
.same_p
;
3899 /* Return true iff T1 and T2 are structurally identical. When
3900 FOR_MERGING_P is true the an incomplete type and a complete type
3901 are considered different, otherwise they are considered compatible. */
3904 gimple_types_compatible_p (tree t1
, tree t2
, enum gtc_mode mode
)
3906 VEC(type_pair_t
, heap
) *sccstack
= NULL
;
3907 struct pointer_map_t
*sccstate
;
3908 struct obstack sccstate_obstack
;
3909 type_pair_t p
= NULL
;
3912 /* Before starting to set up the SCC machinery handle simple cases. */
3914 /* Check first for the obvious case of pointer identity. */
3918 /* Check that we have two types to compare. */
3919 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
3922 /* If the types have been previously registered and found equal
3924 if (mode
== GTC_MERGE
)
3926 tree leader1
= gimple_lookup_type_leader (t1
);
3927 tree leader2
= gimple_lookup_type_leader (t2
);
3930 || (leader1
&& leader1
== leader2
))
3933 else if (mode
== GTC_DIAG
)
3935 if (TYPE_CANONICAL (t1
)
3936 && TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
))
3940 /* Can't be the same type if the types don't have the same code. */
3941 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3944 /* Can't be the same type if they have different CV qualifiers. */
3945 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
3948 /* Void types are always the same. */
3949 if (TREE_CODE (t1
) == VOID_TYPE
)
3952 /* Do some simple checks before doing three hashtable queries. */
3953 if (INTEGRAL_TYPE_P (t1
)
3954 || SCALAR_FLOAT_TYPE_P (t1
)
3955 || FIXED_POINT_TYPE_P (t1
)
3956 || TREE_CODE (t1
) == VECTOR_TYPE
3957 || TREE_CODE (t1
) == COMPLEX_TYPE
3958 || TREE_CODE (t1
) == OFFSET_TYPE
)
3960 /* Can't be the same type if they have different alignment,
3961 sign, precision or mode. */
3962 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3963 || TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
3964 || TYPE_MODE (t1
) != TYPE_MODE (t2
)
3965 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
3968 if (TREE_CODE (t1
) == INTEGER_TYPE
3969 && (TYPE_IS_SIZETYPE (t1
) != TYPE_IS_SIZETYPE (t2
)
3970 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)))
3973 /* That's all we need to check for float and fixed-point types. */
3974 if (SCALAR_FLOAT_TYPE_P (t1
)
3975 || FIXED_POINT_TYPE_P (t1
))
3978 /* For integral types fall thru to more complex checks. */
3981 else if (AGGREGATE_TYPE_P (t1
) || POINTER_TYPE_P (t1
))
3983 /* Can't be the same type if they have different alignment or mode. */
3984 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3985 || TYPE_MODE (t1
) != TYPE_MODE (t2
))
3989 /* If the hash values of t1 and t2 are different the types can't
3990 possibly be the same. This helps keeping the type-pair hashtable
3991 small, only tracking comparisons for hash collisions. */
3992 if (gimple_type_hash_1 (t1
, mode
) != gimple_type_hash_1 (t2
, mode
))
3995 /* If we've visited this type pair before (in the case of aggregates
3996 with self-referential types), and we made a decision, return it. */
3997 p
= lookup_type_pair (t1
, t2
, >c_visited
, >c_ob
);
3998 if (p
->same_p
[mode
] == 0 || p
->same_p
[mode
] == 1)
4000 /* We have already decided whether T1 and T2 are the
4001 same, return the cached result. */
4002 return p
->same_p
[mode
] == 1;
4005 /* Now set up the SCC machinery for the comparison. */
4006 gtc_next_dfs_num
= 1;
4007 sccstate
= pointer_map_create ();
4008 gcc_obstack_init (&sccstate_obstack
);
4009 res
= gimple_types_compatible_p_1 (t1
, t2
, mode
, p
,
4010 &sccstack
, sccstate
, &sccstate_obstack
);
4011 VEC_free (type_pair_t
, heap
, sccstack
);
4012 pointer_map_destroy (sccstate
);
4013 obstack_free (&sccstate_obstack
, NULL
);
4020 iterative_hash_gimple_type (tree
, hashval_t
, VEC(tree
, heap
) **,
4021 struct pointer_map_t
*, struct obstack
*,
4024 /* DFS visit the edge from the callers type with state *STATE to T.
4025 Update the callers type hash V with the hash for T if it is not part
4026 of the SCC containing the callers type and return it.
4027 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
4030 visit (tree t
, struct sccs
*state
, hashval_t v
,
4031 VEC (tree
, heap
) **sccstack
,
4032 struct pointer_map_t
*sccstate
,
4033 struct obstack
*sccstate_obstack
, enum gtc_mode mode
)
4035 struct sccs
*cstate
= NULL
;
4036 struct tree_int_map m
;
4039 /* If there is a hash value recorded for this type then it can't
4040 possibly be part of our parent SCC. Simply mix in its hash. */
4042 if ((slot
= htab_find_slot (mode
== GTC_MERGE
4043 ? type_hash_cache
: canonical_type_hash_cache
,
4046 return iterative_hash_hashval_t (((struct tree_int_map
*) *slot
)->to
, v
);
4048 if ((slot
= pointer_map_contains (sccstate
, t
)) != NULL
)
4049 cstate
= (struct sccs
*)*slot
;
4053 /* Not yet visited. DFS recurse. */
4054 tem
= iterative_hash_gimple_type (t
, v
,
4055 sccstack
, sccstate
, sccstate_obstack
,
4058 cstate
= (struct sccs
*)* pointer_map_contains (sccstate
, t
);
4059 state
->low
= MIN (state
->low
, cstate
->low
);
4060 /* If the type is no longer on the SCC stack and thus is not part
4061 of the parents SCC mix in its hash value. Otherwise we will
4062 ignore the type for hashing purposes and return the unaltered
4064 if (!cstate
->on_sccstack
)
4067 if (cstate
->dfsnum
< state
->dfsnum
4068 && cstate
->on_sccstack
)
4069 state
->low
= MIN (cstate
->dfsnum
, state
->low
);
4071 /* We are part of our parents SCC, skip this type during hashing
4072 and return the unaltered hash value. */
4076 /* Hash NAME with the previous hash value V and return it. */
4079 iterative_hash_name (tree name
, hashval_t v
)
4083 if (TREE_CODE (name
) == TYPE_DECL
)
4084 name
= DECL_NAME (name
);
4087 gcc_assert (TREE_CODE (name
) == IDENTIFIER_NODE
);
4088 return iterative_hash_object (IDENTIFIER_HASH_VALUE (name
), v
);
4091 /* Returning a hash value for gimple type TYPE combined with VAL.
4092 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done.
4094 To hash a type we end up hashing in types that are reachable.
4095 Through pointers we can end up with cycles which messes up the
4096 required property that we need to compute the same hash value
4097 for structurally equivalent types. To avoid this we have to
4098 hash all types in a cycle (the SCC) in a commutative way. The
4099 easiest way is to not mix in the hashes of the SCC members at
4100 all. To make this work we have to delay setting the hash
4101 values of the SCC until it is complete. */
4104 iterative_hash_gimple_type (tree type
, hashval_t val
,
4105 VEC(tree
, heap
) **sccstack
,
4106 struct pointer_map_t
*sccstate
,
4107 struct obstack
*sccstate_obstack
,
4114 /* Not visited during this DFS walk. */
4115 gcc_checking_assert (!pointer_map_contains (sccstate
, type
));
4116 state
= XOBNEW (sccstate_obstack
, struct sccs
);
4117 *pointer_map_insert (sccstate
, type
) = state
;
4119 VEC_safe_push (tree
, heap
, *sccstack
, type
);
4120 state
->dfsnum
= next_dfs_num
++;
4121 state
->low
= state
->dfsnum
;
4122 state
->on_sccstack
= true;
4124 /* Combine a few common features of types so that types are grouped into
4125 smaller sets; when searching for existing matching types to merge,
4126 only existing types having the same features as the new type will be
4128 v
= iterative_hash_hashval_t (TREE_CODE (type
), 0);
4129 v
= iterative_hash_hashval_t (TYPE_QUALS (type
), v
);
4130 v
= iterative_hash_hashval_t (TREE_ADDRESSABLE (type
), v
);
4132 /* Do not hash the types size as this will cause differences in
4133 hash values for the complete vs. the incomplete type variant. */
4135 /* Incorporate common features of numerical types. */
4136 if (INTEGRAL_TYPE_P (type
)
4137 || SCALAR_FLOAT_TYPE_P (type
)
4138 || FIXED_POINT_TYPE_P (type
))
4140 v
= iterative_hash_hashval_t (TYPE_PRECISION (type
), v
);
4141 v
= iterative_hash_hashval_t (TYPE_MODE (type
), v
);
4142 v
= iterative_hash_hashval_t (TYPE_UNSIGNED (type
), v
);
4145 /* For pointer and reference types, fold in information about the type
4146 pointed to but do not recurse into possibly incomplete types to
4147 avoid hash differences for complete vs. incomplete types. */
4148 if (POINTER_TYPE_P (type
))
4150 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type
)))
4152 v
= iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type
)), v
);
4153 v
= iterative_hash_name
4154 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type
))), v
);
4157 v
= visit (TREE_TYPE (type
), state
, v
,
4158 sccstack
, sccstate
, sccstate_obstack
, mode
);
4161 /* For integer types hash the types min/max values and the string flag. */
4162 if (TREE_CODE (type
) == INTEGER_TYPE
)
4164 /* OMP lowering can introduce error_mark_node in place of
4165 random local decls in types. */
4166 if (TYPE_MIN_VALUE (type
) != error_mark_node
)
4167 v
= iterative_hash_expr (TYPE_MIN_VALUE (type
), v
);
4168 if (TYPE_MAX_VALUE (type
) != error_mark_node
)
4169 v
= iterative_hash_expr (TYPE_MAX_VALUE (type
), v
);
4170 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
4173 /* For array types hash their domain and the string flag. */
4174 if (TREE_CODE (type
) == ARRAY_TYPE
4175 && TYPE_DOMAIN (type
))
4177 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
4178 v
= visit (TYPE_DOMAIN (type
), state
, v
,
4179 sccstack
, sccstate
, sccstate_obstack
, mode
);
4182 /* Recurse for aggregates with a single element type. */
4183 if (TREE_CODE (type
) == ARRAY_TYPE
4184 || TREE_CODE (type
) == COMPLEX_TYPE
4185 || TREE_CODE (type
) == VECTOR_TYPE
)
4186 v
= visit (TREE_TYPE (type
), state
, v
,
4187 sccstack
, sccstate
, sccstate_obstack
, mode
);
4189 /* Incorporate function return and argument types. */
4190 if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
4195 /* For method types also incorporate their parent class. */
4196 if (TREE_CODE (type
) == METHOD_TYPE
)
4197 v
= visit (TYPE_METHOD_BASETYPE (type
), state
, v
,
4198 sccstack
, sccstate
, sccstate_obstack
, mode
);
4200 /* For result types allow mismatch in completeness. */
4201 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type
)))
4203 v
= iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type
)), v
);
4204 v
= iterative_hash_name
4205 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type
))), v
);
4208 v
= visit (TREE_TYPE (type
), state
, v
,
4209 sccstack
, sccstate
, sccstate_obstack
, mode
);
4211 for (p
= TYPE_ARG_TYPES (type
), na
= 0; p
; p
= TREE_CHAIN (p
))
4213 /* For argument types allow mismatch in completeness. */
4214 if (RECORD_OR_UNION_TYPE_P (TREE_VALUE (p
)))
4216 v
= iterative_hash_hashval_t (TREE_CODE (TREE_VALUE (p
)), v
);
4217 v
= iterative_hash_name
4218 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_VALUE (p
))), v
);
4221 v
= visit (TREE_VALUE (p
), state
, v
,
4222 sccstack
, sccstate
, sccstate_obstack
, mode
);
4226 v
= iterative_hash_hashval_t (na
, v
);
4229 if (TREE_CODE (type
) == RECORD_TYPE
4230 || TREE_CODE (type
) == UNION_TYPE
4231 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
4236 if (mode
== GTC_MERGE
)
4237 v
= iterative_hash_name (TYPE_NAME (TYPE_MAIN_VARIANT (type
)), v
);
4239 for (f
= TYPE_FIELDS (type
), nf
= 0; f
; f
= TREE_CHAIN (f
))
4241 if (mode
== GTC_MERGE
)
4242 v
= iterative_hash_name (DECL_NAME (f
), v
);
4243 v
= visit (TREE_TYPE (f
), state
, v
,
4244 sccstack
, sccstate
, sccstate_obstack
, mode
);
4248 v
= iterative_hash_hashval_t (nf
, v
);
4251 /* Record hash for us. */
4254 /* See if we found an SCC. */
4255 if (state
->low
== state
->dfsnum
)
4259 /* Pop off the SCC and set its hash values. */
4262 struct sccs
*cstate
;
4263 struct tree_int_map
*m
= ggc_alloc_cleared_tree_int_map ();
4264 x
= VEC_pop (tree
, *sccstack
);
4265 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
4266 cstate
->on_sccstack
= false;
4268 m
->to
= cstate
->u
.hash
;
4269 slot
= htab_find_slot (mode
== GTC_MERGE
4270 ? type_hash_cache
: canonical_type_hash_cache
,
4272 gcc_assert (!*slot
);
4278 return iterative_hash_hashval_t (v
, val
);
4282 /* Returns a hash value for P (assumed to be a type). The hash value
4283 is computed using some distinguishing features of the type. Note
4284 that we cannot use pointer hashing here as we may be dealing with
4285 two distinct instances of the same type.
4287 This function should produce the same hash value for two compatible
4288 types according to gimple_types_compatible_p. */
4291 gimple_type_hash_1 (const void *p
, enum gtc_mode mode
)
4293 const_tree t
= (const_tree
) p
;
4294 VEC(tree
, heap
) *sccstack
= NULL
;
4295 struct pointer_map_t
*sccstate
;
4296 struct obstack sccstate_obstack
;
4299 struct tree_int_map m
;
4301 if (mode
== GTC_MERGE
4302 && type_hash_cache
== NULL
)
4303 type_hash_cache
= htab_create_ggc (512, tree_int_map_hash
,
4304 tree_int_map_eq
, NULL
);
4305 else if (mode
== GTC_DIAG
4306 && canonical_type_hash_cache
== NULL
)
4307 canonical_type_hash_cache
= htab_create_ggc (512, tree_int_map_hash
,
4308 tree_int_map_eq
, NULL
);
4310 m
.base
.from
= CONST_CAST_TREE (t
);
4311 if ((slot
= htab_find_slot (mode
== GTC_MERGE
4312 ? type_hash_cache
: canonical_type_hash_cache
,
4315 return iterative_hash_hashval_t (((struct tree_int_map
*) *slot
)->to
, 0);
4317 /* Perform a DFS walk and pre-hash all reachable types. */
4319 sccstate
= pointer_map_create ();
4320 gcc_obstack_init (&sccstate_obstack
);
4321 val
= iterative_hash_gimple_type (CONST_CAST_TREE (t
), 0,
4322 &sccstack
, sccstate
, &sccstate_obstack
,
4324 VEC_free (tree
, heap
, sccstack
);
4325 pointer_map_destroy (sccstate
);
4326 obstack_free (&sccstate_obstack
, NULL
);
4332 gimple_type_hash (const void *p
)
4334 return gimple_type_hash_1 (p
, GTC_MERGE
);
4338 gimple_canonical_type_hash (const void *p
)
4340 return gimple_type_hash_1 (p
, GTC_DIAG
);
4344 /* Returns nonzero if P1 and P2 are equal. */
4347 gimple_type_eq (const void *p1
, const void *p2
)
4349 const_tree t1
= (const_tree
) p1
;
4350 const_tree t2
= (const_tree
) p2
;
4351 return gimple_types_compatible_p (CONST_CAST_TREE (t1
),
4352 CONST_CAST_TREE (t2
), GTC_MERGE
);
4356 /* Register type T in the global type table gimple_types.
4357 If another type T', compatible with T, already existed in
4358 gimple_types then return T', otherwise return T. This is used by
4359 LTO to merge identical types read from different TUs. */
4362 gimple_register_type (tree t
)
4365 gimple_type_leader_entry
*leader
;
4366 tree mv_leader
= NULL_TREE
;
4368 gcc_assert (TYPE_P (t
));
4370 if (!gimple_type_leader
)
4371 gimple_type_leader
= ggc_alloc_cleared_vec_gimple_type_leader_entry_s
4372 (GIMPLE_TYPE_LEADER_SIZE
);
4373 /* If we registered this type before return the cached result. */
4374 leader
= &gimple_type_leader
[TYPE_UID (t
) % GIMPLE_TYPE_LEADER_SIZE
];
4375 if (leader
->type
== t
)
4376 return leader
->leader
;
4378 /* Always register the main variant first. This is important so we
4379 pick up the non-typedef variants as canonical, otherwise we'll end
4380 up taking typedef ids for structure tags during comparison. */
4381 if (TYPE_MAIN_VARIANT (t
) != t
)
4382 mv_leader
= gimple_register_type (TYPE_MAIN_VARIANT (t
));
4384 if (gimple_types
== NULL
)
4385 gimple_types
= htab_create_ggc (16381, gimple_type_hash
, gimple_type_eq
, 0);
4387 slot
= htab_find_slot (gimple_types
, t
, INSERT
);
4389 && *(tree
*)slot
!= t
)
4391 tree new_type
= (tree
) *((tree
*) slot
);
4393 /* Do not merge types with different addressability. */
4394 gcc_assert (TREE_ADDRESSABLE (t
) == TREE_ADDRESSABLE (new_type
));
4396 /* If t is not its main variant then make t unreachable from its
4397 main variant list. Otherwise we'd queue up a lot of duplicates
4399 if (t
!= TYPE_MAIN_VARIANT (t
))
4401 tree tem
= TYPE_MAIN_VARIANT (t
);
4402 while (tem
&& TYPE_NEXT_VARIANT (tem
) != t
)
4403 tem
= TYPE_NEXT_VARIANT (tem
);
4405 TYPE_NEXT_VARIANT (tem
) = TYPE_NEXT_VARIANT (t
);
4406 TYPE_NEXT_VARIANT (t
) = NULL_TREE
;
4409 /* If we are a pointer then remove us from the pointer-to or
4410 reference-to chain. Otherwise we'd queue up a lot of duplicates
4412 if (TREE_CODE (t
) == POINTER_TYPE
)
4414 if (TYPE_POINTER_TO (TREE_TYPE (t
)) == t
)
4415 TYPE_POINTER_TO (TREE_TYPE (t
)) = TYPE_NEXT_PTR_TO (t
);
4418 tree tem
= TYPE_POINTER_TO (TREE_TYPE (t
));
4419 while (tem
&& TYPE_NEXT_PTR_TO (tem
) != t
)
4420 tem
= TYPE_NEXT_PTR_TO (tem
);
4422 TYPE_NEXT_PTR_TO (tem
) = TYPE_NEXT_PTR_TO (t
);
4424 TYPE_NEXT_PTR_TO (t
) = NULL_TREE
;
4426 else if (TREE_CODE (t
) == REFERENCE_TYPE
)
4428 if (TYPE_REFERENCE_TO (TREE_TYPE (t
)) == t
)
4429 TYPE_REFERENCE_TO (TREE_TYPE (t
)) = TYPE_NEXT_REF_TO (t
);
4432 tree tem
= TYPE_REFERENCE_TO (TREE_TYPE (t
));
4433 while (tem
&& TYPE_NEXT_REF_TO (tem
) != t
)
4434 tem
= TYPE_NEXT_REF_TO (tem
);
4436 TYPE_NEXT_REF_TO (tem
) = TYPE_NEXT_REF_TO (t
);
4438 TYPE_NEXT_REF_TO (t
) = NULL_TREE
;
4442 leader
->leader
= new_type
;
4449 /* We're the type leader. Make our TYPE_MAIN_VARIANT valid. */
4450 if (TYPE_MAIN_VARIANT (t
) != t
4451 && TYPE_MAIN_VARIANT (t
) != mv_leader
)
4453 /* Remove us from our main variant list as we are not the variant
4454 leader and the variant leader will change. */
4455 tree tem
= TYPE_MAIN_VARIANT (t
);
4456 while (tem
&& TYPE_NEXT_VARIANT (tem
) != t
)
4457 tem
= TYPE_NEXT_VARIANT (tem
);
4459 TYPE_NEXT_VARIANT (tem
) = TYPE_NEXT_VARIANT (t
);
4460 TYPE_NEXT_VARIANT (t
) = NULL_TREE
;
4461 /* Adjust our main variant. Linking us into its variant list
4462 will happen at fixup time. */
4463 TYPE_MAIN_VARIANT (t
) = mv_leader
;
4472 /* Returns nonzero if P1 and P2 are equal. */
4475 gimple_canonical_type_eq (const void *p1
, const void *p2
)
4477 const_tree t1
= (const_tree
) p1
;
4478 const_tree t2
= (const_tree
) p2
;
4479 return gimple_types_compatible_p (CONST_CAST_TREE (t1
),
4480 CONST_CAST_TREE (t2
), GTC_DIAG
);
4483 /* Register type T in the global type table gimple_types.
4484 If another type T', compatible with T, already existed in
4485 gimple_types then return T', otherwise return T. This is used by
4486 LTO to merge identical types read from different TUs. */
4489 gimple_register_canonical_type (tree t
)
4494 gcc_assert (TYPE_P (t
));
4496 if (TYPE_CANONICAL (t
))
4497 return TYPE_CANONICAL (t
);
4499 /* Always register the type itself first so that if it turns out
4500 to be the canonical type it will be the one we merge to as well. */
4501 t
= gimple_register_type (t
);
4503 /* Always register the main variant first. This is important so we
4504 pick up the non-typedef variants as canonical, otherwise we'll end
4505 up taking typedef ids for structure tags during comparison. */
4506 if (TYPE_MAIN_VARIANT (t
) != t
)
4507 gimple_register_canonical_type (TYPE_MAIN_VARIANT (t
));
4509 if (gimple_canonical_types
== NULL
)
4510 gimple_canonical_types
= htab_create_ggc (16381, gimple_canonical_type_hash
,
4511 gimple_canonical_type_eq
, 0);
4513 slot
= htab_find_slot (gimple_canonical_types
, t
, INSERT
);
4515 && *(tree
*)slot
!= t
)
4517 tree new_type
= (tree
) *((tree
*) slot
);
4519 TYPE_CANONICAL (t
) = new_type
;
4524 TYPE_CANONICAL (t
) = t
;
4528 /* Also cache the canonical type in the non-leaders. */
4529 TYPE_CANONICAL (orig_t
) = t
;
4535 /* Show statistics on references to the global type table gimple_types. */
4538 print_gimple_types_stats (void)
4541 fprintf (stderr
, "GIMPLE type table: size %ld, %ld elements, "
4542 "%ld searches, %ld collisions (ratio: %f)\n",
4543 (long) htab_size (gimple_types
),
4544 (long) htab_elements (gimple_types
),
4545 (long) gimple_types
->searches
,
4546 (long) gimple_types
->collisions
,
4547 htab_collisions (gimple_types
));
4549 fprintf (stderr
, "GIMPLE type table is empty\n");
4550 if (type_hash_cache
)
4551 fprintf (stderr
, "GIMPLE type hash table: size %ld, %ld elements, "
4552 "%ld searches, %ld collisions (ratio: %f)\n",
4553 (long) htab_size (type_hash_cache
),
4554 (long) htab_elements (type_hash_cache
),
4555 (long) type_hash_cache
->searches
,
4556 (long) type_hash_cache
->collisions
,
4557 htab_collisions (type_hash_cache
));
4559 fprintf (stderr
, "GIMPLE type hash table is empty\n");
4560 if (gimple_canonical_types
)
4561 fprintf (stderr
, "GIMPLE canonical type table: size %ld, %ld elements, "
4562 "%ld searches, %ld collisions (ratio: %f)\n",
4563 (long) htab_size (gimple_canonical_types
),
4564 (long) htab_elements (gimple_canonical_types
),
4565 (long) gimple_canonical_types
->searches
,
4566 (long) gimple_canonical_types
->collisions
,
4567 htab_collisions (gimple_canonical_types
));
4569 fprintf (stderr
, "GIMPLE canonical type table is empty\n");
4570 if (canonical_type_hash_cache
)
4571 fprintf (stderr
, "GIMPLE canonical type hash table: size %ld, %ld elements, "
4572 "%ld searches, %ld collisions (ratio: %f)\n",
4573 (long) htab_size (canonical_type_hash_cache
),
4574 (long) htab_elements (canonical_type_hash_cache
),
4575 (long) canonical_type_hash_cache
->searches
,
4576 (long) canonical_type_hash_cache
->collisions
,
4577 htab_collisions (canonical_type_hash_cache
));
4579 fprintf (stderr
, "GIMPLE canonical type hash table is empty\n");
4581 fprintf (stderr
, "GIMPLE type comparison table: size %ld, %ld "
4582 "elements, %ld searches, %ld collisions (ratio: %f)\n",
4583 (long) htab_size (gtc_visited
),
4584 (long) htab_elements (gtc_visited
),
4585 (long) gtc_visited
->searches
,
4586 (long) gtc_visited
->collisions
,
4587 htab_collisions (gtc_visited
));
4589 fprintf (stderr
, "GIMPLE type comparison table is empty\n");
4592 /* Free the gimple type hashtables used for LTO type merging. */
4595 free_gimple_type_tables (void)
4597 /* Last chance to print stats for the tables. */
4598 if (flag_lto_report
)
4599 print_gimple_types_stats ();
4603 htab_delete (gimple_types
);
4604 gimple_types
= NULL
;
4606 if (gimple_canonical_types
)
4608 htab_delete (gimple_canonical_types
);
4609 gimple_canonical_types
= NULL
;
4611 if (type_hash_cache
)
4613 htab_delete (type_hash_cache
);
4614 type_hash_cache
= NULL
;
4616 if (canonical_type_hash_cache
)
4618 htab_delete (canonical_type_hash_cache
);
4619 canonical_type_hash_cache
= NULL
;
4623 htab_delete (gtc_visited
);
4624 obstack_free (>c_ob
, NULL
);
4627 gimple_type_leader
= NULL
;
4631 /* Return a type the same as TYPE except unsigned or
4632 signed according to UNSIGNEDP. */
4635 gimple_signed_or_unsigned_type (bool unsignedp
, tree type
)
4639 type1
= TYPE_MAIN_VARIANT (type
);
4640 if (type1
== signed_char_type_node
4641 || type1
== char_type_node
4642 || type1
== unsigned_char_type_node
)
4643 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4644 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
4645 return unsignedp
? unsigned_type_node
: integer_type_node
;
4646 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
4647 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4648 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
4649 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4650 if (type1
== long_long_integer_type_node
4651 || type1
== long_long_unsigned_type_node
)
4653 ? long_long_unsigned_type_node
4654 : long_long_integer_type_node
;
4655 if (int128_integer_type_node
&& (type1
== int128_integer_type_node
|| type1
== int128_unsigned_type_node
))
4657 ? int128_unsigned_type_node
4658 : int128_integer_type_node
;
4659 #if HOST_BITS_PER_WIDE_INT >= 64
4660 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
4661 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4663 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
4664 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4665 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
4666 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4667 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
4668 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4669 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
4670 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4672 #define GIMPLE_FIXED_TYPES(NAME) \
4673 if (type1 == short_ ## NAME ## _type_node \
4674 || type1 == unsigned_short_ ## NAME ## _type_node) \
4675 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
4676 : short_ ## NAME ## _type_node; \
4677 if (type1 == NAME ## _type_node \
4678 || type1 == unsigned_ ## NAME ## _type_node) \
4679 return unsignedp ? unsigned_ ## NAME ## _type_node \
4680 : NAME ## _type_node; \
4681 if (type1 == long_ ## NAME ## _type_node \
4682 || type1 == unsigned_long_ ## NAME ## _type_node) \
4683 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
4684 : long_ ## NAME ## _type_node; \
4685 if (type1 == long_long_ ## NAME ## _type_node \
4686 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
4687 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
4688 : long_long_ ## NAME ## _type_node;
4690 #define GIMPLE_FIXED_MODE_TYPES(NAME) \
4691 if (type1 == NAME ## _type_node \
4692 || type1 == u ## NAME ## _type_node) \
4693 return unsignedp ? u ## NAME ## _type_node \
4694 : NAME ## _type_node;
4696 #define GIMPLE_FIXED_TYPES_SAT(NAME) \
4697 if (type1 == sat_ ## short_ ## NAME ## _type_node \
4698 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
4699 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
4700 : sat_ ## short_ ## NAME ## _type_node; \
4701 if (type1 == sat_ ## NAME ## _type_node \
4702 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
4703 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
4704 : sat_ ## NAME ## _type_node; \
4705 if (type1 == sat_ ## long_ ## NAME ## _type_node \
4706 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
4707 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
4708 : sat_ ## long_ ## NAME ## _type_node; \
4709 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
4710 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
4711 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
4712 : sat_ ## long_long_ ## NAME ## _type_node;
4714 #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
4715 if (type1 == sat_ ## NAME ## _type_node \
4716 || type1 == sat_ ## u ## NAME ## _type_node) \
4717 return unsignedp ? sat_ ## u ## NAME ## _type_node \
4718 : sat_ ## NAME ## _type_node;
4720 GIMPLE_FIXED_TYPES (fract
);
4721 GIMPLE_FIXED_TYPES_SAT (fract
);
4722 GIMPLE_FIXED_TYPES (accum
);
4723 GIMPLE_FIXED_TYPES_SAT (accum
);
4725 GIMPLE_FIXED_MODE_TYPES (qq
);
4726 GIMPLE_FIXED_MODE_TYPES (hq
);
4727 GIMPLE_FIXED_MODE_TYPES (sq
);
4728 GIMPLE_FIXED_MODE_TYPES (dq
);
4729 GIMPLE_FIXED_MODE_TYPES (tq
);
4730 GIMPLE_FIXED_MODE_TYPES_SAT (qq
);
4731 GIMPLE_FIXED_MODE_TYPES_SAT (hq
);
4732 GIMPLE_FIXED_MODE_TYPES_SAT (sq
);
4733 GIMPLE_FIXED_MODE_TYPES_SAT (dq
);
4734 GIMPLE_FIXED_MODE_TYPES_SAT (tq
);
4735 GIMPLE_FIXED_MODE_TYPES (ha
);
4736 GIMPLE_FIXED_MODE_TYPES (sa
);
4737 GIMPLE_FIXED_MODE_TYPES (da
);
4738 GIMPLE_FIXED_MODE_TYPES (ta
);
4739 GIMPLE_FIXED_MODE_TYPES_SAT (ha
);
4740 GIMPLE_FIXED_MODE_TYPES_SAT (sa
);
4741 GIMPLE_FIXED_MODE_TYPES_SAT (da
);
4742 GIMPLE_FIXED_MODE_TYPES_SAT (ta
);
4744 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
4745 the precision; they have precision set to match their range, but
4746 may use a wider mode to match an ABI. If we change modes, we may
4747 wind up with bad conversions. For INTEGER_TYPEs in C, must check
4748 the precision as well, so as to yield correct results for
4749 bit-field types. C++ does not have these separate bit-field
4750 types, and producing a signed or unsigned variant of an
4751 ENUMERAL_TYPE may cause other problems as well. */
4752 if (!INTEGRAL_TYPE_P (type
)
4753 || TYPE_UNSIGNED (type
) == unsignedp
)
4756 #define TYPE_OK(node) \
4757 (TYPE_MODE (type) == TYPE_MODE (node) \
4758 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
4759 if (TYPE_OK (signed_char_type_node
))
4760 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4761 if (TYPE_OK (integer_type_node
))
4762 return unsignedp
? unsigned_type_node
: integer_type_node
;
4763 if (TYPE_OK (short_integer_type_node
))
4764 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4765 if (TYPE_OK (long_integer_type_node
))
4766 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4767 if (TYPE_OK (long_long_integer_type_node
))
4769 ? long_long_unsigned_type_node
4770 : long_long_integer_type_node
);
4771 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
4773 ? int128_unsigned_type_node
4774 : int128_integer_type_node
);
4776 #if HOST_BITS_PER_WIDE_INT >= 64
4777 if (TYPE_OK (intTI_type_node
))
4778 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4780 if (TYPE_OK (intDI_type_node
))
4781 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4782 if (TYPE_OK (intSI_type_node
))
4783 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4784 if (TYPE_OK (intHI_type_node
))
4785 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4786 if (TYPE_OK (intQI_type_node
))
4787 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4789 #undef GIMPLE_FIXED_TYPES
4790 #undef GIMPLE_FIXED_MODE_TYPES
4791 #undef GIMPLE_FIXED_TYPES_SAT
4792 #undef GIMPLE_FIXED_MODE_TYPES_SAT
4795 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
4799 /* Return an unsigned type the same as TYPE in other respects. */
4802 gimple_unsigned_type (tree type
)
4804 return gimple_signed_or_unsigned_type (true, type
);
4808 /* Return a signed type the same as TYPE in other respects. */
4811 gimple_signed_type (tree type
)
4813 return gimple_signed_or_unsigned_type (false, type
);
4817 /* Return the typed-based alias set for T, which may be an expression
4818 or a type. Return -1 if we don't do anything special. */
4821 gimple_get_alias_set (tree t
)
4825 /* Permit type-punning when accessing a union, provided the access
4826 is directly through the union. For example, this code does not
4827 permit taking the address of a union member and then storing
4828 through it. Even the type-punning allowed here is a GCC
4829 extension, albeit a common and useful one; the C standard says
4830 that such accesses have implementation-defined behavior. */
4832 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4833 u
= TREE_OPERAND (u
, 0))
4834 if (TREE_CODE (u
) == COMPONENT_REF
4835 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4838 /* That's all the expressions we handle specially. */
4842 /* For convenience, follow the C standard when dealing with
4843 character types. Any object may be accessed via an lvalue that
4844 has character type. */
4845 if (t
== char_type_node
4846 || t
== signed_char_type_node
4847 || t
== unsigned_char_type_node
)
4850 /* Allow aliasing between signed and unsigned variants of the same
4851 type. We treat the signed variant as canonical. */
4852 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4854 tree t1
= gimple_signed_type (t
);
4856 /* t1 == t can happen for boolean nodes which are always unsigned. */
4858 return get_alias_set (t1
);
4865 /* Data structure used to count the number of dereferences to PTR
4866 inside an expression. */
4870 unsigned num_stores
;
4874 /* Helper for count_uses_and_derefs. Called by walk_tree to look for
4875 (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA. */
4878 count_ptr_derefs (tree
*tp
, int *walk_subtrees
, void *data
)
4880 struct walk_stmt_info
*wi_p
= (struct walk_stmt_info
*) data
;
4881 struct count_ptr_d
*count_p
= (struct count_ptr_d
*) wi_p
->info
;
4883 /* Do not walk inside ADDR_EXPR nodes. In the expression &ptr->fld,
4884 pointer 'ptr' is *not* dereferenced, it is simply used to compute
4885 the address of 'fld' as 'ptr + offsetof(fld)'. */
4886 if (TREE_CODE (*tp
) == ADDR_EXPR
)
4892 if (TREE_CODE (*tp
) == MEM_REF
&& TREE_OPERAND (*tp
, 0) == count_p
->ptr
)
4895 count_p
->num_stores
++;
4897 count_p
->num_loads
++;
4903 /* Count the number of direct and indirect uses for pointer PTR in
4904 statement STMT. The number of direct uses is stored in
4905 *NUM_USES_P. Indirect references are counted separately depending
4906 on whether they are store or load operations. The counts are
4907 stored in *NUM_STORES_P and *NUM_LOADS_P. */
4910 count_uses_and_derefs (tree ptr
, gimple stmt
, unsigned *num_uses_p
,
4911 unsigned *num_loads_p
, unsigned *num_stores_p
)
4920 /* Find out the total number of uses of PTR in STMT. */
4921 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, i
, SSA_OP_USE
)
4925 /* Now count the number of indirect references to PTR. This is
4926 truly awful, but we don't have much choice. There are no parent
4927 pointers inside INDIRECT_REFs, so an expression like
4928 '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to
4929 find all the indirect and direct uses of x_1 inside. The only
4930 shortcut we can take is the fact that GIMPLE only allows
4931 INDIRECT_REFs inside the expressions below. */
4932 if (is_gimple_assign (stmt
)
4933 || gimple_code (stmt
) == GIMPLE_RETURN
4934 || gimple_code (stmt
) == GIMPLE_ASM
4935 || is_gimple_call (stmt
))
4937 struct walk_stmt_info wi
;
4938 struct count_ptr_d count
;
4941 count
.num_stores
= 0;
4942 count
.num_loads
= 0;
4944 memset (&wi
, 0, sizeof (wi
));
4946 walk_gimple_op (stmt
, count_ptr_derefs
, &wi
);
4948 *num_stores_p
= count
.num_stores
;
4949 *num_loads_p
= count
.num_loads
;
4952 gcc_assert (*num_uses_p
>= *num_loads_p
+ *num_stores_p
);
4955 /* From a tree operand OP return the base of a load or store operation
4956 or NULL_TREE if OP is not a load or a store. */
4959 get_base_loadstore (tree op
)
4961 while (handled_component_p (op
))
4962 op
= TREE_OPERAND (op
, 0);
4964 || INDIRECT_REF_P (op
)
4965 || TREE_CODE (op
) == MEM_REF
4966 || TREE_CODE (op
) == TARGET_MEM_REF
)
4971 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
4972 VISIT_ADDR if non-NULL on loads, store and address-taken operands
4973 passing the STMT, the base of the operand and DATA to it. The base
4974 will be either a decl, an indirect reference (including TARGET_MEM_REF)
4975 or the argument of an address expression.
4976 Returns the results of these callbacks or'ed. */
4979 walk_stmt_load_store_addr_ops (gimple stmt
, void *data
,
4980 bool (*visit_load
)(gimple
, tree
, void *),
4981 bool (*visit_store
)(gimple
, tree
, void *),
4982 bool (*visit_addr
)(gimple
, tree
, void *))
4986 if (gimple_assign_single_p (stmt
))
4991 lhs
= get_base_loadstore (gimple_assign_lhs (stmt
));
4993 ret
|= visit_store (stmt
, lhs
, data
);
4995 rhs
= gimple_assign_rhs1 (stmt
);
4996 while (handled_component_p (rhs
))
4997 rhs
= TREE_OPERAND (rhs
, 0);
5000 if (TREE_CODE (rhs
) == ADDR_EXPR
)
5001 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
5002 else if (TREE_CODE (rhs
) == TARGET_MEM_REF
5003 && TREE_CODE (TMR_BASE (rhs
)) == ADDR_EXPR
)
5004 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (rhs
), 0), data
);
5005 else if (TREE_CODE (rhs
) == OBJ_TYPE_REF
5006 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs
)) == ADDR_EXPR
)
5007 ret
|= visit_addr (stmt
, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs
),
5009 lhs
= gimple_assign_lhs (stmt
);
5010 if (TREE_CODE (lhs
) == TARGET_MEM_REF
5011 && TREE_CODE (TMR_BASE (lhs
)) == ADDR_EXPR
)
5012 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (lhs
), 0), data
);
5016 rhs
= get_base_loadstore (rhs
);
5018 ret
|= visit_load (stmt
, rhs
, data
);
5022 && (is_gimple_assign (stmt
)
5023 || gimple_code (stmt
) == GIMPLE_COND
))
5025 for (i
= 0; i
< gimple_num_ops (stmt
); ++i
)
5026 if (gimple_op (stmt
, i
)
5027 && TREE_CODE (gimple_op (stmt
, i
)) == ADDR_EXPR
)
5028 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_op (stmt
, i
), 0), data
);
5030 else if (is_gimple_call (stmt
))
5034 tree lhs
= gimple_call_lhs (stmt
);
5037 lhs
= get_base_loadstore (lhs
);
5039 ret
|= visit_store (stmt
, lhs
, data
);
5042 if (visit_load
|| visit_addr
)
5043 for (i
= 0; i
< gimple_call_num_args (stmt
); ++i
)
5045 tree rhs
= gimple_call_arg (stmt
, i
);
5047 && TREE_CODE (rhs
) == ADDR_EXPR
)
5048 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
5049 else if (visit_load
)
5051 rhs
= get_base_loadstore (rhs
);
5053 ret
|= visit_load (stmt
, rhs
, data
);
5057 && gimple_call_chain (stmt
)
5058 && TREE_CODE (gimple_call_chain (stmt
)) == ADDR_EXPR
)
5059 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_call_chain (stmt
), 0),
5062 && gimple_call_return_slot_opt_p (stmt
)
5063 && gimple_call_lhs (stmt
) != NULL_TREE
5064 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt
))))
5065 ret
|= visit_addr (stmt
, gimple_call_lhs (stmt
), data
);
5067 else if (gimple_code (stmt
) == GIMPLE_ASM
)
5070 const char *constraint
;
5071 const char **oconstraints
;
5072 bool allows_mem
, allows_reg
, is_inout
;
5073 noutputs
= gimple_asm_noutputs (stmt
);
5074 oconstraints
= XALLOCAVEC (const char *, noutputs
);
5075 if (visit_store
|| visit_addr
)
5076 for (i
= 0; i
< gimple_asm_noutputs (stmt
); ++i
)
5078 tree link
= gimple_asm_output_op (stmt
, i
);
5079 tree op
= get_base_loadstore (TREE_VALUE (link
));
5080 if (op
&& visit_store
)
5081 ret
|= visit_store (stmt
, op
, data
);
5084 constraint
= TREE_STRING_POINTER
5085 (TREE_VALUE (TREE_PURPOSE (link
)));
5086 oconstraints
[i
] = constraint
;
5087 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
,
5088 &allows_reg
, &is_inout
);
5089 if (op
&& !allows_reg
&& allows_mem
)
5090 ret
|= visit_addr (stmt
, op
, data
);
5093 if (visit_load
|| visit_addr
)
5094 for (i
= 0; i
< gimple_asm_ninputs (stmt
); ++i
)
5096 tree link
= gimple_asm_input_op (stmt
, i
);
5097 tree op
= TREE_VALUE (link
);
5099 && TREE_CODE (op
) == ADDR_EXPR
)
5100 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5101 else if (visit_load
|| visit_addr
)
5103 op
= get_base_loadstore (op
);
5107 ret
|= visit_load (stmt
, op
, data
);
5110 constraint
= TREE_STRING_POINTER
5111 (TREE_VALUE (TREE_PURPOSE (link
)));
5112 parse_input_constraint (&constraint
, 0, 0, noutputs
,
5114 &allows_mem
, &allows_reg
);
5115 if (!allows_reg
&& allows_mem
)
5116 ret
|= visit_addr (stmt
, op
, data
);
5122 else if (gimple_code (stmt
) == GIMPLE_RETURN
)
5124 tree op
= gimple_return_retval (stmt
);
5128 && TREE_CODE (op
) == ADDR_EXPR
)
5129 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5130 else if (visit_load
)
5132 op
= get_base_loadstore (op
);
5134 ret
|= visit_load (stmt
, op
, data
);
5139 && gimple_code (stmt
) == GIMPLE_PHI
)
5141 for (i
= 0; i
< gimple_phi_num_args (stmt
); ++i
)
5143 tree op
= PHI_ARG_DEF (stmt
, i
);
5144 if (TREE_CODE (op
) == ADDR_EXPR
)
5145 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5152 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
5153 should make a faster clone for this case. */
5156 walk_stmt_load_store_ops (gimple stmt
, void *data
,
5157 bool (*visit_load
)(gimple
, tree
, void *),
5158 bool (*visit_store
)(gimple
, tree
, void *))
5160 return walk_stmt_load_store_addr_ops (stmt
, data
,
5161 visit_load
, visit_store
, NULL
);
5164 /* Helper for gimple_ior_addresses_taken_1. */
5167 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED
,
5168 tree addr
, void *data
)
5170 bitmap addresses_taken
= (bitmap
)data
;
5171 addr
= get_base_address (addr
);
5175 bitmap_set_bit (addresses_taken
, DECL_UID (addr
));
5181 /* Set the bit for the uid of all decls that have their address taken
5182 in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
5183 were any in this stmt. */
5186 gimple_ior_addresses_taken (bitmap addresses_taken
, gimple stmt
)
5188 return walk_stmt_load_store_addr_ops (stmt
, addresses_taken
, NULL
, NULL
,
5189 gimple_ior_addresses_taken_1
);
5193 /* Return a printable name for symbol DECL. */
5196 gimple_decl_printable_name (tree decl
, int verbosity
)
5198 if (!DECL_NAME (decl
))
5201 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
5203 const char *str
, *mangled_str
;
5204 int dmgl_opts
= DMGL_NO_OPTS
;
5208 dmgl_opts
= DMGL_VERBOSE
5212 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5213 dmgl_opts
|= DMGL_PARAMS
;
5216 mangled_str
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5217 str
= cplus_demangle_v3 (mangled_str
, dmgl_opts
);
5218 return (str
) ? str
: mangled_str
;
5221 return IDENTIFIER_POINTER (DECL_NAME (decl
));
5224 /* Return true when STMT is builtins call to CODE. */
5227 gimple_call_builtin_p (gimple stmt
, enum built_in_function code
)
5230 return (is_gimple_call (stmt
)
5231 && (fndecl
= gimple_call_fndecl (stmt
)) != NULL
5232 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
5233 && DECL_FUNCTION_CODE (fndecl
) == code
);
5236 /* Return true if STMT clobbers memory. STMT is required to be a
5240 gimple_asm_clobbers_memory_p (const_gimple stmt
)
5244 for (i
= 0; i
< gimple_asm_nclobbers (stmt
); i
++)
5246 tree op
= gimple_asm_clobber_op (stmt
, i
);
5247 if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op
)), "memory") == 0)
5253 #include "gt-gimple.h"