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"
40 /* Global type table. FIXME lto, it should be possible to re-use some
41 of the type hashing routines in tree.c (type_hash_canon, type_hash_lookup,
42 etc), but those assume that types were built with the various
43 build_*_type routines which is not the case with the streamer. */
44 static htab_t gimple_types
;
45 static struct pointer_map_t
*type_hash_cache
;
47 /* Global type comparison cache. */
48 static htab_t gtc_visited
;
49 static struct obstack gtc_ob
;
51 /* All the tuples have their operand vector (if present) at the very bottom
52 of the structure. Therefore, the offset required to find the
53 operands vector the size of the structure minus the size of the 1
54 element tree array at the end (see gimple_ops). */
55 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \
56 (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0),
57 EXPORTED_CONST
size_t gimple_ops_offset_
[] = {
58 #include "gsstruct.def"
62 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof(struct STRUCT),
63 static const size_t gsstruct_code_size
[] = {
64 #include "gsstruct.def"
68 #define DEFGSCODE(SYM, NAME, GSSCODE) NAME,
69 const char *const gimple_code_name
[] = {
74 #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE,
75 EXPORTED_CONST
enum gimple_statement_structure_enum gss_for_code_
[] = {
80 #ifdef GATHER_STATISTICS
83 int gimple_alloc_counts
[(int) gimple_alloc_kind_all
];
84 int gimple_alloc_sizes
[(int) gimple_alloc_kind_all
];
86 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */
87 static const char * const gimple_alloc_kind_names
[] = {
95 #endif /* GATHER_STATISTICS */
97 /* A cache of gimple_seq objects. Sequences are created and destroyed
98 fairly often during gimplification. */
99 static GTY ((deletable
)) struct gimple_seq_d
*gimple_seq_cache
;
101 /* Private API manipulation functions shared only with some
103 extern void gimple_set_stored_syms (gimple
, bitmap
, bitmap_obstack
*);
104 extern void gimple_set_loaded_syms (gimple
, bitmap
, bitmap_obstack
*);
106 /* Gimple tuple constructors.
107 Note: Any constructor taking a ``gimple_seq'' as a parameter, can
108 be passed a NULL to start with an empty sequence. */
110 /* Set the code for statement G to CODE. */
113 gimple_set_code (gimple g
, enum gimple_code code
)
115 g
->gsbase
.code
= code
;
118 /* Return the number of bytes needed to hold a GIMPLE statement with
122 gimple_size (enum gimple_code code
)
124 return gsstruct_code_size
[gss_for_code (code
)];
127 /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
131 gimple_alloc_stat (enum gimple_code code
, unsigned num_ops MEM_STAT_DECL
)
136 size
= gimple_size (code
);
138 size
+= sizeof (tree
) * (num_ops
- 1);
140 #ifdef GATHER_STATISTICS
142 enum gimple_alloc_kind kind
= gimple_alloc_kind (code
);
143 gimple_alloc_counts
[(int) kind
]++;
144 gimple_alloc_sizes
[(int) kind
] += size
;
148 stmt
= ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT
);
149 gimple_set_code (stmt
, code
);
150 gimple_set_num_ops (stmt
, num_ops
);
152 /* Do not call gimple_set_modified here as it has other side
153 effects and this tuple is still not completely built. */
154 stmt
->gsbase
.modified
= 1;
159 /* Set SUBCODE to be the code of the expression computed by statement G. */
162 gimple_set_subcode (gimple g
, unsigned subcode
)
164 /* We only have 16 bits for the RHS code. Assert that we are not
166 gcc_assert (subcode
< (1 << 16));
167 g
->gsbase
.subcode
= subcode
;
172 /* Build a tuple with operands. CODE is the statement to build (which
173 must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the sub-code
174 for the new tuple. NUM_OPS is the number of operands to allocate. */
176 #define gimple_build_with_ops(c, s, n) \
177 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
180 gimple_build_with_ops_stat (enum gimple_code code
, unsigned subcode
,
181 unsigned num_ops MEM_STAT_DECL
)
183 gimple s
= gimple_alloc_stat (code
, num_ops PASS_MEM_STAT
);
184 gimple_set_subcode (s
, subcode
);
190 /* Build a GIMPLE_RETURN statement returning RETVAL. */
193 gimple_build_return (tree retval
)
195 gimple s
= gimple_build_with_ops (GIMPLE_RETURN
, ERROR_MARK
, 1);
197 gimple_return_set_retval (s
, retval
);
201 /* Reset alias information on call S. */
204 gimple_call_reset_alias_info (gimple s
)
206 if (gimple_call_flags (s
) & ECF_CONST
)
207 memset (gimple_call_use_set (s
), 0, sizeof (struct pt_solution
));
209 pt_solution_reset (gimple_call_use_set (s
));
210 if (gimple_call_flags (s
) & (ECF_CONST
|ECF_PURE
|ECF_NOVOPS
))
211 memset (gimple_call_clobber_set (s
), 0, sizeof (struct pt_solution
));
213 pt_solution_reset (gimple_call_clobber_set (s
));
216 /* Helper for gimple_build_call, gimple_build_call_vec and
217 gimple_build_call_from_tree. Build the basic components of a
218 GIMPLE_CALL statement to function FN with NARGS arguments. */
221 gimple_build_call_1 (tree fn
, unsigned nargs
)
223 gimple s
= gimple_build_with_ops (GIMPLE_CALL
, ERROR_MARK
, nargs
+ 3);
224 if (TREE_CODE (fn
) == FUNCTION_DECL
)
225 fn
= build_fold_addr_expr (fn
);
226 gimple_set_op (s
, 1, fn
);
227 gimple_call_reset_alias_info (s
);
232 /* Build a GIMPLE_CALL statement to function FN with the arguments
233 specified in vector ARGS. */
236 gimple_build_call_vec (tree fn
, VEC(tree
, heap
) *args
)
239 unsigned nargs
= VEC_length (tree
, args
);
240 gimple call
= gimple_build_call_1 (fn
, nargs
);
242 for (i
= 0; i
< nargs
; i
++)
243 gimple_call_set_arg (call
, i
, VEC_index (tree
, args
, i
));
249 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
250 arguments. The ... are the arguments. */
253 gimple_build_call (tree fn
, unsigned nargs
, ...)
259 gcc_assert (TREE_CODE (fn
) == FUNCTION_DECL
|| is_gimple_call_addr (fn
));
261 call
= gimple_build_call_1 (fn
, nargs
);
263 va_start (ap
, nargs
);
264 for (i
= 0; i
< nargs
; i
++)
265 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
272 /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
273 assumed to be in GIMPLE form already. Minimal checking is done of
277 gimple_build_call_from_tree (tree t
)
281 tree fndecl
= get_callee_fndecl (t
);
283 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
285 nargs
= call_expr_nargs (t
);
286 call
= gimple_build_call_1 (fndecl
? fndecl
: CALL_EXPR_FN (t
), nargs
);
288 for (i
= 0; i
< nargs
; i
++)
289 gimple_call_set_arg (call
, i
, CALL_EXPR_ARG (t
, i
));
291 gimple_set_block (call
, TREE_BLOCK (t
));
293 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
294 gimple_call_set_chain (call
, CALL_EXPR_STATIC_CHAIN (t
));
295 gimple_call_set_tail (call
, CALL_EXPR_TAILCALL (t
));
296 gimple_call_set_cannot_inline (call
, CALL_CANNOT_INLINE_P (t
));
297 gimple_call_set_return_slot_opt (call
, CALL_EXPR_RETURN_SLOT_OPT (t
));
298 gimple_call_set_from_thunk (call
, CALL_FROM_THUNK_P (t
));
299 gimple_call_set_va_arg_pack (call
, CALL_EXPR_VA_ARG_PACK (t
));
300 gimple_call_set_nothrow (call
, TREE_NOTHROW (t
));
301 gimple_set_no_warning (call
, TREE_NO_WARNING (t
));
307 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
308 *OP1_P, *OP2_P and *OP3_P respectively. */
311 extract_ops_from_tree_1 (tree expr
, enum tree_code
*subcode_p
, tree
*op1_p
,
312 tree
*op2_p
, tree
*op3_p
)
314 enum gimple_rhs_class grhs_class
;
316 *subcode_p
= TREE_CODE (expr
);
317 grhs_class
= get_gimple_rhs_class (*subcode_p
);
319 if (grhs_class
== GIMPLE_TERNARY_RHS
)
321 *op1_p
= TREE_OPERAND (expr
, 0);
322 *op2_p
= TREE_OPERAND (expr
, 1);
323 *op3_p
= TREE_OPERAND (expr
, 2);
325 else if (grhs_class
== GIMPLE_BINARY_RHS
)
327 *op1_p
= TREE_OPERAND (expr
, 0);
328 *op2_p
= TREE_OPERAND (expr
, 1);
331 else if (grhs_class
== GIMPLE_UNARY_RHS
)
333 *op1_p
= TREE_OPERAND (expr
, 0);
337 else if (grhs_class
== GIMPLE_SINGLE_RHS
)
348 /* Build a GIMPLE_ASSIGN statement.
350 LHS of the assignment.
351 RHS of the assignment which can be unary or binary. */
354 gimple_build_assign_stat (tree lhs
, tree rhs MEM_STAT_DECL
)
356 enum tree_code subcode
;
359 extract_ops_from_tree_1 (rhs
, &subcode
, &op1
, &op2
, &op3
);
360 return gimple_build_assign_with_ops_stat (subcode
, lhs
, op1
, op2
, op3
365 /* Build a GIMPLE_ASSIGN statement with sub-code SUBCODE and operands
366 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
367 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
370 gimple_build_assign_with_ops_stat (enum tree_code subcode
, tree lhs
, tree op1
,
371 tree op2
, tree op3 MEM_STAT_DECL
)
376 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
378 num_ops
= get_gimple_rhs_num_ops (subcode
) + 1;
380 p
= gimple_build_with_ops_stat (GIMPLE_ASSIGN
, (unsigned)subcode
, num_ops
382 gimple_assign_set_lhs (p
, lhs
);
383 gimple_assign_set_rhs1 (p
, op1
);
386 gcc_assert (num_ops
> 2);
387 gimple_assign_set_rhs2 (p
, op2
);
392 gcc_assert (num_ops
> 3);
393 gimple_assign_set_rhs3 (p
, op3
);
400 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
402 DST/SRC are the destination and source respectively. You can pass
403 ungimplified trees in DST or SRC, in which case they will be
404 converted to a gimple operand if necessary.
406 This function returns the newly created GIMPLE_ASSIGN tuple. */
409 gimplify_assign (tree dst
, tree src
, gimple_seq
*seq_p
)
411 tree t
= build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
412 gimplify_and_add (t
, seq_p
);
414 return gimple_seq_last_stmt (*seq_p
);
418 /* Build a GIMPLE_COND statement.
420 PRED is the condition used to compare LHS and the RHS.
421 T_LABEL is the label to jump to if the condition is true.
422 F_LABEL is the label to jump to otherwise. */
425 gimple_build_cond (enum tree_code pred_code
, tree lhs
, tree rhs
,
426 tree t_label
, tree f_label
)
430 gcc_assert (TREE_CODE_CLASS (pred_code
) == tcc_comparison
);
431 p
= gimple_build_with_ops (GIMPLE_COND
, pred_code
, 4);
432 gimple_cond_set_lhs (p
, lhs
);
433 gimple_cond_set_rhs (p
, rhs
);
434 gimple_cond_set_true_label (p
, t_label
);
435 gimple_cond_set_false_label (p
, f_label
);
440 /* Extract operands for a GIMPLE_COND statement out of COND_EXPR tree COND. */
443 gimple_cond_get_ops_from_tree (tree cond
, enum tree_code
*code_p
,
444 tree
*lhs_p
, tree
*rhs_p
)
446 location_t loc
= EXPR_LOCATION (cond
);
447 gcc_assert (TREE_CODE_CLASS (TREE_CODE (cond
)) == tcc_comparison
448 || TREE_CODE (cond
) == TRUTH_NOT_EXPR
449 || is_gimple_min_invariant (cond
)
450 || SSA_VAR_P (cond
));
452 extract_ops_from_tree (cond
, code_p
, lhs_p
, rhs_p
);
454 /* Canonicalize conditionals of the form 'if (!VAL)'. */
455 if (*code_p
== TRUTH_NOT_EXPR
)
458 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
459 *rhs_p
= fold_convert_loc (loc
, TREE_TYPE (*lhs_p
), integer_zero_node
);
461 /* Canonicalize conditionals of the form 'if (VAL)' */
462 else if (TREE_CODE_CLASS (*code_p
) != tcc_comparison
)
465 gcc_assert (*lhs_p
&& *rhs_p
== NULL_TREE
);
466 *rhs_p
= fold_convert_loc (loc
, TREE_TYPE (*lhs_p
), integer_zero_node
);
471 /* Build a GIMPLE_COND statement from the conditional expression tree
472 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
475 gimple_build_cond_from_tree (tree cond
, tree t_label
, tree f_label
)
480 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
481 return gimple_build_cond (code
, lhs
, rhs
, t_label
, f_label
);
484 /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
485 boolean expression tree COND. */
488 gimple_cond_set_condition_from_tree (gimple stmt
, tree cond
)
493 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
494 gimple_cond_set_condition (stmt
, code
, lhs
, rhs
);
497 /* Build a GIMPLE_LABEL statement for LABEL. */
500 gimple_build_label (tree label
)
502 gimple p
= gimple_build_with_ops (GIMPLE_LABEL
, ERROR_MARK
, 1);
503 gimple_label_set_label (p
, label
);
507 /* Build a GIMPLE_GOTO statement to label DEST. */
510 gimple_build_goto (tree dest
)
512 gimple p
= gimple_build_with_ops (GIMPLE_GOTO
, ERROR_MARK
, 1);
513 gimple_goto_set_dest (p
, dest
);
518 /* Build a GIMPLE_NOP statement. */
521 gimple_build_nop (void)
523 return gimple_alloc (GIMPLE_NOP
, 0);
527 /* Build a GIMPLE_BIND statement.
528 VARS are the variables in BODY.
529 BLOCK is the containing block. */
532 gimple_build_bind (tree vars
, gimple_seq body
, tree block
)
534 gimple p
= gimple_alloc (GIMPLE_BIND
, 0);
535 gimple_bind_set_vars (p
, vars
);
537 gimple_bind_set_body (p
, body
);
539 gimple_bind_set_block (p
, block
);
543 /* Helper function to set the simple fields of a asm stmt.
545 STRING is a pointer to a string that is the asm blocks assembly code.
546 NINPUT is the number of register inputs.
547 NOUTPUT is the number of register outputs.
548 NCLOBBERS is the number of clobbered registers.
552 gimple_build_asm_1 (const char *string
, unsigned ninputs
, unsigned noutputs
,
553 unsigned nclobbers
, unsigned nlabels
)
556 int size
= strlen (string
);
558 /* ASMs with labels cannot have outputs. This should have been
559 enforced by the front end. */
560 gcc_assert (nlabels
== 0 || noutputs
== 0);
562 p
= gimple_build_with_ops (GIMPLE_ASM
, ERROR_MARK
,
563 ninputs
+ noutputs
+ nclobbers
+ nlabels
);
565 p
->gimple_asm
.ni
= ninputs
;
566 p
->gimple_asm
.no
= noutputs
;
567 p
->gimple_asm
.nc
= nclobbers
;
568 p
->gimple_asm
.nl
= nlabels
;
569 p
->gimple_asm
.string
= ggc_alloc_string (string
, size
);
571 #ifdef GATHER_STATISTICS
572 gimple_alloc_sizes
[(int) gimple_alloc_kind (GIMPLE_ASM
)] += size
;
578 /* Build a GIMPLE_ASM statement.
580 STRING is the assembly code.
581 NINPUT is the number of register inputs.
582 NOUTPUT is the number of register outputs.
583 NCLOBBERS is the number of clobbered registers.
584 INPUTS is a vector of the input register parameters.
585 OUTPUTS is a vector of the output register parameters.
586 CLOBBERS is a vector of the clobbered register parameters.
587 LABELS is a vector of destination labels. */
590 gimple_build_asm_vec (const char *string
, VEC(tree
,gc
)* inputs
,
591 VEC(tree
,gc
)* outputs
, VEC(tree
,gc
)* clobbers
,
592 VEC(tree
,gc
)* labels
)
597 p
= gimple_build_asm_1 (string
,
598 VEC_length (tree
, inputs
),
599 VEC_length (tree
, outputs
),
600 VEC_length (tree
, clobbers
),
601 VEC_length (tree
, labels
));
603 for (i
= 0; i
< VEC_length (tree
, inputs
); i
++)
604 gimple_asm_set_input_op (p
, i
, VEC_index (tree
, inputs
, i
));
606 for (i
= 0; i
< VEC_length (tree
, outputs
); i
++)
607 gimple_asm_set_output_op (p
, i
, VEC_index (tree
, outputs
, i
));
609 for (i
= 0; i
< VEC_length (tree
, clobbers
); i
++)
610 gimple_asm_set_clobber_op (p
, i
, VEC_index (tree
, clobbers
, i
));
612 for (i
= 0; i
< VEC_length (tree
, labels
); i
++)
613 gimple_asm_set_label_op (p
, i
, VEC_index (tree
, labels
, i
));
618 /* Build a GIMPLE_CATCH statement.
620 TYPES are the catch types.
621 HANDLER is the exception handler. */
624 gimple_build_catch (tree types
, gimple_seq handler
)
626 gimple p
= gimple_alloc (GIMPLE_CATCH
, 0);
627 gimple_catch_set_types (p
, types
);
629 gimple_catch_set_handler (p
, handler
);
634 /* Build a GIMPLE_EH_FILTER statement.
636 TYPES are the filter's types.
637 FAILURE is the filter's failure action. */
640 gimple_build_eh_filter (tree types
, gimple_seq failure
)
642 gimple p
= gimple_alloc (GIMPLE_EH_FILTER
, 0);
643 gimple_eh_filter_set_types (p
, types
);
645 gimple_eh_filter_set_failure (p
, failure
);
650 /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
653 gimple_build_eh_must_not_throw (tree decl
)
655 gimple p
= gimple_alloc (GIMPLE_EH_MUST_NOT_THROW
, 0);
657 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
658 gcc_assert (flags_from_decl_or_type (decl
) & ECF_NORETURN
);
659 gimple_eh_must_not_throw_set_fndecl (p
, decl
);
664 /* Build a GIMPLE_TRY statement.
666 EVAL is the expression to evaluate.
667 CLEANUP is the cleanup expression.
668 KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
669 whether this is a try/catch or a try/finally respectively. */
672 gimple_build_try (gimple_seq eval
, gimple_seq cleanup
,
673 enum gimple_try_flags kind
)
677 gcc_assert (kind
== GIMPLE_TRY_CATCH
|| kind
== GIMPLE_TRY_FINALLY
);
678 p
= gimple_alloc (GIMPLE_TRY
, 0);
679 gimple_set_subcode (p
, kind
);
681 gimple_try_set_eval (p
, eval
);
683 gimple_try_set_cleanup (p
, cleanup
);
688 /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
690 CLEANUP is the cleanup expression. */
693 gimple_build_wce (gimple_seq cleanup
)
695 gimple p
= gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR
, 0);
697 gimple_wce_set_cleanup (p
, cleanup
);
703 /* Build a GIMPLE_RESX statement. */
706 gimple_build_resx (int region
)
708 gimple p
= gimple_build_with_ops (GIMPLE_RESX
, ERROR_MARK
, 0);
709 p
->gimple_eh_ctrl
.region
= region
;
714 /* The helper for constructing a gimple switch statement.
715 INDEX is the switch's index.
716 NLABELS is the number of labels in the switch excluding the default.
717 DEFAULT_LABEL is the default label for the switch statement. */
720 gimple_build_switch_nlabels (unsigned nlabels
, tree index
, tree default_label
)
722 /* nlabels + 1 default label + 1 index. */
723 gimple p
= gimple_build_with_ops (GIMPLE_SWITCH
, ERROR_MARK
,
724 1 + (default_label
!= NULL
) + nlabels
);
725 gimple_switch_set_index (p
, index
);
727 gimple_switch_set_default_label (p
, default_label
);
732 /* Build a GIMPLE_SWITCH statement.
734 INDEX is the switch's index.
735 NLABELS is the number of labels in the switch excluding the DEFAULT_LABEL.
736 ... are the labels excluding the default. */
739 gimple_build_switch (unsigned nlabels
, tree index
, tree default_label
, ...)
743 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
745 /* Store the rest of the labels. */
746 va_start (al
, default_label
);
747 offset
= (default_label
!= NULL
);
748 for (i
= 0; i
< nlabels
; i
++)
749 gimple_switch_set_label (p
, i
+ offset
, va_arg (al
, tree
));
756 /* Build a GIMPLE_SWITCH statement.
758 INDEX is the switch's index.
759 DEFAULT_LABEL is the default label
760 ARGS is a vector of labels excluding the default. */
763 gimple_build_switch_vec (tree index
, tree default_label
, VEC(tree
, heap
) *args
)
765 unsigned i
, offset
, nlabels
= VEC_length (tree
, args
);
766 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
768 /* Copy the labels from the vector to the switch statement. */
769 offset
= (default_label
!= NULL
);
770 for (i
= 0; i
< nlabels
; i
++)
771 gimple_switch_set_label (p
, i
+ offset
, VEC_index (tree
, args
, i
));
776 /* Build a GIMPLE_EH_DISPATCH statement. */
779 gimple_build_eh_dispatch (int region
)
781 gimple p
= gimple_build_with_ops (GIMPLE_EH_DISPATCH
, ERROR_MARK
, 0);
782 p
->gimple_eh_ctrl
.region
= region
;
786 /* Build a new GIMPLE_DEBUG_BIND statement.
788 VAR is bound to VALUE; block and location are taken from STMT. */
791 gimple_build_debug_bind_stat (tree var
, tree value
, gimple stmt MEM_STAT_DECL
)
793 gimple p
= gimple_build_with_ops_stat (GIMPLE_DEBUG
,
794 (unsigned)GIMPLE_DEBUG_BIND
, 2
797 gimple_debug_bind_set_var (p
, var
);
798 gimple_debug_bind_set_value (p
, value
);
801 gimple_set_block (p
, gimple_block (stmt
));
802 gimple_set_location (p
, gimple_location (stmt
));
809 /* Build a GIMPLE_OMP_CRITICAL statement.
811 BODY is the sequence of statements for which only one thread can execute.
812 NAME is optional identifier for this critical block. */
815 gimple_build_omp_critical (gimple_seq body
, tree name
)
817 gimple p
= gimple_alloc (GIMPLE_OMP_CRITICAL
, 0);
818 gimple_omp_critical_set_name (p
, name
);
820 gimple_omp_set_body (p
, body
);
825 /* Build a GIMPLE_OMP_FOR statement.
827 BODY is sequence of statements inside the for loop.
828 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate,
829 lastprivate, reductions, ordered, schedule, and nowait.
830 COLLAPSE is the collapse count.
831 PRE_BODY is the sequence of statements that are loop invariant. */
834 gimple_build_omp_for (gimple_seq body
, tree clauses
, size_t collapse
,
837 gimple p
= gimple_alloc (GIMPLE_OMP_FOR
, 0);
839 gimple_omp_set_body (p
, body
);
840 gimple_omp_for_set_clauses (p
, clauses
);
841 p
->gimple_omp_for
.collapse
= collapse
;
842 p
->gimple_omp_for
.iter
843 = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse
);
845 gimple_omp_for_set_pre_body (p
, pre_body
);
851 /* Build a GIMPLE_OMP_PARALLEL statement.
853 BODY is sequence of statements which are executed in parallel.
854 CLAUSES, are the OMP parallel construct's clauses.
855 CHILD_FN is the function created for the parallel threads to execute.
856 DATA_ARG are the shared data argument(s). */
859 gimple_build_omp_parallel (gimple_seq body
, tree clauses
, tree child_fn
,
862 gimple p
= gimple_alloc (GIMPLE_OMP_PARALLEL
, 0);
864 gimple_omp_set_body (p
, body
);
865 gimple_omp_parallel_set_clauses (p
, clauses
);
866 gimple_omp_parallel_set_child_fn (p
, child_fn
);
867 gimple_omp_parallel_set_data_arg (p
, data_arg
);
873 /* Build a GIMPLE_OMP_TASK statement.
875 BODY is sequence of statements which are executed by the explicit task.
876 CLAUSES, are the OMP parallel construct's clauses.
877 CHILD_FN is the function created for the parallel threads to execute.
878 DATA_ARG are the shared data argument(s).
879 COPY_FN is the optional function for firstprivate initialization.
880 ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
883 gimple_build_omp_task (gimple_seq body
, tree clauses
, tree child_fn
,
884 tree data_arg
, tree copy_fn
, tree arg_size
,
887 gimple p
= gimple_alloc (GIMPLE_OMP_TASK
, 0);
889 gimple_omp_set_body (p
, body
);
890 gimple_omp_task_set_clauses (p
, clauses
);
891 gimple_omp_task_set_child_fn (p
, child_fn
);
892 gimple_omp_task_set_data_arg (p
, data_arg
);
893 gimple_omp_task_set_copy_fn (p
, copy_fn
);
894 gimple_omp_task_set_arg_size (p
, arg_size
);
895 gimple_omp_task_set_arg_align (p
, arg_align
);
901 /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
903 BODY is the sequence of statements in the section. */
906 gimple_build_omp_section (gimple_seq body
)
908 gimple p
= gimple_alloc (GIMPLE_OMP_SECTION
, 0);
910 gimple_omp_set_body (p
, body
);
916 /* Build a GIMPLE_OMP_MASTER statement.
918 BODY is the sequence of statements to be executed by just the master. */
921 gimple_build_omp_master (gimple_seq body
)
923 gimple p
= gimple_alloc (GIMPLE_OMP_MASTER
, 0);
925 gimple_omp_set_body (p
, body
);
931 /* Build a GIMPLE_OMP_CONTINUE statement.
933 CONTROL_DEF is the definition of the control variable.
934 CONTROL_USE is the use of the control variable. */
937 gimple_build_omp_continue (tree control_def
, tree control_use
)
939 gimple p
= gimple_alloc (GIMPLE_OMP_CONTINUE
, 0);
940 gimple_omp_continue_set_control_def (p
, control_def
);
941 gimple_omp_continue_set_control_use (p
, control_use
);
945 /* Build a GIMPLE_OMP_ORDERED statement.
947 BODY is the sequence of statements inside a loop that will executed in
951 gimple_build_omp_ordered (gimple_seq body
)
953 gimple p
= gimple_alloc (GIMPLE_OMP_ORDERED
, 0);
955 gimple_omp_set_body (p
, body
);
961 /* Build a GIMPLE_OMP_RETURN statement.
962 WAIT_P is true if this is a non-waiting return. */
965 gimple_build_omp_return (bool wait_p
)
967 gimple p
= gimple_alloc (GIMPLE_OMP_RETURN
, 0);
969 gimple_omp_return_set_nowait (p
);
975 /* Build a GIMPLE_OMP_SECTIONS statement.
977 BODY is a sequence of section statements.
978 CLAUSES are any of the OMP sections contsruct's clauses: private,
979 firstprivate, lastprivate, reduction, and nowait. */
982 gimple_build_omp_sections (gimple_seq body
, tree clauses
)
984 gimple p
= gimple_alloc (GIMPLE_OMP_SECTIONS
, 0);
986 gimple_omp_set_body (p
, body
);
987 gimple_omp_sections_set_clauses (p
, clauses
);
993 /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
996 gimple_build_omp_sections_switch (void)
998 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH
, 0);
1002 /* Build a GIMPLE_OMP_SINGLE statement.
1004 BODY is the sequence of statements that will be executed once.
1005 CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
1006 copyprivate, nowait. */
1009 gimple_build_omp_single (gimple_seq body
, tree clauses
)
1011 gimple p
= gimple_alloc (GIMPLE_OMP_SINGLE
, 0);
1013 gimple_omp_set_body (p
, body
);
1014 gimple_omp_single_set_clauses (p
, clauses
);
1020 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1023 gimple_build_omp_atomic_load (tree lhs
, tree rhs
)
1025 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD
, 0);
1026 gimple_omp_atomic_load_set_lhs (p
, lhs
);
1027 gimple_omp_atomic_load_set_rhs (p
, rhs
);
1031 /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1033 VAL is the value we are storing. */
1036 gimple_build_omp_atomic_store (tree val
)
1038 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_STORE
, 0);
1039 gimple_omp_atomic_store_set_val (p
, val
);
1043 /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
1044 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
1047 gimple_build_predict (enum br_predictor predictor
, enum prediction outcome
)
1049 gimple p
= gimple_alloc (GIMPLE_PREDICT
, 0);
1050 /* Ensure all the predictors fit into the lower bits of the subcode. */
1051 gcc_assert ((int) END_PREDICTORS
<= GF_PREDICT_TAKEN
);
1052 gimple_predict_set_predictor (p
, predictor
);
1053 gimple_predict_set_outcome (p
, outcome
);
1057 #if defined ENABLE_GIMPLE_CHECKING
1058 /* Complain of a gimple type mismatch and die. */
1061 gimple_check_failed (const_gimple gs
, const char *file
, int line
,
1062 const char *function
, enum gimple_code code
,
1063 enum tree_code subcode
)
1065 internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1066 gimple_code_name
[code
],
1067 tree_code_name
[subcode
],
1068 gimple_code_name
[gimple_code (gs
)],
1069 gs
->gsbase
.subcode
> 0
1070 ? tree_code_name
[gs
->gsbase
.subcode
]
1072 function
, trim_filename (file
), line
);
1074 #endif /* ENABLE_GIMPLE_CHECKING */
1077 /* Allocate a new GIMPLE sequence in GC memory and return it. If
1078 there are free sequences in GIMPLE_SEQ_CACHE return one of those
1082 gimple_seq_alloc (void)
1084 gimple_seq seq
= gimple_seq_cache
;
1087 gimple_seq_cache
= gimple_seq_cache
->next_free
;
1088 gcc_assert (gimple_seq_cache
!= seq
);
1089 memset (seq
, 0, sizeof (*seq
));
1093 seq
= ggc_alloc_cleared_gimple_seq_d ();
1094 #ifdef GATHER_STATISTICS
1095 gimple_alloc_counts
[(int) gimple_alloc_kind_seq
]++;
1096 gimple_alloc_sizes
[(int) gimple_alloc_kind_seq
] += sizeof (*seq
);
1103 /* Return SEQ to the free pool of GIMPLE sequences. */
1106 gimple_seq_free (gimple_seq seq
)
1111 gcc_assert (gimple_seq_first (seq
) == NULL
);
1112 gcc_assert (gimple_seq_last (seq
) == NULL
);
1114 /* If this triggers, it's a sign that the same list is being freed
1116 gcc_assert (seq
!= gimple_seq_cache
|| gimple_seq_cache
== NULL
);
1118 /* Add SEQ to the pool of free sequences. */
1119 seq
->next_free
= gimple_seq_cache
;
1120 gimple_seq_cache
= seq
;
1124 /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1125 *SEQ_P is NULL, a new sequence is allocated. */
1128 gimple_seq_add_stmt (gimple_seq
*seq_p
, gimple gs
)
1130 gimple_stmt_iterator si
;
1136 *seq_p
= gimple_seq_alloc ();
1138 si
= gsi_last (*seq_p
);
1139 gsi_insert_after (&si
, gs
, GSI_NEW_STMT
);
1143 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1144 NULL, a new sequence is allocated. */
1147 gimple_seq_add_seq (gimple_seq
*dst_p
, gimple_seq src
)
1149 gimple_stmt_iterator si
;
1155 *dst_p
= gimple_seq_alloc ();
1157 si
= gsi_last (*dst_p
);
1158 gsi_insert_seq_after (&si
, src
, GSI_NEW_STMT
);
1162 /* Helper function of empty_body_p. Return true if STMT is an empty
1166 empty_stmt_p (gimple stmt
)
1168 if (gimple_code (stmt
) == GIMPLE_NOP
)
1170 if (gimple_code (stmt
) == GIMPLE_BIND
)
1171 return empty_body_p (gimple_bind_body (stmt
));
1176 /* Return true if BODY contains nothing but empty statements. */
1179 empty_body_p (gimple_seq body
)
1181 gimple_stmt_iterator i
;
1183 if (gimple_seq_empty_p (body
))
1185 for (i
= gsi_start (body
); !gsi_end_p (i
); gsi_next (&i
))
1186 if (!empty_stmt_p (gsi_stmt (i
))
1187 && !is_gimple_debug (gsi_stmt (i
)))
1194 /* Perform a deep copy of sequence SRC and return the result. */
1197 gimple_seq_copy (gimple_seq src
)
1199 gimple_stmt_iterator gsi
;
1200 gimple_seq new_seq
= gimple_seq_alloc ();
1203 for (gsi
= gsi_start (src
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1205 stmt
= gimple_copy (gsi_stmt (gsi
));
1206 gimple_seq_add_stmt (&new_seq
, stmt
);
1213 /* Walk all the statements in the sequence SEQ calling walk_gimple_stmt
1214 on each one. WI is as in walk_gimple_stmt.
1216 If walk_gimple_stmt returns non-NULL, the walk is stopped, the
1217 value is stored in WI->CALLBACK_RESULT and the statement that
1218 produced the value is returned.
1220 Otherwise, all the statements are walked and NULL returned. */
1223 walk_gimple_seq (gimple_seq seq
, walk_stmt_fn callback_stmt
,
1224 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1226 gimple_stmt_iterator gsi
;
1228 for (gsi
= gsi_start (seq
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1230 tree ret
= walk_gimple_stmt (&gsi
, callback_stmt
, callback_op
, wi
);
1233 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
1236 wi
->callback_result
= ret
;
1237 return gsi_stmt (gsi
);
1242 wi
->callback_result
= NULL_TREE
;
1248 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
1251 walk_gimple_asm (gimple stmt
, walk_tree_fn callback_op
,
1252 struct walk_stmt_info
*wi
)
1256 const char **oconstraints
;
1258 const char *constraint
;
1259 bool allows_mem
, allows_reg
, is_inout
;
1261 noutputs
= gimple_asm_noutputs (stmt
);
1262 oconstraints
= (const char **) alloca ((noutputs
) * sizeof (const char *));
1267 for (i
= 0; i
< noutputs
; i
++)
1269 op
= gimple_asm_output_op (stmt
, i
);
1270 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1271 oconstraints
[i
] = constraint
;
1272 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
, &allows_reg
,
1275 wi
->val_only
= (allows_reg
|| !allows_mem
);
1276 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1281 n
= gimple_asm_ninputs (stmt
);
1282 for (i
= 0; i
< n
; i
++)
1284 op
= gimple_asm_input_op (stmt
, i
);
1285 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1286 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
1287 oconstraints
, &allows_mem
, &allows_reg
);
1290 wi
->val_only
= (allows_reg
|| !allows_mem
);
1291 /* Although input "m" is not really a LHS, we need a lvalue. */
1292 wi
->is_lhs
= !wi
->val_only
;
1294 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1302 wi
->val_only
= true;
1305 n
= gimple_asm_nlabels (stmt
);
1306 for (i
= 0; i
< n
; i
++)
1308 op
= gimple_asm_label_op (stmt
, i
);
1309 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1318 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
1319 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
1321 CALLBACK_OP is called on each operand of STMT via walk_tree.
1322 Additional parameters to walk_tree must be stored in WI. For each operand
1323 OP, walk_tree is called as:
1325 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
1327 If CALLBACK_OP returns non-NULL for an operand, the remaining
1328 operands are not scanned.
1330 The return value is that returned by the last call to walk_tree, or
1331 NULL_TREE if no CALLBACK_OP is specified. */
1334 walk_gimple_op (gimple stmt
, walk_tree_fn callback_op
,
1335 struct walk_stmt_info
*wi
)
1337 struct pointer_set_t
*pset
= (wi
) ? wi
->pset
: NULL
;
1339 tree ret
= NULL_TREE
;
1341 switch (gimple_code (stmt
))
1344 /* Walk the RHS operands. If the LHS is of a non-renamable type or
1345 is a register variable, we may use a COMPONENT_REF on the RHS. */
1348 tree lhs
= gimple_assign_lhs (stmt
);
1350 = (is_gimple_reg_type (TREE_TYPE (lhs
)) && !is_gimple_reg (lhs
))
1351 || !gimple_assign_single_p (stmt
);
1354 for (i
= 1; i
< gimple_num_ops (stmt
); i
++)
1356 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
,
1362 /* Walk the LHS. If the RHS is appropriate for a memory, we
1363 may use a COMPONENT_REF on the LHS. */
1366 /* If the RHS has more than 1 operand, it is not appropriate
1368 wi
->val_only
= !is_gimple_mem_rhs (gimple_assign_rhs1 (stmt
))
1369 || !gimple_assign_single_p (stmt
);
1373 ret
= walk_tree (gimple_op_ptr (stmt
, 0), callback_op
, wi
, pset
);
1379 wi
->val_only
= true;
1388 ret
= walk_tree (gimple_call_chain_ptr (stmt
), callback_op
, wi
, pset
);
1392 ret
= walk_tree (gimple_call_fn_ptr (stmt
), callback_op
, wi
, pset
);
1396 for (i
= 0; i
< gimple_call_num_args (stmt
); i
++)
1398 ret
= walk_tree (gimple_call_arg_ptr (stmt
, i
), callback_op
, wi
,
1407 ret
= walk_tree (gimple_call_lhs_ptr (stmt
), callback_op
, wi
, pset
);
1416 ret
= walk_tree (gimple_catch_types_ptr (stmt
), callback_op
, wi
,
1422 case GIMPLE_EH_FILTER
:
1423 ret
= walk_tree (gimple_eh_filter_types_ptr (stmt
), callback_op
, wi
,
1430 ret
= walk_gimple_asm (stmt
, callback_op
, wi
);
1435 case GIMPLE_OMP_CONTINUE
:
1436 ret
= walk_tree (gimple_omp_continue_control_def_ptr (stmt
),
1437 callback_op
, wi
, pset
);
1441 ret
= walk_tree (gimple_omp_continue_control_use_ptr (stmt
),
1442 callback_op
, wi
, pset
);
1447 case GIMPLE_OMP_CRITICAL
:
1448 ret
= walk_tree (gimple_omp_critical_name_ptr (stmt
), callback_op
, wi
,
1454 case GIMPLE_OMP_FOR
:
1455 ret
= walk_tree (gimple_omp_for_clauses_ptr (stmt
), callback_op
, wi
,
1459 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
1461 ret
= walk_tree (gimple_omp_for_index_ptr (stmt
, i
), callback_op
,
1465 ret
= walk_tree (gimple_omp_for_initial_ptr (stmt
, i
), callback_op
,
1469 ret
= walk_tree (gimple_omp_for_final_ptr (stmt
, i
), callback_op
,
1473 ret
= walk_tree (gimple_omp_for_incr_ptr (stmt
, i
), callback_op
,
1480 case GIMPLE_OMP_PARALLEL
:
1481 ret
= walk_tree (gimple_omp_parallel_clauses_ptr (stmt
), callback_op
,
1485 ret
= walk_tree (gimple_omp_parallel_child_fn_ptr (stmt
), callback_op
,
1489 ret
= walk_tree (gimple_omp_parallel_data_arg_ptr (stmt
), callback_op
,
1495 case GIMPLE_OMP_TASK
:
1496 ret
= walk_tree (gimple_omp_task_clauses_ptr (stmt
), callback_op
,
1500 ret
= walk_tree (gimple_omp_task_child_fn_ptr (stmt
), callback_op
,
1504 ret
= walk_tree (gimple_omp_task_data_arg_ptr (stmt
), callback_op
,
1508 ret
= walk_tree (gimple_omp_task_copy_fn_ptr (stmt
), callback_op
,
1512 ret
= walk_tree (gimple_omp_task_arg_size_ptr (stmt
), callback_op
,
1516 ret
= walk_tree (gimple_omp_task_arg_align_ptr (stmt
), callback_op
,
1522 case GIMPLE_OMP_SECTIONS
:
1523 ret
= walk_tree (gimple_omp_sections_clauses_ptr (stmt
), callback_op
,
1528 ret
= walk_tree (gimple_omp_sections_control_ptr (stmt
), callback_op
,
1535 case GIMPLE_OMP_SINGLE
:
1536 ret
= walk_tree (gimple_omp_single_clauses_ptr (stmt
), callback_op
, wi
,
1542 case GIMPLE_OMP_ATOMIC_LOAD
:
1543 ret
= walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt
), callback_op
, wi
,
1548 ret
= walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt
), callback_op
, wi
,
1554 case GIMPLE_OMP_ATOMIC_STORE
:
1555 ret
= walk_tree (gimple_omp_atomic_store_val_ptr (stmt
), callback_op
,
1561 /* Tuples that do not have operands. */
1564 case GIMPLE_OMP_RETURN
:
1565 case GIMPLE_PREDICT
:
1570 enum gimple_statement_structure_enum gss
;
1571 gss
= gimple_statement_structure (stmt
);
1572 if (gss
== GSS_WITH_OPS
|| gss
== GSS_WITH_MEM_OPS
)
1573 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
1575 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
, pset
);
1587 /* Walk the current statement in GSI (optionally using traversal state
1588 stored in WI). If WI is NULL, no state is kept during traversal.
1589 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
1590 that it has handled all the operands of the statement, its return
1591 value is returned. Otherwise, the return value from CALLBACK_STMT
1592 is discarded and its operands are scanned.
1594 If CALLBACK_STMT is NULL or it didn't handle the operands,
1595 CALLBACK_OP is called on each operand of the statement via
1596 walk_gimple_op. If walk_gimple_op returns non-NULL for any
1597 operand, the remaining operands are not scanned. In this case, the
1598 return value from CALLBACK_OP is returned.
1600 In any other case, NULL_TREE is returned. */
1603 walk_gimple_stmt (gimple_stmt_iterator
*gsi
, walk_stmt_fn callback_stmt
,
1604 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1608 gimple stmt
= gsi_stmt (*gsi
);
1613 if (wi
&& wi
->want_locations
&& gimple_has_location (stmt
))
1614 input_location
= gimple_location (stmt
);
1618 /* Invoke the statement callback. Return if the callback handled
1619 all of STMT operands by itself. */
1622 bool handled_ops
= false;
1623 tree_ret
= callback_stmt (gsi
, &handled_ops
, wi
);
1627 /* If CALLBACK_STMT did not handle operands, it should not have
1628 a value to return. */
1629 gcc_assert (tree_ret
== NULL
);
1631 /* Re-read stmt in case the callback changed it. */
1632 stmt
= gsi_stmt (*gsi
);
1635 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
1638 tree_ret
= walk_gimple_op (stmt
, callback_op
, wi
);
1643 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
1644 switch (gimple_code (stmt
))
1647 ret
= walk_gimple_seq (gimple_bind_body (stmt
), callback_stmt
,
1650 return wi
->callback_result
;
1654 ret
= walk_gimple_seq (gimple_catch_handler (stmt
), callback_stmt
,
1657 return wi
->callback_result
;
1660 case GIMPLE_EH_FILTER
:
1661 ret
= walk_gimple_seq (gimple_eh_filter_failure (stmt
), callback_stmt
,
1664 return wi
->callback_result
;
1668 ret
= walk_gimple_seq (gimple_try_eval (stmt
), callback_stmt
, callback_op
,
1671 return wi
->callback_result
;
1673 ret
= walk_gimple_seq (gimple_try_cleanup (stmt
), callback_stmt
,
1676 return wi
->callback_result
;
1679 case GIMPLE_OMP_FOR
:
1680 ret
= walk_gimple_seq (gimple_omp_for_pre_body (stmt
), callback_stmt
,
1683 return wi
->callback_result
;
1686 case GIMPLE_OMP_CRITICAL
:
1687 case GIMPLE_OMP_MASTER
:
1688 case GIMPLE_OMP_ORDERED
:
1689 case GIMPLE_OMP_SECTION
:
1690 case GIMPLE_OMP_PARALLEL
:
1691 case GIMPLE_OMP_TASK
:
1692 case GIMPLE_OMP_SECTIONS
:
1693 case GIMPLE_OMP_SINGLE
:
1694 ret
= walk_gimple_seq (gimple_omp_body (stmt
), callback_stmt
, callback_op
,
1697 return wi
->callback_result
;
1700 case GIMPLE_WITH_CLEANUP_EXPR
:
1701 ret
= walk_gimple_seq (gimple_wce_cleanup (stmt
), callback_stmt
,
1704 return wi
->callback_result
;
1708 gcc_assert (!gimple_has_substatements (stmt
));
1716 /* Set sequence SEQ to be the GIMPLE body for function FN. */
1719 gimple_set_body (tree fndecl
, gimple_seq seq
)
1721 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1724 /* If FNDECL still does not have a function structure associated
1725 with it, then it does not make sense for it to receive a
1727 gcc_assert (seq
== NULL
);
1730 fn
->gimple_body
= seq
;
1734 /* Return the body of GIMPLE statements for function FN. */
1737 gimple_body (tree fndecl
)
1739 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1740 return fn
? fn
->gimple_body
: NULL
;
1743 /* Return true when FNDECL has Gimple body either in unlowered
1746 gimple_has_body_p (tree fndecl
)
1748 struct function
*fn
= DECL_STRUCT_FUNCTION (fndecl
);
1749 return (gimple_body (fndecl
) || (fn
&& fn
->cfg
));
1752 /* Detect flags from a GIMPLE_CALL. This is just like
1753 call_expr_flags, but for gimple tuples. */
1756 gimple_call_flags (const_gimple stmt
)
1759 tree decl
= gimple_call_fndecl (stmt
);
1763 flags
= flags_from_decl_or_type (decl
);
1766 t
= TREE_TYPE (gimple_call_fn (stmt
));
1767 if (t
&& TREE_CODE (t
) == POINTER_TYPE
)
1768 flags
= flags_from_decl_or_type (TREE_TYPE (t
));
1773 if (stmt
->gsbase
.subcode
& GF_CALL_NOTHROW
)
1774 flags
|= ECF_NOTHROW
;
1779 /* Detects argument flags for argument number ARG on call STMT. */
1782 gimple_call_arg_flags (const_gimple stmt
, unsigned arg
)
1784 tree type
= TREE_TYPE (TREE_TYPE (gimple_call_fn (stmt
)));
1785 tree attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
1789 attr
= TREE_VALUE (TREE_VALUE (attr
));
1790 if (1 + arg
>= (unsigned) TREE_STRING_LENGTH (attr
))
1793 switch (TREE_STRING_POINTER (attr
)[1 + arg
])
1800 return EAF_DIRECT
| EAF_NOCLOBBER
| EAF_NOESCAPE
;
1803 return EAF_NOCLOBBER
| EAF_NOESCAPE
;
1806 return EAF_DIRECT
| EAF_NOESCAPE
;
1809 return EAF_NOESCAPE
;
1817 /* Detects return flags for the call STMT. */
1820 gimple_call_return_flags (const_gimple stmt
)
1823 tree attr
= NULL_TREE
;
1825 if (gimple_call_flags (stmt
) & ECF_MALLOC
)
1828 type
= TREE_TYPE (TREE_TYPE (gimple_call_fn (stmt
)));
1829 attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
1833 attr
= TREE_VALUE (TREE_VALUE (attr
));
1834 if (TREE_STRING_LENGTH (attr
) < 1)
1837 switch (TREE_STRING_POINTER (attr
)[0])
1843 return ERF_RETURNS_ARG
| (TREE_STRING_POINTER (attr
)[0] - '1');
1854 /* Return true if GS is a copy assignment. */
1857 gimple_assign_copy_p (gimple gs
)
1859 return gimple_code (gs
) == GIMPLE_ASSIGN
1860 && get_gimple_rhs_class (gimple_assign_rhs_code (gs
))
1861 == GIMPLE_SINGLE_RHS
1862 && is_gimple_val (gimple_op (gs
, 1));
1866 /* Return true if GS is a SSA_NAME copy assignment. */
1869 gimple_assign_ssa_name_copy_p (gimple gs
)
1871 return (gimple_code (gs
) == GIMPLE_ASSIGN
1872 && (get_gimple_rhs_class (gimple_assign_rhs_code (gs
))
1873 == GIMPLE_SINGLE_RHS
)
1874 && TREE_CODE (gimple_assign_lhs (gs
)) == SSA_NAME
1875 && TREE_CODE (gimple_assign_rhs1 (gs
)) == SSA_NAME
);
1879 /* Return true if GS is an assignment with a singleton RHS, i.e.,
1880 there is no operator associated with the assignment itself.
1881 Unlike gimple_assign_copy_p, this predicate returns true for
1882 any RHS operand, including those that perform an operation
1883 and do not have the semantics of a copy, such as COND_EXPR. */
1886 gimple_assign_single_p (gimple gs
)
1888 return (gimple_code (gs
) == GIMPLE_ASSIGN
1889 && get_gimple_rhs_class (gimple_assign_rhs_code (gs
))
1890 == GIMPLE_SINGLE_RHS
);
1893 /* Return true if GS is an assignment with a unary RHS, but the
1894 operator has no effect on the assigned value. The logic is adapted
1895 from STRIP_NOPS. This predicate is intended to be used in tuplifying
1896 instances in which STRIP_NOPS was previously applied to the RHS of
1899 NOTE: In the use cases that led to the creation of this function
1900 and of gimple_assign_single_p, it is typical to test for either
1901 condition and to proceed in the same manner. In each case, the
1902 assigned value is represented by the single RHS operand of the
1903 assignment. I suspect there may be cases where gimple_assign_copy_p,
1904 gimple_assign_single_p, or equivalent logic is used where a similar
1905 treatment of unary NOPs is appropriate. */
1908 gimple_assign_unary_nop_p (gimple gs
)
1910 return (gimple_code (gs
) == GIMPLE_ASSIGN
1911 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs
))
1912 || gimple_assign_rhs_code (gs
) == NON_LVALUE_EXPR
)
1913 && gimple_assign_rhs1 (gs
) != error_mark_node
1914 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs
)))
1915 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs
)))));
1918 /* Set BB to be the basic block holding G. */
1921 gimple_set_bb (gimple stmt
, basic_block bb
)
1923 stmt
->gsbase
.bb
= bb
;
1925 /* If the statement is a label, add the label to block-to-labels map
1926 so that we can speed up edge creation for GIMPLE_GOTOs. */
1927 if (cfun
->cfg
&& gimple_code (stmt
) == GIMPLE_LABEL
)
1932 t
= gimple_label_label (stmt
);
1933 uid
= LABEL_DECL_UID (t
);
1936 unsigned old_len
= VEC_length (basic_block
, label_to_block_map
);
1937 LABEL_DECL_UID (t
) = uid
= cfun
->cfg
->last_label_uid
++;
1938 if (old_len
<= (unsigned) uid
)
1940 unsigned new_len
= 3 * uid
/ 2 + 1;
1942 VEC_safe_grow_cleared (basic_block
, gc
, label_to_block_map
,
1947 VEC_replace (basic_block
, label_to_block_map
, uid
, bb
);
1952 /* Modify the RHS of the assignment pointed-to by GSI using the
1953 operands in the expression tree EXPR.
1955 NOTE: The statement pointed-to by GSI may be reallocated if it
1956 did not have enough operand slots.
1958 This function is useful to convert an existing tree expression into
1959 the flat representation used for the RHS of a GIMPLE assignment.
1960 It will reallocate memory as needed to expand or shrink the number
1961 of operand slots needed to represent EXPR.
1963 NOTE: If you find yourself building a tree and then calling this
1964 function, you are most certainly doing it the slow way. It is much
1965 better to build a new assignment or to use the function
1966 gimple_assign_set_rhs_with_ops, which does not require an
1967 expression tree to be built. */
1970 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator
*gsi
, tree expr
)
1972 enum tree_code subcode
;
1975 extract_ops_from_tree_1 (expr
, &subcode
, &op1
, &op2
, &op3
);
1976 gimple_assign_set_rhs_with_ops_1 (gsi
, subcode
, op1
, op2
, op3
);
1980 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
1981 operands OP1, OP2 and OP3.
1983 NOTE: The statement pointed-to by GSI may be reallocated if it
1984 did not have enough operand slots. */
1987 gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator
*gsi
, enum tree_code code
,
1988 tree op1
, tree op2
, tree op3
)
1990 unsigned new_rhs_ops
= get_gimple_rhs_num_ops (code
);
1991 gimple stmt
= gsi_stmt (*gsi
);
1993 /* If the new CODE needs more operands, allocate a new statement. */
1994 if (gimple_num_ops (stmt
) < new_rhs_ops
+ 1)
1996 tree lhs
= gimple_assign_lhs (stmt
);
1997 gimple new_stmt
= gimple_alloc (gimple_code (stmt
), new_rhs_ops
+ 1);
1998 memcpy (new_stmt
, stmt
, gimple_size (gimple_code (stmt
)));
1999 gsi_replace (gsi
, new_stmt
, true);
2002 /* The LHS needs to be reset as this also changes the SSA name
2004 gimple_assign_set_lhs (stmt
, lhs
);
2007 gimple_set_num_ops (stmt
, new_rhs_ops
+ 1);
2008 gimple_set_subcode (stmt
, code
);
2009 gimple_assign_set_rhs1 (stmt
, op1
);
2010 if (new_rhs_ops
> 1)
2011 gimple_assign_set_rhs2 (stmt
, op2
);
2012 if (new_rhs_ops
> 2)
2013 gimple_assign_set_rhs3 (stmt
, op3
);
2017 /* Return the LHS of a statement that performs an assignment,
2018 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2019 for a call to a function that returns no value, or for a
2020 statement other than an assignment or a call. */
2023 gimple_get_lhs (const_gimple stmt
)
2025 enum gimple_code code
= gimple_code (stmt
);
2027 if (code
== GIMPLE_ASSIGN
)
2028 return gimple_assign_lhs (stmt
);
2029 else if (code
== GIMPLE_CALL
)
2030 return gimple_call_lhs (stmt
);
2036 /* Set the LHS of a statement that performs an assignment,
2037 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2040 gimple_set_lhs (gimple stmt
, tree lhs
)
2042 enum gimple_code code
= gimple_code (stmt
);
2044 if (code
== GIMPLE_ASSIGN
)
2045 gimple_assign_set_lhs (stmt
, lhs
);
2046 else if (code
== GIMPLE_CALL
)
2047 gimple_call_set_lhs (stmt
, lhs
);
2052 /* Replace the LHS of STMT, an assignment, either a GIMPLE_ASSIGN or a
2053 GIMPLE_CALL, with NLHS, in preparation for modifying the RHS to an
2054 expression with a different value.
2056 This will update any annotations (say debug bind stmts) referring
2057 to the original LHS, so that they use the RHS instead. This is
2058 done even if NLHS and LHS are the same, for it is understood that
2059 the RHS will be modified afterwards, and NLHS will not be assigned
2060 an equivalent value.
2062 Adjusting any non-annotation uses of the LHS, if needed, is a
2063 responsibility of the caller.
2065 The effect of this call should be pretty much the same as that of
2066 inserting a copy of STMT before STMT, and then removing the
2067 original stmt, at which time gsi_remove() would have update
2068 annotations, but using this function saves all the inserting,
2069 copying and removing. */
2072 gimple_replace_lhs (gimple stmt
, tree nlhs
)
2074 if (MAY_HAVE_DEBUG_STMTS
)
2076 tree lhs
= gimple_get_lhs (stmt
);
2078 gcc_assert (SSA_NAME_DEF_STMT (lhs
) == stmt
);
2080 insert_debug_temp_for_var_def (NULL
, lhs
);
2083 gimple_set_lhs (stmt
, nlhs
);
2086 /* Return a deep copy of statement STMT. All the operands from STMT
2087 are reallocated and copied using unshare_expr. The DEF, USE, VDEF
2088 and VUSE operand arrays are set to empty in the new copy. */
2091 gimple_copy (gimple stmt
)
2093 enum gimple_code code
= gimple_code (stmt
);
2094 unsigned num_ops
= gimple_num_ops (stmt
);
2095 gimple copy
= gimple_alloc (code
, num_ops
);
2098 /* Shallow copy all the fields from STMT. */
2099 memcpy (copy
, stmt
, gimple_size (code
));
2101 /* If STMT has sub-statements, deep-copy them as well. */
2102 if (gimple_has_substatements (stmt
))
2107 switch (gimple_code (stmt
))
2110 new_seq
= gimple_seq_copy (gimple_bind_body (stmt
));
2111 gimple_bind_set_body (copy
, new_seq
);
2112 gimple_bind_set_vars (copy
, unshare_expr (gimple_bind_vars (stmt
)));
2113 gimple_bind_set_block (copy
, gimple_bind_block (stmt
));
2117 new_seq
= gimple_seq_copy (gimple_catch_handler (stmt
));
2118 gimple_catch_set_handler (copy
, new_seq
);
2119 t
= unshare_expr (gimple_catch_types (stmt
));
2120 gimple_catch_set_types (copy
, t
);
2123 case GIMPLE_EH_FILTER
:
2124 new_seq
= gimple_seq_copy (gimple_eh_filter_failure (stmt
));
2125 gimple_eh_filter_set_failure (copy
, new_seq
);
2126 t
= unshare_expr (gimple_eh_filter_types (stmt
));
2127 gimple_eh_filter_set_types (copy
, t
);
2131 new_seq
= gimple_seq_copy (gimple_try_eval (stmt
));
2132 gimple_try_set_eval (copy
, new_seq
);
2133 new_seq
= gimple_seq_copy (gimple_try_cleanup (stmt
));
2134 gimple_try_set_cleanup (copy
, new_seq
);
2137 case GIMPLE_OMP_FOR
:
2138 new_seq
= gimple_seq_copy (gimple_omp_for_pre_body (stmt
));
2139 gimple_omp_for_set_pre_body (copy
, new_seq
);
2140 t
= unshare_expr (gimple_omp_for_clauses (stmt
));
2141 gimple_omp_for_set_clauses (copy
, t
);
2142 copy
->gimple_omp_for
.iter
2143 = ggc_alloc_vec_gimple_omp_for_iter
2144 (gimple_omp_for_collapse (stmt
));
2145 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
2147 gimple_omp_for_set_cond (copy
, i
,
2148 gimple_omp_for_cond (stmt
, i
));
2149 gimple_omp_for_set_index (copy
, i
,
2150 gimple_omp_for_index (stmt
, i
));
2151 t
= unshare_expr (gimple_omp_for_initial (stmt
, i
));
2152 gimple_omp_for_set_initial (copy
, i
, t
);
2153 t
= unshare_expr (gimple_omp_for_final (stmt
, i
));
2154 gimple_omp_for_set_final (copy
, i
, t
);
2155 t
= unshare_expr (gimple_omp_for_incr (stmt
, i
));
2156 gimple_omp_for_set_incr (copy
, i
, t
);
2160 case GIMPLE_OMP_PARALLEL
:
2161 t
= unshare_expr (gimple_omp_parallel_clauses (stmt
));
2162 gimple_omp_parallel_set_clauses (copy
, t
);
2163 t
= unshare_expr (gimple_omp_parallel_child_fn (stmt
));
2164 gimple_omp_parallel_set_child_fn (copy
, t
);
2165 t
= unshare_expr (gimple_omp_parallel_data_arg (stmt
));
2166 gimple_omp_parallel_set_data_arg (copy
, t
);
2169 case GIMPLE_OMP_TASK
:
2170 t
= unshare_expr (gimple_omp_task_clauses (stmt
));
2171 gimple_omp_task_set_clauses (copy
, t
);
2172 t
= unshare_expr (gimple_omp_task_child_fn (stmt
));
2173 gimple_omp_task_set_child_fn (copy
, t
);
2174 t
= unshare_expr (gimple_omp_task_data_arg (stmt
));
2175 gimple_omp_task_set_data_arg (copy
, t
);
2176 t
= unshare_expr (gimple_omp_task_copy_fn (stmt
));
2177 gimple_omp_task_set_copy_fn (copy
, t
);
2178 t
= unshare_expr (gimple_omp_task_arg_size (stmt
));
2179 gimple_omp_task_set_arg_size (copy
, t
);
2180 t
= unshare_expr (gimple_omp_task_arg_align (stmt
));
2181 gimple_omp_task_set_arg_align (copy
, t
);
2184 case GIMPLE_OMP_CRITICAL
:
2185 t
= unshare_expr (gimple_omp_critical_name (stmt
));
2186 gimple_omp_critical_set_name (copy
, t
);
2189 case GIMPLE_OMP_SECTIONS
:
2190 t
= unshare_expr (gimple_omp_sections_clauses (stmt
));
2191 gimple_omp_sections_set_clauses (copy
, t
);
2192 t
= unshare_expr (gimple_omp_sections_control (stmt
));
2193 gimple_omp_sections_set_control (copy
, t
);
2196 case GIMPLE_OMP_SINGLE
:
2197 case GIMPLE_OMP_SECTION
:
2198 case GIMPLE_OMP_MASTER
:
2199 case GIMPLE_OMP_ORDERED
:
2201 new_seq
= gimple_seq_copy (gimple_omp_body (stmt
));
2202 gimple_omp_set_body (copy
, new_seq
);
2205 case GIMPLE_WITH_CLEANUP_EXPR
:
2206 new_seq
= gimple_seq_copy (gimple_wce_cleanup (stmt
));
2207 gimple_wce_set_cleanup (copy
, new_seq
);
2215 /* Make copy of operands. */
2218 for (i
= 0; i
< num_ops
; i
++)
2219 gimple_set_op (copy
, i
, unshare_expr (gimple_op (stmt
, i
)));
2221 /* Clear out SSA operand vectors on COPY. */
2222 if (gimple_has_ops (stmt
))
2224 gimple_set_def_ops (copy
, NULL
);
2225 gimple_set_use_ops (copy
, NULL
);
2228 if (gimple_has_mem_ops (stmt
))
2230 gimple_set_vdef (copy
, gimple_vdef (stmt
));
2231 gimple_set_vuse (copy
, gimple_vuse (stmt
));
2234 /* SSA operands need to be updated. */
2235 gimple_set_modified (copy
, true);
2242 /* Set the MODIFIED flag to MODIFIEDP, iff the gimple statement G has
2243 a MODIFIED field. */
2246 gimple_set_modified (gimple s
, bool modifiedp
)
2248 if (gimple_has_ops (s
))
2250 s
->gsbase
.modified
= (unsigned) modifiedp
;
2254 && is_gimple_call (s
)
2255 && gimple_call_noreturn_p (s
))
2256 VEC_safe_push (gimple
, gc
, MODIFIED_NORETURN_CALLS (cfun
), s
);
2261 /* Return true if statement S has side-effects. We consider a
2262 statement to have side effects if:
2264 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2265 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2268 gimple_has_side_effects (const_gimple s
)
2272 if (is_gimple_debug (s
))
2275 /* We don't have to scan the arguments to check for
2276 volatile arguments, though, at present, we still
2277 do a scan to check for TREE_SIDE_EFFECTS. */
2278 if (gimple_has_volatile_ops (s
))
2281 if (is_gimple_call (s
))
2283 unsigned nargs
= gimple_call_num_args (s
);
2285 if (!(gimple_call_flags (s
) & (ECF_CONST
| ECF_PURE
)))
2287 else if (gimple_call_flags (s
) & ECF_LOOPING_CONST_OR_PURE
)
2288 /* An infinite loop is considered a side effect. */
2291 if (gimple_call_lhs (s
)
2292 && TREE_SIDE_EFFECTS (gimple_call_lhs (s
)))
2294 gcc_assert (gimple_has_volatile_ops (s
));
2298 if (TREE_SIDE_EFFECTS (gimple_call_fn (s
)))
2301 for (i
= 0; i
< nargs
; i
++)
2302 if (TREE_SIDE_EFFECTS (gimple_call_arg (s
, i
)))
2304 gcc_assert (gimple_has_volatile_ops (s
));
2312 for (i
= 0; i
< gimple_num_ops (s
); i
++)
2313 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
)))
2315 gcc_assert (gimple_has_volatile_ops (s
));
2323 /* Return true if the RHS of statement S has side effects.
2324 We may use it to determine if it is admissable to replace
2325 an assignment or call with a copy of a previously-computed
2326 value. In such cases, side-effects due the the LHS are
2330 gimple_rhs_has_side_effects (const_gimple s
)
2334 if (is_gimple_call (s
))
2336 unsigned nargs
= gimple_call_num_args (s
);
2338 if (!(gimple_call_flags (s
) & (ECF_CONST
| ECF_PURE
)))
2341 /* We cannot use gimple_has_volatile_ops here,
2342 because we must ignore a volatile LHS. */
2343 if (TREE_SIDE_EFFECTS (gimple_call_fn (s
))
2344 || TREE_THIS_VOLATILE (gimple_call_fn (s
)))
2346 gcc_assert (gimple_has_volatile_ops (s
));
2350 for (i
= 0; i
< nargs
; i
++)
2351 if (TREE_SIDE_EFFECTS (gimple_call_arg (s
, i
))
2352 || TREE_THIS_VOLATILE (gimple_call_arg (s
, i
)))
2357 else if (is_gimple_assign (s
))
2359 /* Skip the first operand, the LHS. */
2360 for (i
= 1; i
< gimple_num_ops (s
); i
++)
2361 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
))
2362 || TREE_THIS_VOLATILE (gimple_op (s
, i
)))
2364 gcc_assert (gimple_has_volatile_ops (s
));
2368 else if (is_gimple_debug (s
))
2372 /* For statements without an LHS, examine all arguments. */
2373 for (i
= 0; i
< gimple_num_ops (s
); i
++)
2374 if (TREE_SIDE_EFFECTS (gimple_op (s
, i
))
2375 || TREE_THIS_VOLATILE (gimple_op (s
, i
)))
2377 gcc_assert (gimple_has_volatile_ops (s
));
2386 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2387 Return true if S can trap. If INCLUDE_LHS is true and S is a
2388 GIMPLE_ASSIGN, the LHS of the assignment is also checked.
2389 Otherwise, only the RHS of the assignment is checked. */
2392 gimple_could_trap_p_1 (gimple s
, bool include_lhs
)
2395 tree t
, div
= NULL_TREE
;
2398 start
= (is_gimple_assign (s
) && !include_lhs
) ? 1 : 0;
2400 for (i
= start
; i
< gimple_num_ops (s
); i
++)
2401 if (tree_could_trap_p (gimple_op (s
, i
)))
2404 switch (gimple_code (s
))
2407 return gimple_asm_volatile_p (s
);
2410 t
= gimple_call_fndecl (s
);
2411 /* Assume that calls to weak functions may trap. */
2412 if (!t
|| !DECL_P (t
) || DECL_WEAK (t
))
2417 t
= gimple_expr_type (s
);
2418 op
= gimple_assign_rhs_code (s
);
2419 if (get_gimple_rhs_class (op
) == GIMPLE_BINARY_RHS
)
2420 div
= gimple_assign_rhs2 (s
);
2421 return (operation_could_trap_p (op
, FLOAT_TYPE_P (t
),
2422 (INTEGRAL_TYPE_P (t
)
2423 && TYPE_OVERFLOW_TRAPS (t
)),
2435 /* Return true if statement S can trap. */
2438 gimple_could_trap_p (gimple s
)
2440 return gimple_could_trap_p_1 (s
, true);
2444 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2447 gimple_assign_rhs_could_trap_p (gimple s
)
2449 gcc_assert (is_gimple_assign (s
));
2450 return gimple_could_trap_p_1 (s
, false);
2454 /* Print debugging information for gimple stmts generated. */
2457 dump_gimple_statistics (void)
2459 #ifdef GATHER_STATISTICS
2460 int i
, total_tuples
= 0, total_bytes
= 0;
2462 fprintf (stderr
, "\nGIMPLE statements\n");
2463 fprintf (stderr
, "Kind Stmts Bytes\n");
2464 fprintf (stderr
, "---------------------------------------\n");
2465 for (i
= 0; i
< (int) gimple_alloc_kind_all
; ++i
)
2467 fprintf (stderr
, "%-20s %7d %10d\n", gimple_alloc_kind_names
[i
],
2468 gimple_alloc_counts
[i
], gimple_alloc_sizes
[i
]);
2469 total_tuples
+= gimple_alloc_counts
[i
];
2470 total_bytes
+= gimple_alloc_sizes
[i
];
2472 fprintf (stderr
, "---------------------------------------\n");
2473 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_tuples
, total_bytes
);
2474 fprintf (stderr
, "---------------------------------------\n");
2476 fprintf (stderr
, "No gimple statistics\n");
2481 /* Return the number of operands needed on the RHS of a GIMPLE
2482 assignment for an expression with tree code CODE. */
2485 get_gimple_rhs_num_ops (enum tree_code code
)
2487 enum gimple_rhs_class rhs_class
= get_gimple_rhs_class (code
);
2489 if (rhs_class
== GIMPLE_UNARY_RHS
|| rhs_class
== GIMPLE_SINGLE_RHS
)
2491 else if (rhs_class
== GIMPLE_BINARY_RHS
)
2493 else if (rhs_class
== GIMPLE_TERNARY_RHS
)
2499 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2501 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2502 : ((TYPE) == tcc_binary \
2503 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2504 : ((TYPE) == tcc_constant \
2505 || (TYPE) == tcc_declaration \
2506 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2507 : ((SYM) == TRUTH_AND_EXPR \
2508 || (SYM) == TRUTH_OR_EXPR \
2509 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2510 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2511 : ((SYM) == WIDEN_MULT_PLUS_EXPR \
2512 || (SYM) == WIDEN_MULT_MINUS_EXPR) ? GIMPLE_TERNARY_RHS \
2513 : ((SYM) == COND_EXPR \
2514 || (SYM) == CONSTRUCTOR \
2515 || (SYM) == OBJ_TYPE_REF \
2516 || (SYM) == ASSERT_EXPR \
2517 || (SYM) == ADDR_EXPR \
2518 || (SYM) == WITH_SIZE_EXPR \
2519 || (SYM) == SSA_NAME \
2520 || (SYM) == POLYNOMIAL_CHREC \
2521 || (SYM) == DOT_PROD_EXPR \
2522 || (SYM) == VEC_COND_EXPR \
2523 || (SYM) == REALIGN_LOAD_EXPR) ? GIMPLE_SINGLE_RHS \
2524 : GIMPLE_INVALID_RHS),
2525 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2527 const unsigned char gimple_rhs_class_table
[] = {
2528 #include "all-tree.def"
2532 #undef END_OF_BASE_TREE_CODES
2534 /* For the definitive definition of GIMPLE, see doc/tree-ssa.texi. */
2536 /* Validation of GIMPLE expressions. */
2538 /* Return true if OP is an acceptable tree node to be used as a GIMPLE
2542 is_gimple_operand (const_tree op
)
2544 return op
&& get_gimple_rhs_class (TREE_CODE (op
)) == GIMPLE_SINGLE_RHS
;
2547 /* Returns true iff T is a valid RHS for an assignment to a renamed
2548 user -- or front-end generated artificial -- variable. */
2551 is_gimple_reg_rhs (tree t
)
2553 return get_gimple_rhs_class (TREE_CODE (t
)) != GIMPLE_INVALID_RHS
;
2556 /* Returns true iff T is a valid RHS for an assignment to an un-renamed
2557 LHS, or for a call argument. */
2560 is_gimple_mem_rhs (tree t
)
2562 /* If we're dealing with a renamable type, either source or dest must be
2563 a renamed variable. */
2564 if (is_gimple_reg_type (TREE_TYPE (t
)))
2565 return is_gimple_val (t
);
2567 return is_gimple_val (t
) || is_gimple_lvalue (t
);
2570 /* Return true if T is a valid LHS for a GIMPLE assignment expression. */
2573 is_gimple_lvalue (tree t
)
2575 return (is_gimple_addressable (t
)
2576 || TREE_CODE (t
) == WITH_SIZE_EXPR
2577 /* These are complex lvalues, but don't have addresses, so they
2579 || TREE_CODE (t
) == BIT_FIELD_REF
);
2582 /* Return true if T is a GIMPLE condition. */
2585 is_gimple_condexpr (tree t
)
2587 return (is_gimple_val (t
) || (COMPARISON_CLASS_P (t
)
2588 && !tree_could_trap_p (t
)
2589 && is_gimple_val (TREE_OPERAND (t
, 0))
2590 && is_gimple_val (TREE_OPERAND (t
, 1))));
2593 /* Return true if T is something whose address can be taken. */
2596 is_gimple_addressable (tree t
)
2598 return (is_gimple_id (t
) || handled_component_p (t
) || INDIRECT_REF_P (t
));
2601 /* Return true if T is a valid gimple constant. */
2604 is_gimple_constant (const_tree t
)
2606 switch (TREE_CODE (t
))
2616 /* Vector constant constructors are gimple invariant. */
2618 if (TREE_TYPE (t
) && TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2619 return TREE_CONSTANT (t
);
2628 /* Return true if T is a gimple address. */
2631 is_gimple_address (const_tree t
)
2635 if (TREE_CODE (t
) != ADDR_EXPR
)
2638 op
= TREE_OPERAND (t
, 0);
2639 while (handled_component_p (op
))
2641 if ((TREE_CODE (op
) == ARRAY_REF
2642 || TREE_CODE (op
) == ARRAY_RANGE_REF
)
2643 && !is_gimple_val (TREE_OPERAND (op
, 1)))
2646 op
= TREE_OPERAND (op
, 0);
2649 if (CONSTANT_CLASS_P (op
) || INDIRECT_REF_P (op
))
2652 switch (TREE_CODE (op
))
2667 /* Strip out all handled components that produce invariant
2671 strip_invariant_refs (const_tree op
)
2673 while (handled_component_p (op
))
2675 switch (TREE_CODE (op
))
2678 case ARRAY_RANGE_REF
:
2679 if (!is_gimple_constant (TREE_OPERAND (op
, 1))
2680 || TREE_OPERAND (op
, 2) != NULL_TREE
2681 || TREE_OPERAND (op
, 3) != NULL_TREE
)
2686 if (TREE_OPERAND (op
, 2) != NULL_TREE
)
2692 op
= TREE_OPERAND (op
, 0);
2698 /* Return true if T is a gimple invariant address. */
2701 is_gimple_invariant_address (const_tree t
)
2705 if (TREE_CODE (t
) != ADDR_EXPR
)
2708 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2710 return op
&& (CONSTANT_CLASS_P (op
) || decl_address_invariant_p (op
));
2713 /* Return true if T is a gimple invariant address at IPA level
2714 (so addresses of variables on stack are not allowed). */
2717 is_gimple_ip_invariant_address (const_tree t
)
2721 if (TREE_CODE (t
) != ADDR_EXPR
)
2724 op
= strip_invariant_refs (TREE_OPERAND (t
, 0));
2726 return op
&& (CONSTANT_CLASS_P (op
) || decl_address_ip_invariant_p (op
));
2729 /* Return true if T is a GIMPLE minimal invariant. It's a restricted
2730 form of function invariant. */
2733 is_gimple_min_invariant (const_tree t
)
2735 if (TREE_CODE (t
) == ADDR_EXPR
)
2736 return is_gimple_invariant_address (t
);
2738 return is_gimple_constant (t
);
2741 /* Return true if T is a GIMPLE interprocedural invariant. It's a restricted
2742 form of gimple minimal invariant. */
2745 is_gimple_ip_invariant (const_tree t
)
2747 if (TREE_CODE (t
) == ADDR_EXPR
)
2748 return is_gimple_ip_invariant_address (t
);
2750 return is_gimple_constant (t
);
2753 /* Return true if T looks like a valid GIMPLE statement. */
2756 is_gimple_stmt (tree t
)
2758 const enum tree_code code
= TREE_CODE (t
);
2763 /* The only valid NOP_EXPR is the empty statement. */
2764 return IS_EMPTY_STMT (t
);
2768 /* These are only valid if they're void. */
2769 return TREE_TYPE (t
) == NULL
|| VOID_TYPE_P (TREE_TYPE (t
));
2775 case CASE_LABEL_EXPR
:
2776 case TRY_CATCH_EXPR
:
2777 case TRY_FINALLY_EXPR
:
2778 case EH_FILTER_EXPR
:
2781 case STATEMENT_LIST
:
2791 /* These are always void. */
2797 /* These are valid regardless of their type. */
2805 /* Return true if T is a variable. */
2808 is_gimple_variable (tree t
)
2810 return (TREE_CODE (t
) == VAR_DECL
2811 || TREE_CODE (t
) == PARM_DECL
2812 || TREE_CODE (t
) == RESULT_DECL
2813 || TREE_CODE (t
) == SSA_NAME
);
2816 /* Return true if T is a GIMPLE identifier (something with an address). */
2819 is_gimple_id (tree t
)
2821 return (is_gimple_variable (t
)
2822 || TREE_CODE (t
) == FUNCTION_DECL
2823 || TREE_CODE (t
) == LABEL_DECL
2824 || TREE_CODE (t
) == CONST_DECL
2825 /* Allow string constants, since they are addressable. */
2826 || TREE_CODE (t
) == STRING_CST
);
2829 /* Return true if TYPE is a suitable type for a scalar register variable. */
2832 is_gimple_reg_type (tree type
)
2834 return !AGGREGATE_TYPE_P (type
);
2837 /* Return true if T is a non-aggregate register variable. */
2840 is_gimple_reg (tree t
)
2842 if (TREE_CODE (t
) == SSA_NAME
)
2843 t
= SSA_NAME_VAR (t
);
2845 if (!is_gimple_variable (t
))
2848 if (!is_gimple_reg_type (TREE_TYPE (t
)))
2851 /* A volatile decl is not acceptable because we can't reuse it as
2852 needed. We need to copy it into a temp first. */
2853 if (TREE_THIS_VOLATILE (t
))
2856 /* We define "registers" as things that can be renamed as needed,
2857 which with our infrastructure does not apply to memory. */
2858 if (needs_to_live_in_memory (t
))
2861 /* Hard register variables are an interesting case. For those that
2862 are call-clobbered, we don't know where all the calls are, since
2863 we don't (want to) take into account which operations will turn
2864 into libcalls at the rtl level. For those that are call-saved,
2865 we don't currently model the fact that calls may in fact change
2866 global hard registers, nor do we examine ASM_CLOBBERS at the tree
2867 level, and so miss variable changes that might imply. All around,
2868 it seems safest to not do too much optimization with these at the
2869 tree level at all. We'll have to rely on the rtl optimizers to
2870 clean this up, as there we've got all the appropriate bits exposed. */
2871 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2874 /* Complex and vector values must have been put into SSA-like form.
2875 That is, no assignments to the individual components. */
2876 if (TREE_CODE (TREE_TYPE (t
)) == COMPLEX_TYPE
2877 || TREE_CODE (TREE_TYPE (t
)) == VECTOR_TYPE
)
2878 return DECL_GIMPLE_REG_P (t
);
2884 /* Return true if T is a GIMPLE variable whose address is not needed. */
2887 is_gimple_non_addressable (tree t
)
2889 if (TREE_CODE (t
) == SSA_NAME
)
2890 t
= SSA_NAME_VAR (t
);
2892 return (is_gimple_variable (t
) && ! needs_to_live_in_memory (t
));
2895 /* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant. */
2898 is_gimple_val (tree t
)
2900 /* Make loads from volatiles and memory vars explicit. */
2901 if (is_gimple_variable (t
)
2902 && is_gimple_reg_type (TREE_TYPE (t
))
2903 && !is_gimple_reg (t
))
2906 return (is_gimple_variable (t
) || is_gimple_min_invariant (t
));
2909 /* Similarly, but accept hard registers as inputs to asm statements. */
2912 is_gimple_asm_val (tree t
)
2914 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HARD_REGISTER (t
))
2917 return is_gimple_val (t
);
2920 /* Return true if T is a GIMPLE minimal lvalue. */
2923 is_gimple_min_lval (tree t
)
2925 if (!(t
= CONST_CAST_TREE (strip_invariant_refs (t
))))
2927 return (is_gimple_id (t
) || TREE_CODE (t
) == INDIRECT_REF
);
2930 /* Return true if T is a typecast operation. */
2933 is_gimple_cast (tree t
)
2935 return (CONVERT_EXPR_P (t
)
2936 || TREE_CODE (t
) == FIX_TRUNC_EXPR
);
2939 /* Return true if T is a valid function operand of a CALL_EXPR. */
2942 is_gimple_call_addr (tree t
)
2944 return (TREE_CODE (t
) == OBJ_TYPE_REF
|| is_gimple_val (t
));
2947 /* If T makes a function call, return the corresponding CALL_EXPR operand.
2948 Otherwise, return NULL_TREE. */
2951 get_call_expr_in (tree t
)
2953 if (TREE_CODE (t
) == MODIFY_EXPR
)
2954 t
= TREE_OPERAND (t
, 1);
2955 if (TREE_CODE (t
) == WITH_SIZE_EXPR
)
2956 t
= TREE_OPERAND (t
, 0);
2957 if (TREE_CODE (t
) == CALL_EXPR
)
2963 /* Given a memory reference expression T, return its base address.
2964 The base address of a memory reference expression is the main
2965 object being referenced. For instance, the base address for
2966 'array[i].fld[j]' is 'array'. You can think of this as stripping
2967 away the offset part from a memory address.
2969 This function calls handled_component_p to strip away all the inner
2970 parts of the memory reference until it reaches the base object. */
2973 get_base_address (tree t
)
2975 while (handled_component_p (t
))
2976 t
= TREE_OPERAND (t
, 0);
2979 || TREE_CODE (t
) == STRING_CST
2980 || TREE_CODE (t
) == CONSTRUCTOR
2981 || INDIRECT_REF_P (t
))
2988 recalculate_side_effects (tree t
)
2990 enum tree_code code
= TREE_CODE (t
);
2991 int len
= TREE_OPERAND_LENGTH (t
);
2994 switch (TREE_CODE_CLASS (code
))
2996 case tcc_expression
:
3002 case PREDECREMENT_EXPR
:
3003 case PREINCREMENT_EXPR
:
3004 case POSTDECREMENT_EXPR
:
3005 case POSTINCREMENT_EXPR
:
3006 /* All of these have side-effects, no matter what their
3015 case tcc_comparison
: /* a comparison expression */
3016 case tcc_unary
: /* a unary arithmetic expression */
3017 case tcc_binary
: /* a binary arithmetic expression */
3018 case tcc_reference
: /* a reference */
3019 case tcc_vl_exp
: /* a function call */
3020 TREE_SIDE_EFFECTS (t
) = TREE_THIS_VOLATILE (t
);
3021 for (i
= 0; i
< len
; ++i
)
3023 tree op
= TREE_OPERAND (t
, i
);
3024 if (op
&& TREE_SIDE_EFFECTS (op
))
3025 TREE_SIDE_EFFECTS (t
) = 1;
3030 /* No side-effects. */
3038 /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
3039 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
3040 we failed to create one. */
3043 canonicalize_cond_expr_cond (tree t
)
3045 /* Strip conversions around boolean operations. */
3046 if (CONVERT_EXPR_P (t
)
3047 && truth_value_p (TREE_CODE (TREE_OPERAND (t
, 0))))
3048 t
= TREE_OPERAND (t
, 0);
3050 /* For (bool)x use x != 0. */
3051 if (CONVERT_EXPR_P (t
)
3052 && TREE_CODE (TREE_TYPE (t
)) == BOOLEAN_TYPE
)
3054 tree top0
= TREE_OPERAND (t
, 0);
3055 t
= build2 (NE_EXPR
, TREE_TYPE (t
),
3056 top0
, build_int_cst (TREE_TYPE (top0
), 0));
3058 /* For !x use x == 0. */
3059 else if (TREE_CODE (t
) == TRUTH_NOT_EXPR
)
3061 tree top0
= TREE_OPERAND (t
, 0);
3062 t
= build2 (EQ_EXPR
, TREE_TYPE (t
),
3063 top0
, build_int_cst (TREE_TYPE (top0
), 0));
3065 /* For cmp ? 1 : 0 use cmp. */
3066 else if (TREE_CODE (t
) == COND_EXPR
3067 && COMPARISON_CLASS_P (TREE_OPERAND (t
, 0))
3068 && integer_onep (TREE_OPERAND (t
, 1))
3069 && integer_zerop (TREE_OPERAND (t
, 2)))
3071 tree top0
= TREE_OPERAND (t
, 0);
3072 t
= build2 (TREE_CODE (top0
), TREE_TYPE (t
),
3073 TREE_OPERAND (top0
, 0), TREE_OPERAND (top0
, 1));
3076 if (is_gimple_condexpr (t
))
3082 /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
3083 the positions marked by the set ARGS_TO_SKIP. */
3086 gimple_call_copy_skip_args (gimple stmt
, bitmap args_to_skip
)
3089 tree fn
= gimple_call_fn (stmt
);
3090 int nargs
= gimple_call_num_args (stmt
);
3091 VEC(tree
, heap
) *vargs
= VEC_alloc (tree
, heap
, nargs
);
3094 for (i
= 0; i
< nargs
; i
++)
3095 if (!bitmap_bit_p (args_to_skip
, i
))
3096 VEC_quick_push (tree
, vargs
, gimple_call_arg (stmt
, i
));
3098 new_stmt
= gimple_build_call_vec (fn
, vargs
);
3099 VEC_free (tree
, heap
, vargs
);
3100 if (gimple_call_lhs (stmt
))
3101 gimple_call_set_lhs (new_stmt
, gimple_call_lhs (stmt
));
3103 gimple_set_vuse (new_stmt
, gimple_vuse (stmt
));
3104 gimple_set_vdef (new_stmt
, gimple_vdef (stmt
));
3106 gimple_set_block (new_stmt
, gimple_block (stmt
));
3107 if (gimple_has_location (stmt
))
3108 gimple_set_location (new_stmt
, gimple_location (stmt
));
3109 gimple_call_copy_flags (new_stmt
, stmt
);
3110 gimple_call_set_chain (new_stmt
, gimple_call_chain (stmt
));
3112 gimple_set_modified (new_stmt
, true);
3118 static hashval_t
gimple_type_hash (const void *);
3120 /* Structure used to maintain a cache of some type pairs compared by
3121 gimple_types_compatible_p when comparing aggregate types. There are
3122 four possible values for SAME_P:
3124 -2: The pair (T1, T2) has just been inserted in the table.
3125 -1: The pair (T1, T2) is currently being compared.
3126 0: T1 and T2 are different types.
3127 1: T1 and T2 are the same type.
3129 This table is only used when comparing aggregate types to avoid
3130 infinite recursion due to self-referential types. */
3137 typedef struct type_pair_d
*type_pair_t
;
3139 /* Return a hash value for the type pair pointed-to by P. */
3142 type_pair_hash (const void *p
)
3144 const struct type_pair_d
*pair
= (const struct type_pair_d
*) p
;
3145 hashval_t val1
= pair
->uid1
;
3146 hashval_t val2
= pair
->uid2
;
3147 return (iterative_hash_hashval_t (val2
, val1
)
3148 ^ iterative_hash_hashval_t (val1
, val2
));
3151 /* Compare two type pairs pointed-to by P1 and P2. */
3154 type_pair_eq (const void *p1
, const void *p2
)
3156 const struct type_pair_d
*pair1
= (const struct type_pair_d
*) p1
;
3157 const struct type_pair_d
*pair2
= (const struct type_pair_d
*) p2
;
3158 return ((pair1
->uid1
== pair2
->uid1
&& pair1
->uid2
== pair2
->uid2
)
3159 || (pair1
->uid1
== pair2
->uid2
&& pair1
->uid2
== pair2
->uid1
));
3162 /* Lookup the pair of types T1 and T2 in *VISITED_P. Insert a new
3163 entry if none existed. */
3166 lookup_type_pair (tree t1
, tree t2
, htab_t
*visited_p
, struct obstack
*ob_p
)
3168 struct type_pair_d pair
;
3172 if (*visited_p
== NULL
)
3174 *visited_p
= htab_create (251, type_pair_hash
, type_pair_eq
, NULL
);
3175 gcc_obstack_init (ob_p
);
3178 pair
.uid1
= TYPE_UID (t1
);
3179 pair
.uid2
= TYPE_UID (t2
);
3180 slot
= htab_find_slot (*visited_p
, &pair
, INSERT
);
3183 p
= *((type_pair_t
*) slot
);
3186 p
= XOBNEW (ob_p
, struct type_pair_d
);
3187 p
->uid1
= TYPE_UID (t1
);
3188 p
->uid2
= TYPE_UID (t2
);
3197 /* Return true if T1 and T2 have the same name. If FOR_COMPLETION_P is
3198 true then if any type has no name return false, otherwise return
3199 true if both types have no names. */
3202 compare_type_names_p (tree t1
, tree t2
, bool for_completion_p
)
3204 tree name1
= TYPE_NAME (t1
);
3205 tree name2
= TYPE_NAME (t2
);
3207 /* Consider anonymous types all unique for completion. */
3208 if (for_completion_p
3209 && (!name1
|| !name2
))
3212 if (name1
&& TREE_CODE (name1
) == TYPE_DECL
)
3214 name1
= DECL_NAME (name1
);
3215 if (for_completion_p
3219 gcc_assert (!name1
|| TREE_CODE (name1
) == IDENTIFIER_NODE
);
3221 if (name2
&& TREE_CODE (name2
) == TYPE_DECL
)
3223 name2
= DECL_NAME (name2
);
3224 if (for_completion_p
3228 gcc_assert (!name2
|| TREE_CODE (name2
) == IDENTIFIER_NODE
);
3230 /* Identifiers can be compared with pointer equality rather
3231 than a string comparison. */
3238 /* Return true if the field decls F1 and F2 are at the same offset.
3240 This is intended to be used on GIMPLE types only. In order to
3241 compare GENERIC types, use fields_compatible_p instead. */
3244 gimple_compare_field_offset (tree f1
, tree f2
)
3246 if (DECL_OFFSET_ALIGN (f1
) == DECL_OFFSET_ALIGN (f2
))
3248 tree offset1
= DECL_FIELD_OFFSET (f1
);
3249 tree offset2
= DECL_FIELD_OFFSET (f2
);
3250 return ((offset1
== offset2
3251 /* Once gimplification is done, self-referential offsets are
3252 instantiated as operand #2 of the COMPONENT_REF built for
3253 each access and reset. Therefore, they are not relevant
3254 anymore and fields are interchangeable provided that they
3255 represent the same access. */
3256 || (TREE_CODE (offset1
) == PLACEHOLDER_EXPR
3257 && TREE_CODE (offset2
) == PLACEHOLDER_EXPR
3258 && (DECL_SIZE (f1
) == DECL_SIZE (f2
)
3259 || (TREE_CODE (DECL_SIZE (f1
)) == PLACEHOLDER_EXPR
3260 && TREE_CODE (DECL_SIZE (f2
)) == PLACEHOLDER_EXPR
)
3261 || operand_equal_p (DECL_SIZE (f1
), DECL_SIZE (f2
), 0))
3262 && DECL_ALIGN (f1
) == DECL_ALIGN (f2
))
3263 || operand_equal_p (offset1
, offset2
, 0))
3264 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1
),
3265 DECL_FIELD_BIT_OFFSET (f2
)));
3268 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
3269 should be, so handle differing ones specially by decomposing
3270 the offset into a byte and bit offset manually. */
3271 if (host_integerp (DECL_FIELD_OFFSET (f1
), 0)
3272 && host_integerp (DECL_FIELD_OFFSET (f2
), 0))
3274 unsigned HOST_WIDE_INT byte_offset1
, byte_offset2
;
3275 unsigned HOST_WIDE_INT bit_offset1
, bit_offset2
;
3276 bit_offset1
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1
));
3277 byte_offset1
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1
))
3278 + bit_offset1
/ BITS_PER_UNIT
);
3279 bit_offset2
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2
));
3280 byte_offset2
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2
))
3281 + bit_offset2
/ BITS_PER_UNIT
);
3282 if (byte_offset1
!= byte_offset2
)
3284 return bit_offset1
% BITS_PER_UNIT
== bit_offset2
% BITS_PER_UNIT
;
3290 /* Return 1 iff T1 and T2 are structurally identical.
3291 Otherwise, return 0. */
3294 gimple_types_compatible_p (tree t1
, tree t2
)
3296 type_pair_t p
= NULL
;
3298 /* Check first for the obvious case of pointer identity. */
3302 /* Check that we have two types to compare. */
3303 if (t1
== NULL_TREE
|| t2
== NULL_TREE
)
3306 /* Can't be the same type if the types don't have the same code. */
3307 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3310 /* Can't be the same type if they have different CV qualifiers. */
3311 if (TYPE_QUALS (t1
) != TYPE_QUALS (t2
))
3314 /* Void types are always the same. */
3315 if (TREE_CODE (t1
) == VOID_TYPE
)
3318 /* Do some simple checks before doing three hashtable queries. */
3319 if (INTEGRAL_TYPE_P (t1
)
3320 || SCALAR_FLOAT_TYPE_P (t1
)
3321 || FIXED_POINT_TYPE_P (t1
)
3322 || TREE_CODE (t1
) == VECTOR_TYPE
3323 || TREE_CODE (t1
) == COMPLEX_TYPE
3324 || TREE_CODE (t1
) == OFFSET_TYPE
)
3326 /* Can't be the same type if they have different alignment,
3327 sign, precision or mode. */
3328 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3329 || TYPE_PRECISION (t1
) != TYPE_PRECISION (t2
)
3330 || TYPE_MODE (t1
) != TYPE_MODE (t2
)
3331 || TYPE_UNSIGNED (t1
) != TYPE_UNSIGNED (t2
))
3334 if (TREE_CODE (t1
) == INTEGER_TYPE
3335 && (TYPE_IS_SIZETYPE (t1
) != TYPE_IS_SIZETYPE (t2
)
3336 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)))
3339 /* That's all we need to check for float and fixed-point types. */
3340 if (SCALAR_FLOAT_TYPE_P (t1
)
3341 || FIXED_POINT_TYPE_P (t1
))
3344 /* Perform cheap tail-recursion for vector and complex types. */
3345 if (TREE_CODE (t1
) == VECTOR_TYPE
3346 || TREE_CODE (t1
) == COMPLEX_TYPE
)
3347 return gimple_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
));
3349 /* For integral types fall thru to more complex checks. */
3352 else if (AGGREGATE_TYPE_P (t1
) || POINTER_TYPE_P (t1
))
3354 /* Can't be the same type if they have different alignment or mode. */
3355 if (TYPE_ALIGN (t1
) != TYPE_ALIGN (t2
)
3356 || TYPE_MODE (t1
) != TYPE_MODE (t2
))
3360 /* If the hash values of t1 and t2 are different the types can't
3361 possibly be the same. This helps keeping the type-pair hashtable
3362 small, only tracking comparisons for hash collisions. */
3363 if (gimple_type_hash (t1
) != gimple_type_hash (t2
))
3366 /* If we've visited this type pair before (in the case of aggregates
3367 with self-referential types), and we made a decision, return it. */
3368 p
= lookup_type_pair (t1
, t2
, >c_visited
, >c_ob
);
3369 if (p
->same_p
== 0 || p
->same_p
== 1)
3371 /* We have already decided whether T1 and T2 are the
3372 same, return the cached result. */
3373 return p
->same_p
== 1;
3375 else if (p
->same_p
== -1)
3377 /* We are currently comparing this pair of types, assume
3378 that they are the same and let the caller decide. */
3382 gcc_assert (p
->same_p
== -2);
3384 /* Mark the (T1, T2) comparison in progress. */
3387 /* If their attributes are not the same they can't be the same type. */
3388 if (!attribute_list_equal (TYPE_ATTRIBUTES (t1
), TYPE_ATTRIBUTES (t2
)))
3389 goto different_types
;
3391 /* Do type-specific comparisons. */
3392 switch (TREE_CODE (t1
))
3395 /* Array types are the same if the element types are the same and
3396 the number of elements are the same. */
3397 if (!gimple_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
3398 || TYPE_STRING_FLAG (t1
) != TYPE_STRING_FLAG (t2
)
3399 || TYPE_NONALIASED_COMPONENT (t1
) != TYPE_NONALIASED_COMPONENT (t2
))
3400 goto different_types
;
3403 tree i1
= TYPE_DOMAIN (t1
);
3404 tree i2
= TYPE_DOMAIN (t2
);
3406 /* For an incomplete external array, the type domain can be
3407 NULL_TREE. Check this condition also. */
3408 if (i1
== NULL_TREE
&& i2
== NULL_TREE
)
3410 else if (i1
== NULL_TREE
|| i2
== NULL_TREE
)
3411 goto different_types
;
3412 /* If for a complete array type the possibly gimplified sizes
3413 are different the types are different. */
3414 else if (((TYPE_SIZE (i1
) != NULL
) ^ (TYPE_SIZE (i2
) != NULL
))
3417 && !operand_equal_p (TYPE_SIZE (i1
), TYPE_SIZE (i2
), 0)))
3418 goto different_types
;
3421 tree min1
= TYPE_MIN_VALUE (i1
);
3422 tree min2
= TYPE_MIN_VALUE (i2
);
3423 tree max1
= TYPE_MAX_VALUE (i1
);
3424 tree max2
= TYPE_MAX_VALUE (i2
);
3426 /* The minimum/maximum values have to be the same. */
3429 && ((TREE_CODE (min1
) == PLACEHOLDER_EXPR
3430 && TREE_CODE (min2
) == PLACEHOLDER_EXPR
)
3431 || operand_equal_p (min1
, min2
, 0))))
3434 && ((TREE_CODE (max1
) == PLACEHOLDER_EXPR
3435 && TREE_CODE (max2
) == PLACEHOLDER_EXPR
)
3436 || operand_equal_p (max1
, max2
, 0)))))
3439 goto different_types
;
3444 /* Method types should belong to the same class. */
3445 if (!gimple_types_compatible_p (TYPE_METHOD_BASETYPE (t1
),
3446 TYPE_METHOD_BASETYPE (t2
)))
3447 goto different_types
;
3452 /* Function types are the same if the return type and arguments types
3454 if (!gimple_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
3455 goto different_types
;
3458 if (!targetm
.comp_type_attributes (t1
, t2
))
3459 goto different_types
;
3461 if (TYPE_ARG_TYPES (t1
) == TYPE_ARG_TYPES (t2
))
3465 tree parms1
, parms2
;
3467 for (parms1
= TYPE_ARG_TYPES (t1
), parms2
= TYPE_ARG_TYPES (t2
);
3469 parms1
= TREE_CHAIN (parms1
), parms2
= TREE_CHAIN (parms2
))
3471 if (!gimple_types_compatible_p (TREE_VALUE (parms1
),
3472 TREE_VALUE (parms2
)))
3473 goto different_types
;
3476 if (parms1
|| parms2
)
3477 goto different_types
;
3485 if (!gimple_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
))
3486 || !gimple_types_compatible_p (TYPE_OFFSET_BASETYPE (t1
),
3487 TYPE_OFFSET_BASETYPE (t2
)))
3488 goto different_types
;
3494 case REFERENCE_TYPE
:
3496 /* If the two pointers have different ref-all attributes,
3497 they can't be the same type. */
3498 if (TYPE_REF_CAN_ALIAS_ALL (t1
) != TYPE_REF_CAN_ALIAS_ALL (t2
))
3499 goto different_types
;
3501 /* If one pointer points to an incomplete type variant of
3502 the other pointed-to type they are the same. */
3503 if (TREE_CODE (TREE_TYPE (t1
)) == TREE_CODE (TREE_TYPE (t2
))
3504 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t1
))
3505 && (!COMPLETE_TYPE_P (TREE_TYPE (t1
))
3506 || !COMPLETE_TYPE_P (TREE_TYPE (t2
)))
3507 && TYPE_QUALS (TREE_TYPE (t1
)) == TYPE_QUALS (TREE_TYPE (t2
))
3508 && compare_type_names_p (TYPE_MAIN_VARIANT (TREE_TYPE (t1
)),
3509 TYPE_MAIN_VARIANT (TREE_TYPE (t2
)), true))
3511 /* Replace the pointed-to incomplete type with the
3513 ??? This simple name-based merging causes at least some
3514 of the ICEs in canonicalizing FIELD_DECLs during stmt
3515 read. For example in GCC we have two different struct deps
3516 and we mismatch the use in struct cpp_reader in sched-int.h
3517 vs. mkdeps.c. Of course the whole exercise is for TBAA
3518 with structs which contain pointers to incomplete types
3519 in one unit and to complete ones in another. So we
3520 probably should merge these types only with more context. */
3521 if (COMPLETE_TYPE_P (TREE_TYPE (t2
)))
3522 TREE_TYPE (t1
) = TREE_TYPE (t2
);
3524 TREE_TYPE (t2
) = TREE_TYPE (t1
);
3528 /* Otherwise, pointer and reference types are the same if the
3529 pointed-to types are the same. */
3530 if (gimple_types_compatible_p (TREE_TYPE (t1
), TREE_TYPE (t2
)))
3533 goto different_types
;
3539 tree min1
= TYPE_MIN_VALUE (t1
);
3540 tree max1
= TYPE_MAX_VALUE (t1
);
3541 tree min2
= TYPE_MIN_VALUE (t2
);
3542 tree max2
= TYPE_MAX_VALUE (t2
);
3543 bool min_equal_p
= false;
3544 bool max_equal_p
= false;
3546 /* If either type has a minimum value, the other type must
3548 if (min1
== NULL_TREE
&& min2
== NULL_TREE
)
3550 else if (min1
&& min2
&& operand_equal_p (min1
, min2
, 0))
3553 /* Likewise, if either type has a maximum value, the other
3554 type must have the same. */
3555 if (max1
== NULL_TREE
&& max2
== NULL_TREE
)
3557 else if (max1
&& max2
&& operand_equal_p (max1
, max2
, 0))
3560 if (!min_equal_p
|| !max_equal_p
)
3561 goto different_types
;
3568 /* FIXME lto, we cannot check bounds on enumeral types because
3569 different front ends will produce different values.
3570 In C, enumeral types are integers, while in C++ each element
3571 will have its own symbolic value. We should decide how enums
3572 are to be represented in GIMPLE and have each front end lower
3576 /* For enumeral types, all the values must be the same. */
3577 if (TYPE_VALUES (t1
) == TYPE_VALUES (t2
))
3580 for (v1
= TYPE_VALUES (t1
), v2
= TYPE_VALUES (t2
);
3582 v1
= TREE_CHAIN (v1
), v2
= TREE_CHAIN (v2
))
3584 tree c1
= TREE_VALUE (v1
);
3585 tree c2
= TREE_VALUE (v2
);
3587 if (TREE_CODE (c1
) == CONST_DECL
)
3588 c1
= DECL_INITIAL (c1
);
3590 if (TREE_CODE (c2
) == CONST_DECL
)
3591 c2
= DECL_INITIAL (c2
);
3593 if (tree_int_cst_equal (c1
, c2
) != 1)
3594 goto different_types
;
3597 /* If one enumeration has more values than the other, they
3598 are not the same. */
3600 goto different_types
;
3607 case QUAL_UNION_TYPE
:
3611 /* The struct tags shall compare equal. */
3612 if (!compare_type_names_p (TYPE_MAIN_VARIANT (t1
),
3613 TYPE_MAIN_VARIANT (t2
), false))
3614 goto different_types
;
3616 /* For aggregate types, all the fields must be the same. */
3617 for (f1
= TYPE_FIELDS (t1
), f2
= TYPE_FIELDS (t2
);
3619 f1
= TREE_CHAIN (f1
), f2
= TREE_CHAIN (f2
))
3621 /* The fields must have the same name, offset and type. */
3622 if (DECL_NAME (f1
) != DECL_NAME (f2
)
3623 || DECL_NONADDRESSABLE_P (f1
) != DECL_NONADDRESSABLE_P (f2
)
3624 || !gimple_compare_field_offset (f1
, f2
)
3625 || !gimple_types_compatible_p (TREE_TYPE (f1
),
3627 goto different_types
;
3630 /* If one aggregate has more fields than the other, they
3631 are not the same. */
3633 goto different_types
;
3642 /* Common exit path for types that are not compatible. */
3647 /* Common exit path for types that are compatible. */
3656 /* Per pointer state for the SCC finding. The on_sccstack flag
3657 is not strictly required, it is true when there is no hash value
3658 recorded for the type and false otherwise. But querying that
3663 unsigned int dfsnum
;
3669 static unsigned int next_dfs_num
;
3672 iterative_hash_gimple_type (tree
, hashval_t
, VEC(tree
, heap
) **,
3673 struct pointer_map_t
*, struct obstack
*);
3675 /* DFS visit the edge from the callers type with state *STATE to T.
3676 Update the callers type hash V with the hash for T if it is not part
3677 of the SCC containing the callers type and return it.
3678 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done. */
3681 visit (tree t
, struct sccs
*state
, hashval_t v
,
3682 VEC (tree
, heap
) **sccstack
,
3683 struct pointer_map_t
*sccstate
,
3684 struct obstack
*sccstate_obstack
)
3686 struct sccs
*cstate
= NULL
;
3689 /* If there is a hash value recorded for this type then it can't
3690 possibly be part of our parent SCC. Simply mix in its hash. */
3691 if ((slot
= pointer_map_contains (type_hash_cache
, t
)))
3692 return iterative_hash_hashval_t ((hashval_t
) (size_t) *slot
, v
);
3694 if ((slot
= pointer_map_contains (sccstate
, t
)) != NULL
)
3695 cstate
= (struct sccs
*)*slot
;
3699 /* Not yet visited. DFS recurse. */
3700 tem
= iterative_hash_gimple_type (t
, v
,
3701 sccstack
, sccstate
, sccstate_obstack
);
3703 cstate
= (struct sccs
*)* pointer_map_contains (sccstate
, t
);
3704 state
->low
= MIN (state
->low
, cstate
->low
);
3705 /* If the type is no longer on the SCC stack and thus is not part
3706 of the parents SCC mix in its hash value. Otherwise we will
3707 ignore the type for hashing purposes and return the unaltered
3709 if (!cstate
->on_sccstack
)
3712 if (cstate
->dfsnum
< state
->dfsnum
3713 && cstate
->on_sccstack
)
3714 state
->low
= MIN (cstate
->dfsnum
, state
->low
);
3716 /* We are part of our parents SCC, skip this type during hashing
3717 and return the unaltered hash value. */
3721 /* Hash NAME with the previous hash value V and return it. */
3724 iterative_hash_name (tree name
, hashval_t v
)
3728 if (TREE_CODE (name
) == TYPE_DECL
)
3729 name
= DECL_NAME (name
);
3732 gcc_assert (TREE_CODE (name
) == IDENTIFIER_NODE
);
3733 return iterative_hash_object (IDENTIFIER_HASH_VALUE (name
), v
);
3736 /* Returning a hash value for gimple type TYPE combined with VAL.
3737 SCCSTACK, SCCSTATE and SCCSTATE_OBSTACK are state for the DFS walk done.
3739 To hash a type we end up hashing in types that are reachable.
3740 Through pointers we can end up with cycles which messes up the
3741 required property that we need to compute the same hash value
3742 for structurally equivalent types. To avoid this we have to
3743 hash all types in a cycle (the SCC) in a commutative way. The
3744 easiest way is to not mix in the hashes of the SCC members at
3745 all. To make this work we have to delay setting the hash
3746 values of the SCC until it is complete. */
3749 iterative_hash_gimple_type (tree type
, hashval_t val
,
3750 VEC(tree
, heap
) **sccstack
,
3751 struct pointer_map_t
*sccstate
,
3752 struct obstack
*sccstate_obstack
)
3758 #ifdef ENABLE_CHECKING
3759 /* Not visited during this DFS walk nor during previous walks. */
3760 gcc_assert (!pointer_map_contains (type_hash_cache
, type
)
3761 && !pointer_map_contains (sccstate
, type
));
3763 state
= XOBNEW (sccstate_obstack
, struct sccs
);
3764 *pointer_map_insert (sccstate
, type
) = state
;
3766 VEC_safe_push (tree
, heap
, *sccstack
, type
);
3767 state
->dfsnum
= next_dfs_num
++;
3768 state
->low
= state
->dfsnum
;
3769 state
->on_sccstack
= true;
3771 /* Combine a few common features of types so that types are grouped into
3772 smaller sets; when searching for existing matching types to merge,
3773 only existing types having the same features as the new type will be
3775 v
= iterative_hash_hashval_t (TREE_CODE (type
), 0);
3776 v
= iterative_hash_hashval_t (TYPE_QUALS (type
), v
);
3777 v
= iterative_hash_hashval_t (TREE_ADDRESSABLE (type
), v
);
3779 /* Do not hash the types size as this will cause differences in
3780 hash values for the complete vs. the incomplete type variant. */
3782 /* Incorporate common features of numerical types. */
3783 if (INTEGRAL_TYPE_P (type
)
3784 || SCALAR_FLOAT_TYPE_P (type
)
3785 || FIXED_POINT_TYPE_P (type
))
3787 v
= iterative_hash_hashval_t (TYPE_PRECISION (type
), v
);
3788 v
= iterative_hash_hashval_t (TYPE_MODE (type
), v
);
3789 v
= iterative_hash_hashval_t (TYPE_UNSIGNED (type
), v
);
3792 /* For pointer and reference types, fold in information about the type
3793 pointed to but do not recurse into possibly incomplete types to
3794 avoid hash differences for complete vs. incomplete types. */
3795 if (POINTER_TYPE_P (type
))
3797 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type
)))
3799 v
= iterative_hash_hashval_t (TREE_CODE (TREE_TYPE (type
)), v
);
3800 v
= iterative_hash_name
3801 (TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (type
))), v
);
3804 v
= visit (TREE_TYPE (type
), state
, v
,
3805 sccstack
, sccstate
, sccstate_obstack
);
3808 /* For integer types hash the types min/max values and the string flag. */
3809 if (TREE_CODE (type
) == INTEGER_TYPE
)
3811 /* OMP lowering can introduce error_mark_node in place of
3812 random local decls in types. */
3813 if (TYPE_MIN_VALUE (type
) != error_mark_node
)
3814 v
= iterative_hash_expr (TYPE_MIN_VALUE (type
), v
);
3815 if (TYPE_MAX_VALUE (type
) != error_mark_node
)
3816 v
= iterative_hash_expr (TYPE_MAX_VALUE (type
), v
);
3817 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
3820 /* For array types hash their domain and the string flag. */
3821 if (TREE_CODE (type
) == ARRAY_TYPE
3822 && TYPE_DOMAIN (type
))
3824 v
= iterative_hash_hashval_t (TYPE_STRING_FLAG (type
), v
);
3825 v
= visit (TYPE_DOMAIN (type
), state
, v
,
3826 sccstack
, sccstate
, sccstate_obstack
);
3829 /* Recurse for aggregates with a single element type. */
3830 if (TREE_CODE (type
) == ARRAY_TYPE
3831 || TREE_CODE (type
) == COMPLEX_TYPE
3832 || TREE_CODE (type
) == VECTOR_TYPE
)
3833 v
= visit (TREE_TYPE (type
), state
, v
,
3834 sccstack
, sccstate
, sccstate_obstack
);
3836 /* Incorporate function return and argument types. */
3837 if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
3842 /* For method types also incorporate their parent class. */
3843 if (TREE_CODE (type
) == METHOD_TYPE
)
3844 v
= visit (TYPE_METHOD_BASETYPE (type
), state
, v
,
3845 sccstack
, sccstate
, sccstate_obstack
);
3847 v
= visit (TREE_TYPE (type
), state
, v
,
3848 sccstack
, sccstate
, sccstate_obstack
);
3850 for (p
= TYPE_ARG_TYPES (type
), na
= 0; p
; p
= TREE_CHAIN (p
))
3852 v
= visit (TREE_VALUE (p
), state
, v
,
3853 sccstack
, sccstate
, sccstate_obstack
);
3857 v
= iterative_hash_hashval_t (na
, v
);
3860 if (TREE_CODE (type
) == RECORD_TYPE
3861 || TREE_CODE (type
) == UNION_TYPE
3862 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
3867 v
= iterative_hash_name (TYPE_NAME (TYPE_MAIN_VARIANT (type
)), v
);
3869 for (f
= TYPE_FIELDS (type
), nf
= 0; f
; f
= TREE_CHAIN (f
))
3871 v
= iterative_hash_name (DECL_NAME (f
), v
);
3872 v
= visit (TREE_TYPE (f
), state
, v
,
3873 sccstack
, sccstate
, sccstate_obstack
);
3877 v
= iterative_hash_hashval_t (nf
, v
);
3880 /* Record hash for us. */
3883 /* See if we found an SCC. */
3884 if (state
->low
== state
->dfsnum
)
3888 /* Pop off the SCC and set its hash values. */
3891 struct sccs
*cstate
;
3892 x
= VEC_pop (tree
, *sccstack
);
3893 gcc_assert (!pointer_map_contains (type_hash_cache
, x
));
3894 cstate
= (struct sccs
*)*pointer_map_contains (sccstate
, x
);
3895 cstate
->on_sccstack
= false;
3896 slot
= pointer_map_insert (type_hash_cache
, x
);
3897 *slot
= (void *) (size_t) cstate
->hash
;
3902 return iterative_hash_hashval_t (v
, val
);
3906 /* Returns a hash value for P (assumed to be a type). The hash value
3907 is computed using some distinguishing features of the type. Note
3908 that we cannot use pointer hashing here as we may be dealing with
3909 two distinct instances of the same type.
3911 This function should produce the same hash value for two compatible
3912 types according to gimple_types_compatible_p. */
3915 gimple_type_hash (const void *p
)
3917 const_tree t
= (const_tree
) p
;
3918 VEC(tree
, heap
) *sccstack
= NULL
;
3919 struct pointer_map_t
*sccstate
;
3920 struct obstack sccstate_obstack
;
3924 if (type_hash_cache
== NULL
)
3925 type_hash_cache
= pointer_map_create ();
3927 if ((slot
= pointer_map_contains (type_hash_cache
, p
)) != NULL
)
3928 return iterative_hash_hashval_t ((hashval_t
) (size_t) *slot
, 0);
3930 /* Perform a DFS walk and pre-hash all reachable types. */
3932 sccstate
= pointer_map_create ();
3933 gcc_obstack_init (&sccstate_obstack
);
3934 val
= iterative_hash_gimple_type (CONST_CAST_TREE (t
), 0,
3935 &sccstack
, sccstate
, &sccstate_obstack
);
3936 VEC_free (tree
, heap
, sccstack
);
3937 pointer_map_destroy (sccstate
);
3938 obstack_free (&sccstate_obstack
, NULL
);
3944 /* Returns nonzero if P1 and P2 are equal. */
3947 gimple_type_eq (const void *p1
, const void *p2
)
3949 const_tree t1
= (const_tree
) p1
;
3950 const_tree t2
= (const_tree
) p2
;
3951 return gimple_types_compatible_p (CONST_CAST_TREE (t1
), CONST_CAST_TREE (t2
));
3955 /* Register type T in the global type table gimple_types.
3956 If another type T', compatible with T, already existed in
3957 gimple_types then return T', otherwise return T. This is used by
3958 LTO to merge identical types read from different TUs. */
3961 gimple_register_type (tree t
)
3965 gcc_assert (TYPE_P (t
));
3967 /* In TYPE_CANONICAL we cache the result of gimple_register_type.
3968 It is initially set to NULL during LTO streaming. */
3969 if (TYPE_CANONICAL (t
))
3970 return TYPE_CANONICAL (t
);
3972 /* Always register the main variant first. This is important so we
3973 pick up the non-typedef variants as canonical, otherwise we'll end
3974 up taking typedef ids for structure tags during comparison. */
3975 if (TYPE_MAIN_VARIANT (t
) != t
)
3976 gimple_register_type (TYPE_MAIN_VARIANT (t
));
3978 if (gimple_types
== NULL
)
3979 gimple_types
= htab_create (16381, gimple_type_hash
, gimple_type_eq
, 0);
3981 slot
= htab_find_slot (gimple_types
, t
, INSERT
);
3983 && *(tree
*)slot
!= t
)
3985 tree new_type
= (tree
) *((tree
*) slot
);
3987 /* Do not merge types with different addressability. */
3988 gcc_assert (TREE_ADDRESSABLE (t
) == TREE_ADDRESSABLE (new_type
));
3990 /* If t is not its main variant then make t unreachable from its
3991 main variant list. Otherwise we'd queue up a lot of duplicates
3993 if (t
!= TYPE_MAIN_VARIANT (t
))
3995 tree tem
= TYPE_MAIN_VARIANT (t
);
3996 while (tem
&& TYPE_NEXT_VARIANT (tem
) != t
)
3997 tem
= TYPE_NEXT_VARIANT (tem
);
3999 TYPE_NEXT_VARIANT (tem
) = TYPE_NEXT_VARIANT (t
);
4000 TYPE_NEXT_VARIANT (t
) = NULL_TREE
;
4003 /* If we are a pointer then remove us from the pointer-to or
4004 reference-to chain. Otherwise we'd queue up a lot of duplicates
4006 if (TREE_CODE (t
) == POINTER_TYPE
)
4008 if (TYPE_POINTER_TO (TREE_TYPE (t
)) == t
)
4009 TYPE_POINTER_TO (TREE_TYPE (t
)) = TYPE_NEXT_PTR_TO (t
);
4012 tree tem
= TYPE_POINTER_TO (TREE_TYPE (t
));
4013 while (tem
&& TYPE_NEXT_PTR_TO (tem
) != t
)
4014 tem
= TYPE_NEXT_PTR_TO (tem
);
4016 TYPE_NEXT_PTR_TO (tem
) = TYPE_NEXT_PTR_TO (t
);
4018 TYPE_NEXT_PTR_TO (t
) = NULL_TREE
;
4020 else if (TREE_CODE (t
) == REFERENCE_TYPE
)
4022 if (TYPE_REFERENCE_TO (TREE_TYPE (t
)) == t
)
4023 TYPE_REFERENCE_TO (TREE_TYPE (t
)) = TYPE_NEXT_REF_TO (t
);
4026 tree tem
= TYPE_REFERENCE_TO (TREE_TYPE (t
));
4027 while (tem
&& TYPE_NEXT_REF_TO (tem
) != t
)
4028 tem
= TYPE_NEXT_REF_TO (tem
);
4030 TYPE_NEXT_REF_TO (tem
) = TYPE_NEXT_REF_TO (t
);
4032 TYPE_NEXT_REF_TO (t
) = NULL_TREE
;
4035 TYPE_CANONICAL (t
) = new_type
;
4040 TYPE_CANONICAL (t
) = t
;
4048 /* Show statistics on references to the global type table gimple_types. */
4051 print_gimple_types_stats (void)
4054 fprintf (stderr
, "GIMPLE type table: size %ld, %ld elements, "
4055 "%ld searches, %ld collisions (ratio: %f)\n",
4056 (long) htab_size (gimple_types
),
4057 (long) htab_elements (gimple_types
),
4058 (long) gimple_types
->searches
,
4059 (long) gimple_types
->collisions
,
4060 htab_collisions (gimple_types
));
4062 fprintf (stderr
, "GIMPLE type table is empty\n");
4064 fprintf (stderr
, "GIMPLE type comparison table: size %ld, %ld "
4065 "elements, %ld searches, %ld collisions (ratio: %f)\n",
4066 (long) htab_size (gtc_visited
),
4067 (long) htab_elements (gtc_visited
),
4068 (long) gtc_visited
->searches
,
4069 (long) gtc_visited
->collisions
,
4070 htab_collisions (gtc_visited
));
4072 fprintf (stderr
, "GIMPLE type comparison table is empty\n");
4075 /* Free the gimple type hashtables used for LTO type merging. */
4078 free_gimple_type_tables (void)
4080 /* Last chance to print stats for the tables. */
4081 if (flag_lto_report
)
4082 print_gimple_types_stats ();
4086 htab_delete (gimple_types
);
4087 gimple_types
= NULL
;
4089 if (type_hash_cache
)
4091 pointer_map_destroy (type_hash_cache
);
4092 type_hash_cache
= NULL
;
4096 htab_delete (gtc_visited
);
4097 obstack_free (>c_ob
, NULL
);
4103 /* Return a type the same as TYPE except unsigned or
4104 signed according to UNSIGNEDP. */
4107 gimple_signed_or_unsigned_type (bool unsignedp
, tree type
)
4111 type1
= TYPE_MAIN_VARIANT (type
);
4112 if (type1
== signed_char_type_node
4113 || type1
== char_type_node
4114 || type1
== unsigned_char_type_node
)
4115 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4116 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
4117 return unsignedp
? unsigned_type_node
: integer_type_node
;
4118 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
4119 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4120 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
4121 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4122 if (type1
== long_long_integer_type_node
4123 || type1
== long_long_unsigned_type_node
)
4125 ? long_long_unsigned_type_node
4126 : long_long_integer_type_node
;
4127 if (int128_integer_type_node
&& (type1
== int128_integer_type_node
|| type1
== int128_unsigned_type_node
))
4129 ? int128_unsigned_type_node
4130 : int128_integer_type_node
;
4131 #if HOST_BITS_PER_WIDE_INT >= 64
4132 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
4133 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4135 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
4136 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4137 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
4138 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4139 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
4140 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4141 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
4142 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4144 #define GIMPLE_FIXED_TYPES(NAME) \
4145 if (type1 == short_ ## NAME ## _type_node \
4146 || type1 == unsigned_short_ ## NAME ## _type_node) \
4147 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
4148 : short_ ## NAME ## _type_node; \
4149 if (type1 == NAME ## _type_node \
4150 || type1 == unsigned_ ## NAME ## _type_node) \
4151 return unsignedp ? unsigned_ ## NAME ## _type_node \
4152 : NAME ## _type_node; \
4153 if (type1 == long_ ## NAME ## _type_node \
4154 || type1 == unsigned_long_ ## NAME ## _type_node) \
4155 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
4156 : long_ ## NAME ## _type_node; \
4157 if (type1 == long_long_ ## NAME ## _type_node \
4158 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
4159 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
4160 : long_long_ ## NAME ## _type_node;
4162 #define GIMPLE_FIXED_MODE_TYPES(NAME) \
4163 if (type1 == NAME ## _type_node \
4164 || type1 == u ## NAME ## _type_node) \
4165 return unsignedp ? u ## NAME ## _type_node \
4166 : NAME ## _type_node;
4168 #define GIMPLE_FIXED_TYPES_SAT(NAME) \
4169 if (type1 == sat_ ## short_ ## NAME ## _type_node \
4170 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
4171 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
4172 : sat_ ## short_ ## NAME ## _type_node; \
4173 if (type1 == sat_ ## NAME ## _type_node \
4174 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
4175 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
4176 : sat_ ## NAME ## _type_node; \
4177 if (type1 == sat_ ## long_ ## NAME ## _type_node \
4178 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
4179 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
4180 : sat_ ## long_ ## NAME ## _type_node; \
4181 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
4182 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
4183 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
4184 : sat_ ## long_long_ ## NAME ## _type_node;
4186 #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
4187 if (type1 == sat_ ## NAME ## _type_node \
4188 || type1 == sat_ ## u ## NAME ## _type_node) \
4189 return unsignedp ? sat_ ## u ## NAME ## _type_node \
4190 : sat_ ## NAME ## _type_node;
4192 GIMPLE_FIXED_TYPES (fract
);
4193 GIMPLE_FIXED_TYPES_SAT (fract
);
4194 GIMPLE_FIXED_TYPES (accum
);
4195 GIMPLE_FIXED_TYPES_SAT (accum
);
4197 GIMPLE_FIXED_MODE_TYPES (qq
);
4198 GIMPLE_FIXED_MODE_TYPES (hq
);
4199 GIMPLE_FIXED_MODE_TYPES (sq
);
4200 GIMPLE_FIXED_MODE_TYPES (dq
);
4201 GIMPLE_FIXED_MODE_TYPES (tq
);
4202 GIMPLE_FIXED_MODE_TYPES_SAT (qq
);
4203 GIMPLE_FIXED_MODE_TYPES_SAT (hq
);
4204 GIMPLE_FIXED_MODE_TYPES_SAT (sq
);
4205 GIMPLE_FIXED_MODE_TYPES_SAT (dq
);
4206 GIMPLE_FIXED_MODE_TYPES_SAT (tq
);
4207 GIMPLE_FIXED_MODE_TYPES (ha
);
4208 GIMPLE_FIXED_MODE_TYPES (sa
);
4209 GIMPLE_FIXED_MODE_TYPES (da
);
4210 GIMPLE_FIXED_MODE_TYPES (ta
);
4211 GIMPLE_FIXED_MODE_TYPES_SAT (ha
);
4212 GIMPLE_FIXED_MODE_TYPES_SAT (sa
);
4213 GIMPLE_FIXED_MODE_TYPES_SAT (da
);
4214 GIMPLE_FIXED_MODE_TYPES_SAT (ta
);
4216 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
4217 the precision; they have precision set to match their range, but
4218 may use a wider mode to match an ABI. If we change modes, we may
4219 wind up with bad conversions. For INTEGER_TYPEs in C, must check
4220 the precision as well, so as to yield correct results for
4221 bit-field types. C++ does not have these separate bit-field
4222 types, and producing a signed or unsigned variant of an
4223 ENUMERAL_TYPE may cause other problems as well. */
4224 if (!INTEGRAL_TYPE_P (type
)
4225 || TYPE_UNSIGNED (type
) == unsignedp
)
4228 #define TYPE_OK(node) \
4229 (TYPE_MODE (type) == TYPE_MODE (node) \
4230 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
4231 if (TYPE_OK (signed_char_type_node
))
4232 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
4233 if (TYPE_OK (integer_type_node
))
4234 return unsignedp
? unsigned_type_node
: integer_type_node
;
4235 if (TYPE_OK (short_integer_type_node
))
4236 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
4237 if (TYPE_OK (long_integer_type_node
))
4238 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
4239 if (TYPE_OK (long_long_integer_type_node
))
4241 ? long_long_unsigned_type_node
4242 : long_long_integer_type_node
);
4243 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
4245 ? int128_unsigned_type_node
4246 : int128_integer_type_node
);
4248 #if HOST_BITS_PER_WIDE_INT >= 64
4249 if (TYPE_OK (intTI_type_node
))
4250 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
4252 if (TYPE_OK (intDI_type_node
))
4253 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
4254 if (TYPE_OK (intSI_type_node
))
4255 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
4256 if (TYPE_OK (intHI_type_node
))
4257 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
4258 if (TYPE_OK (intQI_type_node
))
4259 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
4261 #undef GIMPLE_FIXED_TYPES
4262 #undef GIMPLE_FIXED_MODE_TYPES
4263 #undef GIMPLE_FIXED_TYPES_SAT
4264 #undef GIMPLE_FIXED_MODE_TYPES_SAT
4267 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
4271 /* Return an unsigned type the same as TYPE in other respects. */
4274 gimple_unsigned_type (tree type
)
4276 return gimple_signed_or_unsigned_type (true, type
);
4280 /* Return a signed type the same as TYPE in other respects. */
4283 gimple_signed_type (tree type
)
4285 return gimple_signed_or_unsigned_type (false, type
);
4289 /* Return the typed-based alias set for T, which may be an expression
4290 or a type. Return -1 if we don't do anything special. */
4293 gimple_get_alias_set (tree t
)
4297 /* Permit type-punning when accessing a union, provided the access
4298 is directly through the union. For example, this code does not
4299 permit taking the address of a union member and then storing
4300 through it. Even the type-punning allowed here is a GCC
4301 extension, albeit a common and useful one; the C standard says
4302 that such accesses have implementation-defined behavior. */
4304 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
4305 u
= TREE_OPERAND (u
, 0))
4306 if (TREE_CODE (u
) == COMPONENT_REF
4307 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
4310 /* That's all the expressions we handle specially. */
4314 /* For convenience, follow the C standard when dealing with
4315 character types. Any object may be accessed via an lvalue that
4316 has character type. */
4317 if (t
== char_type_node
4318 || t
== signed_char_type_node
4319 || t
== unsigned_char_type_node
)
4322 /* Allow aliasing between signed and unsigned variants of the same
4323 type. We treat the signed variant as canonical. */
4324 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
4326 tree t1
= gimple_signed_type (t
);
4328 /* t1 == t can happen for boolean nodes which are always unsigned. */
4330 return get_alias_set (t1
);
4332 else if (POINTER_TYPE_P (t
))
4334 /* From the common C and C++ langhook implementation:
4336 Unfortunately, there is no canonical form of a pointer type.
4337 In particular, if we have `typedef int I', then `int *', and
4338 `I *' are different types. So, we have to pick a canonical
4339 representative. We do this below.
4341 Technically, this approach is actually more conservative that
4342 it needs to be. In particular, `const int *' and `int *'
4343 should be in different alias sets, according to the C and C++
4344 standard, since their types are not the same, and so,
4345 technically, an `int **' and `const int **' cannot point at
4348 But, the standard is wrong. In particular, this code is
4353 const int* const* cipp = ipp;
4354 And, it doesn't make sense for that to be legal unless you
4355 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
4356 the pointed-to types. This issue has been reported to the
4359 /* In addition to the above canonicalization issue with LTO
4360 we should also canonicalize `T (*)[]' to `T *' avoiding
4361 alias issues with pointer-to element types and pointer-to
4364 Likewise we need to deal with the situation of incomplete
4365 pointed-to types and make `*(struct X **)&a' and
4366 `*(struct X {} **)&a' alias. Otherwise we will have to
4367 guarantee that all pointer-to incomplete type variants
4368 will be replaced by pointer-to complete type variants if
4371 With LTO the convenient situation of using `void *' to
4372 access and store any pointer type will also become
4373 more apparent (and `void *' is just another pointer-to
4374 incomplete type). Assigning alias-set zero to `void *'
4375 and all pointer-to incomplete types is a not appealing
4376 solution. Assigning an effective alias-set zero only
4377 affecting pointers might be - by recording proper subset
4378 relationships of all pointer alias-sets.
4380 Pointer-to function types are another grey area which
4381 needs caution. Globbing them all into one alias-set
4382 or the above effective zero set would work. */
4384 /* For now just assign the same alias-set to all pointers.
4385 That's simple and avoids all the above problems. */
4386 if (t
!= ptr_type_node
)
4387 return get_alias_set (ptr_type_node
);
4394 /* Data structure used to count the number of dereferences to PTR
4395 inside an expression. */
4399 unsigned num_stores
;
4403 /* Helper for count_uses_and_derefs. Called by walk_tree to look for
4404 (ALIGN/MISALIGNED_)INDIRECT_REF nodes for the pointer passed in DATA. */
4407 count_ptr_derefs (tree
*tp
, int *walk_subtrees
, void *data
)
4409 struct walk_stmt_info
*wi_p
= (struct walk_stmt_info
*) data
;
4410 struct count_ptr_d
*count_p
= (struct count_ptr_d
*) wi_p
->info
;
4412 /* Do not walk inside ADDR_EXPR nodes. In the expression &ptr->fld,
4413 pointer 'ptr' is *not* dereferenced, it is simply used to compute
4414 the address of 'fld' as 'ptr + offsetof(fld)'. */
4415 if (TREE_CODE (*tp
) == ADDR_EXPR
)
4421 if (INDIRECT_REF_P (*tp
) && TREE_OPERAND (*tp
, 0) == count_p
->ptr
)
4424 count_p
->num_stores
++;
4426 count_p
->num_loads
++;
4432 /* Count the number of direct and indirect uses for pointer PTR in
4433 statement STMT. The number of direct uses is stored in
4434 *NUM_USES_P. Indirect references are counted separately depending
4435 on whether they are store or load operations. The counts are
4436 stored in *NUM_STORES_P and *NUM_LOADS_P. */
4439 count_uses_and_derefs (tree ptr
, gimple stmt
, unsigned *num_uses_p
,
4440 unsigned *num_loads_p
, unsigned *num_stores_p
)
4449 /* Find out the total number of uses of PTR in STMT. */
4450 FOR_EACH_SSA_TREE_OPERAND (use
, stmt
, i
, SSA_OP_USE
)
4454 /* Now count the number of indirect references to PTR. This is
4455 truly awful, but we don't have much choice. There are no parent
4456 pointers inside INDIRECT_REFs, so an expression like
4457 '*x_1 = foo (x_1, *x_1)' needs to be traversed piece by piece to
4458 find all the indirect and direct uses of x_1 inside. The only
4459 shortcut we can take is the fact that GIMPLE only allows
4460 INDIRECT_REFs inside the expressions below. */
4461 if (is_gimple_assign (stmt
)
4462 || gimple_code (stmt
) == GIMPLE_RETURN
4463 || gimple_code (stmt
) == GIMPLE_ASM
4464 || is_gimple_call (stmt
))
4466 struct walk_stmt_info wi
;
4467 struct count_ptr_d count
;
4470 count
.num_stores
= 0;
4471 count
.num_loads
= 0;
4473 memset (&wi
, 0, sizeof (wi
));
4475 walk_gimple_op (stmt
, count_ptr_derefs
, &wi
);
4477 *num_stores_p
= count
.num_stores
;
4478 *num_loads_p
= count
.num_loads
;
4481 gcc_assert (*num_uses_p
>= *num_loads_p
+ *num_stores_p
);
4484 /* From a tree operand OP return the base of a load or store operation
4485 or NULL_TREE if OP is not a load or a store. */
4488 get_base_loadstore (tree op
)
4490 while (handled_component_p (op
))
4491 op
= TREE_OPERAND (op
, 0);
4493 || INDIRECT_REF_P (op
)
4494 || TREE_CODE (op
) == TARGET_MEM_REF
)
4499 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
4500 VISIT_ADDR if non-NULL on loads, store and address-taken operands
4501 passing the STMT, the base of the operand and DATA to it. The base
4502 will be either a decl, an indirect reference (including TARGET_MEM_REF)
4503 or the argument of an address expression.
4504 Returns the results of these callbacks or'ed. */
4507 walk_stmt_load_store_addr_ops (gimple stmt
, void *data
,
4508 bool (*visit_load
)(gimple
, tree
, void *),
4509 bool (*visit_store
)(gimple
, tree
, void *),
4510 bool (*visit_addr
)(gimple
, tree
, void *))
4514 if (gimple_assign_single_p (stmt
))
4519 lhs
= get_base_loadstore (gimple_assign_lhs (stmt
));
4521 ret
|= visit_store (stmt
, lhs
, data
);
4523 rhs
= gimple_assign_rhs1 (stmt
);
4524 while (handled_component_p (rhs
))
4525 rhs
= TREE_OPERAND (rhs
, 0);
4528 if (TREE_CODE (rhs
) == ADDR_EXPR
)
4529 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
4530 else if (TREE_CODE (rhs
) == TARGET_MEM_REF
4531 && TMR_BASE (rhs
) != NULL_TREE
4532 && TREE_CODE (TMR_BASE (rhs
)) == ADDR_EXPR
)
4533 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (rhs
), 0), data
);
4534 else if (TREE_CODE (rhs
) == OBJ_TYPE_REF
4535 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs
)) == ADDR_EXPR
)
4536 ret
|= visit_addr (stmt
, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs
),
4538 lhs
= gimple_assign_lhs (stmt
);
4539 if (TREE_CODE (lhs
) == TARGET_MEM_REF
4540 && TMR_BASE (lhs
) != NULL_TREE
4541 && TREE_CODE (TMR_BASE (lhs
)) == ADDR_EXPR
)
4542 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (lhs
), 0), data
);
4546 rhs
= get_base_loadstore (rhs
);
4548 ret
|= visit_load (stmt
, rhs
, data
);
4552 && (is_gimple_assign (stmt
)
4553 || gimple_code (stmt
) == GIMPLE_COND
))
4555 for (i
= 0; i
< gimple_num_ops (stmt
); ++i
)
4556 if (gimple_op (stmt
, i
)
4557 && TREE_CODE (gimple_op (stmt
, i
)) == ADDR_EXPR
)
4558 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_op (stmt
, i
), 0), data
);
4560 else if (is_gimple_call (stmt
))
4564 tree lhs
= gimple_call_lhs (stmt
);
4567 lhs
= get_base_loadstore (lhs
);
4569 ret
|= visit_store (stmt
, lhs
, data
);
4572 if (visit_load
|| visit_addr
)
4573 for (i
= 0; i
< gimple_call_num_args (stmt
); ++i
)
4575 tree rhs
= gimple_call_arg (stmt
, i
);
4577 && TREE_CODE (rhs
) == ADDR_EXPR
)
4578 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
4579 else if (visit_load
)
4581 rhs
= get_base_loadstore (rhs
);
4583 ret
|= visit_load (stmt
, rhs
, data
);
4587 && gimple_call_chain (stmt
)
4588 && TREE_CODE (gimple_call_chain (stmt
)) == ADDR_EXPR
)
4589 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_call_chain (stmt
), 0),
4592 && gimple_call_return_slot_opt_p (stmt
)
4593 && gimple_call_lhs (stmt
) != NULL_TREE
4594 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt
))))
4595 ret
|= visit_addr (stmt
, gimple_call_lhs (stmt
), data
);
4597 else if (gimple_code (stmt
) == GIMPLE_ASM
)
4600 const char *constraint
;
4601 const char **oconstraints
;
4602 bool allows_mem
, allows_reg
, is_inout
;
4603 noutputs
= gimple_asm_noutputs (stmt
);
4604 oconstraints
= XALLOCAVEC (const char *, noutputs
);
4605 if (visit_store
|| visit_addr
)
4606 for (i
= 0; i
< gimple_asm_noutputs (stmt
); ++i
)
4608 tree link
= gimple_asm_output_op (stmt
, i
);
4609 tree op
= get_base_loadstore (TREE_VALUE (link
));
4610 if (op
&& visit_store
)
4611 ret
|= visit_store (stmt
, op
, data
);
4614 constraint
= TREE_STRING_POINTER
4615 (TREE_VALUE (TREE_PURPOSE (link
)));
4616 oconstraints
[i
] = constraint
;
4617 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
,
4618 &allows_reg
, &is_inout
);
4619 if (op
&& !allows_reg
&& allows_mem
)
4620 ret
|= visit_addr (stmt
, op
, data
);
4623 if (visit_load
|| visit_addr
)
4624 for (i
= 0; i
< gimple_asm_ninputs (stmt
); ++i
)
4626 tree link
= gimple_asm_input_op (stmt
, i
);
4627 tree op
= TREE_VALUE (link
);
4629 && TREE_CODE (op
) == ADDR_EXPR
)
4630 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
4631 else if (visit_load
|| visit_addr
)
4633 op
= get_base_loadstore (op
);
4637 ret
|= visit_load (stmt
, op
, data
);
4640 constraint
= TREE_STRING_POINTER
4641 (TREE_VALUE (TREE_PURPOSE (link
)));
4642 parse_input_constraint (&constraint
, 0, 0, noutputs
,
4644 &allows_mem
, &allows_reg
);
4645 if (!allows_reg
&& allows_mem
)
4646 ret
|= visit_addr (stmt
, op
, data
);
4652 else if (gimple_code (stmt
) == GIMPLE_RETURN
)
4654 tree op
= gimple_return_retval (stmt
);
4658 && TREE_CODE (op
) == ADDR_EXPR
)
4659 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
4660 else if (visit_load
)
4662 op
= get_base_loadstore (op
);
4664 ret
|= visit_load (stmt
, op
, data
);
4669 && gimple_code (stmt
) == GIMPLE_PHI
)
4671 for (i
= 0; i
< gimple_phi_num_args (stmt
); ++i
)
4673 tree op
= PHI_ARG_DEF (stmt
, i
);
4674 if (TREE_CODE (op
) == ADDR_EXPR
)
4675 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
4682 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
4683 should make a faster clone for this case. */
4686 walk_stmt_load_store_ops (gimple stmt
, void *data
,
4687 bool (*visit_load
)(gimple
, tree
, void *),
4688 bool (*visit_store
)(gimple
, tree
, void *))
4690 return walk_stmt_load_store_addr_ops (stmt
, data
,
4691 visit_load
, visit_store
, NULL
);
4694 /* Helper for gimple_ior_addresses_taken_1. */
4697 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED
,
4698 tree addr
, void *data
)
4700 bitmap addresses_taken
= (bitmap
)data
;
4701 addr
= get_base_address (addr
);
4705 bitmap_set_bit (addresses_taken
, DECL_UID (addr
));
4711 /* Set the bit for the uid of all decls that have their address taken
4712 in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
4713 were any in this stmt. */
4716 gimple_ior_addresses_taken (bitmap addresses_taken
, gimple stmt
)
4718 return walk_stmt_load_store_addr_ops (stmt
, addresses_taken
, NULL
, NULL
,
4719 gimple_ior_addresses_taken_1
);
4723 /* Return a printable name for symbol DECL. */
4726 gimple_decl_printable_name (tree decl
, int verbosity
)
4728 if (!DECL_NAME (decl
))
4731 if (DECL_ASSEMBLER_NAME_SET_P (decl
))
4733 const char *str
, *mangled_str
;
4734 int dmgl_opts
= DMGL_NO_OPTS
;
4738 dmgl_opts
= DMGL_VERBOSE
4742 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4743 dmgl_opts
|= DMGL_PARAMS
;
4746 mangled_str
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4747 str
= cplus_demangle_v3 (mangled_str
, dmgl_opts
);
4748 return (str
) ? str
: mangled_str
;
4751 return IDENTIFIER_POINTER (DECL_NAME (decl
));
4754 /* Return true when STMT is builtins call to CODE. */
4757 gimple_call_builtin_p (gimple stmt
, enum built_in_function code
)
4760 return (is_gimple_call (stmt
)
4761 && (fndecl
= gimple_call_fndecl (stmt
)) != NULL
4762 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
4763 && DECL_FUNCTION_CODE (fndecl
) == code
);
4766 #include "gt-gimple.h"