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"
33 #include "diagnostic.h"
34 #include "tree-flow.h"
35 #include "value-prof.h"
39 #include "langhooks.h"
41 /* Global type table. FIXME lto, it should be possible to re-use some
42 of the type hashing routines in tree.c (type_hash_canon, type_hash_lookup,
43 etc), but those assume that types were built with the various
44 build_*_type routines which is not the case with the streamer. */
45 static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
47 static GTY((if_marked ("ggc_marked_p"), param_is (union tree_node
)))
48 htab_t gimple_canonical_types
;
49 static GTY((if_marked ("tree_int_map_marked_p"), param_is (struct tree_int_map
)))
50 htab_t type_hash_cache
;
52 /* Global type comparison cache. This is by TYPE_UID for space efficiency
53 and thus cannot use and does not need GC. */
54 static htab_t gtc_visited
;
55 static struct obstack gtc_ob
;
57 /* All the tuples have their operand vector (if present) at the very bottom
58 of the structure. Therefore, the offset required to find the
59 operands vector the size of the structure minus the size of the 1
60 element tree array at the end (see gimple_ops). */
61 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \
62 (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0),
63 EXPORTED_CONST
size_t gimple_ops_offset_
[] = {
64 #include "gsstruct.def"
68 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof(struct STRUCT),
69 static const size_t gsstruct_code_size
[] = {
70 #include "gsstruct.def"
74 #define DEFGSCODE(SYM, NAME, GSSCODE) NAME,
75 const char *const gimple_code_name
[] = {
80 #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE,
81 EXPORTED_CONST
enum gimple_statement_structure_enum gss_for_code_
[] = {
86 #ifdef GATHER_STATISTICS
89 int gimple_alloc_counts
[(int) gimple_alloc_kind_all
];
90 int gimple_alloc_sizes
[(int) gimple_alloc_kind_all
];
92 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */
93 static const char * const gimple_alloc_kind_names
[] = {
101 #endif /* GATHER_STATISTICS */
103 /* A cache of gimple_seq objects. Sequences are created and destroyed
104 fairly often during gimplification. */
105 static GTY ((deletable
)) struct gimple_seq_d
*gimple_seq_cache
;
107 /* Private API manipulation functions shared only with some
109 extern void gimple_set_stored_syms (gimple
, bitmap
, bitmap_obstack
*);
110 extern void gimple_set_loaded_syms (gimple
, bitmap
, bitmap_obstack
*);
112 /* Gimple tuple constructors.
113 Note: Any constructor taking a ``gimple_seq'' as a parameter, can
114 be passed a NULL to start with an empty sequence. */
116 /* Set the code for statement G to CODE. */
119 gimple_set_code (gimple g
, enum gimple_code code
)
121 g
->gsbase
.code
= code
;
124 /* Return the number of bytes needed to hold a GIMPLE statement with
128 gimple_size (enum gimple_code code
)
130 return gsstruct_code_size
[gss_for_code (code
)];
133 /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
137 gimple_alloc_stat (enum gimple_code code
, unsigned num_ops MEM_STAT_DECL
)
142 size
= gimple_size (code
);
144 size
+= sizeof (tree
) * (num_ops
- 1);
146 #ifdef GATHER_STATISTICS
148 enum gimple_alloc_kind kind
= gimple_alloc_kind (code
);
149 gimple_alloc_counts
[(int) kind
]++;
150 gimple_alloc_sizes
[(int) kind
] += size
;
154 stmt
= ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT
);
155 gimple_set_code (stmt
, code
);
156 gimple_set_num_ops (stmt
, num_ops
);
158 /* Do not call gimple_set_modified here as it has other side
159 effects and this tuple is still not completely built. */
160 stmt
->gsbase
.modified
= 1;
165 /* Set SUBCODE to be the code of the expression computed by statement G. */
168 gimple_set_subcode (gimple g
, unsigned subcode
)
170 /* We only have 16 bits for the RHS code. Assert that we are not
172 gcc_assert (subcode
< (1 << 16));
173 g
->gsbase
.subcode
= subcode
;
178 /* Build a tuple with operands. CODE is the statement to build (which
179 must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the sub-code
180 for the new tuple. NUM_OPS is the number of operands to allocate. */
182 #define gimple_build_with_ops(c, s, n) \
183 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
186 gimple_build_with_ops_stat (enum gimple_code code
, unsigned subcode
,
187 unsigned num_ops MEM_STAT_DECL
)
189 gimple s
= gimple_alloc_stat (code
, num_ops PASS_MEM_STAT
);
190 gimple_set_subcode (s
, subcode
);
196 /* Build a GIMPLE_RETURN statement returning RETVAL. */
199 gimple_build_return (tree retval
)
201 gimple s
= gimple_build_with_ops (GIMPLE_RETURN
, ERROR_MARK
, 1);
203 gimple_return_set_retval (s
, retval
);
207 /* Reset alias information on call S. */
210 gimple_call_reset_alias_info (gimple s
)
212 if (gimple_call_flags (s
) & ECF_CONST
)
213 memset (gimple_call_use_set (s
), 0, sizeof (struct pt_solution
));
215 pt_solution_reset (gimple_call_use_set (s
));
216 if (gimple_call_flags (s
) & (ECF_CONST
|ECF_PURE
|ECF_NOVOPS
))
217 memset (gimple_call_clobber_set (s
), 0, sizeof (struct pt_solution
));
219 pt_solution_reset (gimple_call_clobber_set (s
));
222 /* Helper for gimple_build_call, gimple_build_call_vec and
223 gimple_build_call_from_tree. Build the basic components of a
224 GIMPLE_CALL statement to function FN with NARGS arguments. */
227 gimple_build_call_1 (tree fn
, unsigned nargs
)
229 gimple s
= gimple_build_with_ops (GIMPLE_CALL
, ERROR_MARK
, nargs
+ 3);
230 if (TREE_CODE (fn
) == FUNCTION_DECL
)
231 fn
= build_fold_addr_expr (fn
);
232 gimple_set_op (s
, 1, fn
);
233 gimple_call_reset_alias_info (s
);
238 /* Build a GIMPLE_CALL statement to function FN with the arguments
239 specified in vector ARGS. */
242 gimple_build_call_vec (tree fn
, VEC(tree
, heap
) *args
)
245 unsigned nargs
= VEC_length (tree
, args
);
246 gimple call
= gimple_build_call_1 (fn
, nargs
);
248 for (i
= 0; i
< nargs
; i
++)
249 gimple_call_set_arg (call
, i
, VEC_index (tree
, args
, i
));
255 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
256 arguments. The ... are the arguments. */
259 gimple_build_call (tree fn
, unsigned nargs
, ...)
265 gcc_assert (TREE_CODE (fn
) == FUNCTION_DECL
|| is_gimple_call_addr (fn
));
267 call
= gimple_build_call_1 (fn
, nargs
);
269 va_start (ap
, nargs
);
270 for (i
= 0; i
< nargs
; i
++)
271 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
278 /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
279 assumed to be in GIMPLE form already. Minimal checking is done of
283 gimple_build_call_from_tree (tree t
)
287 tree fndecl
= get_callee_fndecl (t
);
289 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
291 nargs
= call_expr_nargs (t
);
292 call
= gimple_build_call_1 (fndecl
? fndecl
: CALL_EXPR_FN (t
), nargs
);
294 for (i
= 0; i
< nargs
; i
++)
295 gimple_call_set_arg (call
, i
, CALL_EXPR_ARG (t
, i
));
297 gimple_set_block (call
, TREE_BLOCK (t
));
299 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
300 gimple_call_set_chain (call
, CALL_EXPR_STATIC_CHAIN (t
));
301 gimple_call_set_tail (call
, CALL_EXPR_TAILCALL (t
));
302 gimple_call_set_cannot_inline (call
, CALL_CANNOT_INLINE_P (t
));
303 gimple_call_set_return_slot_opt (call
, CALL_EXPR_RETURN_SLOT_OPT (t
));
304 gimple_call_set_from_thunk (call
, CALL_FROM_THUNK_P (t
));
305 gimple_call_set_va_arg_pack (call
, CALL_EXPR_VA_ARG_PACK (t
));
306 gimple_call_set_nothrow (call
, TREE_NOTHROW (t
));
307 gimple_set_no_warning (call
, TREE_NO_WARNING (t
));
313 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
314 *OP1_P, *OP2_P and *OP3_P respectively. */
317 extract_ops_from_tree_1 (tree expr
, enum tree_code
*subcode_p
, tree
*op1_p
,
318 tree
*op2_p
, tree
*op3_p
)
320 enum gimple_rhs_class grhs_class
;
322 *subcode_p
= TREE_CODE (expr
);
323 grhs_class
= get_gimple_rhs_class (*subcode_p
);
325 if (grhs_class
== GIMPLE_TERNARY_RHS
)
327 *op1_p
= TREE_OPERAND (expr
, 0);
328 *op2_p
= TREE_OPERAND (expr
, 1);
329 *op3_p
= TREE_OPERAND (expr
, 2);
331 else if (grhs_class
== GIMPLE_BINARY_RHS
)
333 *op1_p
= TREE_OPERAND (expr
, 0);
334 *op2_p
= TREE_OPERAND (expr
, 1);
337 else if (grhs_class
== GIMPLE_UNARY_RHS
)
339 *op1_p
= TREE_OPERAND (expr
, 0);
343 else if (grhs_class
== GIMPLE_SINGLE_RHS
)
354 /* Build a GIMPLE_ASSIGN statement.
356 LHS of the assignment.
357 RHS of the assignment which can be unary or binary. */
360 gimple_build_assign_stat (tree lhs
, tree rhs MEM_STAT_DECL
)
362 enum tree_code subcode
;
365 extract_ops_from_tree_1 (rhs
, &subcode
, &op1
, &op2
, &op3
);
366 return gimple_build_assign_with_ops_stat (subcode
, lhs
, op1
, op2
, op3
371 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands
372 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
373 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
376 gimple_build_assign_with_ops_stat (enum tree_code subcode
, tree lhs
, tree op1
,
377 tree op2
, tree op3 MEM_STAT_DECL
)
382 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
384 num_ops
= get_gimple_rhs_num_ops (subcode
) + 1;
386 p
= gimple_build_with_ops_stat (GIMPLE_ASSIGN
, (unsigned)subcode
, num_ops
388 gimple_assign_set_lhs (p
, lhs
);
389 gimple_assign_set_rhs1 (p
, op1
);
392 gcc_assert (num_ops
> 2);
393 gimple_assign_set_rhs2 (p
, op2
);
398 gcc_assert (num_ops
> 3);
399 gimple_assign_set_rhs3 (p
, op3
);
406 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
408 DST/SRC are the destination and source respectively. You can pass
409 ungimplified trees in DST or SRC, in which case they will be
410 converted to a gimple operand if necessary.
412 This function returns the newly created GIMPLE_ASSIGN tuple. */
415 gimplify_assign (tree dst
, tree src
, gimple_seq
*seq_p
)
417 tree t
= build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
418 gimplify_and_add (t
, seq_p
);
420 return gimple_seq_last_stmt (*seq_p
);
424 /* Build a GIMPLE_COND statement.
426 PRED is the condition used to compare LHS and the RHS.
427 T_LABEL is the label to jump to if the condition is true.
428 F_LABEL is the label to jump to otherwise. */
431 gimple_build_cond (enum tree_code pred_code
, tree lhs
, tree rhs
,
432 tree t_label
, tree f_label
)
436 gcc_assert (TREE_CODE_CLASS (pred_code
) == tcc_comparison
);
437 p
= gimple_build_with_ops (GIMPLE_COND
, pred_code
, 4);
438 gimple_cond_set_lhs (p
, lhs
);
439 gimple_cond_set_rhs (p
, rhs
);
440 gimple_cond_set_true_label (p
, t_label
);
441 gimple_cond_set_false_label (p
, f_label
);
446 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
449 gimple_cond_get_ops_from_tree (tree cond
, enum tree_code
*code_p
,
450 tree
*lhs_p
, tree
*rhs_p
)
452 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond
)) == tcc_comparison
453 || TREE_CODE (cond
) == TRUTH_NOT_EXPR
454 || is_gimple_min_invariant (cond
)
455 || SSA_VAR_P (cond
));
457 extract_ops_from_tree (cond
, code_p
, lhs_p
, rhs_p
);
459 /* Canonicalize conditionals of the form 'if (!VAL)'. */
460 if (*code_p
== TRUTH_NOT_EXPR
)
463 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
464 *rhs_p
= build_zero_cst (TREE_TYPE (*lhs_p
));
466 /* Canonicalize conditionals of the form 'if (VAL)' */
467 else if (TREE_CODE_CLASS (*code_p
) != tcc_comparison
)
470 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
471 *rhs_p
= build_zero_cst (TREE_TYPE (*lhs_p
));
476 /* Build a GIMPLE_COND statement from the conditional expression tree
477 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
480 gimple_build_cond_from_tree (tree cond
, tree t_label
, tree f_label
)
485 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
486 return gimple_build_cond (code
, lhs
, rhs
, t_label
, f_label
);
489 /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
490 boolean expression tree COND. */
493 gimple_cond_set_condition_from_tree (gimple stmt
, tree cond
)
498 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
499 gimple_cond_set_condition (stmt
, code
, lhs
, rhs
);
502 /* Build a GIMPLE_LABEL statement for LABEL. */
505 gimple_build_label (tree label
)
507 gimple p
= gimple_build_with_ops (GIMPLE_LABEL
, ERROR_MARK
, 1);
508 gimple_label_set_label (p
, label
);
512 /* Build a GIMPLE_GOTO statement to label DEST. */
515 gimple_build_goto (tree dest
)
517 gimple p
= gimple_build_with_ops (GIMPLE_GOTO
, ERROR_MARK
, 1);
518 gimple_goto_set_dest (p
, dest
);
523 /* Build a GIMPLE_NOP statement. */
526 gimple_build_nop (void)
528 return gimple_alloc (GIMPLE_NOP
, 0);
532 /* Build a GIMPLE_BIND statement.
533 VARS are the variables in BODY.
534 BLOCK is the containing block. */
537 gimple_build_bind (tree vars
, gimple_seq body
, tree block
)
539 gimple p
= gimple_alloc (GIMPLE_BIND
, 0);
540 gimple_bind_set_vars (p
, vars
);
542 gimple_bind_set_body (p
, body
);
544 gimple_bind_set_block (p
, block
);
548 /* Helper function to set the simple fields of a asm stmt.
550 STRING is a pointer to a string that is the asm blocks assembly code.
551 NINPUT is the number of register inputs.
552 NOUTPUT is the number of register outputs.
553 NCLOBBERS is the number of clobbered registers.
557 gimple_build_asm_1 (const char *string
, unsigned ninputs
, unsigned noutputs
,
558 unsigned nclobbers
, unsigned nlabels
)
561 int size
= strlen (string
);
563 /* ASMs with labels cannot have outputs. This should have been
564 enforced by the front end. */
565 gcc_assert (nlabels
== 0 || noutputs
== 0);
567 p
= gimple_build_with_ops (GIMPLE_ASM
, ERROR_MARK
,
568 ninputs
+ noutputs
+ nclobbers
+ nlabels
);
570 p
->gimple_asm
.ni
= ninputs
;
571 p
->gimple_asm
.no
= noutputs
;
572 p
->gimple_asm
.nc
= nclobbers
;
573 p
->gimple_asm
.nl
= nlabels
;
574 p
->gimple_asm
.string
= ggc_alloc_string (string
, size
);
576 #ifdef GATHER_STATISTICS
577 gimple_alloc_sizes
[(int) gimple_alloc_kind (GIMPLE_ASM
)] += size
;
583 /* Build a GIMPLE_ASM statement.
585 STRING is the assembly code.
586 NINPUT is the number of register inputs.
587 NOUTPUT is the number of register outputs.
588 NCLOBBERS is the number of clobbered registers.
589 INPUTS is a vector of the input register parameters.
590 OUTPUTS is a vector of the output register parameters.
591 CLOBBERS is a vector of the clobbered register parameters.
592 LABELS is a vector of destination labels. */
595 gimple_build_asm_vec (const char *string
, VEC(tree
,gc
)* inputs
,
596 VEC(tree
,gc
)* outputs
, VEC(tree
,gc
)* clobbers
,
597 VEC(tree
,gc
)* labels
)
602 p
= gimple_build_asm_1 (string
,
603 VEC_length (tree
, inputs
),
604 VEC_length (tree
, outputs
),
605 VEC_length (tree
, clobbers
),
606 VEC_length (tree
, labels
));
608 for (i
= 0; i
< VEC_length (tree
, inputs
); i
++)
609 gimple_asm_set_input_op (p
, i
, VEC_index (tree
, inputs
, i
));
611 for (i
= 0; i
< VEC_length (tree
, outputs
); i
++)
612 gimple_asm_set_output_op (p
, i
, VEC_index (tree
, outputs
, i
));
614 for (i
= 0; i
< VEC_length (tree
, clobbers
); i
++)
615 gimple_asm_set_clobber_op (p
, i
, VEC_index (tree
, clobbers
, i
));
617 for (i
= 0; i
< VEC_length (tree
, labels
); i
++)
618 gimple_asm_set_label_op (p
, i
, VEC_index (tree
, labels
, i
));
623 /* Build a GIMPLE_CATCH statement.
625 TYPES are the catch types.
626 HANDLER is the exception handler. */
629 gimple_build_catch (tree types
, gimple_seq handler
)
631 gimple p
= gimple_alloc (GIMPLE_CATCH
, 0);
632 gimple_catch_set_types (p
, types
);
634 gimple_catch_set_handler (p
, handler
);
639 /* Build a GIMPLE_EH_FILTER statement.
641 TYPES are the filter's types.
642 FAILURE is the filter's failure action. */
645 gimple_build_eh_filter (tree types
, gimple_seq failure
)
647 gimple p
= gimple_alloc (GIMPLE_EH_FILTER
, 0);
648 gimple_eh_filter_set_types (p
, types
);
650 gimple_eh_filter_set_failure (p
, failure
);
655 /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
658 gimple_build_eh_must_not_throw (tree decl
)
660 gimple p
= gimple_alloc (GIMPLE_EH_MUST_NOT_THROW
, 0);
662 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
663 gcc_assert (flags_from_decl_or_type (decl
) & ECF_NORETURN
);
664 gimple_eh_must_not_throw_set_fndecl (p
, decl
);
669 /* Build a GIMPLE_TRY statement.
671 EVAL is the expression to evaluate.
672 CLEANUP is the cleanup expression.
673 KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
674 whether this is a try/catch or a try/finally respectively. */
677 gimple_build_try (gimple_seq eval
, gimple_seq cleanup
,
678 enum gimple_try_flags kind
)
682 gcc_assert (kind
== GIMPLE_TRY_CATCH
|| kind
== GIMPLE_TRY_FINALLY
);
683 p
= gimple_alloc (GIMPLE_TRY
, 0);
684 gimple_set_subcode (p
, kind
);
686 gimple_try_set_eval (p
, eval
);
688 gimple_try_set_cleanup (p
, cleanup
);
693 /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
695 CLEANUP is the cleanup expression. */
698 gimple_build_wce (gimple_seq cleanup
)
700 gimple p
= gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR
, 0);
702 gimple_wce_set_cleanup (p
, cleanup
);
708 /* Build a GIMPLE_RESX statement. */
711 gimple_build_resx (int region
)
713 gimple p
= gimple_build_with_ops (GIMPLE_RESX
, ERROR_MARK
, 0);
714 p
->gimple_eh_ctrl
.region
= region
;
719 /* The helper for constructing a gimple switch statement.
720 INDEX is the switch's index.
721 NLABELS is the number of labels in the switch excluding the default.
722 DEFAULT_LABEL is the default label for the switch statement. */
725 gimple_build_switch_nlabels (unsigned nlabels
, tree index
, tree default_label
)
727 /* nlabels + 1 default label + 1 index. */
728 gimple p
= gimple_build_with_ops (GIMPLE_SWITCH
, ERROR_MARK
,
729 1 + (default_label
!= NULL
) + nlabels
);
730 gimple_switch_set_index (p
, index
);
732 gimple_switch_set_default_label (p
, default_label
);
737 /* Build a GIMPLE_SWITCH statement.
739 INDEX is the switch's index.
740 NLABELS is the number of labels in the switch excluding the DEFAULT_LABEL.
741 ... are the labels excluding the default. */
744 gimple_build_switch (unsigned nlabels
, tree index
, tree default_label
, ...)
748 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
750 /* Store the rest of the labels. */
751 va_start (al
, default_label
);
752 offset
= (default_label
!= NULL
);
753 for (i
= 0; i
< nlabels
; i
++)
754 gimple_switch_set_label (p
, i
+ offset
, va_arg (al
, tree
));
761 /* Build a GIMPLE_SWITCH statement.
763 INDEX is the switch's index.
764 DEFAULT_LABEL is the default label
765 ARGS is a vector of labels excluding the default. */
768 gimple_build_switch_vec (tree index
, tree default_label
, VEC(tree
, heap
) *args
)
770 unsigned i
, offset
, nlabels
= VEC_length (tree
, args
);
771 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
773 /* Copy the labels from the vector to the switch statement. */
774 offset
= (default_label
!= NULL
);
775 for (i
= 0; i
< nlabels
; i
++)
776 gimple_switch_set_label (p
, i
+ offset
, VEC_index (tree
, args
, i
));
781 /* Build a GIMPLE_EH_DISPATCH statement. */
784 gimple_build_eh_dispatch (int region
)
786 gimple p
= gimple_build_with_ops (GIMPLE_EH_DISPATCH
, ERROR_MARK
, 0);
787 p
->gimple_eh_ctrl
.region
= region
;
791 /* Build a new GIMPLE_DEBUG_BIND statement.
793 VAR is bound to VALUE; block and location are taken from STMT. */
796 gimple_build_debug_bind_stat (tree var
, tree value
, gimple stmt MEM_STAT_DECL
)
798 gimple p
= gimple_build_with_ops_stat (GIMPLE_DEBUG
,
799 (unsigned)GIMPLE_DEBUG_BIND
, 2
802 gimple_debug_bind_set_var (p
, var
);
803 gimple_debug_bind_set_value (p
, value
);
806 gimple_set_block (p
, gimple_block (stmt
));
807 gimple_set_location (p
, gimple_location (stmt
));
814 /* Build a GIMPLE_OMP_CRITICAL statement.
816 BODY is the sequence of statements for which only one thread can execute.
817 NAME is optional identifier for this critical block. */
820 gimple_build_omp_critical (gimple_seq body
, tree name
)
822 gimple p
= gimple_alloc (GIMPLE_OMP_CRITICAL
, 0);
823 gimple_omp_critical_set_name (p
, name
);
825 gimple_omp_set_body (p
, body
);
830 /* Build a GIMPLE_OMP_FOR statement.
832 BODY is sequence of statements inside the for loop.
833 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate,
834 lastprivate, reductions, ordered, schedule, and nowait.
835 COLLAPSE is the collapse count.
836 PRE_BODY is the sequence of statements that are loop invariant. */
839 gimple_build_omp_for (gimple_seq body
, tree clauses
, size_t collapse
,
842 gimple p
= gimple_alloc (GIMPLE_OMP_FOR
, 0);
844 gimple_omp_set_body (p
, body
);
845 gimple_omp_for_set_clauses (p
, clauses
);
846 p
->gimple_omp_for
.collapse
= collapse
;
847 p
->gimple_omp_for
.iter
848 = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse
);
850 gimple_omp_for_set_pre_body (p
, pre_body
);
856 /* Build a GIMPLE_OMP_PARALLEL statement.
858 BODY is sequence of statements which are executed in parallel.
859 CLAUSES, are the OMP parallel construct's clauses.
860 CHILD_FN is the function created for the parallel threads to execute.
861 DATA_ARG are the shared data argument(s). */
864 gimple_build_omp_parallel (gimple_seq body
, tree clauses
, tree child_fn
,
867 gimple p
= gimple_alloc (GIMPLE_OMP_PARALLEL
, 0);
869 gimple_omp_set_body (p
, body
);
870 gimple_omp_parallel_set_clauses (p
, clauses
);
871 gimple_omp_parallel_set_child_fn (p
, child_fn
);
872 gimple_omp_parallel_set_data_arg (p
, data_arg
);
878 /* Build a GIMPLE_OMP_TASK statement.
880 BODY is sequence of statements which are executed by the explicit task.
881 CLAUSES, are the OMP parallel construct's clauses.
882 CHILD_FN is the function created for the parallel threads to execute.
883 DATA_ARG are the shared data argument(s).
884 COPY_FN is the optional function for firstprivate initialization.
885 ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
888 gimple_build_omp_task (gimple_seq body
, tree clauses
, tree child_fn
,
889 tree data_arg
, tree copy_fn
, tree arg_size
,
892 gimple p
= gimple_alloc (GIMPLE_OMP_TASK
, 0);
894 gimple_omp_set_body (p
, body
);
895 gimple_omp_task_set_clauses (p
, clauses
);
896 gimple_omp_task_set_child_fn (p
, child_fn
);
897 gimple_omp_task_set_data_arg (p
, data_arg
);
898 gimple_omp_task_set_copy_fn (p
, copy_fn
);
899 gimple_omp_task_set_arg_size (p
, arg_size
);
900 gimple_omp_task_set_arg_align (p
, arg_align
);
906 /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
908 BODY is the sequence of statements in the section. */
911 gimple_build_omp_section (gimple_seq body
)
913 gimple p
= gimple_alloc (GIMPLE_OMP_SECTION
, 0);
915 gimple_omp_set_body (p
, body
);
921 /* Build a GIMPLE_OMP_MASTER statement.
923 BODY is the sequence of statements to be executed by just the master. */
926 gimple_build_omp_master (gimple_seq body
)
928 gimple p
= gimple_alloc (GIMPLE_OMP_MASTER
, 0);
930 gimple_omp_set_body (p
, body
);
936 /* Build a GIMPLE_OMP_CONTINUE statement.
938 CONTROL_DEF is the definition of the control variable.
939 CONTROL_USE is the use of the control variable. */
942 gimple_build_omp_continue (tree control_def
, tree control_use
)
944 gimple p
= gimple_alloc (GIMPLE_OMP_CONTINUE
, 0);
945 gimple_omp_continue_set_control_def (p
, control_def
);
946 gimple_omp_continue_set_control_use (p
, control_use
);
950 /* Build a GIMPLE_OMP_ORDERED statement.
952 BODY is the sequence of statements inside a loop that will executed in
956 gimple_build_omp_ordered (gimple_seq body
)
958 gimple p
= gimple_alloc (GIMPLE_OMP_ORDERED
, 0);
960 gimple_omp_set_body (p
, body
);
966 /* Build a GIMPLE_OMP_RETURN statement.
967 WAIT_P is true if this is a non-waiting return. */
970 gimple_build_omp_return (bool wait_p
)
972 gimple p
= gimple_alloc (GIMPLE_OMP_RETURN
, 0);
974 gimple_omp_return_set_nowait (p
);
980 /* Build a GIMPLE_OMP_SECTIONS statement.
982 BODY is a sequence of section statements.
983 CLAUSES are any of the OMP sections contsruct's clauses: private,
984 firstprivate, lastprivate, reduction, and nowait. */
987 gimple_build_omp_sections (gimple_seq body
, tree clauses
)
989 gimple p
= gimple_alloc (GIMPLE_OMP_SECTIONS
, 0);
991 gimple_omp_set_body (p
, body
);
992 gimple_omp_sections_set_clauses (p
, clauses
);
998 /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
1001 gimple_build_omp_sections_switch (void)
1003 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH
, 0);
1007 /* Build a GIMPLE_OMP_SINGLE statement.
1009 BODY is the sequence of statements that will be executed once.
1010 CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
1011 copyprivate, nowait. */
1014 gimple_build_omp_single (gimple_seq body
, tree clauses
)
1016 gimple p
= gimple_alloc (GIMPLE_OMP_SINGLE
, 0);
1018 gimple_omp_set_body (p
, body
);
1019 gimple_omp_single_set_clauses (p
, clauses
);
1025 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1028 gimple_build_omp_atomic_load (tree lhs
, tree rhs
)
1030 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD
, 0);
1031 gimple_omp_atomic_load_set_lhs (p
, lhs
);
1032 gimple_omp_atomic_load_set_rhs (p
, rhs
);
1036 /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1038 VAL is the value we are storing. */
1041 gimple_build_omp_atomic_store (tree val
)
1043 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_STORE
, 0);
1044 gimple_omp_atomic_store_set_val (p
, val
);
1048 /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
1049 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
1052 gimple_build_predict (enum br_predictor predictor
, enum prediction outcome
)
1054 gimple p
= gimple_alloc (GIMPLE_PREDICT
, 0);
1055 /* Ensure all the predictors fit into the lower bits of the subcode. */
1056 gcc_assert ((int) END_PREDICTORS
<= GF_PREDICT_TAKEN
);
1057 gimple_predict_set_predictor (p
, predictor
);
1058 gimple_predict_set_outcome (p
, outcome
);
1062 #if defined ENABLE_GIMPLE_CHECKING
1063 /* Complain of a gimple type mismatch and die. */
1066 gimple_check_failed (const_gimple gs
, const char *file
, int line
,
1067 const char *function
, enum gimple_code code
,
1068 enum tree_code subcode
)
1070 internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1071 gimple_code_name
[code
],
1072 tree_code_name
[subcode
],
1073 gimple_code_name
[gimple_code (gs
)],
1074 gs
->gsbase
.subcode
> 0
1075 ? tree_code_name
[gs
->gsbase
.subcode
]
1077 function
, trim_filename (file
), line
);
1079 #endif /* ENABLE_GIMPLE_CHECKING */
1082 /* Allocate a new GIMPLE sequence in GC memory and return it. If
1083 there are free sequences in GIMPLE_SEQ_CACHE return one of those
1087 gimple_seq_alloc (void)
1089 gimple_seq seq
= gimple_seq_cache
;
1092 gimple_seq_cache
= gimple_seq_cache
->next_free
;
1093 gcc_assert (gimple_seq_cache
!= seq
);
1094 memset (seq
, 0, sizeof (*seq
));
1098 seq
= ggc_alloc_cleared_gimple_seq_d ();
1099 #ifdef GATHER_STATISTICS
1100 gimple_alloc_counts
[(int) gimple_alloc_kind_seq
]++;
1101 gimple_alloc_sizes
[(int) gimple_alloc_kind_seq
] += sizeof (*seq
);
1108 /* Return SEQ to the free pool of GIMPLE sequences. */
1111 gimple_seq_free (gimple_seq seq
)
1116 gcc_assert (gimple_seq_first (seq
) == NULL
);
1117 gcc_assert (gimple_seq_last (seq
) == NULL
);
1119 /* If this triggers, it's a sign that the same list is being freed
1121 gcc_assert (seq
!= gimple_seq_cache
|| gimple_seq_cache
== NULL
);
1123 /* Add SEQ to the pool of free sequences. */
1124 seq
->next_free
= gimple_seq_cache
;
1125 gimple_seq_cache
= seq
;
1129 /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1130 *SEQ_P is NULL, a new sequence is allocated. */
1133 gimple_seq_add_stmt (gimple_seq
*seq_p
, gimple gs
)
1135 gimple_stmt_iterator si
;
1141 *seq_p
= gimple_seq_alloc ();
1143 si
= gsi_last (*seq_p
);
1144 gsi_insert_after (&si
, gs
, GSI_NEW_STMT
);
1148 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1149 NULL, a new sequence is allocated. */
1152 gimple_seq_add_seq (gimple_seq
*dst_p
, gimple_seq src
)
1154 gimple_stmt_iterator si
;
1160 *dst_p
= gimple_seq_alloc ();
1162 si
= gsi_last (*dst_p
);
1163 gsi_insert_seq_after (&si
, src
, GSI_NEW_STMT
);
1167 /* Helper function of empty_body_p. Return true if STMT is an empty
1171 empty_stmt_p (gimple stmt
)
1173 if (gimple_code (stmt
) == GIMPLE_NOP
)
1175 if (gimple_code (stmt
) == GIMPLE_BIND
)
1176 return empty_body_p (gimple_bind_body (stmt
));
1181 /* Return true if BODY contains nothing but empty statements. */
1184 empty_body_p (gimple_seq body
)
1186 gimple_stmt_iterator i
;
1188 if (gimple_seq_empty_p (body
))
1190 for (i
= gsi_start (body
); !gsi_end_p (i
); gsi_next (&i
))
1191 if (!empty_stmt_p (gsi_stmt (i
))
1192 && !is_gimple_debug (gsi_stmt (i
)))
1199 /* Perform a deep copy of sequence SRC and return the result. */
1202 gimple_seq_copy (gimple_seq src
)
1204 gimple_stmt_iterator gsi
;
1205 gimple_seq new_seq
= gimple_seq_alloc ();
1208 for (gsi
= gsi_start (src
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1210 stmt
= gimple_copy (gsi_stmt (gsi
));
1211 gimple_seq_add_stmt (&new_seq
, stmt
);
1218 /* Walk all the statements in the sequence SEQ calling walk_gimple_stmt
1219 on each one. WI is as in walk_gimple_stmt.
1221 If walk_gimple_stmt returns non-NULL, the walk is stopped, the
1222 value is stored in WI->CALLBACK_RESULT and the statement that
1223 produced the value is returned.
1225 Otherwise, all the statements are walked and NULL returned. */
1228 walk_gimple_seq (gimple_seq seq
, walk_stmt_fn callback_stmt
,
1229 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1231 gimple_stmt_iterator gsi
;
1233 for (gsi
= gsi_start (seq
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1235 tree ret
= walk_gimple_stmt (&gsi
, callback_stmt
, callback_op
, wi
);
1238 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
1241 wi
->callback_result
= ret
;
1242 return gsi_stmt (gsi
);
1247 wi
->callback_result
= NULL_TREE
;
1253 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
1256 walk_gimple_asm (gimple stmt
, walk_tree_fn callback_op
,
1257 struct walk_stmt_info
*wi
)
1261 const char **oconstraints
;
1263 const char *constraint
;
1264 bool allows_mem
, allows_reg
, is_inout
;
1266 noutputs
= gimple_asm_noutputs (stmt
);
1267 oconstraints
= (const char **) alloca ((noutputs
) * sizeof (const char *));
1272 for (i
= 0; i
< noutputs
; i
++)
1274 op
= gimple_asm_output_op (stmt
, i
);
1275 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1276 oconstraints
[i
] = constraint
;
1277 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
, &allows_reg
,
1280 wi
->val_only
= (allows_reg
|| !allows_mem
);
1281 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1286 n
= gimple_asm_ninputs (stmt
);
1287 for (i
= 0; i
< n
; i
++)
1289 op
= gimple_asm_input_op (stmt
, i
);
1290 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1291 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
1292 oconstraints
, &allows_mem
, &allows_reg
);
1295 wi
->val_only
= (allows_reg
|| !allows_mem
);
1296 /* Although input "m" is not really a LHS, we need a lvalue. */
1297 wi
->is_lhs
= !wi
->val_only
;
1299 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1307 wi
->val_only
= true;
1310 n
= gimple_asm_nlabels (stmt
);
1311 for (i
= 0; i
< n
; i
++)
1313 op
= gimple_asm_label_op (stmt
, i
);
1314 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1323 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
1324 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
1326 CALLBACK_OP is called on each operand of STMT via walk_tree.
1327 Additional parameters to walk_tree must be stored in WI. For each operand
1328 OP, walk_tree is called as:
1330 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
1332 If CALLBACK_OP returns non-NULL for an operand, the remaining
1333 operands are not scanned.
1335 The return value is that returned by the last call to walk_tree, or
1336 NULL_TREE if no CALLBACK_OP is specified. */
1339 walk_gimple_op (gimple stmt
, walk_tree_fn callback_op
,
1340 struct walk_stmt_info
*wi
)
1342 struct pointer_set_t
*pset
= (wi
) ? wi
->pset
: NULL
;
1344 tree ret
= NULL_TREE
;
1346 switch (gimple_code (stmt
))
1349 /* Walk the RHS operands. If the LHS is of a non-renamable type or
1350 is a register variable, we may use a COMPONENT_REF on the RHS. */
1353 tree lhs
= gimple_assign_lhs (stmt
);
1355 = (is_gimple_reg_type (TREE_TYPE (lhs
)) && !is_gimple_reg (lhs
))
1356 || !gimple_assign_single_p (stmt
);
1359 for (i
= 1; i
< gimple_num_ops (stmt
); i
++)
1361 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
,
1367 /* Walk the LHS. If the RHS is appropriate for a memory, we
1368 may use a COMPONENT_REF on the LHS. */
1371 /* If the RHS has more than 1 operand, it is not appropriate
1373 wi
->val_only
= !is_gimple_mem_rhs (gimple_assign_rhs1 (stmt
))
1374 || !gimple_assign_single_p (stmt
);
1378 ret
= walk_tree (gimple_op_ptr (stmt
, 0), callback_op
, wi
, pset
);
1384 wi
->val_only
= true;
1393 wi
->val_only
= true;
1396 ret
= walk_tree (gimple_call_chain_ptr (stmt
), callback_op
, wi
, pset
);
1400 ret
= walk_tree (gimple_call_fn_ptr (stmt
), callback_op
, wi
, pset
);
1404 for (i
= 0; i
< gimple_call_num_args (stmt
); i
++)
1407 wi
->val_only
= is_gimple_reg_type (gimple_call_arg (stmt
, i
));
1408 ret
= walk_tree (gimple_call_arg_ptr (stmt
, i
), callback_op
, wi
,
1414 if (gimple_call_lhs (stmt
))
1419 wi
->val_only
= is_gimple_reg_type (gimple_call_lhs (stmt
));
1422 ret
= walk_tree (gimple_call_lhs_ptr (stmt
), callback_op
, wi
, pset
);
1430 wi
->val_only
= true;
1435 ret
= walk_tree (gimple_catch_types_ptr (stmt
), callback_op
, wi
,
1441 case GIMPLE_EH_FILTER
:
1442 ret
= walk_tree (gimple_eh_filter_types_ptr (stmt
), callback_op
, wi
,
1449 ret
= walk_gimple_asm (stmt
, callback_op
, wi
);
1454 case GIMPLE_OMP_CONTINUE
:
1455 ret
= walk_tree (gimple_omp_continue_control_def_ptr (stmt
),
1456 callback_op
, wi
, pset
);
1460 ret
= walk_tree (gimple_omp_continue_control_use_ptr (stmt
),
1461 callback_op
, wi
, pset
);
1466 case GIMPLE_OMP_CRITICAL
:
1467 ret
= walk_tree (gimple_omp_critical_name_ptr (stmt
), callback_op
, wi
,
1473 case GIMPLE_OMP_FOR
:
1474 ret
= walk_tree (gimple_omp_for_clauses_ptr (stmt
), callback_op
, wi
,
1478 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
1480 ret
= walk_tree (gimple_omp_for_index_ptr (stmt
, i
), callback_op
,
1484 ret
= walk_tree (gimple_omp_for_initial_ptr (stmt
, i
), callback_op
,
1488 ret
= walk_tree (gimple_omp_for_final_ptr (stmt
, i
), callback_op
,
1492 ret
= walk_tree (gimple_omp_for_incr_ptr (stmt
, i
), callback_op
,
1499 case GIMPLE_OMP_PARALLEL
:
1500 ret
= walk_tree (gimple_omp_parallel_clauses_ptr (stmt
), callback_op
,
1504 ret
= walk_tree (gimple_omp_parallel_child_fn_ptr (stmt
), callback_op
,
1508 ret
= walk_tree (gimple_omp_parallel_data_arg_ptr (stmt
), callback_op
,
1514 case GIMPLE_OMP_TASK
:
1515 ret
= walk_tree (gimple_omp_task_clauses_ptr (stmt
), callback_op
,
1519 ret
= walk_tree (gimple_omp_task_child_fn_ptr (stmt
), callback_op
,
1523 ret
= walk_tree (gimple_omp_task_data_arg_ptr (stmt
), callback_op
,
1527 ret
= walk_tree (gimple_omp_task_copy_fn_ptr (stmt
), callback_op
,
1531 ret
= walk_tree (gimple_omp_task_arg_size_ptr (stmt
), callback_op
,
1535 ret
= walk_tree (gimple_omp_task_arg_align_ptr (stmt
), callback_op
,
1541 case GIMPLE_OMP_SECTIONS
:
1542 ret
= walk_tree (gimple_omp_sections_clauses_ptr (stmt
), callback_op
,
1547 ret
= walk_tree (gimple_omp_sections_control_ptr (stmt
), callback_op
,
1554 case GIMPLE_OMP_SINGLE
:
1555 ret
= walk_tree (gimple_omp_single_clauses_ptr (stmt
), callback_op
, wi
,
1561 case GIMPLE_OMP_ATOMIC_LOAD
:
1562 ret
= walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt
), callback_op
, wi
,
1567 ret
= walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt
), callback_op
, wi
,
1573 case GIMPLE_OMP_ATOMIC_STORE
:
1574 ret
= walk_tree (gimple_omp_atomic_store_val_ptr (stmt
), callback_op
,
1580 /* Tuples that do not have operands. */
1583 case GIMPLE_OMP_RETURN
:
1584 case GIMPLE_PREDICT
:
1589 enum gimple_statement_structure_enum gss
;
1590 gss
= gimple_statement_structure (stmt
);
1591 if (gss
== GSS_WITH_OPS
|| gss
== GSS_WITH_MEM_OPS
)
1592 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
1594 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
, pset
);
1606 /* Walk the current statement in GSI (optionally using traversal state
1607 stored in WI). If WI is NULL, no state is kept during traversal.
1608 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
1609 that it has handled all the operands of the statement, its return
1610 value is returned. Otherwise, the return value from CALLBACK_STMT
1611 is discarded and its operands are scanned.
1613 If CALLBACK_STMT is NULL or it didn't handle the operands,
1614 CALLBACK_OP is called on each operand of the statement via
1615 walk_gimple_op. If walk_gimple_op returns non-NULL for any
1616 operand, the remaining operands are not scanned. In this case, the
1617 return value from CALLBACK_OP is returned.
1619 In any other case, NULL_TREE is returned. */
1622 walk_gimple_stmt (gimple_stmt_iterator
*gsi
, walk_stmt_fn callback_stmt
,
1623 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1627 gimple stmt
= gsi_stmt (*gsi
);
1632 if (wi
&& wi
->want_locations
&& gimple_has_location (stmt
))
1633 input_location
= gimple_location (stmt
);
1637 /* Invoke the statement callback. Return if the callback handled
1638 all of STMT operands by itself. */
1641 bool handled_ops
= false;
1642 tree_ret
= callback_stmt (gsi
, &handled_ops
, wi
);
1646 /* If CALLBACK_STMT did not handle operands, it should not have
1647 a value to return. */
1648 gcc_assert (tree_ret
== NULL
);
1650 /* Re-read stmt in case the callback changed it. */
1651 stmt
= gsi_stmt (*gsi
);
1654 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
1657 tree_ret
= walk_gimple_op (stmt
, callback_op
, wi
);
1662 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
1663 switch (gimple_code (stmt
))
1666 ret
= walk_gimple_seq (gimple_bind_body (stmt
), callback_stmt
,
1669 return wi
->callback_result
;
1673 ret
= walk_gimple_seq (gimple_catch_handler (stmt
), callback_stmt
,
1676 return wi
->callback_result
;
1679 case GIMPLE_EH_FILTER
:
1680 ret
= walk_gimple_seq (gimple_eh_filter_failure (stmt
), callback_stmt
,
1683 return wi
->callback_result
;
1687 ret
= walk_gimple_seq (gimple_try_eval (stmt
), callback_stmt
, callback_op
,
1690 return wi
->callback_result
;
1692 ret
= walk_gimple_seq (gimple_try_cleanup (stmt
), callback_stmt
,
1695 return wi
->callback_result
;
1698 case GIMPLE_OMP_FOR
:
1699 ret
= walk_gimple_seq (gimple_omp_for_pre_body (stmt
), callback_stmt
,
1702 return wi
->callback_result
;
1705 case GIMPLE_OMP_CRITICAL
:
1706 case GIMPLE_OMP_MASTER
:
1707 case GIMPLE_OMP_ORDERED
:
1708 case GIMPLE_OMP_SECTION
:
1709 case GIMPLE_OMP_PARALLEL
:
1710 case GIMPLE_OMP_TASK
:
1711 case GIMPLE_OMP_SECTIONS
:
1712 case GIMPLE_OMP_SINGLE
:
1713 ret
= walk_gimple_seq (gimple_omp_body (stmt
), callback_stmt
, callback_op
,
1716 return wi
->callback_result
;
1719 case GIMPLE_WITH_CLEANUP_EXPR
:
1720 ret
= walk_gimple_seq (gimple_wce_cleanup (stmt
), callback_stmt
,
1723 return wi
->callback_result
;
1727 gcc_assert (!gimple_has_substatements (stmt
));
1735 /* Set sequence SEQ to be the GIMPLE body for function FN. */
1738 gimple_set_body (tree fndecl
, gimple_seq seq
)
1740 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1743 /* If FNDECL still does not have a function structure associated
1744 with it, then it does not make sense for it to receive a
1746 gcc_assert (seq
== NULL
);
1749 fn
->gimple_body
= seq
;
1753 /* Return the body of GIMPLE statements for function FN. After the
1754 CFG pass, the function body doesn't exist anymore because it has
1755 been split up into basic blocks. In this case, it returns
1759 gimple_body (tree fndecl
)
1761 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1762 return fn
? fn
->gimple_body
: NULL
;
1765 /* Return true when FNDECL has Gimple body either in unlowered
1768 gimple_has_body_p (tree fndecl
)
1770 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1771 return (gimple_body (fndecl
) || (fn
&& fn
->cfg
));
1774 /* Detect flags from a GIMPLE_CALL. This is just like
1775 call_expr_flags, but for gimple tuples. */
1778 gimple_call_flags (const_gimple stmt
)
1781 tree decl
= gimple_call_fndecl (stmt
);
1785 flags
= flags_from_decl_or_type (decl
);
1788 t
= TREE_TYPE (gimple_call_fn (stmt
));
1789 if (t
&& TREE_CODE (t
) == POINTER_TYPE
)
1790 flags
= flags_from_decl_or_type (TREE_TYPE (t
));
1795 if (stmt
->gsbase
.subcode
& GF_CALL_NOTHROW
)
1796 flags
|= ECF_NOTHROW
;
1801 /* Detects argument flags for argument number ARG on call STMT. */
1804 gimple_call_arg_flags (const_gimple stmt
, unsigned arg
)
1806 tree type
= TREE_TYPE (TREE_TYPE (gimple_call_fn (stmt
)));
1807 tree attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
1811 attr
= TREE_VALUE (TREE_VALUE (attr
));
1812 if (1 + arg
>= (unsigned) TREE_STRING_LENGTH (attr
))
1815 switch (TREE_STRING_POINTER (attr
)[1 + arg
])
1822 return EAF_DIRECT
| EAF_NOCLOBBER
| EAF_NOESCAPE
;
1825 return EAF_NOCLOBBER
| EAF_NOESCAPE
;
1828 return EAF_DIRECT
| EAF_NOESCAPE
;
1831 return EAF_NOESCAPE
;
1839 /* Detects return flags for the call STMT. */
1842 gimple_call_return_flags (const_gimple stmt
)
1845 tree attr
= NULL_TREE
;
1847 if (gimple_call_flags (stmt
) & ECF_MALLOC
)
1850 type
= TREE_TYPE (TREE_TYPE (gimple_call_fn (stmt
)));
1851 attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
1855 attr
= TREE_VALUE (TREE_VALUE (attr
));
1856 if (TREE_STRING_LENGTH (attr
) < 1)
1859 switch (TREE_STRING_POINTER (attr
)[0])
1865 return ERF_RETURNS_ARG
| (TREE_STRING_POINTER (attr
)[0] - '1');
1877 /* Return true if GS is a copy assignment. */
1880 gimple_assign_copy_p (gimple gs
)
1882 return (gimple_assign_single_p (gs
)
1883 && is_gimple_val (gimple_op (gs
, 1)));
1887 /* Return true if GS is a SSA_NAME copy assignment. */
1890 gimple_assign_ssa_name_copy_p (gimple gs
)
1892 return (gimple_assign_single_p (gs
)
1893 && TREE_CODE (gimple_assign_lhs (gs
)) == SSA_NAME
1894 && TREE_CODE (gimple_assign_rhs1 (gs
)) == SSA_NAME
);
1898 /* Return true if GS is an assignment with a unary RHS, but the
1899 operator has no effect on the assigned value. The logic is adapted
1900 from STRIP_NOPS. This predicate is intended to be used in tuplifying
1901 instances in which STRIP_NOPS was previously applied to the RHS of
1904 NOTE: In the use cases that led to the creation of this function
1905 and of gimple_assign_single_p, it is typical to test for either
1906 condition and to proceed in the same manner. In each case, the
1907 assigned value is represented by the single RHS operand of the
1908 assignment. I suspect there may be cases where gimple_assign_copy_p,
1909 gimple_assign_single_p, or equivalent logic is used where a similar
1910 treatment of unary NOPs is appropriate. */
1913 gimple_assign_unary_nop_p (gimple gs
)
1915 return (is_gimple_assign (gs
)
1916 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs
))
1917 || gimple_assign_rhs_code (gs
) == NON_LVALUE_EXPR
)
1918 && gimple_assign_rhs1 (gs
) != error_mark_node
1919 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs
)))
1920 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs
)))));
1923 /* Set BB to be the basic block holding G. */
1926 gimple_set_bb (gimple stmt
, basic_block bb
)
1928 stmt
->gsbase
.bb
= bb
;
1930 /* If the statement is a label, add the label to block-to-labels map
1931 so that we can speed up edge creation for GIMPLE_GOTOs. */
1932 if (cfun
->cfg
&& gimple_code (stmt
) == GIMPLE_LABEL
)
1937 t
= gimple_label_label (stmt
);
1938 uid
= LABEL_DECL_UID (t
);
1941 unsigned old_len
= VEC_length (basic_block
, label_to_block_map
);
1942 LABEL_DECL_UID (t
) = uid
= cfun
->cfg
->last_label_uid
++;
1943 if (old_len
<= (unsigned) uid
)
1945 unsigned new_len
= 3 * uid
/ 2 + 1;
1947 VEC_safe_grow_cleared (basic_block
, gc
, label_to_block_map
,
1952 VEC_replace (basic_block
, label_to_block_map
, uid
, bb
);
1957 /* Modify the RHS of the assignment pointed-to by GSI using the
1958 operands in the expression tree EXPR.
1960 NOTE: The statement pointed-to by GSI may be reallocated if it
1961 did not have enough operand slots.
1963 This function is useful to convert an existing tree expression into
1964 the flat representation used for the RHS of a GIMPLE assignment.
1965 It will reallocate memory as needed to expand or shrink the number
1966 of operand slots needed to represent EXPR.
1968 NOTE: If you find yourself building a tree and then calling this
1969 function, you are most certainly doing it the slow way. It is much
1970 better to build a new assignment or to use the function
1971 gimple_assign_set_rhs_with_ops, which does not require an
1972 expression tree to be built. */
1975 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator
*gsi
, tree expr
)
1977 enum tree_code subcode
;
1980 extract_ops_from_tree_1 (expr
, &subcode
, &op1
, &op2
, &op3
);
1981 gimple_assign_set_rhs_with_ops_1 (gsi
, subcode
, op1
, op2
, op3
);
1985 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
1986 operands OP1, OP2 and OP3.
1988 NOTE: The statement pointed-to by GSI may be reallocated if it
1989 did not have enough operand slots. */
1992 gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator
*gsi
, enum tree_code code
,
1993 tree op1
, tree op2
, tree op3
)
1995 unsigned new_rhs_ops
= get_gimple_rhs_num_ops (code
);
1996 gimple stmt
= gsi_stmt (*gsi
);
1998 /* If the new CODE needs more operands, allocate a new statement. */
1999 if (gimple_num_ops (stmt
) < new_rhs_ops
+ 1)
2001 tree lhs
= gimple_assign_lhs (stmt
);
2002 gimple new_stmt
= gimple_alloc (gimple_code (stmt
), new_rhs_ops
+ 1);
2003 memcpy (new_stmt
, stmt
, gimple_size (gimple_code (stmt
)));
2004 gsi_replace (gsi
, new_stmt
, true);
2007 /* The LHS needs to be reset as this also changes the SSA name
2009 gimple_assign_set_lhs (stmt
, lhs
);
2012 gimple_set_num_ops (stmt
, new_rhs_ops
+ 1);
2013 gimple_set_subcode (stmt
, code
);
2014 gimple_assign_set_rhs1 (stmt
, op1
);
2015 if (new_rhs_ops
> 1)
2016 gimple_assign_set_rhs2 (stmt
, op2
);
2017 if (new_rhs_ops
> 2)
2018 gimple_assign_set_rhs3 (stmt
, op3
);
2022 /* Return the LHS of a statement that performs an assignment,
2023 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2024 for a call to a function that returns no value, or for a
2025 statement other than an assignment or a call. */
2028 gimple_get_lhs (const_gimple stmt
)
2030 enum gimple_code code
= gimple_code (stmt
);
2032 if (code
== GIMPLE_ASSIGN
)
2033 return gimple_assign_lhs (stmt
);
2034 else if (code
== GIMPLE_CALL
)
2035 return gimple_call_lhs (stmt
);
2041 /* Set the LHS of a statement that performs an assignment,
2042 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2045 gimple_set_lhs (gimple stmt
, tree lhs
)
2047 enum gimple_code code
= gimple_code (stmt
);
2049 if (code
== GIMPLE_ASSIGN
)
2050 gimple_assign_set_lhs (stmt
, lhs
);
2051 else if (code
== GIMPLE_CALL
)
2052 gimple_call_set_lhs (stmt
, lhs
);
2057 /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
2058 GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
2059 expression with a different value.
2061 This will update any annotations (say debug bind stmts) referring
2062 to the original LHS, so that they use the RHS instead. This is
2063 done even if NLHS and LHS are the same, for it is understood that
2064 the RHS will be modified afterwards, and NLHS will not be assigned
2065 an equivalent value.
2067 Adjusting any non-annotation uses of the LHS, if needed, is a
2068 responsibility of the caller.
2070 The effect of this call should be pretty much the same as that of
2071 inserting a copy of STMT before STMT, and then removing the
2072 original stmt, at which time gsi_remove() would have update
2073 annotations, but using this function saves all the inserting,
2074 copying and removing. */
2077 gimple_replace_lhs (gimple stmt
, tree nlhs
)
2079 if (MAY_HAVE_DEBUG_STMTS
)
2081 tree lhs
= gimple_get_lhs (stmt
);
2083 gcc_assert (SSA_NAME_DEF_STMT (lhs
) == stmt
);
2085 insert_debug_temp_for_var_def (NULL
, lhs
);
2088 gimple_set_lhs (stmt
, nlhs
);
2091 /* Return a deep copy of statement STMT. All the operands from STMT
2092 are reallocated and copied using unshare_expr. The DEF, USE, VDEF
2093 and VUSE operand arrays are set to empty in the new copy. */
2096 gimple_copy (gimple stmt
)
2098 enum gimple_code code
= gimple_code (stmt
);
2099 unsigned num_ops
= gimple_num_ops (stmt
);
2100 gimple copy
= gimple_alloc (code
, num_ops
);
2103 /* Shallow copy all the fields from STMT. */
2104 memcpy (copy
, stmt
, gimple_size (code
));
2106 /* If STMT has sub-statements, deep-copy them as well. */
2107 if (gimple_has_substatements (stmt
))
2112 switch (gimple_code (stmt
))
2115 new_seq
= gimple_seq_copy (gimple_bind_body (stmt
));
2116 gimple_bind_set_body (copy
, new_seq
);
2117 gimple_bind_set_vars (copy
, unshare_expr (gimple_bind_vars (stmt
)));
2118 gimple_bind_set_block (copy
, gimple_bind_block (stmt
));
2122 new_seq
= gimple_seq_copy (gimple_catch_handler (stmt
));
2123 gimple_catch_set_handler (copy
, new_seq
);
2124 t
= unshare_expr (gimple_catch_types (stmt
));
2125 gimple_catch_set_types (copy
, t
);
2128 case GIMPLE_EH_FILTER
:
2129 new_seq
= gimple_seq_copy (gimple_eh_filter_failure (stmt
));
2130 gimple_eh_filter_set_failure (copy
, new_seq
);
2131 t
= unshare_expr (gimple_eh_filter_types (stmt
));
2132 gimple_eh_filter_set_types (copy
, t
);
2136 new_seq
= gimple_seq_copy (gimple_try_eval (stmt
));
2137 gimple_try_set_eval (copy
, new_seq
);
2138 new_seq
= gimple_seq_copy (gimple_try_cleanup (stmt
));
2139 gimple_try_set_cleanup (copy
, new_seq
);
2142 case GIMPLE_OMP_FOR
:
2143 new_seq
= gimple_seq_copy (gimple_omp_for_pre_body (stmt
));
2144 gimple_omp_for_set_pre_body (copy
, new_seq
);
2145 t
= unshare_expr (gimple_omp_for_clauses (stmt
));
2146 gimple_omp_for_set_clauses (copy
, t
);
2147 copy
->gimple_omp_for
.iter
2148 = ggc_alloc_vec_gimple_omp_for_iter
2149 (gimple_omp_for_collapse (stmt
));
2150 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
2152 gimple_omp_for_set_cond (copy
, i
,
2153 gimple_omp_for_cond (stmt
, i
));
2154 gimple_omp_for_set_index (copy
, i
,
2155 gimple_omp_for_index (stmt
, i
));
2156 t
= unshare_expr (gimple_omp_for_initial (stmt
, i
));
2157 gimple_omp_for_set_initial (copy
, i
, t
);
2158 t
= unshare_expr (gimple_omp_for_final (stmt
, i
));
2159 gimple_omp_for_set_final (copy
, i
, t
);
2160 t
= unshare_expr (gimple_omp_for_incr (stmt
, i
));
2161 gimple_omp_for_set_incr (copy
, i
, t
);
2165 case GIMPLE_OMP_PARALLEL
:
2166 t
= unshare_expr (gimple_omp_parallel_clauses (stmt
));
2167 gimple_omp_parallel_set_clauses (copy
, t
);
2168 t
= unshare_expr (gimple_omp_parallel_child_fn (stmt
));
2169 gimple_omp_parallel_set_child_fn (copy
, t
);
2170 t
= unshare_expr (gimple_omp_parallel_data_arg (stmt
));
2171 gimple_omp_parallel_set_data_arg (copy
, t
);
2174 case GIMPLE_OMP_TASK
:
2175 t
= unshare_expr (gimple_omp_task_clauses (stmt
));
2176 gimple_omp_task_set_clauses (copy
, t
);
2177 t
= unshare_expr (gimple_omp_task_child_fn (stmt
));
2178 gimple_omp_task_set_child_fn (copy
, t
);
2179 t
= unshare_expr (gimple_omp_task_data_arg (stmt
));
2180 gimple_omp_task_set_data_arg (copy
, t
);
2181 t
= unshare_expr (gimple_omp_task_copy_fn (stmt
));
2182 gimple_omp_task_set_copy_fn (copy
, t
);
2183 t
= unshare_expr (gimple_omp_task_arg_size (stmt
));
2184 gimple_omp_task_set_arg_size (copy
, t
);
2185 t
= unshare_expr (gimple_omp_task_arg_align (stmt
));
2186 gimple_omp_task_set_arg_align (copy
, t
);
2189 case GIMPLE_OMP_CRITICAL
:
2190 t
= unshare_expr (gimple_omp_critical_name (stmt
));
2191 gimple_omp_critical_set_name (copy
, t
);
2194 case GIMPLE_OMP_SECTIONS
:
2195 t
= unshare_expr (gimple_omp_sections_clauses (stmt
));
2196 gimple_omp_sections_set_clauses (copy
, t
);
2197 t
= unshare_expr (gimple_omp_sections_control (stmt
));
2198 gimple_omp_sections_set_control (copy
, t
);
2201 case GIMPLE_OMP_SINGLE
:
2202 case GIMPLE_OMP_SECTION
:
2203 case GIMPLE_OMP_MASTER
:
2204 case GIMPLE_OMP_ORDERED
:
2206 new_seq
= gimple_seq_copy (gimple_omp_body (stmt
));
2207 gimple_omp_set_body (copy
, new_seq
);
2210 case GIMPLE_WITH_CLEANUP_EXPR
:
2211 new_seq
= gimple_seq_copy (gimple_wce_cleanup (stmt
));
2212 gimple_wce_set_cleanup (copy
, new_seq
);
2220 /* Make copy of operands. */
2223 for (i
= 0; i
< num_ops
; i
++)
2224 gimple_set_op (copy
, i
, unshare_expr (gimple_op (stmt
, i
)));
2226 /* Clear out SSA operand vectors on COPY. */
2227 if (gimple_has_ops (stmt
))
2229 gimple_set_def_ops (copy
, NULL
);
2230 gimple_set_use_ops (copy
, NULL
);
2233 if (gimple_has_mem_ops (stmt
))
2235 gimple_set_vdef (copy
, gimple_vdef (stmt
));
2236 gimple_set_vuse (copy
, gimple_vuse (stmt
));
2239 /* SSA operands need to be updated. */
2240 gimple_set_modified (copy
, true);
2247 /* Set the MODIFIED flag to MODIFIEDP, iff the gimple statement G has
2248 a MODIFIED field. */
2251 gimple_set_modified (gimple s
, bool modifiedp
)
2253 if (gimple_has_ops (s
))
2255 s
->gsbase
.modified
= (unsigned) modifiedp
;
2259 && is_gimple_call (s
)
2260 && gimple_call_noreturn_p (s
))
2261 VEC_safe_push (gimple
, gc
, MODIFIED_NORETURN_CALLS (cfun
), s
);
2266 /* Return true if statement S has side-effects. We consider a
2267 statement to have side effects if:
2269 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2270 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2273 gimple_has_side_effects (const_gimple s
)
2277 if (is_gimple_debug (s
))
2280 /* We don't have to scan the arguments to check for
2281 volatile arguments, though, at present, we still
2282 do a scan to check for TREE_SIDE_EFFECTS. */
2283 if (gimple_has_volatile_ops (s
))
2286 if (is_gimple_call (s
))
2288 unsigned nargs
= gimple_call_num_args (s
);
2290 if (!(gimple_call_flags (s
) & (ECF_CONST
| ECF_PURE
)))
2292 else if (gimple_call_flags (s
) & ECF_LOOPING_CONST_OR_PURE
)
2293 /* An infinite loop is considered a side effect. */
2296 if (gimple_call_lhs (s
)
2297 && TREE_SIDE_EFFECTS (gimple_call_lhs (s
)))
2299 gcc_assert (gimple_has_volatile_ops (s
));
2303 if (TREE_SIDE_EFFECTS (gimple_call_fn (s
)))
2306 for (i
= 0; i
< nargs
; i
++)
2307 if (TREE_SIDE_EFFECTS (gimple_call_arg (s
, i
)))
2309 gcc_assert (gimple_has_volatile_ops (s
));
2317 for (i
= 0; i
< gimple_num_ops (s
); i
++)
2318 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
)))
2320 gcc_assert (gimple_has_volatile_ops (s
));
2328 /* Return true if the RHS of statement S has side effects.
2329 We may use it to determine if it is admissable to replace
2330 an assignment or call with a copy of a previously-computed
2331 value. In such cases, side-effects due the the LHS are
2335 gimple_rhs_has_side_effects (const_gimple s
)
2339 if (is_gimple_call (s
))
2341 unsigned nargs
= gimple_call_num_args (s
);
2343 if (!(gimple_call_flags (s
) & (ECF_CONST
| ECF_PURE
)))
2346 /* We cannot use gimple_has_volatile_ops here,
2347 because we must ignore a volatile LHS. */
2348 if (TREE_SIDE_EFFECTS (gimple_call_fn (s
))
2349 || TREE_THIS_VOLATILE (gimple_call_fn (s
)))
2351 gcc_assert (gimple_has_volatile_ops (s
));
2355 for (i
= 0; i
< nargs
; i
++)
2356 if (TREE_SIDE_EFFECTS (gimple_call_arg (s
, i
))
2357 || TREE_THIS_VOLATILE (gimple_call_arg (s
, i
)))
2362 else if (is_gimple_assign (s
))
2364 /* Skip the first operand, the LHS. */
2365 for (i
= 1; i
< gimple_num_ops (s
); i
++)
2366 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
))
2367 || TREE_THIS_VOLATILE (gimple_op (s
, i
)))
2369 gcc_assert (gimple_has_volatile_ops (s
));
2373 else if (is_gimple_debug (s
))
2377 /* For statements without an LHS, examine all arguments. */
2378 for (i
= 0; i
< gimple_num_ops (s
); i
++)
2379 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
))
2380 || TREE_THIS_VOLATILE (gimple_op (s
, i
)))
2382 gcc_assert (gimple_has_volatile_ops (s
));
2390 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2391 Return true if S can trap. When INCLUDE_MEM is true, check whether
2392 the memory operations could trap. When INCLUDE_STORES is true and
2393 S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
2396 gimple_could_trap_p_1 (gimple s
, bool include_mem
, bool include_stores
)
2398 tree t
, div
= NULL_TREE
;
2403 unsigned i
, start
= (is_gimple_assign (s
) && !include_stores
) ? 1 : 0;
2405 for (i
= start
; i
< gimple_num_ops (s
); i
++)
2406 if (tree_could_trap_p (gimple_op (s
, i
)))
2410 switch (gimple_code (s
))
2413 return gimple_asm_volatile_p (s
);
2416 t
= gimple_call_fndecl (s
);
2417 /* Assume that calls to weak functions may trap. */
2418 if (!t
|| !DECL_P (t
) || DECL_WEAK (t
))
2423 t
= gimple_expr_type (s
);
2424 op
= gimple_assign_rhs_code (s
);
2425 if (get_gimple_rhs_class (op
) == GIMPLE_BINARY_RHS
)
2426 div
= gimple_assign_rhs2 (s
);
2427 return (operation_could_trap_p (op
, FLOAT_TYPE_P (t
),
2428 (INTEGRAL_TYPE_P (t
)
2429 && TYPE_OVERFLOW_TRAPS (t
)),
2439 /* Return true if statement S can trap. */
2442 gimple_could_trap_p (gimple s
)
2444 return gimple_could_trap_p_1 (s
, true, true);
2447 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2450 gimple_assign_rhs_could_trap_p (gimple s
)
2452 gcc_assert (is_gimple_assign (s
));
2453 return gimple_could_trap_p_1 (s
, true, false);
2457 /* Print debugging information for gimple stmts generated. */
2460 dump_gimple_statistics (void)
2462 #ifdef GATHER_STATISTICS
2463 int i
, total_tuples
= 0, total_bytes
= 0;
2465 fprintf (stderr
, "\nGIMPLE statements\n");
2466 fprintf (stderr
, "Kind Stmts Bytes\n");
2467 fprintf (stderr
, "---------------------------------------\n");
2468 for (i
= 0; i
< (int) gimple_alloc_kind_all
; ++i
)
2470 fprintf (stderr
, "%-20s %7d %10d\n", gimple_alloc_kind_names
[i
],
2471 gimple_alloc_counts
[i
], gimple_alloc_sizes
[i
]);
2472 total_tuples
+= gimple_alloc_counts
[i
];
2473 total_bytes
+= gimple_alloc_sizes
[i
];
2475 fprintf (stderr
, "---------------------------------------\n");
2476 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_tuples
, total_bytes
);
2477 fprintf (stderr
, "---------------------------------------\n");
2479 fprintf (stderr
, "No gimple statistics\n");
2484 /* Return the number of operands needed on the RHS of a GIMPLE
2485 assignment for an expression with tree code CODE. */
2488 get_gimple_rhs_num_ops (enum tree_code code
)
2490 enum gimple_rhs_class rhs_class
= get_gimple_rhs_class (code
);
2492 if (rhs_class
== GIMPLE_UNARY_RHS
|| rhs_class
== GIMPLE_SINGLE_RHS
)
2494 else if (rhs_class
== GIMPLE_BINARY_RHS
)
2496 else if (rhs_class
== GIMPLE_TERNARY_RHS
)
2502 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2504 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2505 : ((TYPE) == tcc_binary \
2506 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2507 : ((TYPE) == tcc_constant \
2508 || (TYPE) == tcc_declaration \
2509 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2510 : ((SYM) == TRUTH_AND_EXPR \
2511 || (SYM) == TRUTH_OR_EXPR \
2512 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2513 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2514 : ((SYM) == WIDEN_MULT_PLUS_EXPR \
2515 || (SYM) == WIDEN_MULT_MINUS_EXPR \
2516 || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \
2517 : ((SYM) == COND_EXPR \
2518 || (SYM) == CONSTRUCTOR \
2519 || (SYM) == OBJ_TYPE_REF \
2520 || (SYM) == ASSERT_EXPR \
2521 || (SYM) == ADDR_EXPR \
2522 || (SYM) == WITH_SIZE_EXPR \
2523 || (SYM) == SSA_NAME \
2524 || (SYM) == POLYNOMIAL_CHREC \
2525 || (SYM) == DOT_PROD_EXPR \
2526 || (SYM) == VEC_COND_EXPR \
2527 || (SYM) == REALIGN_LOAD_EXPR) ? GIMPLE_SINGLE_RHS \
2528 : GIMPLE_INVALID_RHS),
2529 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2531 const unsigned char gimple_rhs_class_table
[] = {
2532 #include "all-tree.def"
2536 #undef END_OF_BASE_TREE_CODES
2538 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2540 /* Validation of GIMPLE expressions. */
2542 /* Returns true iff T is a valid RHS for an assignment to a renamed
2543 user -- or front-end generated artificial -- variable. */
2546 is_gimple_reg_rhs (tree t
)
2548 return get_gimple_rhs_class (TREE_CODE (t
)) != GIMPLE_INVALID_RHS
;
2551 /* Returns true iff T is a valid RHS for an assignment to an un-renamed
2552 LHS, or for a call argument. */
2555 is_gimple_mem_rhs (tree t
)
2557 /* If we're dealing with a renamable type, either source or dest must be
2558 a renamed variable. */
2559 if (is_gimple_reg_type (TREE_TYPE (t
)))
2560 return is_gimple_val (t
);
2562 return is_gimple_val (t
) || is_gimple_lvalue (t
);
2565 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
2568 is_gimple_lvalue (tree t
)
2570 return (is_gimple_addressable (t
)
2571 || TREE_CODE (t
) == WITH_SIZE_EXPR
2572 /* These are complex lvalues, but don't have addresses, so they
2574 || TREE_CODE (t
) == BIT_FIELD_REF
);
2577 /* Return true if T is a GIMPLE condition. */
2580 is_gimple_condexpr (tree t
)
2582 return (is_gimple_val (t
) || (COMPARISON_CLASS_P (t
)
2583 && !tree_could_trap_p (t
)
2584 && is_gimple_val (TREE_OPERAND (t
, 0))
2585 && is_gimple_val (TREE_OPERAND (t
, 1))));
2588 /* Return true if T is something whose address can be taken. */
2591 is_gimple_addressable (tree t
)
2593 return (is_gimple_id (t
) || handled_component_p (t
)
2594 || TREE_CODE (t
) == MEM_REF
);
2597 /* Return true if T is a valid gimple constant. */
2600 is_gimple_constant (const_tree t
)
2602 switch (TREE_CODE (t
))
2612 /* Vector constant constructors are gimple invariant. */
2614 if (TREE_TYPE (t
) && TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2615 return TREE_CONSTANT (t
);
2624 /* Return true if T is a gimple address. */
2627 is_gimple_address (const_tree t
)
2631 if (TREE_CODE (t
) != ADDR_EXPR
)
2634 op
= TREE_OPERAND (t
, 0);
2635 while (handled_component_p (op
))
2637 if ((TREE_CODE (op
) == ARRAY_REF
2638 || TREE_CODE (op
) == ARRAY_RANGE_REF
)
2639 && !is_gimple_val (TREE_OPERAND (op
, 1)))
2642 op
= TREE_OPERAND (op
, 0);
2645 if (CONSTANT_CLASS_P (op
) || TREE_CODE (op
) == MEM_REF
)
2648 switch (TREE_CODE (op
))
2663 /* Strip out all handled components that produce invariant
2667 strip_invariant_refs (const_tree op
)
2669 while (handled_component_p (op
))
2671 switch (TREE_CODE (op
))
2674 case ARRAY_RANGE_REF
:
2675 if (!is_gimple_constant (TREE_OPERAND (op
, 1))
2676 || TREE_OPERAND (op
, 2) != NULL_TREE
2677 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2682 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2688 op
= TREE_OPERAND (op
, 0);
2694 /* Return true if T is a gimple invariant address. */
2697 is_gimple_invariant_address (const_tree t
)
2701 if (TREE_CODE (t
) != ADDR_EXPR
)
2704 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2708 if (TREE_CODE (op
) == MEM_REF
)
2710 const_tree op0
= TREE_OPERAND (op
, 0);
2711 return (TREE_CODE (op0
) == ADDR_EXPR
2712 && (CONSTANT_CLASS_P (TREE_OPERAND (op0
, 0))
2713 || decl_address_invariant_p (TREE_OPERAND (op0
, 0))));
2716 return CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
);
2719 /* Return true if T is a gimple invariant address at IPA level
2720 (so addresses of variables on stack are not allowed). */
2723 is_gimple_ip_invariant_address (const_tree t
)
2727 if (TREE_CODE (t
) != ADDR_EXPR
)
2730 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2732 return op
&& (CONSTANT_CLASS_P (op
) || decl_address_ip_invariant_p (op
));
2735 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
2736 form of function invariant. */
2739 is_gimple_min_invariant (const_tree t
)
2741 if (TREE_CODE (t
) == ADDR_EXPR
)
2742 return is_gimple_invariant_address (t
);
2744 return is_gimple_constant (t
);
2747 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
2748 form of gimple minimal invariant. */
2751 is_gimple_ip_invariant (const_tree t
)
2753 if (TREE_CODE (t
) == ADDR_EXPR
)
2754 return is_gimple_ip_invariant_address (t
);
2756 return is_gimple_constant (t
);
2759 /* Return true if T looks like a valid GIMPLE statement. */
2762 is_gimple_stmt (tree t
)
2764 const enum tree_code code
= TREE_CODE (t
);
2769 /* The only valid NOP_EXPR is the empty statement. */
2770 return IS_EMPTY_STMT (t
);
2774 /* These are only valid if they're void. */
2775 return TREE_TYPE (t
) == NULL
|| VOID_TYPE_P (TREE_TYPE (t
));
2781 case CASE_LABEL_EXPR
:
2782 case TRY_CATCH_EXPR
:
2783 case TRY_FINALLY_EXPR
:
2784 case EH_FILTER_EXPR
:
2787 case STATEMENT_LIST
:
2797 /* These are always void. */
2803 /* These are valid regardless of their type. */
2811 /* Return true if T is a variable. */
2814 is_gimple_variable (tree t
)
2816 return (TREE_CODE (t
) == VAR_DECL
2817 || TREE_CODE (t
) == PARM_DECL
2818 || TREE_CODE (t
) == RESULT_DECL
2819 || TREE_CODE (t
) == SSA_NAME
);
2822 /* Return true if T is a GIMPLE identifier (something with an address). */
2825 is_gimple_id (tree t
)
2827 return (is_gimple_variable (t
)
2828 || TREE_CODE (t
) == FUNCTION_DECL
2829 || TREE_CODE (t
) == LABEL_DECL
2830 || TREE_CODE (t
) == CONST_DECL
2831 /* Allow string constants, since they are addressable. */
2832 || TREE_CODE (t
) == STRING_CST
);
2835 /* Return true if TYPE is a suitable type for a scalar register variable. */
2838 is_gimple_reg_type (tree type
)
2840 return !AGGREGATE_TYPE_P (type
);
2843 /* Return true if T is a non-aggregate register variable. */
2846 is_gimple_reg (tree t
)
2848 if (TREE_CODE (t
) == SSA_NAME
)
2849 t
= SSA_NAME_VAR (t
);
2851 if (!is_gimple_variable (t
))
2854 if (!is_gimple_reg_type (TREE_TYPE (t
)))
2857 /* A volatile decl is not acceptable because we can't reuse it as
2858 needed. We need to copy it into a temp first. */
2859 if (TREE_THIS_VOLATILE (t
))
2862 /* We define "registers" as things that can be renamed as needed,
2863 which with our infrastructure does not apply to memory. */
2864 if (needs_to_live_in_memory (t
))
2867 /* Hard register variables are an interesting case. For those that
2868 are call-clobbered, we don't know where all the calls are, since
2869 we don't (want to) take into account which operations will turn
2870 into libcalls at the rtl level. For those that are call-saved,
2871 we don't currently model the fact that calls may in fact change
2872 global hard registers, nor do we examine ASM_CLOBBERS at the tree
2873 level, and so miss variable changes that might imply. All around,
2874 it seems safest to not do too much optimization with these at the
2875 tree level at all. We'll have to rely on the rtl optimizers to
2876 clean this up, as there we've got all the appropriate bits exposed. */
2877 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2880 /* Complex and vector values must have been put into SSA-like form.
2881 That is, no assignments to the individual components. */
2882 if (TREE_CODE (TREE_TYPE (t
)) == COMPLEX_TYPE
2883 || TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2884 return DECL_GIMPLE_REG_P (t
);
2890 /* Return true if T is a GIMPLE variable whose address is not needed. */
2893 is_gimple_non_addressable (tree t
)
2895 if (TREE_CODE (t
) == SSA_NAME
)
2896 t
= SSA_NAME_VAR (t
);
2898 return (is_gimple_variable (t
) && ! needs_to_live_in_memory (t
));
2901 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
2904 is_gimple_val (tree t
)
2906 /* Make loads from volatiles and memory vars explicit. */
2907 if (is_gimple_variable (t
)
2908 && is_gimple_reg_type (TREE_TYPE (t
))
2909 && !is_gimple_reg (t
))
2912 return (is_gimple_variable (t
) || is_gimple_min_invariant (t
));
2915 /* Similarly, but accept hard registers as inputs to asm statements. */
2918 is_gimple_asm_val (tree t
)
2920 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2923 return is_gimple_val (t
);
2926 /* Return true if T is a GIMPLE minimal lvalue. */
2929 is_gimple_min_lval (tree t
)
2931 if (!(t
= CONST_CAST_TREE (strip_invariant_refs (t
))))
2933 return (is_gimple_id (t
) || TREE_CODE (t
) == MEM_REF
);
2936 /* Return true if T is a valid function operand of a CALL_EXPR. */
2939 is_gimple_call_addr (tree t
)
2941 return (TREE_CODE (t
) == OBJ_TYPE_REF
|| is_gimple_val (t
));
2944 /* Return true if T is a valid address operand of a MEM_REF. */
2947 is_gimple_mem_ref_addr (tree t
)
2949 return (is_gimple_reg (t
)
2950 || TREE_CODE (t
) == INTEGER_CST
2951 || (TREE_CODE (t
) == ADDR_EXPR
2952 && (CONSTANT_CLASS_P (TREE_OPERAND (t
, 0))
2953 || decl_address_invariant_p (TREE_OPERAND (t
, 0)))));
2956 /* If T makes a function call, return the corresponding CALL_EXPR operand.
2957 Otherwise, return NULL_TREE. */
2960 get_call_expr_in (tree t
)
2962 if (TREE_CODE (t
) == MODIFY_EXPR
)
2963 t
= TREE_OPERAND (t
, 1);
2964 if (TREE_CODE (t
) == WITH_SIZE_EXPR
)
2965 t
= TREE_OPERAND (t
, 0);
2966 if (TREE_CODE (t
) == CALL_EXPR
)
2972 /* Given a memory reference expression T, return its base address.
2973 The base address of a memory reference expression is the main
2974 object being referenced. For instance, the base address for
2975 'array[i].fld[j]' is 'array'. You can think of this as stripping
2976 away the offset part from a memory address.
2978 This function calls handled_component_p to strip away all the inner
2979 parts of the memory reference until it reaches the base object. */
2982 get_base_address (tree t
)
2984 while (handled_component_p (t
))
2985 t
= TREE_OPERAND (t
, 0);
2987 if ((TREE_CODE (t
) == MEM_REF
2988 || TREE_CODE (t
) == TARGET_MEM_REF
)
2989 && TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
2990 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
2992 if (TREE_CODE (t
) == SSA_NAME
2994 || TREE_CODE (t
) == STRING_CST
2995 || TREE_CODE (t
) == CONSTRUCTOR
2996 || INDIRECT_REF_P (t
)
2997 || TREE_CODE (t
) == MEM_REF
2998 || TREE_CODE (t
) == TARGET_MEM_REF
)
3005 recalculate_side_effects (tree t
)
3007 enum tree_code code
= TREE_CODE (t
);
3008 int len
= TREE_OPERAND_LENGTH (t
);
3011 switch (TREE_CODE_CLASS (code
))
3013 case tcc_expression
:
3019 case PREDECREMENT_EXPR
:
3020 case PREINCREMENT_EXPR
:
3021 case POSTDECREMENT_EXPR
:
3022 case POSTINCREMENT_EXPR
:
3023 /* All of these have side-effects, no matter what their
3032 case tcc_comparison
: /* a comparison expression */
3033 case tcc_unary
: /* a unary arithmetic expression */
3034 case tcc_binary
: /* a binary arithmetic expression */
3035 case tcc_reference
: /* a reference */
3036 case tcc_vl_exp
: /* a function call */
3037 TREE_SIDE_EFFECTS (t
) = TREE_THIS_VOLATILE (t
);
3038 for (i
= 0; i
< len
; ++i
)
3040 tree op
= TREE_OPERAND (t
, i
);
3041 if (op
&& TREE_SIDE_EFFECTS (op
))
3042 TREE_SIDE_EFFECTS (t
) = 1;
3047 /* No side-effects. */
3055 /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
3056 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
3057 we failed to create one. */
3060 canonicalize_cond_expr_cond (tree t
)
3062 /* Strip conversions around boolean operations. */
3063 if (CONVERT_EXPR_P (t
)
3064 && truth_value_p (TREE_CODE (TREE_OPERAND (t
, 0))))
3065 t
= TREE_OPERAND (t
, 0);
3067 /* For (bool)x use x != 0. */
3068 if (CONVERT_EXPR_P (t
)
3069 && TREE_CODE (TREE_TYPE (t
)) == BOOLEAN_TYPE
)
3071 tree top0
= TREE_OPERAND (t
, 0);
3072 t
= build2 (NE_EXPR
, TREE_TYPE (t
),
3073 top0
, build_int_cst (TREE_TYPE (top0
), 0));
3075 /* For !x use x == 0. */
3076 else if (TREE_CODE (t
) == TRUTH_NOT_EXPR
)
3078 tree top0
= TREE_OPERAND (t
, 0);
3079 t
= build2 (EQ_EXPR
, TREE_TYPE (t
),
3080 top0
, build_int_cst (TREE_TYPE (top0
), 0));
3082 /* For cmp ? 1 : 0 use cmp. */
3083 else if (TREE_CODE (t
) == COND_EXPR
3084 && COMPARISON_CLASS_P (TREE_OPERAND (t
, 0))
3085 && integer_onep (TREE_OPERAND (t
, 1))
3086 && integer_zerop (TREE_OPERAND (t
, 2)))
3088 tree top0
= TREE_OPERAND (t
, 0);
3089 t
= build2 (TREE_CODE (top0
), TREE_TYPE (t
),
3090 TREE_OPERAND (top0
, 0), TREE_OPERAND (top0
, 1));
3093 if (is_gimple_condexpr (t
))
3099 /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
3100 the positions marked by the set ARGS_TO_SKIP. */
3103 gimple_call_copy_skip_args (gimple stmt
, bitmap args_to_skip
)
3106 tree fn
= gimple_call_fn (stmt
);
3107 int nargs
= gimple_call_num_args (stmt
);
3108 VEC(tree
, heap
) *vargs
= VEC_alloc (tree
, heap
, nargs
);
3111 for (i
= 0; i
< nargs
; i
++)
3112 if (!bitmap_bit_p (args_to_skip
, i
))
3113 VEC_quick_push (tree
, vargs
, gimple_call_arg (stmt
, i
));
3115 new_stmt
= gimple_build_call_vec (fn
, vargs
);
3116 VEC_free (tree
, heap
, vargs
);
3117 if (gimple_call_lhs (stmt
))
3118 gimple_call_set_lhs (new_stmt
, gimple_call_lhs (stmt
));
3120 gimple_set_vuse (new_stmt
, gimple_vuse (stmt
));
3121 gimple_set_vdef (new_stmt
, gimple_vdef (stmt
));
3123 gimple_set_block (new_stmt
, gimple_block (stmt
));
3124 if (gimple_has_location (stmt
))
3125 gimple_set_location (new_stmt
, gimple_location (stmt
));
3126 gimple_call_copy_flags (new_stmt
, stmt
);
3127 gimple_call_set_chain (new_stmt
, gimple_call_chain (stmt
));
3129 gimple_set_modified (new_stmt
, true);
3135 static hashval_t
gimple_type_hash (const void *);
3137 /* Structure used to maintain a cache of some type pairs compared by
3138 gimple_types_compatible_p when comparing aggregate types. There are
3139 three possible values for SAME_P:
3141 -2: The pair (T1, T2) has just been inserted in the table.
3142 0: T1 and T2 are different types.
3143 1: T1 and T2 are the same type.
3145 The two elements in the SAME_P array are indexed by the comparison
3152 signed char same_p
[2];
3154 typedef struct type_pair_d
*type_pair_t
;
3156 DEF_VEC_P(type_pair_t
);
3157 DEF_VEC_ALLOC_P(type_pair_t
,heap
);
3159 /* Return a hash value for the type pair pointed-to by P. */
3162 type_pair_hash (const void *p
)
3164 const struct type_pair_d
*pair
= (const struct type_pair_d
*) p
;
3165 hashval_t val1
= pair
->uid1
;
3166 hashval_t val2
= pair
->uid2
;
3167 return (iterative_hash_hashval_t (val2
, val1
)
3168 ^ iterative_hash_hashval_t (val1
, val2
));
3171 /* Compare two type pairs pointed-to by P1 and P2. */
3174 type_pair_eq (const void *p1
, const void *p2
)
3176 const struct type_pair_d
*pair1
= (const struct type_pair_d
*) p1
;
3177 const struct type_pair_d
*pair2
= (const struct type_pair_d
*) p2
;
3178 return ((pair1
->uid1
== pair2
->uid1
&& pair1
->uid2
== pair2
->uid2
)
3179 || (pair1
->uid1
== pair2
->uid2
&& pair1
->uid2
== pair2
->uid1
));
3182 /* Lookup the pair of types T1 and T2 in *VISITED_P. Insert a new
3183 entry if none existed. */
3186 lookup_type_pair (tree t1
, tree t2
, htab_t
*visited_p
, struct obstack
*ob_p
)
3188 struct type_pair_d pair
;
3192 if (*visited_p
== NULL
)
3194 *visited_p
= htab_create (251, type_pair_hash
, type_pair_eq
, NULL
);
3195 gcc_obstack_init (ob_p
);
3198 pair
.uid1
= TYPE_UID (t1
);
3199 pair
.uid2
= TYPE_UID (t2
);
3200 slot
= htab_find_slot (*visited_p
, &pair
, INSERT
);
3203 p
= *((type_pair_t
*) slot
);
3206 p
= XOBNEW (ob_p
, struct type_pair_d
);
3207 p
->uid1
= TYPE_UID (t1
);
3208 p
->uid2
= TYPE_UID (t2
);
3217 /* Per pointer state for the SCC finding. The on_sccstack flag
3218 is not strictly required, it is true when there is no hash value
3219 recorded for the type and false otherwise. But querying that
3224 unsigned int dfsnum
;
3233 static unsigned int next_dfs_num
;
3234 static unsigned int gtc_next_dfs_num
;
3237 /* GIMPLE type merging cache. A direct-mapped cache based on TYPE_UID. */
3239 typedef struct GTY(()) gimple_type_leader_entry_s
{
3242 } gimple_type_leader_entry
;
3244 #define GIMPLE_TYPE_LEADER_SIZE 16381
3245 static GTY((length("GIMPLE_TYPE_LEADER_SIZE"))) gimple_type_leader_entry
3246 *gimple_type_leader
;
3248 /* Lookup an existing leader for T and return it or NULL_TREE, if
3249 there is none in the cache. */
3252 gimple_lookup_type_leader (tree t
)
3254 gimple_type_leader_entry
*leader
;
3256 if (!gimple_type_leader
)
3259 leader
= &gimple_type_leader
[TYPE_UID (t
) % GIMPLE_TYPE_LEADER_SIZE
];
3260 if (leader
->type
!= t
)
3263 return leader
->leader
;
3266 /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is
3267 true then if any type has no name return false, otherwise return
3268 true if both types have no names. */
3271 compare_type_names_p (tree t1
, tree t2
, bool for_completion_p
)
3273 tree name1
= TYPE_NAME (t1
);
3274 tree name2
= TYPE_NAME (t2
);
3276 /* Consider anonymous types all unique for completion. */
3277 if (for_completion_p
3278 && (!name1
|| !name2
))
3281 if (name1
&& TREE_CODE (name1
) == TYPE_DECL
)
3283 name1
= DECL_NAME (name1
);
3284 if (for_completion_p
3288 gcc_assert (!name1
|| TREE_CODE (name1
) == IDENTIFIER_NODE
);
3290 if (name2
&& TREE_CODE (name2
) == TYPE_DECL
)
3292 name2
= DECL_NAME (name2
);
3293 if (for_completion_p
3297 gcc_assert (!name2
|| TREE_CODE (name2
) == IDENTIFIER_NODE
);
3299 /* Identifiers can be compared with pointer equality rather
3300 than a string comparison. */
3307 /* Return true if the field decls F1 and F2 are at the same offset.
3309 This is intended to be used on GIMPLE types only. In order to
3310 compare GENERIC types, use fields_compatible_p instead. */
3313 gimple_compare_field_offset (tree f1
, tree f2
)
3315 if (DECL_OFFSET_ALIGN (f1
) == DECL_OFFSET_ALIGN (f2
))
3317 tree offset1
= DECL_FIELD_OFFSET (f1
);
3318 tree offset2
= DECL_FIELD_OFFSET (f2
);
3319 return ((offset1
== offset2
3320 /* Once gimplification is done, self-referential offsets are
3321 instantiated as operand #2 of the COMPONENT_REF built for
3322 each access and reset. Therefore, they are not relevant
3323 anymore and fields are interchangeable provided that they
3324 represent the same access. */
3325 || (TREE_CODE (offset1
) == PLACEHOLDER_EXPR
3326 && TREE_CODE (offset2
) == PLACEHOLDER_EXPR
3327 && (DECL_SIZE (f1
) == DECL_SIZE (f2
)
3328 || (TREE_CODE (DECL_SIZE (f1
)) == PLACEHOLDER_EXPR
3329 && TREE_CODE (DECL_SIZE (f2
)) == PLACEHOLDER_EXPR
)
3330 || operand_equal_p (DECL_SIZE (f1
), DECL_SIZE (f2
), 0))
3331 && DECL_ALIGN (f1
) == DECL_ALIGN (f2
))
3332 || operand_equal_p (offset1
, offset2
, 0))
3333 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1
),
3334 DECL_FIELD_BIT_OFFSET (f2
)));
3337 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
3338 should be, so handle differing ones specially by decomposing
3339 the offset into a byte and bit offset manually. */
3340 if (host_integerp (DECL_FIELD_OFFSET (f1
), 0)
3341 && host_integerp (DECL_FIELD_OFFSET (f2
), 0))
3343 unsigned HOST_WIDE_INT byte_offset1
, byte_offset2
;
3344 unsigned HOST_WIDE_INT bit_offset1
, bit_offset2
;
3345 bit_offset1
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1
));
3346 byte_offset1
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1
))
3347 + bit_offset1
/ BITS_PER_UNIT
);
3348 bit_offset2
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2
));
3349 byte_offset2
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2
))
3350 + bit_offset2
/ BITS_PER_UNIT
);
3351 if (byte_offset1
!= byte_offset2
)
3353 return bit_offset1
% BITS_PER_UNIT
== bit_offset2
% BITS_PER_UNIT
;
3359 /* If the type T1 and the type T2 are a complete and an incomplete
3360 variant of the same type return true. */
3363 gimple_compatible_complete_and_incomplete_subtype_p (tree t1
, tree t2
)
3365 /* If one pointer points to an incomplete type variant of
3366 the other pointed-to type they are the same. */
3367 if (TREE_CODE (t1
) == TREE_CODE (t2
)
3368 && RECORD_OR_UNION_TYPE_P (t1
)
3369 && (!COMPLETE_TYPE_P (t1
)
3370 || !COMPLETE_TYPE_P (t2
))
3371 && TYPE_QUALS (t1
) == TYPE_QUALS (t2
)
3372 && compare_type_names_p (TYPE_MAIN_VARIANT (t1
),
3373 TYPE_MAIN_VARIANT (t2
), true))
3379 gimple_types_compatible_p_1 (tree
, tree
, enum gtc_mode
, type_pair_t
,
3380 VEC(type_pair_t
, heap
) **,
3381 struct pointer_map_t
*, struct obstack
*);
3383 /* DFS visit the edge from the callers type pair with state *STATE to
3384 the pair T1, T2 while operating in FOR_MERGING_P mode.
3385 Update the merging status if it is not part of the SCC containing the
3386 callers pair and return it.
3387 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3390 gtc_visit (tree t1
, tree t2
, enum gtc_mode mode
,
3392 VEC(type_pair_t
, heap
) **sccstack
,
3393 struct pointer_map_t
*sccstate
,
3394 struct obstack
*sccstate_obstack
)
3396 struct sccs
*cstate
= NULL
;
3400 /* Check first for the obvious case of pointer identity. */
3404 /* Check that we have two types to compare. */
3405 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
3408 /* If the types have been previously registered and found equal
3410 if (mode
== GTC_MERGE
)
3412 tree leader1
= gimple_lookup_type_leader (t1
);
3413 tree leader2
= gimple_lookup_type_leader (t2
);
3416 || (leader1
&& leader1
== leader2
))
3419 else if (mode
== GTC_DIAG
)
3421 if (TYPE_CANONICAL (t1
)
3422 && TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
))
3426 /* Can't be the same type if the types don't have the same code. */
3427 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3430 /* Can't be the same type if they have different CV qualifiers. */
3431 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
3434 /* Void types are always the same. */
3435 if (TREE_CODE (t1
) == VOID_TYPE
)
3438 /* Do some simple checks before doing three hashtable queries. */
3439 if (INTEGRAL_TYPE_P (t1
)
3440 || SCALAR_FLOAT_TYPE_P (t1
)
3441 || FIXED_POINT_TYPE_P (t1
)
3442 || TREE_CODE (t1
) == VECTOR_TYPE
3443 || TREE_CODE (t1
) == COMPLEX_TYPE
3444 || TREE_CODE (t1
) == OFFSET_TYPE
)
3446 /* Can't be the same type if they have different alignment,
3447 sign, precision or mode. */
3448 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3449 || TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
3450 || TYPE_MODE (t1
) != TYPE_MODE (t2
)
3451 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
3454 if (TREE_CODE (t1
) == INTEGER_TYPE
3455 && (TYPE_IS_SIZETYPE (t1
) != TYPE_IS_SIZETYPE (t2
)
3456 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)))
3459 /* That's all we need to check for float and fixed-point types. */
3460 if (SCALAR_FLOAT_TYPE_P (t1
)
3461 || FIXED_POINT_TYPE_P (t1
))
3464 /* For integral types fall thru to more complex checks. */
3467 else if (AGGREGATE_TYPE_P (t1
) || POINTER_TYPE_P (t1
))
3469 /* Can't be the same type if they have different alignment or mode. */
3470 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3471 || TYPE_MODE (t1
) != TYPE_MODE (t2
))
3475 /* If the hash values of t1 and t2 are different the types can't
3476 possibly be the same. This helps keeping the type-pair hashtable
3477 small, only tracking comparisons for hash collisions. */
3478 if (gimple_type_hash (t1
) != gimple_type_hash (t2
))
3481 /* Allocate a new cache entry for this comparison. */
3482 p
= lookup_type_pair (t1
, t2
, >c_visited
, >c_ob
);
3483 if (p
->same_p
[mode
] == 0 || p
->same_p
[mode
] == 1)
3485 /* We have already decided whether T1 and T2 are the
3486 same, return the cached result. */
3487 return p
->same_p
[mode
] == 1;
3490 if ((slot
= pointer_map_contains (sccstate
, p
)) != NULL
)
3491 cstate
= (struct sccs
*)*slot
;
3492 /* Not yet visited. DFS recurse. */
3495 gimple_types_compatible_p_1 (t1
, t2
, mode
, p
,
3496 sccstack
, sccstate
, sccstate_obstack
);
3497 cstate
= (struct sccs
*)* pointer_map_contains (sccstate
, p
);
3498 state
->low
= MIN (state
->low
, cstate
->low
);
3500 /* If the type is still on the SCC stack adjust the parents low. */
3501 if (cstate
->dfsnum
< state
->dfsnum
3502 && cstate
->on_sccstack
)
3503 state
->low
= MIN (cstate
->dfsnum
, state
->low
);
3505 /* Return the current lattice value. We start with an equality
3506 assumption so types part of a SCC will be optimistically
3507 treated equal unless proven otherwise. */
3508 return cstate
->u
.same_p
;
3511 /* Worker for gimple_types_compatible.
3512 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3515 gimple_types_compatible_p_1 (tree t1
, tree t2
, enum gtc_mode mode
,
3517 VEC(type_pair_t
, heap
) **sccstack
,
3518 struct pointer_map_t
*sccstate
,
3519 struct obstack
*sccstate_obstack
)
3523 gcc_assert (p
->same_p
[mode
] == -2);
3525 state
= XOBNEW (sccstate_obstack
, struct sccs
);
3526 *pointer_map_insert (sccstate
, p
) = state
;
3528 VEC_safe_push (type_pair_t
, heap
, *sccstack
, p
);
3529 state
->dfsnum
= gtc_next_dfs_num
++;
3530 state
->low
= state
->dfsnum
;
3531 state
->on_sccstack
= true;
3532 /* Start with an equality assumption. As we DFS recurse into child
3533 SCCs this assumption may get revisited. */
3534 state
->u
.same_p
= 1;
3536 /* If their attributes are not the same they can't be the same type. */
3537 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1
), TYPE_ATTRIBUTES (t2
)))
3538 goto different_types
;
3540 /* Do type-specific comparisons. */
3541 switch (TREE_CODE (t1
))
3545 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
), mode
,
3546 state
, sccstack
, sccstate
, sccstate_obstack
))
3547 goto different_types
;
3551 /* Array types are the same if the element types are the same and
3552 the number of elements are the same. */
3553 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
), mode
,
3554 state
, sccstack
, sccstate
, sccstate_obstack
)
3555 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)
3556 || TYPE_NONALIASED_COMPONENT (t1
) != TYPE_NONALIASED_COMPONENT (t2
))
3557 goto different_types
;
3560 tree i1
= TYPE_DOMAIN (t1
);
3561 tree i2
= TYPE_DOMAIN (t2
);
3563 /* For an incomplete external array, the type domain can be
3564 NULL_TREE. Check this condition also. */
3565 if (i1
== NULL_TREE
&& i2
== NULL_TREE
)
3567 else if (i1
== NULL_TREE
|| i2
== NULL_TREE
)
3568 goto different_types
;
3569 /* If for a complete array type the possibly gimplified sizes
3570 are different the types are different. */
3571 else if (((TYPE_SIZE (i1
) != NULL
) ^ (TYPE_SIZE (i2
) != NULL
))
3574 && !operand_equal_p (TYPE_SIZE (i1
), TYPE_SIZE (i2
), 0)))
3575 goto different_types
;
3578 tree min1
= TYPE_MIN_VALUE (i1
);
3579 tree min2
= TYPE_MIN_VALUE (i2
);
3580 tree max1
= TYPE_MAX_VALUE (i1
);
3581 tree max2
= TYPE_MAX_VALUE (i2
);
3583 /* The minimum/maximum values have to be the same. */
3586 && ((TREE_CODE (min1
) == PLACEHOLDER_EXPR
3587 && TREE_CODE (min2
) == PLACEHOLDER_EXPR
)
3588 || operand_equal_p (min1
, min2
, 0))))
3591 && ((TREE_CODE (max1
) == PLACEHOLDER_EXPR
3592 && TREE_CODE (max2
) == PLACEHOLDER_EXPR
)
3593 || operand_equal_p (max1
, max2
, 0)))))
3596 goto different_types
;
3601 /* Method types should belong to the same class. */
3602 if (!gtc_visit (TYPE_METHOD_BASETYPE (t1
), TYPE_METHOD_BASETYPE (t2
),
3603 mode
, state
, sccstack
, sccstate
, sccstate_obstack
))
3604 goto different_types
;
3609 /* Function types are the same if the return type and arguments types
3611 if ((mode
!= GTC_DIAG
3612 || !gimple_compatible_complete_and_incomplete_subtype_p
3613 (TREE_TYPE (t1
), TREE_TYPE (t2
)))
3614 && !gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
), mode
,
3615 state
, sccstack
, sccstate
, sccstate_obstack
))
3616 goto different_types
;
3618 if (!targetm
.comp_type_attributes (t1
, t2
))
3619 goto different_types
;
3621 if (TYPE_ARG_TYPES (t1
) == TYPE_ARG_TYPES (t2
))
3625 tree parms1
, parms2
;
3627 for (parms1
= TYPE_ARG_TYPES (t1
), parms2
= TYPE_ARG_TYPES (t2
);
3629 parms1
= TREE_CHAIN (parms1
), parms2
= TREE_CHAIN (parms2
))
3631 if ((mode
== GTC_MERGE
3632 || !gimple_compatible_complete_and_incomplete_subtype_p
3633 (TREE_VALUE (parms1
), TREE_VALUE (parms2
)))
3634 && !gtc_visit (TREE_VALUE (parms1
), TREE_VALUE (parms2
), mode
,
3635 state
, sccstack
, sccstate
, sccstate_obstack
))
3636 goto different_types
;
3639 if (parms1
|| parms2
)
3640 goto different_types
;
3647 if (!gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
), mode
,
3648 state
, sccstack
, sccstate
, sccstate_obstack
)
3649 || !gtc_visit (TYPE_OFFSET_BASETYPE (t1
),
3650 TYPE_OFFSET_BASETYPE (t2
), mode
,
3651 state
, sccstack
, sccstate
, sccstate_obstack
))
3652 goto different_types
;
3658 case REFERENCE_TYPE
:
3660 /* If the two pointers have different ref-all attributes,
3661 they can't be the same type. */
3662 if (TYPE_REF_CAN_ALIAS_ALL (t1
) != TYPE_REF_CAN_ALIAS_ALL (t2
))
3663 goto different_types
;
3665 /* If one pointer points to an incomplete type variant of
3666 the other pointed-to type they are the same. */
3667 if (mode
== GTC_DIAG
3668 && gimple_compatible_complete_and_incomplete_subtype_p
3669 (TREE_TYPE (t1
), TREE_TYPE (t2
)))
3672 /* Otherwise, pointer and reference types are the same if the
3673 pointed-to types are the same. */
3674 if (gtc_visit (TREE_TYPE (t1
), TREE_TYPE (t2
), mode
,
3675 state
, sccstack
, sccstate
, sccstate_obstack
))
3678 goto different_types
;
3682 /* There is only one decltype(nullptr). */
3688 tree min1
= TYPE_MIN_VALUE (t1
);
3689 tree max1
= TYPE_MAX_VALUE (t1
);
3690 tree min2
= TYPE_MIN_VALUE (t2
);
3691 tree max2
= TYPE_MAX_VALUE (t2
);
3692 bool min_equal_p
= false;
3693 bool max_equal_p
= false;
3695 /* If either type has a minimum value, the other type must
3697 if (min1
== NULL_TREE
&& min2
== NULL_TREE
)
3699 else if (min1
&& min2
&& operand_equal_p (min1
, min2
, 0))
3702 /* Likewise, if either type has a maximum value, the other
3703 type must have the same. */
3704 if (max1
== NULL_TREE
&& max2
== NULL_TREE
)
3706 else if (max1
&& max2
&& operand_equal_p (max1
, max2
, 0))
3709 if (!min_equal_p
|| !max_equal_p
)
3710 goto different_types
;
3717 /* FIXME lto, we cannot check bounds on enumeral types because
3718 different front ends will produce different values.
3719 In C, enumeral types are integers, while in C++ each element
3720 will have its own symbolic value. We should decide how enums
3721 are to be represented in GIMPLE and have each front end lower
3725 /* For enumeral types, all the values must be the same. */
3726 if (TYPE_VALUES (t1
) == TYPE_VALUES (t2
))
3729 for (v1
= TYPE_VALUES (t1
), v2
= TYPE_VALUES (t2
);
3731 v1
= TREE_CHAIN (v1
), v2
= TREE_CHAIN (v2
))
3733 tree c1
= TREE_VALUE (v1
);
3734 tree c2
= TREE_VALUE (v2
);
3736 if (TREE_CODE (c1
) == CONST_DECL
)
3737 c1
= DECL_INITIAL (c1
);
3739 if (TREE_CODE (c2
) == CONST_DECL
)
3740 c2
= DECL_INITIAL (c2
);
3742 if (tree_int_cst_equal (c1
, c2
) != 1)
3743 goto different_types
;
3746 /* If one enumeration has more values than the other, they
3747 are not the same. */
3749 goto different_types
;
3756 case QUAL_UNION_TYPE
:
3760 /* The struct tags shall compare equal. */
3761 if (!compare_type_names_p (TYPE_MAIN_VARIANT (t1
),
3762 TYPE_MAIN_VARIANT (t2
), false))
3763 goto different_types
;
3765 /* For aggregate types, all the fields must be the same. */
3766 for (f1
= TYPE_FIELDS (t1
), f2
= TYPE_FIELDS (t2
);
3768 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
3770 /* The fields must have the same name, offset and type. */
3771 if (DECL_NAME (f1
) != DECL_NAME (f2
)
3772 || DECL_NONADDRESSABLE_P (f1
) != DECL_NONADDRESSABLE_P (f2
)
3773 || !gimple_compare_field_offset (f1
, f2
)
3774 || !gtc_visit (TREE_TYPE (f1
), TREE_TYPE (f2
), mode
,
3775 state
, sccstack
, sccstate
, sccstate_obstack
))
3776 goto different_types
;
3779 /* If one aggregate has more fields than the other, they
3780 are not the same. */
3782 goto different_types
;
3791 /* Common exit path for types that are not compatible. */
3793 state
->u
.same_p
= 0;
3796 /* Common exit path for types that are compatible. */
3798 gcc_assert (state
->u
.same_p
== 1);
3801 if (state
->low
== state
->dfsnum
)
3805 /* Pop off the SCC and set its cache values to the final
3806 comparison result. */
3809 struct sccs
*cstate
;
3810 x
= VEC_pop (type_pair_t
, *sccstack
);
3811 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
3812 cstate
->on_sccstack
= false;
3813 x
->same_p
[mode
] = state
->u
.same_p
;
3818 return state
->u
.same_p
;
3821 /* Return true iff T1 and T2 are structurally identical. When
3822 FOR_MERGING_P is true the an incomplete type and a complete type
3823 are considered different, otherwise they are considered compatible. */
3826 gimple_types_compatible_p (tree t1
, tree t2
, enum gtc_mode mode
)
3828 VEC(type_pair_t
, heap
) *sccstack
= NULL
;
3829 struct pointer_map_t
*sccstate
;
3830 struct obstack sccstate_obstack
;
3831 type_pair_t p
= NULL
;
3834 /* Before starting to set up the SCC machinery handle simple cases. */
3836 /* Check first for the obvious case of pointer identity. */
3840 /* Check that we have two types to compare. */
3841 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
3844 /* If the types have been previously registered and found equal
3846 if (mode
== GTC_MERGE
)
3848 tree leader1
= gimple_lookup_type_leader (t1
);
3849 tree leader2
= gimple_lookup_type_leader (t2
);
3852 || (leader1
&& leader1
== leader2
))
3855 else if (mode
== GTC_DIAG
)
3857 if (TYPE_CANONICAL (t1
)
3858 && TYPE_CANONICAL (t1
) == TYPE_CANONICAL (t2
))
3862 /* Can't be the same type if the types don't have the same code. */
3863 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3866 /* Can't be the same type if they have different CV qualifiers. */
3867 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
3870 /* Void types are always the same. */
3871 if (TREE_CODE (t1
) == VOID_TYPE
)
3874 /* Do some simple checks before doing three hashtable queries. */
3875 if (INTEGRAL_TYPE_P (t1
)
3876 || SCALAR_FLOAT_TYPE_P (t1
)
3877 || FIXED_POINT_TYPE_P (t1
)
3878 || TREE_CODE (t1
) == VECTOR_TYPE
3879 || TREE_CODE (t1
) == COMPLEX_TYPE
3880 || TREE_CODE (t1
) == OFFSET_TYPE
)
3882 /* Can't be the same type if they have different alignment,
3883 sign, precision or mode. */
3884 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3885 || TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
3886 || TYPE_MODE (t1
) != TYPE_MODE (t2
)
3887 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
3890 if (TREE_CODE (t1
) == INTEGER_TYPE
3891 && (TYPE_IS_SIZETYPE (t1
) != TYPE_IS_SIZETYPE (t2
)
3892 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)))
3895 /* That's all we need to check for float and fixed-point types. */
3896 if (SCALAR_FLOAT_TYPE_P (t1
)
3897 || FIXED_POINT_TYPE_P (t1
))
3900 /* For integral types fall thru to more complex checks. */
3903 else if (AGGREGATE_TYPE_P (t1
) || POINTER_TYPE_P (t1
))
3905 /* Can't be the same type if they have different alignment or mode. */
3906 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3907 || TYPE_MODE (t1
) != TYPE_MODE (t2
))
3911 /* If the hash values of t1 and t2 are different the types can't
3912 possibly be the same. This helps keeping the type-pair hashtable
3913 small, only tracking comparisons for hash collisions. */
3914 if (gimple_type_hash (t1
) != gimple_type_hash (t2
))
3917 /* If we've visited this type pair before (in the case of aggregates
3918 with self-referential types), and we made a decision, return it. */
3919 p
= lookup_type_pair (t1
, t2
, >c_visited
, >c_ob
);
3920 if (p
->same_p
[mode
] == 0 || p
->same_p
[mode
] == 1)
3922 /* We have already decided whether T1 and T2 are the
3923 same, return the cached result. */
3924 return p
->same_p
[mode
] == 1;
3927 /* Now set up the SCC machinery for the comparison. */
3928 gtc_next_dfs_num
= 1;
3929 sccstate
= pointer_map_create ();
3930 gcc_obstack_init (&sccstate_obstack
);
3931 res
= gimple_types_compatible_p_1 (t1
, t2
, mode
, p
,
3932 &sccstack
, sccstate
, &sccstate_obstack
);
3933 VEC_free (type_pair_t
, heap
, sccstack
);
3934 pointer_map_destroy (sccstate
);
3935 obstack_free (&sccstate_obstack
, NULL
);
3942 iterative_hash_gimple_type (tree
, hashval_t
, VEC(tree
, heap
) **,
3943 struct pointer_map_t
*, struct obstack
*);
3945 /* DFS visit the edge from the callers type with state *STATE to T.
3946 Update the callers type hash V with the hash for T if it is not part
3947 of the SCC containing the callers type and return it.
3948 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3951 visit (tree t
, struct sccs
*state
, hashval_t v
,
3952 VEC (tree
, heap
) **sccstack
,
3953 struct pointer_map_t
*sccstate
,
3954 struct obstack
*sccstate_obstack
)
3956 struct sccs
*cstate
= NULL
;
3957 struct tree_int_map m
;
3960 /* If there is a hash value recorded for this type then it can't
3961 possibly be part of our parent SCC. Simply mix in its hash. */
3963 if ((slot
= htab_find_slot (type_hash_cache
, &m
, NO_INSERT
))
3965 return iterative_hash_hashval_t (((struct tree_int_map
*) *slot
)->to
, v
);
3967 if ((slot
= pointer_map_contains (sccstate
, t
)) != NULL
)
3968 cstate
= (struct sccs
*)*slot
;
3972 /* Not yet visited. DFS recurse. */
3973 tem
= iterative_hash_gimple_type (t
, v
,
3974 sccstack
, sccstate
, sccstate_obstack
);
3976 cstate
= (struct sccs
*)* pointer_map_contains (sccstate
, t
);
3977 state
->low
= MIN (state
->low
, cstate
->low
);
3978 /* If the type is no longer on the SCC stack and thus is not part
3979 of the parents SCC mix in its hash value. Otherwise we will
3980 ignore the type for hashing purposes and return the unaltered
3982 if (!cstate
->on_sccstack
)
3985 if (cstate
->dfsnum
< state
->dfsnum
3986 && cstate
->on_sccstack
)
3987 state
->low
= MIN (cstate
->dfsnum
, state
->low
);
3989 /* We are part of our parents SCC, skip this type during hashing
3990 and return the unaltered hash value. */
3994 /* Hash NAME with the previous hash value V and return it. */
3997 iterative_hash_name (tree name
, hashval_t v
)
4001 if (TREE_CODE (name
) == TYPE_DECL
)
4002 name
= DECL_NAME (name
);
4005 gcc_assert (TREE_CODE (name
) == IDENTIFIER_NODE
);
4006 return iterative_hash_object (IDENTIFIER_HASH_VALUE (name
), v
);
4009 /* Returning a hash value for gimple type TYPE combined with VAL.
4010 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done.
4012 To hash a type we end up hashing in types that are reachable.
4013 Through pointers we can end up with cycles which messes up the
4014 required property that we need to compute the same hash value
4015 for structurally equivalent types. To avoid this we have to
4016 hash all types in a cycle (the SCC) in a commutative way. The
4017 easiest way is to not mix in the hashes of the SCC members at
4018 all. To make this work we have to delay setting the hash
4019 values of the SCC until it is complete. */
4022 iterative_hash_gimple_type (tree type
, hashval_t val
,
4023 VEC(tree
, heap
) **sccstack
,
4024 struct pointer_map_t
*sccstate
,
4025 struct obstack
*sccstate_obstack
)
4031 /* Not visited during this DFS walk. */
4032 gcc_checking_assert (!pointer_map_contains (sccstate
, type
));
4033 state
= XOBNEW (sccstate_obstack
, struct sccs
);
4034 *pointer_map_insert (sccstate
, type
) = state
;
4036 VEC_safe_push (tree
, heap
, *sccstack
, type
);
4037 state
->dfsnum
= next_dfs_num
++;
4038 state
->low
= state
->dfsnum
;
4039 state
->on_sccstack
= true;
4041 /* Combine a few common features of types so that types are grouped into
4042 smaller sets; when searching for existing matching types to merge,
4043 only existing types having the same features as the new type will be
4045 v
= iterative_hash_hashval_t (TREE_CODE (type
), 0);
4046 v
= iterative_hash_hashval_t (TYPE_QUALS (type
), v
);
4047 v
= iterative_hash_hashval_t (TREE_ADDRESSABLE (type
), v
);
4049 /* Do not hash the types size as this will cause differences in
4050 hash values for the complete vs. the incomplete type variant. */
4052 /* Incorporate common features of numerical types. */
4053 if (INTEGRAL_TYPE_P (type
)
4054 || SCALAR_FLOAT_TYPE_P (type
)
4055 || FIXED_POINT_TYPE_P (type
))
4057 v
= iterative_hash_hashval_t (TYPE_PRECISION (type
), v
);
4058 v
= iterative_hash_hashval_t (TYPE_MODE (type
), v
);
4059 v
= iterative_hash_hashval_t (TYPE_UNSIGNED (type
), v
);
4062 /* For pointer and reference types, fold in information about the type
4063 pointed to but do not recurse into possibly incomplete types to
4064 avoid hash differences for complete vs. incomplete types. */
4065 if (POINTER_TYPE_P (type
))
4067 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type
)))
4069 v
= iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type
)), v
);
4070 v
= iterative_hash_name
4071 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type
))), v
);
4074 v
= visit (TREE_TYPE (type
), state
, v
,
4075 sccstack
, sccstate
, sccstate_obstack
);
4078 /* For integer types hash the types min/max values and the string flag. */
4079 if (TREE_CODE (type
) == INTEGER_TYPE
)
4081 /* OMP lowering can introduce error_mark_node in place of
4082 random local decls in types. */
4083 if (TYPE_MIN_VALUE (type
) != error_mark_node
)
4084 v
= iterative_hash_expr (TYPE_MIN_VALUE (type
), v
);
4085 if (TYPE_MAX_VALUE (type
) != error_mark_node
)
4086 v
= iterative_hash_expr (TYPE_MAX_VALUE (type
), v
);
4087 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
4090 /* For array types hash their domain and the string flag. */
4091 if (TREE_CODE (type
) == ARRAY_TYPE
4092 && TYPE_DOMAIN (type
))
4094 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
4095 v
= visit (TYPE_DOMAIN (type
), state
, v
,
4096 sccstack
, sccstate
, sccstate_obstack
);
4099 /* Recurse for aggregates with a single element type. */
4100 if (TREE_CODE (type
) == ARRAY_TYPE
4101 || TREE_CODE (type
) == COMPLEX_TYPE
4102 || TREE_CODE (type
) == VECTOR_TYPE
)
4103 v
= visit (TREE_TYPE (type
), state
, v
,
4104 sccstack
, sccstate
, sccstate_obstack
);
4106 /* Incorporate function return and argument types. */
4107 if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
4112 /* For method types also incorporate their parent class. */
4113 if (TREE_CODE (type
) == METHOD_TYPE
)
4114 v
= visit (TYPE_METHOD_BASETYPE (type
), state
, v
,
4115 sccstack
, sccstate
, sccstate_obstack
);
4117 /* For result types allow mismatch in completeness. */
4118 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type
)))
4120 v
= iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type
)), v
);
4121 v
= iterative_hash_name
4122 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type
))), v
);
4125 v
= visit (TREE_TYPE (type
), state
, v
,
4126 sccstack
, sccstate
, sccstate_obstack
);
4128 for (p
= TYPE_ARG_TYPES (type
), na
= 0; p
; p
= TREE_CHAIN (p
))
4130 /* For argument types allow mismatch in completeness. */
4131 if (RECORD_OR_UNION_TYPE_P (TREE_VALUE (p
)))
4133 v
= iterative_hash_hashval_t (TREE_CODE (TREE_VALUE (p
)), v
);
4134 v
= iterative_hash_name
4135 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_VALUE (p
))), v
);
4138 v
= visit (TREE_VALUE (p
), state
, v
,
4139 sccstack
, sccstate
, sccstate_obstack
);
4143 v
= iterative_hash_hashval_t (na
, v
);
4146 if (TREE_CODE (type
) == RECORD_TYPE
4147 || TREE_CODE (type
) == UNION_TYPE
4148 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
4153 v
= iterative_hash_name (TYPE_NAME (TYPE_MAIN_VARIANT (type
)), v
);
4155 for (f
= TYPE_FIELDS (type
), nf
= 0; f
; f
= TREE_CHAIN (f
))
4157 v
= iterative_hash_name (DECL_NAME (f
), v
);
4158 v
= visit (TREE_TYPE (f
), state
, v
,
4159 sccstack
, sccstate
, sccstate_obstack
);
4163 v
= iterative_hash_hashval_t (nf
, v
);
4166 /* Record hash for us. */
4169 /* See if we found an SCC. */
4170 if (state
->low
== state
->dfsnum
)
4174 /* Pop off the SCC and set its hash values. */
4177 struct sccs
*cstate
;
4178 struct tree_int_map
*m
= ggc_alloc_cleared_tree_int_map ();
4179 x
= VEC_pop (tree
, *sccstack
);
4180 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
4181 cstate
->on_sccstack
= false;
4183 m
->to
= cstate
->u
.hash
;
4184 slot
= htab_find_slot (type_hash_cache
, m
, INSERT
);
4185 gcc_assert (!*slot
);
4191 return iterative_hash_hashval_t (v
, val
);
4195 /* Returns a hash value for P (assumed to be a type). The hash value
4196 is computed using some distinguishing features of the type. Note
4197 that we cannot use pointer hashing here as we may be dealing with
4198 two distinct instances of the same type.
4200 This function should produce the same hash value for two compatible
4201 types according to gimple_types_compatible_p. */
4204 gimple_type_hash (const void *p
)
4206 const_tree t
= (const_tree
) p
;
4207 VEC(tree
, heap
) *sccstack
= NULL
;
4208 struct pointer_map_t
*sccstate
;
4209 struct obstack sccstate_obstack
;
4212 struct tree_int_map m
;
4214 if (type_hash_cache
== NULL
)
4215 type_hash_cache
= htab_create_ggc (512, tree_int_map_hash
,
4216 tree_int_map_eq
, NULL
);
4218 m
.base
.from
= CONST_CAST_TREE (t
);
4219 if ((slot
= htab_find_slot (type_hash_cache
, &m
, NO_INSERT
))
4221 return iterative_hash_hashval_t (((struct tree_int_map
*) *slot
)->to
, 0);
4223 /* Perform a DFS walk and pre-hash all reachable types. */
4225 sccstate
= pointer_map_create ();
4226 gcc_obstack_init (&sccstate_obstack
);
4227 val
= iterative_hash_gimple_type (CONST_CAST_TREE (t
), 0,
4228 &sccstack
, sccstate
, &sccstate_obstack
);
4229 VEC_free (tree
, heap
, sccstack
);
4230 pointer_map_destroy (sccstate
);
4231 obstack_free (&sccstate_obstack
, NULL
);
4237 /* Returns nonzero if P1 and P2 are equal. */
4240 gimple_type_eq (const void *p1
, const void *p2
)
4242 const_tree t1
= (const_tree
) p1
;
4243 const_tree t2
= (const_tree
) p2
;
4244 return gimple_types_compatible_p (CONST_CAST_TREE (t1
),
4245 CONST_CAST_TREE (t2
), GTC_MERGE
);
4249 /* Register type T in the global type table gimple_types.
4250 If another type T', compatible with T, already existed in
4251 gimple_types then return T', otherwise return T. This is used by
4252 LTO to merge identical types read from different TUs. */
4255 gimple_register_type (tree t
)
4258 gimple_type_leader_entry
*leader
;
4259 tree mv_leader
= NULL_TREE
;
4261 gcc_assert (TYPE_P (t
));
4263 if (!gimple_type_leader
)
4264 gimple_type_leader
= ggc_alloc_cleared_vec_gimple_type_leader_entry_s
4265 (GIMPLE_TYPE_LEADER_SIZE
);
4266 /* If we registered this type before return the cached result. */
4267 leader
= &gimple_type_leader
[TYPE_UID (t
) % GIMPLE_TYPE_LEADER_SIZE
];
4268 if (leader
->type
== t
)
4269 return leader
->leader
;
4271 /* Always register the main variant first. This is important so we
4272 pick up the non-typedef variants as canonical, otherwise we'll end
4273 up taking typedef ids for structure tags during comparison. */
4274 if (TYPE_MAIN_VARIANT (t
) != t
)
4275 mv_leader
= gimple_register_type (TYPE_MAIN_VARIANT (t
));
4277 if (gimple_types
== NULL
)
4278 gimple_types
= htab_create_ggc (16381, gimple_type_hash
, gimple_type_eq
, 0);
4280 slot
= htab_find_slot (gimple_types
, t
, INSERT
);
4282 && *(tree
*)slot
!= t
)
4284 tree new_type
= (tree
) *((tree
*) slot
);
4286 /* Do not merge types with different addressability. */
4287 gcc_assert (TREE_ADDRESSABLE (t
) == TREE_ADDRESSABLE (new_type
));
4289 /* If t is not its main variant then make t unreachable from its
4290 main variant list. Otherwise we'd queue up a lot of duplicates
4292 if (t
!= TYPE_MAIN_VARIANT (t
))
4294 tree tem
= TYPE_MAIN_VARIANT (t
);
4295 while (tem
&& TYPE_NEXT_VARIANT (tem
) != t
)
4296 tem
= TYPE_NEXT_VARIANT (tem
);
4298 TYPE_NEXT_VARIANT (tem
) = TYPE_NEXT_VARIANT (t
);
4299 TYPE_NEXT_VARIANT (t
) = NULL_TREE
;
4302 /* If we are a pointer then remove us from the pointer-to or
4303 reference-to chain. Otherwise we'd queue up a lot of duplicates
4305 if (TREE_CODE (t
) == POINTER_TYPE
)
4307 if (TYPE_POINTER_TO (TREE_TYPE (t
)) == t
)
4308 TYPE_POINTER_TO (TREE_TYPE (t
)) = TYPE_NEXT_PTR_TO (t
);
4311 tree tem
= TYPE_POINTER_TO (TREE_TYPE (t
));
4312 while (tem
&& TYPE_NEXT_PTR_TO (tem
) != t
)
4313 tem
= TYPE_NEXT_PTR_TO (tem
);
4315 TYPE_NEXT_PTR_TO (tem
) = TYPE_NEXT_PTR_TO (t
);
4317 TYPE_NEXT_PTR_TO (t
) = NULL_TREE
;
4319 else if (TREE_CODE (t
) == REFERENCE_TYPE
)
4321 if (TYPE_REFERENCE_TO (TREE_TYPE (t
)) == t
)
4322 TYPE_REFERENCE_TO (TREE_TYPE (t
)) = TYPE_NEXT_REF_TO (t
);
4325 tree tem
= TYPE_REFERENCE_TO (TREE_TYPE (t
));
4326 while (tem
&& TYPE_NEXT_REF_TO (tem
) != t
)
4327 tem
= TYPE_NEXT_REF_TO (tem
);
4329 TYPE_NEXT_REF_TO (tem
) = TYPE_NEXT_REF_TO (t
);
4331 TYPE_NEXT_REF_TO (t
) = NULL_TREE
;
4335 leader
->leader
= new_type
;
4342 /* We're the type leader. Make our TYPE_MAIN_VARIANT valid. */
4343 if (TYPE_MAIN_VARIANT (t
) != t
4344 && TYPE_MAIN_VARIANT (t
) != mv_leader
)
4346 /* Remove us from our main variant list as we are not the variant
4347 leader and the variant leader will change. */
4348 tree tem
= TYPE_MAIN_VARIANT (t
);
4349 while (tem
&& TYPE_NEXT_VARIANT (tem
) != t
)
4350 tem
= TYPE_NEXT_VARIANT (tem
);
4352 TYPE_NEXT_VARIANT (tem
) = TYPE_NEXT_VARIANT (t
);
4353 TYPE_NEXT_VARIANT (t
) = NULL_TREE
;
4354 /* Adjust our main variant. Linking us into its variant list
4355 will happen at fixup time. */
4356 TYPE_MAIN_VARIANT (t
) = mv_leader
;
4365 /* Returns nonzero if P1 and P2 are equal. */
4368 gimple_canonical_type_eq (const void *p1
, const void *p2
)
4370 const_tree t1
= (const_tree
) p1
;
4371 const_tree t2
= (const_tree
) p2
;
4372 return gimple_types_compatible_p (CONST_CAST_TREE (t1
),
4373 CONST_CAST_TREE (t2
), GTC_DIAG
);
4376 /* Register type T in the global type table gimple_types.
4377 If another type T', compatible with T, already existed in
4378 gimple_types then return T', otherwise return T. This is used by
4379 LTO to merge identical types read from different TUs. */
4382 gimple_register_canonical_type (tree t
)
4387 gcc_assert (TYPE_P (t
));
4389 if (TYPE_CANONICAL (t
))
4390 return TYPE_CANONICAL (t
);
4392 /* Always register the type itself first so that if it turns out
4393 to be the canonical type it will be the one we merge to as well. */
4394 t
= gimple_register_type (t
);
4396 /* Always register the main variant first. This is important so we
4397 pick up the non-typedef variants as canonical, otherwise we'll end
4398 up taking typedef ids for structure tags during comparison. */
4399 if (TYPE_MAIN_VARIANT (t
) != t
)
4400 gimple_register_canonical_type (TYPE_MAIN_VARIANT (t
));
4402 if (gimple_canonical_types
== NULL
)
4403 gimple_canonical_types
= htab_create_ggc (16381, gimple_type_hash
,
4404 gimple_canonical_type_eq
, 0);
4406 slot
= htab_find_slot (gimple_canonical_types
, t
, INSERT
);
4408 && *(tree
*)slot
!= t
)
4410 tree new_type
= (tree
) *((tree
*) slot
);
4412 TYPE_CANONICAL (t
) = new_type
;
4417 TYPE_CANONICAL (t
) = t
;
4421 /* Also cache the canonical type in the non-leaders. */
4422 TYPE_CANONICAL (orig_t
) = t
;
4428 /* Show statistics on references to the global type table gimple_types. */
4431 print_gimple_types_stats (void)
4434 fprintf (stderr
, "GIMPLE type table: size %ld, %ld elements, "
4435 "%ld searches, %ld collisions (ratio: %f)\n",
4436 (long) htab_size (gimple_types
),
4437 (long) htab_elements (gimple_types
),
4438 (long) gimple_types
->searches
,
4439 (long) gimple_types
->collisions
,
4440 htab_collisions (gimple_types
));
4442 fprintf (stderr
, "GIMPLE type table is empty\n");
4443 if (gimple_canonical_types
)
4444 fprintf (stderr
, "GIMPLE canonical type table: size %ld, %ld elements, "
4445 "%ld searches, %ld collisions (ratio: %f)\n",
4446 (long) htab_size (gimple_canonical_types
),
4447 (long) htab_elements (gimple_canonical_types
),
4448 (long) gimple_canonical_types
->searches
,
4449 (long) gimple_canonical_types
->collisions
,
4450 htab_collisions (gimple_canonical_types
));
4452 fprintf (stderr
, "GIMPLE canonical type table is empty\n");
4453 if (type_hash_cache
)
4454 fprintf (stderr
, "GIMPLE type hash table: size %ld, %ld elements, "
4455 "%ld searches, %ld collisions (ratio: %f)\n",
4456 (long) htab_size (type_hash_cache
),
4457 (long) htab_elements (type_hash_cache
),
4458 (long) type_hash_cache
->searches
,
4459 (long) type_hash_cache
->collisions
,
4460 htab_collisions (type_hash_cache
));
4462 fprintf (stderr
, "GIMPLE type hash table is empty\n");
4464 fprintf (stderr
, "GIMPLE type comparison table: size %ld, %ld "
4465 "elements, %ld searches, %ld collisions (ratio: %f)\n",
4466 (long) htab_size (gtc_visited
),
4467 (long) htab_elements (gtc_visited
),
4468 (long) gtc_visited
->searches
,
4469 (long) gtc_visited
->collisions
,
4470 htab_collisions (gtc_visited
));
4472 fprintf (stderr
, "GIMPLE type comparison table is empty\n");
4475 /* Free the gimple type hashtables used for LTO type merging. */
4478 free_gimple_type_tables (void)
4480 /* Last chance to print stats for the tables. */
4481 if (flag_lto_report
)
4482 print_gimple_types_stats ();
4486 htab_delete (gimple_types
);
4487 gimple_types
= NULL
;
4489 if (gimple_canonical_types
)
4491 htab_delete (gimple_canonical_types
);
4492 gimple_canonical_types
= NULL
;
4494 if (type_hash_cache
)
4496 htab_delete (type_hash_cache
);
4497 type_hash_cache
= NULL
;
4501 htab_delete (gtc_visited
);
4502 obstack_free (>c_ob
, NULL
);
4505 gimple_type_leader
= NULL
;
4509 /* Return a type the same as TYPE except unsigned or
4510 signed according to UNSIGNEDP. */
4513 gimple_signed_or_unsigned_type (bool unsignedp
, tree type
)
4517 type1
= TYPE_MAIN_VARIANT (type
);
4518 if (type1
== signed_char_type_node
4519 || type1
== char_type_node
4520 || type1
== unsigned_char_type_node
)
4521 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4522 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
4523 return unsignedp
? unsigned_type_node
: integer_type_node
;
4524 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
4525 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4526 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
4527 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4528 if (type1
== long_long_integer_type_node
4529 || type1
== long_long_unsigned_type_node
)
4531 ? long_long_unsigned_type_node
4532 : long_long_integer_type_node
;
4533 if (int128_integer_type_node
&& (type1
== int128_integer_type_node
|| type1
== int128_unsigned_type_node
))
4535 ? int128_unsigned_type_node
4536 : int128_integer_type_node
;
4537 #if HOST_BITS_PER_WIDE_INT >= 64
4538 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
4539 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4541 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
4542 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4543 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
4544 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4545 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
4546 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4547 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
4548 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4550 #define GIMPLE_FIXED_TYPES(NAME) \
4551 if (type1 == short_ ## NAME ## _type_node \
4552 || type1 == unsigned_short_ ## NAME ## _type_node) \
4553 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
4554 : short_ ## NAME ## _type_node; \
4555 if (type1 == NAME ## _type_node \
4556 || type1 == unsigned_ ## NAME ## _type_node) \
4557 return unsignedp ? unsigned_ ## NAME ## _type_node \
4558 : NAME ## _type_node; \
4559 if (type1 == long_ ## NAME ## _type_node \
4560 || type1 == unsigned_long_ ## NAME ## _type_node) \
4561 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
4562 : long_ ## NAME ## _type_node; \
4563 if (type1 == long_long_ ## NAME ## _type_node \
4564 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
4565 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
4566 : long_long_ ## NAME ## _type_node;
4568 #define GIMPLE_FIXED_MODE_TYPES(NAME) \
4569 if (type1 == NAME ## _type_node \
4570 || type1 == u ## NAME ## _type_node) \
4571 return unsignedp ? u ## NAME ## _type_node \
4572 : NAME ## _type_node;
4574 #define GIMPLE_FIXED_TYPES_SAT(NAME) \
4575 if (type1 == sat_ ## short_ ## NAME ## _type_node \
4576 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
4577 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
4578 : sat_ ## short_ ## NAME ## _type_node; \
4579 if (type1 == sat_ ## NAME ## _type_node \
4580 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
4581 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
4582 : sat_ ## NAME ## _type_node; \
4583 if (type1 == sat_ ## long_ ## NAME ## _type_node \
4584 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
4585 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
4586 : sat_ ## long_ ## NAME ## _type_node; \
4587 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
4588 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
4589 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
4590 : sat_ ## long_long_ ## NAME ## _type_node;
4592 #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
4593 if (type1 == sat_ ## NAME ## _type_node \
4594 || type1 == sat_ ## u ## NAME ## _type_node) \
4595 return unsignedp ? sat_ ## u ## NAME ## _type_node \
4596 : sat_ ## NAME ## _type_node;
4598 GIMPLE_FIXED_TYPES (fract
);
4599 GIMPLE_FIXED_TYPES_SAT (fract
);
4600 GIMPLE_FIXED_TYPES (accum
);
4601 GIMPLE_FIXED_TYPES_SAT (accum
);
4603 GIMPLE_FIXED_MODE_TYPES (qq
);
4604 GIMPLE_FIXED_MODE_TYPES (hq
);
4605 GIMPLE_FIXED_MODE_TYPES (sq
);
4606 GIMPLE_FIXED_MODE_TYPES (dq
);
4607 GIMPLE_FIXED_MODE_TYPES (tq
);
4608 GIMPLE_FIXED_MODE_TYPES_SAT (qq
);
4609 GIMPLE_FIXED_MODE_TYPES_SAT (hq
);
4610 GIMPLE_FIXED_MODE_TYPES_SAT (sq
);
4611 GIMPLE_FIXED_MODE_TYPES_SAT (dq
);
4612 GIMPLE_FIXED_MODE_TYPES_SAT (tq
);
4613 GIMPLE_FIXED_MODE_TYPES (ha
);
4614 GIMPLE_FIXED_MODE_TYPES (sa
);
4615 GIMPLE_FIXED_MODE_TYPES (da
);
4616 GIMPLE_FIXED_MODE_TYPES (ta
);
4617 GIMPLE_FIXED_MODE_TYPES_SAT (ha
);
4618 GIMPLE_FIXED_MODE_TYPES_SAT (sa
);
4619 GIMPLE_FIXED_MODE_TYPES_SAT (da
);
4620 GIMPLE_FIXED_MODE_TYPES_SAT (ta
);
4622 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
4623 the precision; they have precision set to match their range, but
4624 may use a wider mode to match an ABI. If we change modes, we may
4625 wind up with bad conversions. For INTEGER_TYPEs in C, must check
4626 the precision as well, so as to yield correct results for
4627 bit-field types. C++ does not have these separate bit-field
4628 types, and producing a signed or unsigned variant of an
4629 ENUMERAL_TYPE may cause other problems as well. */
4630 if (!INTEGRAL_TYPE_P (type
)
4631 || TYPE_UNSIGNED (type
) == unsignedp
)
4634 #define TYPE_OK(node) \
4635 (TYPE_MODE (type) == TYPE_MODE (node) \
4636 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
4637 if (TYPE_OK (signed_char_type_node
))
4638 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4639 if (TYPE_OK (integer_type_node
))
4640 return unsignedp
? unsigned_type_node
: integer_type_node
;
4641 if (TYPE_OK (short_integer_type_node
))
4642 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4643 if (TYPE_OK (long_integer_type_node
))
4644 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4645 if (TYPE_OK (long_long_integer_type_node
))
4647 ? long_long_unsigned_type_node
4648 : long_long_integer_type_node
);
4649 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
4651 ? int128_unsigned_type_node
4652 : int128_integer_type_node
);
4654 #if HOST_BITS_PER_WIDE_INT >= 64
4655 if (TYPE_OK (intTI_type_node
))
4656 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4658 if (TYPE_OK (intDI_type_node
))
4659 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4660 if (TYPE_OK (intSI_type_node
))
4661 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4662 if (TYPE_OK (intHI_type_node
))
4663 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4664 if (TYPE_OK (intQI_type_node
))
4665 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4667 #undef GIMPLE_FIXED_TYPES
4668 #undef GIMPLE_FIXED_MODE_TYPES
4669 #undef GIMPLE_FIXED_TYPES_SAT
4670 #undef GIMPLE_FIXED_MODE_TYPES_SAT
4673 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
4677 /* Return an unsigned type the same as TYPE in other respects. */
4680 gimple_unsigned_type (tree type
)
4682 return gimple_signed_or_unsigned_type (true, type
);
4686 /* Return a signed type the same as TYPE in other respects. */
4689 gimple_signed_type (tree type
)
4691 return gimple_signed_or_unsigned_type (false, type
);
4695 /* Return the typed-based alias set for T, which may be an expression
4696 or a type. Return -1 if we don't do anything special. */
4699 gimple_get_alias_set (tree t
)
4703 /* Permit type-punning when accessing a union, provided the access
4704 is directly through the union. For example, this code does not
4705 permit taking the address of a union member and then storing
4706 through it. Even the type-punning allowed here is a GCC
4707 extension, albeit a common and useful one; the C standard says
4708 that such accesses have implementation-defined behavior. */
4710 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4711 u
= TREE_OPERAND (u
, 0))
4712 if (TREE_CODE (u
) == COMPONENT_REF
4713 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4716 /* That's all the expressions we handle specially. */
4720 /* For convenience, follow the C standard when dealing with
4721 character types. Any object may be accessed via an lvalue that
4722 has character type. */
4723 if (t
== char_type_node
4724 || t
== signed_char_type_node
4725 || t
== unsigned_char_type_node
)
4728 /* Allow aliasing between signed and unsigned variants of the same
4729 type. We treat the signed variant as canonical. */
4730 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4732 tree t1
= gimple_signed_type (t
);
4734 /* t1 == t can happen for boolean nodes which are always unsigned. */
4736 return get_alias_set (t1
);
4743 /* Data structure used to count the number of dereferences to PTR
4744 inside an expression. */
4748 unsigned num_stores
;
4752 /* Helper for count_uses_and_derefs. Called by walk_tree to look for
4753 (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA. */
4756 count_ptr_derefs (tree
*tp
, int *walk_subtrees
, void *data
)
4758 struct walk_stmt_info
*wi_p
= (struct walk_stmt_info
*) data
;
4759 struct count_ptr_d
*count_p
= (struct count_ptr_d
*) wi_p
->info
;
4761 /* Do not walk inside ADDR_EXPR nodes. In the expression &ptr->fld,
4762 pointer 'ptr' is *not* dereferenced, it is simply used to compute
4763 the address of 'fld' as 'ptr + offsetof(fld)'. */
4764 if (TREE_CODE (*tp
) == ADDR_EXPR
)
4770 if (TREE_CODE (*tp
) == MEM_REF
&& TREE_OPERAND (*tp
, 0) == count_p
->ptr
)
4773 count_p
->num_stores
++;
4775 count_p
->num_loads
++;
4781 /* Count the number of direct and indirect uses for pointer PTR in
4782 statement STMT. The number of direct uses is stored in
4783 *NUM_USES_P. Indirect references are counted separately depending
4784 on whether they are store or load operations. The counts are
4785 stored in *NUM_STORES_P and *NUM_LOADS_P. */
4788 count_uses_and_derefs (tree ptr
, gimple stmt
, unsigned *num_uses_p
,
4789 unsigned *num_loads_p
, unsigned *num_stores_p
)
4798 /* Find out the total number of uses of PTR in STMT. */
4799 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, i
, SSA_OP_USE
)
4803 /* Now count the number of indirect references to PTR. This is
4804 truly awful, but we don't have much choice. There are no parent
4805 pointers inside INDIRECT_REFs, so an expression like
4806 '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to
4807 find all the indirect and direct uses of x_1 inside. The only
4808 shortcut we can take is the fact that GIMPLE only allows
4809 INDIRECT_REFs inside the expressions below. */
4810 if (is_gimple_assign (stmt
)
4811 || gimple_code (stmt
) == GIMPLE_RETURN
4812 || gimple_code (stmt
) == GIMPLE_ASM
4813 || is_gimple_call (stmt
))
4815 struct walk_stmt_info wi
;
4816 struct count_ptr_d count
;
4819 count
.num_stores
= 0;
4820 count
.num_loads
= 0;
4822 memset (&wi
, 0, sizeof (wi
));
4824 walk_gimple_op (stmt
, count_ptr_derefs
, &wi
);
4826 *num_stores_p
= count
.num_stores
;
4827 *num_loads_p
= count
.num_loads
;
4830 gcc_assert (*num_uses_p
>= *num_loads_p
+ *num_stores_p
);
4833 /* From a tree operand OP return the base of a load or store operation
4834 or NULL_TREE if OP is not a load or a store. */
4837 get_base_loadstore (tree op
)
4839 while (handled_component_p (op
))
4840 op
= TREE_OPERAND (op
, 0);
4842 || INDIRECT_REF_P (op
)
4843 || TREE_CODE (op
) == MEM_REF
4844 || TREE_CODE (op
) == TARGET_MEM_REF
)
4849 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
4850 VISIT_ADDR if non-NULL on loads, store and address-taken operands
4851 passing the STMT, the base of the operand and DATA to it. The base
4852 will be either a decl, an indirect reference (including TARGET_MEM_REF)
4853 or the argument of an address expression.
4854 Returns the results of these callbacks or'ed. */
4857 walk_stmt_load_store_addr_ops (gimple stmt
, void *data
,
4858 bool (*visit_load
)(gimple
, tree
, void *),
4859 bool (*visit_store
)(gimple
, tree
, void *),
4860 bool (*visit_addr
)(gimple
, tree
, void *))
4864 if (gimple_assign_single_p (stmt
))
4869 lhs
= get_base_loadstore (gimple_assign_lhs (stmt
));
4871 ret
|= visit_store (stmt
, lhs
, data
);
4873 rhs
= gimple_assign_rhs1 (stmt
);
4874 while (handled_component_p (rhs
))
4875 rhs
= TREE_OPERAND (rhs
, 0);
4878 if (TREE_CODE (rhs
) == ADDR_EXPR
)
4879 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
4880 else if (TREE_CODE (rhs
) == TARGET_MEM_REF
4881 && TREE_CODE (TMR_BASE (rhs
)) == ADDR_EXPR
)
4882 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (rhs
), 0), data
);
4883 else if (TREE_CODE (rhs
) == OBJ_TYPE_REF
4884 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs
)) == ADDR_EXPR
)
4885 ret
|= visit_addr (stmt
, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs
),
4887 lhs
= gimple_assign_lhs (stmt
);
4888 if (TREE_CODE (lhs
) == TARGET_MEM_REF
4889 && TREE_CODE (TMR_BASE (lhs
)) == ADDR_EXPR
)
4890 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (lhs
), 0), data
);
4894 rhs
= get_base_loadstore (rhs
);
4896 ret
|= visit_load (stmt
, rhs
, data
);
4900 && (is_gimple_assign (stmt
)
4901 || gimple_code (stmt
) == GIMPLE_COND
))
4903 for (i
= 0; i
< gimple_num_ops (stmt
); ++i
)
4904 if (gimple_op (stmt
, i
)
4905 && TREE_CODE (gimple_op (stmt
, i
)) == ADDR_EXPR
)
4906 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_op (stmt
, i
), 0), data
);
4908 else if (is_gimple_call (stmt
))
4912 tree lhs
= gimple_call_lhs (stmt
);
4915 lhs
= get_base_loadstore (lhs
);
4917 ret
|= visit_store (stmt
, lhs
, data
);
4920 if (visit_load
|| visit_addr
)
4921 for (i
= 0; i
< gimple_call_num_args (stmt
); ++i
)
4923 tree rhs
= gimple_call_arg (stmt
, i
);
4925 && TREE_CODE (rhs
) == ADDR_EXPR
)
4926 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
4927 else if (visit_load
)
4929 rhs
= get_base_loadstore (rhs
);
4931 ret
|= visit_load (stmt
, rhs
, data
);
4935 && gimple_call_chain (stmt
)
4936 && TREE_CODE (gimple_call_chain (stmt
)) == ADDR_EXPR
)
4937 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_call_chain (stmt
), 0),
4940 && gimple_call_return_slot_opt_p (stmt
)
4941 && gimple_call_lhs (stmt
) != NULL_TREE
4942 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt
))))
4943 ret
|= visit_addr (stmt
, gimple_call_lhs (stmt
), data
);
4945 else if (gimple_code (stmt
) == GIMPLE_ASM
)
4948 const char *constraint
;
4949 const char **oconstraints
;
4950 bool allows_mem
, allows_reg
, is_inout
;
4951 noutputs
= gimple_asm_noutputs (stmt
);
4952 oconstraints
= XALLOCAVEC (const char *, noutputs
);
4953 if (visit_store
|| visit_addr
)
4954 for (i
= 0; i
< gimple_asm_noutputs (stmt
); ++i
)
4956 tree link
= gimple_asm_output_op (stmt
, i
);
4957 tree op
= get_base_loadstore (TREE_VALUE (link
));
4958 if (op
&& visit_store
)
4959 ret
|= visit_store (stmt
, op
, data
);
4962 constraint
= TREE_STRING_POINTER
4963 (TREE_VALUE (TREE_PURPOSE (link
)));
4964 oconstraints
[i
] = constraint
;
4965 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
,
4966 &allows_reg
, &is_inout
);
4967 if (op
&& !allows_reg
&& allows_mem
)
4968 ret
|= visit_addr (stmt
, op
, data
);
4971 if (visit_load
|| visit_addr
)
4972 for (i
= 0; i
< gimple_asm_ninputs (stmt
); ++i
)
4974 tree link
= gimple_asm_input_op (stmt
, i
);
4975 tree op
= TREE_VALUE (link
);
4977 && TREE_CODE (op
) == ADDR_EXPR
)
4978 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
4979 else if (visit_load
|| visit_addr
)
4981 op
= get_base_loadstore (op
);
4985 ret
|= visit_load (stmt
, op
, data
);
4988 constraint
= TREE_STRING_POINTER
4989 (TREE_VALUE (TREE_PURPOSE (link
)));
4990 parse_input_constraint (&constraint
, 0, 0, noutputs
,
4992 &allows_mem
, &allows_reg
);
4993 if (!allows_reg
&& allows_mem
)
4994 ret
|= visit_addr (stmt
, op
, data
);
5000 else if (gimple_code (stmt
) == GIMPLE_RETURN
)
5002 tree op
= gimple_return_retval (stmt
);
5006 && TREE_CODE (op
) == ADDR_EXPR
)
5007 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5008 else if (visit_load
)
5010 op
= get_base_loadstore (op
);
5012 ret
|= visit_load (stmt
, op
, data
);
5017 && gimple_code (stmt
) == GIMPLE_PHI
)
5019 for (i
= 0; i
< gimple_phi_num_args (stmt
); ++i
)
5021 tree op
= PHI_ARG_DEF (stmt
, i
);
5022 if (TREE_CODE (op
) == ADDR_EXPR
)
5023 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
5030 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
5031 should make a faster clone for this case. */
5034 walk_stmt_load_store_ops (gimple stmt
, void *data
,
5035 bool (*visit_load
)(gimple
, tree
, void *),
5036 bool (*visit_store
)(gimple
, tree
, void *))
5038 return walk_stmt_load_store_addr_ops (stmt
, data
,
5039 visit_load
, visit_store
, NULL
);
5042 /* Helper for gimple_ior_addresses_taken_1. */
5045 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED
,
5046 tree addr
, void *data
)
5048 bitmap addresses_taken
= (bitmap
)data
;
5049 addr
= get_base_address (addr
);
5053 bitmap_set_bit (addresses_taken
, DECL_UID (addr
));
5059 /* Set the bit for the uid of all decls that have their address taken
5060 in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
5061 were any in this stmt. */
5064 gimple_ior_addresses_taken (bitmap addresses_taken
, gimple stmt
)
5066 return walk_stmt_load_store_addr_ops (stmt
, addresses_taken
, NULL
, NULL
,
5067 gimple_ior_addresses_taken_1
);
5071 /* Return a printable name for symbol DECL. */
5074 gimple_decl_printable_name (tree decl
, int verbosity
)
5076 if (!DECL_NAME (decl
))
5079 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
5081 const char *str
, *mangled_str
;
5082 int dmgl_opts
= DMGL_NO_OPTS
;
5086 dmgl_opts
= DMGL_VERBOSE
5090 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5091 dmgl_opts
|= DMGL_PARAMS
;
5094 mangled_str
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5095 str
= cplus_demangle_v3 (mangled_str
, dmgl_opts
);
5096 return (str
) ? str
: mangled_str
;
5099 return IDENTIFIER_POINTER (DECL_NAME (decl
));
5102 /* Return true when STMT is builtins call to CODE. */
5105 gimple_call_builtin_p (gimple stmt
, enum built_in_function code
)
5108 return (is_gimple_call (stmt
)
5109 && (fndecl
= gimple_call_fndecl (stmt
)) != NULL
5110 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
5111 && DECL_FUNCTION_CODE (fndecl
) == code
);
5114 #include "gt-gimple.h"