1 /* Gimple IR support functions.
3 Copyright (C) 2007-2013 Free Software Foundation, Inc.
4 Contributed by Aldy Hernandez <aldyh@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
29 #include "hard-reg-set.h"
30 #include "basic-block.h"
32 #include "diagnostic.h"
33 #include "value-prof.h"
37 #include "langhooks.h"
41 /* All the tuples have their operand vector (if present) at the very bottom
42 of the structure. Therefore, the offset required to find the
43 operands vector the size of the structure minus the size of the 1
44 element tree array at the end (see gimple_ops). */
45 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \
46 (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0),
47 EXPORTED_CONST
size_t gimple_ops_offset_
[] = {
48 #include "gsstruct.def"
52 #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) sizeof (struct STRUCT),
53 static const size_t gsstruct_code_size
[] = {
54 #include "gsstruct.def"
58 #define DEFGSCODE(SYM, NAME, GSSCODE) NAME,
59 const char *const gimple_code_name
[] = {
64 #define DEFGSCODE(SYM, NAME, GSSCODE) GSSCODE,
65 EXPORTED_CONST
enum gimple_statement_structure_enum gss_for_code_
[] = {
72 int gimple_alloc_counts
[(int) gimple_alloc_kind_all
];
73 int gimple_alloc_sizes
[(int) gimple_alloc_kind_all
];
75 /* Keep in sync with gimple.h:enum gimple_alloc_kind. */
76 static const char * const gimple_alloc_kind_names
[] = {
83 /* Private API manipulation functions shared only with some
85 extern void gimple_set_stored_syms (gimple
, bitmap
, bitmap_obstack
*);
86 extern void gimple_set_loaded_syms (gimple
, bitmap
, bitmap_obstack
*);
88 /* Gimple tuple constructors.
89 Note: Any constructor taking a ``gimple_seq'' as a parameter, can
90 be passed a NULL to start with an empty sequence. */
92 /* Set the code for statement G to CODE. */
95 gimple_set_code (gimple g
, enum gimple_code code
)
97 g
->gsbase
.code
= code
;
100 /* Return the number of bytes needed to hold a GIMPLE statement with
104 gimple_size (enum gimple_code code
)
106 return gsstruct_code_size
[gss_for_code (code
)];
109 /* Allocate memory for a GIMPLE statement with code CODE and NUM_OPS
113 gimple_alloc_stat (enum gimple_code code
, unsigned num_ops MEM_STAT_DECL
)
118 size
= gimple_size (code
);
120 size
+= sizeof (tree
) * (num_ops
- 1);
122 if (GATHER_STATISTICS
)
124 enum gimple_alloc_kind kind
= gimple_alloc_kind (code
);
125 gimple_alloc_counts
[(int) kind
]++;
126 gimple_alloc_sizes
[(int) kind
] += size
;
129 stmt
= ggc_alloc_cleared_gimple_statement_d_stat (size PASS_MEM_STAT
);
130 gimple_set_code (stmt
, code
);
131 gimple_set_num_ops (stmt
, num_ops
);
133 /* Do not call gimple_set_modified here as it has other side
134 effects and this tuple is still not completely built. */
135 stmt
->gsbase
.modified
= 1;
136 gimple_init_singleton (stmt
);
141 /* Set SUBCODE to be the code of the expression computed by statement G. */
144 gimple_set_subcode (gimple g
, unsigned subcode
)
146 /* We only have 16 bits for the RHS code. Assert that we are not
148 gcc_assert (subcode
< (1 << 16));
149 g
->gsbase
.subcode
= subcode
;
154 /* Build a tuple with operands. CODE is the statement to build (which
155 must be one of the GIMPLE_WITH_OPS tuples). SUBCODE is the subcode
156 for the new tuple. NUM_OPS is the number of operands to allocate. */
158 #define gimple_build_with_ops(c, s, n) \
159 gimple_build_with_ops_stat (c, s, n MEM_STAT_INFO)
162 gimple_build_with_ops_stat (enum gimple_code code
, unsigned subcode
,
163 unsigned num_ops MEM_STAT_DECL
)
165 gimple s
= gimple_alloc_stat (code
, num_ops PASS_MEM_STAT
);
166 gimple_set_subcode (s
, subcode
);
172 /* Build a GIMPLE_RETURN statement returning RETVAL. */
175 gimple_build_return (tree retval
)
177 gimple s
= gimple_build_with_ops (GIMPLE_RETURN
, ERROR_MARK
, 2);
179 gimple_return_set_retval (s
, retval
);
183 /* Reset alias information on call S. */
186 gimple_call_reset_alias_info (gimple s
)
188 if (gimple_call_flags (s
) & ECF_CONST
)
189 memset (gimple_call_use_set (s
), 0, sizeof (struct pt_solution
));
191 pt_solution_reset (gimple_call_use_set (s
));
192 if (gimple_call_flags (s
) & (ECF_CONST
|ECF_PURE
|ECF_NOVOPS
))
193 memset (gimple_call_clobber_set (s
), 0, sizeof (struct pt_solution
));
195 pt_solution_reset (gimple_call_clobber_set (s
));
198 /* Helper for gimple_build_call, gimple_build_call_valist,
199 gimple_build_call_vec and gimple_build_call_from_tree. Build the basic
200 components of a GIMPLE_CALL statement to function FN with NARGS
204 gimple_build_call_1 (tree fn
, unsigned nargs
)
206 gimple s
= gimple_build_with_ops (GIMPLE_CALL
, ERROR_MARK
, nargs
+ 3);
207 if (TREE_CODE (fn
) == FUNCTION_DECL
)
208 fn
= build_fold_addr_expr (fn
);
209 gimple_set_op (s
, 1, fn
);
210 gimple_call_set_fntype (s
, TREE_TYPE (TREE_TYPE (fn
)));
211 gimple_call_reset_alias_info (s
);
216 /* Build a GIMPLE_CALL statement to function FN with the arguments
217 specified in vector ARGS. */
220 gimple_build_call_vec (tree fn
, vec
<tree
> args
)
223 unsigned nargs
= args
.length ();
224 gimple call
= gimple_build_call_1 (fn
, nargs
);
226 for (i
= 0; i
< nargs
; i
++)
227 gimple_call_set_arg (call
, i
, args
[i
]);
233 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
234 arguments. The ... are the arguments. */
237 gimple_build_call (tree fn
, unsigned nargs
, ...)
243 gcc_assert (TREE_CODE (fn
) == FUNCTION_DECL
|| is_gimple_call_addr (fn
));
245 call
= gimple_build_call_1 (fn
, nargs
);
247 va_start (ap
, nargs
);
248 for (i
= 0; i
< nargs
; i
++)
249 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
256 /* Build a GIMPLE_CALL statement to function FN. NARGS is the number of
257 arguments. AP contains the arguments. */
260 gimple_build_call_valist (tree fn
, unsigned nargs
, va_list ap
)
265 gcc_assert (TREE_CODE (fn
) == FUNCTION_DECL
|| is_gimple_call_addr (fn
));
267 call
= gimple_build_call_1 (fn
, nargs
);
269 for (i
= 0; i
< nargs
; i
++)
270 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
276 /* Helper for gimple_build_call_internal and gimple_build_call_internal_vec.
277 Build the basic components of a GIMPLE_CALL statement to internal
278 function FN with NARGS arguments. */
281 gimple_build_call_internal_1 (enum internal_fn fn
, unsigned nargs
)
283 gimple s
= gimple_build_with_ops (GIMPLE_CALL
, ERROR_MARK
, nargs
+ 3);
284 s
->gsbase
.subcode
|= GF_CALL_INTERNAL
;
285 gimple_call_set_internal_fn (s
, fn
);
286 gimple_call_reset_alias_info (s
);
291 /* Build a GIMPLE_CALL statement to internal function FN. NARGS is
292 the number of arguments. The ... are the arguments. */
295 gimple_build_call_internal (enum internal_fn fn
, unsigned nargs
, ...)
301 call
= gimple_build_call_internal_1 (fn
, nargs
);
302 va_start (ap
, nargs
);
303 for (i
= 0; i
< nargs
; i
++)
304 gimple_call_set_arg (call
, i
, va_arg (ap
, tree
));
311 /* Build a GIMPLE_CALL statement to internal function FN with the arguments
312 specified in vector ARGS. */
315 gimple_build_call_internal_vec (enum internal_fn fn
, vec
<tree
> args
)
320 nargs
= args
.length ();
321 call
= gimple_build_call_internal_1 (fn
, nargs
);
322 for (i
= 0; i
< nargs
; i
++)
323 gimple_call_set_arg (call
, i
, args
[i
]);
329 /* Build a GIMPLE_CALL statement from CALL_EXPR T. Note that T is
330 assumed to be in GIMPLE form already. Minimal checking is done of
334 gimple_build_call_from_tree (tree t
)
338 tree fndecl
= get_callee_fndecl (t
);
340 gcc_assert (TREE_CODE (t
) == CALL_EXPR
);
342 nargs
= call_expr_nargs (t
);
343 call
= gimple_build_call_1 (fndecl
? fndecl
: CALL_EXPR_FN (t
), nargs
);
345 for (i
= 0; i
< nargs
; i
++)
346 gimple_call_set_arg (call
, i
, CALL_EXPR_ARG (t
, i
));
348 gimple_set_block (call
, TREE_BLOCK (t
));
350 /* Carry all the CALL_EXPR flags to the new GIMPLE_CALL. */
351 gimple_call_set_chain (call
, CALL_EXPR_STATIC_CHAIN (t
));
352 gimple_call_set_tail (call
, CALL_EXPR_TAILCALL (t
));
353 gimple_call_set_return_slot_opt (call
, CALL_EXPR_RETURN_SLOT_OPT (t
));
355 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
356 && (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_ALLOCA
357 || DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_ALLOCA_WITH_ALIGN
))
358 gimple_call_set_alloca_for_var (call
, CALL_ALLOCA_FOR_VAR_P (t
));
360 gimple_call_set_from_thunk (call
, CALL_FROM_THUNK_P (t
));
361 gimple_call_set_va_arg_pack (call
, CALL_EXPR_VA_ARG_PACK (t
));
362 gimple_call_set_nothrow (call
, TREE_NOTHROW (t
));
363 gimple_set_no_warning (call
, TREE_NO_WARNING (t
));
369 /* Return index of INDEX's non bound argument of the call. */
372 gimple_call_get_nobnd_arg_index (const_gimple gs
, unsigned index
)
374 unsigned num_args
= gimple_call_num_args (gs
);
375 for (unsigned n
= 0; n
< num_args
; n
++)
377 if (POINTER_BOUNDS_P (gimple_call_arg (gs
, n
)))
389 /* Build a GIMPLE_ASSIGN statement.
391 LHS of the assignment.
392 RHS of the assignment which can be unary or binary. */
395 gimple_build_assign_stat (tree lhs
, tree rhs MEM_STAT_DECL
)
397 enum tree_code subcode
;
400 extract_ops_from_tree_1 (rhs
, &subcode
, &op1
, &op2
, &op3
);
401 return gimple_build_assign_with_ops (subcode
, lhs
, op1
, op2
, op3
406 /* Build a GIMPLE_ASSIGN statement with subcode SUBCODE and operands
407 OP1 and OP2. If OP2 is NULL then SUBCODE must be of class
408 GIMPLE_UNARY_RHS or GIMPLE_SINGLE_RHS. */
411 gimple_build_assign_with_ops (enum tree_code subcode
, tree lhs
, tree op1
,
412 tree op2
, tree op3 MEM_STAT_DECL
)
417 /* Need 1 operand for LHS and 1 or 2 for the RHS (depending on the
419 num_ops
= get_gimple_rhs_num_ops (subcode
) + 1;
421 p
= gimple_build_with_ops_stat (GIMPLE_ASSIGN
, (unsigned)subcode
, num_ops
423 gimple_assign_set_lhs (p
, lhs
);
424 gimple_assign_set_rhs1 (p
, op1
);
427 gcc_assert (num_ops
> 2);
428 gimple_assign_set_rhs2 (p
, op2
);
433 gcc_assert (num_ops
> 3);
434 gimple_assign_set_rhs3 (p
, op3
);
441 gimple_build_assign_with_ops (enum tree_code subcode
, tree lhs
, tree op1
,
442 tree op2 MEM_STAT_DECL
)
444 return gimple_build_assign_with_ops (subcode
, lhs
, op1
, op2
, NULL_TREE
449 /* Build a new GIMPLE_ASSIGN tuple and append it to the end of *SEQ_P.
451 DST/SRC are the destination and source respectively. You can pass
452 ungimplified trees in DST or SRC, in which case they will be
453 converted to a gimple operand if necessary.
455 This function returns the newly created GIMPLE_ASSIGN tuple. */
458 gimplify_assign (tree dst
, tree src
, gimple_seq
*seq_p
)
460 tree t
= build2 (MODIFY_EXPR
, TREE_TYPE (dst
), dst
, src
);
461 gimplify_and_add (t
, seq_p
);
463 return gimple_seq_last_stmt (*seq_p
);
467 /* Build a GIMPLE_COND statement.
469 PRED is the condition used to compare LHS and the RHS.
470 T_LABEL is the label to jump to if the condition is true.
471 F_LABEL is the label to jump to otherwise. */
474 gimple_build_cond (enum tree_code pred_code
, tree lhs
, tree rhs
,
475 tree t_label
, tree f_label
)
479 gcc_assert (TREE_CODE_CLASS (pred_code
) == tcc_comparison
);
480 p
= gimple_build_with_ops (GIMPLE_COND
, pred_code
, 4);
481 gimple_cond_set_lhs (p
, lhs
);
482 gimple_cond_set_rhs (p
, rhs
);
483 gimple_cond_set_true_label (p
, t_label
);
484 gimple_cond_set_false_label (p
, f_label
);
488 /* Build a GIMPLE_COND statement from the conditional expression tree
489 COND. T_LABEL and F_LABEL are as in gimple_build_cond. */
492 gimple_build_cond_from_tree (tree cond
, tree t_label
, tree f_label
)
497 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
498 return gimple_build_cond (code
, lhs
, rhs
, t_label
, f_label
);
501 /* Set code, lhs, and rhs of a GIMPLE_COND from a suitable
502 boolean expression tree COND. */
505 gimple_cond_set_condition_from_tree (gimple stmt
, tree cond
)
510 gimple_cond_get_ops_from_tree (cond
, &code
, &lhs
, &rhs
);
511 gimple_cond_set_condition (stmt
, code
, lhs
, rhs
);
514 /* Build a GIMPLE_LABEL statement for LABEL. */
517 gimple_build_label (tree label
)
519 gimple p
= gimple_build_with_ops (GIMPLE_LABEL
, ERROR_MARK
, 1);
520 gimple_label_set_label (p
, label
);
524 /* Build a GIMPLE_GOTO statement to label DEST. */
527 gimple_build_goto (tree dest
)
529 gimple p
= gimple_build_with_ops (GIMPLE_GOTO
, ERROR_MARK
, 1);
530 gimple_goto_set_dest (p
, dest
);
535 /* Build a GIMPLE_NOP statement. */
538 gimple_build_nop (void)
540 return gimple_alloc (GIMPLE_NOP
, 0);
544 /* Build a GIMPLE_BIND statement.
545 VARS are the variables in BODY.
546 BLOCK is the containing block. */
549 gimple_build_bind (tree vars
, gimple_seq body
, tree block
)
551 gimple p
= gimple_alloc (GIMPLE_BIND
, 0);
552 gimple_bind_set_vars (p
, vars
);
554 gimple_bind_set_body (p
, body
);
556 gimple_bind_set_block (p
, block
);
560 /* Helper function to set the simple fields of a asm stmt.
562 STRING is a pointer to a string that is the asm blocks assembly code.
563 NINPUT is the number of register inputs.
564 NOUTPUT is the number of register outputs.
565 NCLOBBERS is the number of clobbered registers.
569 gimple_build_asm_1 (const char *string
, unsigned ninputs
, unsigned noutputs
,
570 unsigned nclobbers
, unsigned nlabels
)
573 int size
= strlen (string
);
575 /* ASMs with labels cannot have outputs. This should have been
576 enforced by the front end. */
577 gcc_assert (nlabels
== 0 || noutputs
== 0);
579 p
= gimple_build_with_ops (GIMPLE_ASM
, ERROR_MARK
,
580 ninputs
+ noutputs
+ nclobbers
+ nlabels
);
582 p
->gimple_asm
.ni
= ninputs
;
583 p
->gimple_asm
.no
= noutputs
;
584 p
->gimple_asm
.nc
= nclobbers
;
585 p
->gimple_asm
.nl
= nlabels
;
586 p
->gimple_asm
.string
= ggc_alloc_string (string
, size
);
588 if (GATHER_STATISTICS
)
589 gimple_alloc_sizes
[(int) gimple_alloc_kind (GIMPLE_ASM
)] += size
;
594 /* Build a GIMPLE_ASM statement.
596 STRING is the assembly code.
597 NINPUT is the number of register inputs.
598 NOUTPUT is the number of register outputs.
599 NCLOBBERS is the number of clobbered registers.
600 INPUTS is a vector of the input register parameters.
601 OUTPUTS is a vector of the output register parameters.
602 CLOBBERS is a vector of the clobbered register parameters.
603 LABELS is a vector of destination labels. */
606 gimple_build_asm_vec (const char *string
, vec
<tree
, va_gc
> *inputs
,
607 vec
<tree
, va_gc
> *outputs
, vec
<tree
, va_gc
> *clobbers
,
608 vec
<tree
, va_gc
> *labels
)
613 p
= gimple_build_asm_1 (string
,
614 vec_safe_length (inputs
),
615 vec_safe_length (outputs
),
616 vec_safe_length (clobbers
),
617 vec_safe_length (labels
));
619 for (i
= 0; i
< vec_safe_length (inputs
); i
++)
620 gimple_asm_set_input_op (p
, i
, (*inputs
)[i
]);
622 for (i
= 0; i
< vec_safe_length (outputs
); i
++)
623 gimple_asm_set_output_op (p
, i
, (*outputs
)[i
]);
625 for (i
= 0; i
< vec_safe_length (clobbers
); i
++)
626 gimple_asm_set_clobber_op (p
, i
, (*clobbers
)[i
]);
628 for (i
= 0; i
< vec_safe_length (labels
); i
++)
629 gimple_asm_set_label_op (p
, i
, (*labels
)[i
]);
634 /* Build a GIMPLE_CATCH statement.
636 TYPES are the catch types.
637 HANDLER is the exception handler. */
640 gimple_build_catch (tree types
, gimple_seq handler
)
642 gimple p
= gimple_alloc (GIMPLE_CATCH
, 0);
643 gimple_catch_set_types (p
, types
);
645 gimple_catch_set_handler (p
, handler
);
650 /* Build a GIMPLE_EH_FILTER statement.
652 TYPES are the filter's types.
653 FAILURE is the filter's failure action. */
656 gimple_build_eh_filter (tree types
, gimple_seq failure
)
658 gimple p
= gimple_alloc (GIMPLE_EH_FILTER
, 0);
659 gimple_eh_filter_set_types (p
, types
);
661 gimple_eh_filter_set_failure (p
, failure
);
666 /* Build a GIMPLE_EH_MUST_NOT_THROW statement. */
669 gimple_build_eh_must_not_throw (tree decl
)
671 gimple p
= gimple_alloc (GIMPLE_EH_MUST_NOT_THROW
, 0);
673 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
674 gcc_assert (flags_from_decl_or_type (decl
) & ECF_NORETURN
);
675 gimple_eh_must_not_throw_set_fndecl (p
, decl
);
680 /* Build a GIMPLE_EH_ELSE statement. */
683 gimple_build_eh_else (gimple_seq n_body
, gimple_seq e_body
)
685 gimple p
= gimple_alloc (GIMPLE_EH_ELSE
, 0);
686 gimple_eh_else_set_n_body (p
, n_body
);
687 gimple_eh_else_set_e_body (p
, e_body
);
691 /* Build a GIMPLE_TRY statement.
693 EVAL is the expression to evaluate.
694 CLEANUP is the cleanup expression.
695 KIND is either GIMPLE_TRY_CATCH or GIMPLE_TRY_FINALLY depending on
696 whether this is a try/catch or a try/finally respectively. */
699 gimple_build_try (gimple_seq eval
, gimple_seq cleanup
,
700 enum gimple_try_flags kind
)
704 gcc_assert (kind
== GIMPLE_TRY_CATCH
|| kind
== GIMPLE_TRY_FINALLY
);
705 p
= gimple_alloc (GIMPLE_TRY
, 0);
706 gimple_set_subcode (p
, kind
);
708 gimple_try_set_eval (p
, eval
);
710 gimple_try_set_cleanup (p
, cleanup
);
715 /* Construct a GIMPLE_WITH_CLEANUP_EXPR statement.
717 CLEANUP is the cleanup expression. */
720 gimple_build_wce (gimple_seq cleanup
)
722 gimple p
= gimple_alloc (GIMPLE_WITH_CLEANUP_EXPR
, 0);
724 gimple_wce_set_cleanup (p
, cleanup
);
730 /* Build a GIMPLE_RESX statement. */
733 gimple_build_resx (int region
)
735 gimple p
= gimple_build_with_ops (GIMPLE_RESX
, ERROR_MARK
, 0);
736 p
->gimple_eh_ctrl
.region
= region
;
741 /* The helper for constructing a gimple switch statement.
742 INDEX is the switch's index.
743 NLABELS is the number of labels in the switch excluding the default.
744 DEFAULT_LABEL is the default label for the switch statement. */
747 gimple_build_switch_nlabels (unsigned nlabels
, tree index
, tree default_label
)
749 /* nlabels + 1 default label + 1 index. */
750 gcc_checking_assert (default_label
);
751 gimple p
= gimple_build_with_ops (GIMPLE_SWITCH
, ERROR_MARK
,
753 gimple_switch_set_index (p
, index
);
754 gimple_switch_set_default_label (p
, default_label
);
758 /* Build a GIMPLE_SWITCH statement.
760 INDEX is the switch's index.
761 DEFAULT_LABEL is the default label
762 ARGS is a vector of labels excluding the default. */
765 gimple_build_switch (tree index
, tree default_label
, vec
<tree
> args
)
767 unsigned i
, nlabels
= args
.length ();
769 gimple p
= gimple_build_switch_nlabels (nlabels
, index
, default_label
);
771 /* Copy the labels from the vector to the switch statement. */
772 for (i
= 0; i
< nlabels
; i
++)
773 gimple_switch_set_label (p
, i
+ 1, args
[i
]);
778 /* Build a GIMPLE_EH_DISPATCH statement. */
781 gimple_build_eh_dispatch (int region
)
783 gimple p
= gimple_build_with_ops (GIMPLE_EH_DISPATCH
, ERROR_MARK
, 0);
784 p
->gimple_eh_ctrl
.region
= region
;
788 /* Build a new GIMPLE_DEBUG_BIND statement.
790 VAR is bound to VALUE; block and location are taken from STMT. */
793 gimple_build_debug_bind_stat (tree var
, tree value
, gimple stmt MEM_STAT_DECL
)
795 gimple p
= gimple_build_with_ops_stat (GIMPLE_DEBUG
,
796 (unsigned)GIMPLE_DEBUG_BIND
, 2
799 gimple_debug_bind_set_var (p
, var
);
800 gimple_debug_bind_set_value (p
, value
);
802 gimple_set_location (p
, gimple_location (stmt
));
808 /* Build a new GIMPLE_DEBUG_SOURCE_BIND statement.
810 VAR is bound to VALUE; block and location are taken from STMT. */
813 gimple_build_debug_source_bind_stat (tree var
, tree value
,
814 gimple stmt MEM_STAT_DECL
)
816 gimple p
= gimple_build_with_ops_stat (GIMPLE_DEBUG
,
817 (unsigned)GIMPLE_DEBUG_SOURCE_BIND
, 2
820 gimple_debug_source_bind_set_var (p
, var
);
821 gimple_debug_source_bind_set_value (p
, value
);
823 gimple_set_location (p
, gimple_location (stmt
));
829 /* Build a GIMPLE_OMP_CRITICAL statement.
831 BODY is the sequence of statements for which only one thread can execute.
832 NAME is optional identifier for this critical block. */
835 gimple_build_omp_critical (gimple_seq body
, tree name
)
837 gimple p
= gimple_alloc (GIMPLE_OMP_CRITICAL
, 0);
838 gimple_omp_critical_set_name (p
, name
);
840 gimple_omp_set_body (p
, body
);
845 /* Build a GIMPLE_OMP_FOR statement.
847 BODY is sequence of statements inside the for loop.
848 KIND is the `for' variant.
849 CLAUSES, are any of the OMP loop construct's clauses: private, firstprivate,
850 lastprivate, reductions, ordered, schedule, and nowait.
851 COLLAPSE is the collapse count.
852 PRE_BODY is the sequence of statements that are loop invariant. */
855 gimple_build_omp_for (gimple_seq body
, int kind
, tree clauses
, size_t collapse
,
858 gimple p
= gimple_alloc (GIMPLE_OMP_FOR
, 0);
860 gimple_omp_set_body (p
, body
);
861 gimple_omp_for_set_clauses (p
, clauses
);
862 gimple_omp_for_set_kind (p
, kind
);
863 p
->gimple_omp_for
.collapse
= collapse
;
864 p
->gimple_omp_for
.iter
865 = ggc_alloc_cleared_vec_gimple_omp_for_iter (collapse
);
867 gimple_omp_for_set_pre_body (p
, pre_body
);
873 /* Build a GIMPLE_OMP_PARALLEL statement.
875 BODY is sequence of statements which are executed in parallel.
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). */
881 gimple_build_omp_parallel (gimple_seq body
, tree clauses
, tree child_fn
,
884 gimple p
= gimple_alloc (GIMPLE_OMP_PARALLEL
, 0);
886 gimple_omp_set_body (p
, body
);
887 gimple_omp_parallel_set_clauses (p
, clauses
);
888 gimple_omp_parallel_set_child_fn (p
, child_fn
);
889 gimple_omp_parallel_set_data_arg (p
, data_arg
);
895 /* Build a GIMPLE_OMP_TASK statement.
897 BODY is sequence of statements which are executed by the explicit task.
898 CLAUSES, are the OMP parallel construct's clauses.
899 CHILD_FN is the function created for the parallel threads to execute.
900 DATA_ARG are the shared data argument(s).
901 COPY_FN is the optional function for firstprivate initialization.
902 ARG_SIZE and ARG_ALIGN are size and alignment of the data block. */
905 gimple_build_omp_task (gimple_seq body
, tree clauses
, tree child_fn
,
906 tree data_arg
, tree copy_fn
, tree arg_size
,
909 gimple p
= gimple_alloc (GIMPLE_OMP_TASK
, 0);
911 gimple_omp_set_body (p
, body
);
912 gimple_omp_task_set_clauses (p
, clauses
);
913 gimple_omp_task_set_child_fn (p
, child_fn
);
914 gimple_omp_task_set_data_arg (p
, data_arg
);
915 gimple_omp_task_set_copy_fn (p
, copy_fn
);
916 gimple_omp_task_set_arg_size (p
, arg_size
);
917 gimple_omp_task_set_arg_align (p
, arg_align
);
923 /* Build a GIMPLE_OMP_SECTION statement for a sections statement.
925 BODY is the sequence of statements in the section. */
928 gimple_build_omp_section (gimple_seq body
)
930 gimple p
= gimple_alloc (GIMPLE_OMP_SECTION
, 0);
932 gimple_omp_set_body (p
, body
);
938 /* Build a GIMPLE_OMP_MASTER statement.
940 BODY is the sequence of statements to be executed by just the master. */
943 gimple_build_omp_master (gimple_seq body
)
945 gimple p
= gimple_alloc (GIMPLE_OMP_MASTER
, 0);
947 gimple_omp_set_body (p
, body
);
953 /* Build a GIMPLE_OMP_TASKGROUP statement.
955 BODY is the sequence of statements to be executed by the taskgroup
959 gimple_build_omp_taskgroup (gimple_seq body
)
961 gimple p
= gimple_alloc (GIMPLE_OMP_TASKGROUP
, 0);
963 gimple_omp_set_body (p
, body
);
969 /* Build a GIMPLE_OMP_CONTINUE statement.
971 CONTROL_DEF is the definition of the control variable.
972 CONTROL_USE is the use of the control variable. */
975 gimple_build_omp_continue (tree control_def
, tree control_use
)
977 gimple p
= gimple_alloc (GIMPLE_OMP_CONTINUE
, 0);
978 gimple_omp_continue_set_control_def (p
, control_def
);
979 gimple_omp_continue_set_control_use (p
, control_use
);
983 /* Build a GIMPLE_OMP_ORDERED statement.
985 BODY is the sequence of statements inside a loop that will executed in
989 gimple_build_omp_ordered (gimple_seq body
)
991 gimple p
= gimple_alloc (GIMPLE_OMP_ORDERED
, 0);
993 gimple_omp_set_body (p
, body
);
999 /* Build a GIMPLE_OMP_RETURN statement.
1000 WAIT_P is true if this is a non-waiting return. */
1003 gimple_build_omp_return (bool wait_p
)
1005 gimple p
= gimple_alloc (GIMPLE_OMP_RETURN
, 0);
1007 gimple_omp_return_set_nowait (p
);
1013 /* Build a GIMPLE_OMP_SECTIONS statement.
1015 BODY is a sequence of section statements.
1016 CLAUSES are any of the OMP sections contsruct's clauses: private,
1017 firstprivate, lastprivate, reduction, and nowait. */
1020 gimple_build_omp_sections (gimple_seq body
, tree clauses
)
1022 gimple p
= gimple_alloc (GIMPLE_OMP_SECTIONS
, 0);
1024 gimple_omp_set_body (p
, body
);
1025 gimple_omp_sections_set_clauses (p
, clauses
);
1031 /* Build a GIMPLE_OMP_SECTIONS_SWITCH. */
1034 gimple_build_omp_sections_switch (void)
1036 return gimple_alloc (GIMPLE_OMP_SECTIONS_SWITCH
, 0);
1040 /* Build a GIMPLE_OMP_SINGLE statement.
1042 BODY is the sequence of statements that will be executed once.
1043 CLAUSES are any of the OMP single construct's clauses: private, firstprivate,
1044 copyprivate, nowait. */
1047 gimple_build_omp_single (gimple_seq body
, tree clauses
)
1049 gimple p
= gimple_alloc (GIMPLE_OMP_SINGLE
, 0);
1051 gimple_omp_set_body (p
, body
);
1052 gimple_omp_single_set_clauses (p
, clauses
);
1058 /* Build a GIMPLE_OMP_TARGET statement.
1060 BODY is the sequence of statements that will be executed.
1061 CLAUSES are any of the OMP target construct's clauses. */
1064 gimple_build_omp_target (gimple_seq body
, int kind
, tree clauses
)
1066 gimple p
= gimple_alloc (GIMPLE_OMP_TARGET
, 0);
1068 gimple_omp_set_body (p
, body
);
1069 gimple_omp_target_set_clauses (p
, clauses
);
1070 gimple_omp_target_set_kind (p
, kind
);
1076 /* Build a GIMPLE_OMP_TEAMS statement.
1078 BODY is the sequence of statements that will be executed.
1079 CLAUSES are any of the OMP teams construct's clauses. */
1082 gimple_build_omp_teams (gimple_seq body
, tree clauses
)
1084 gimple p
= gimple_alloc (GIMPLE_OMP_TEAMS
, 0);
1086 gimple_omp_set_body (p
, body
);
1087 gimple_omp_teams_set_clauses (p
, clauses
);
1093 /* Build a GIMPLE_OMP_ATOMIC_LOAD statement. */
1096 gimple_build_omp_atomic_load (tree lhs
, tree rhs
)
1098 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_LOAD
, 0);
1099 gimple_omp_atomic_load_set_lhs (p
, lhs
);
1100 gimple_omp_atomic_load_set_rhs (p
, rhs
);
1104 /* Build a GIMPLE_OMP_ATOMIC_STORE statement.
1106 VAL is the value we are storing. */
1109 gimple_build_omp_atomic_store (tree val
)
1111 gimple p
= gimple_alloc (GIMPLE_OMP_ATOMIC_STORE
, 0);
1112 gimple_omp_atomic_store_set_val (p
, val
);
1116 /* Build a GIMPLE_TRANSACTION statement. */
1119 gimple_build_transaction (gimple_seq body
, tree label
)
1121 gimple p
= gimple_alloc (GIMPLE_TRANSACTION
, 0);
1122 gimple_transaction_set_body (p
, body
);
1123 gimple_transaction_set_label (p
, label
);
1127 /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
1128 predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
1131 gimple_build_predict (enum br_predictor predictor
, enum prediction outcome
)
1133 gimple p
= gimple_alloc (GIMPLE_PREDICT
, 0);
1134 /* Ensure all the predictors fit into the lower bits of the subcode. */
1135 gcc_assert ((int) END_PREDICTORS
<= GF_PREDICT_TAKEN
);
1136 gimple_predict_set_predictor (p
, predictor
);
1137 gimple_predict_set_outcome (p
, outcome
);
1141 #if defined ENABLE_GIMPLE_CHECKING
1142 /* Complain of a gimple type mismatch and die. */
1145 gimple_check_failed (const_gimple gs
, const char *file
, int line
,
1146 const char *function
, enum gimple_code code
,
1147 enum tree_code subcode
)
1149 internal_error ("gimple check: expected %s(%s), have %s(%s) in %s, at %s:%d",
1150 gimple_code_name
[code
],
1151 get_tree_code_name (subcode
),
1152 gimple_code_name
[gimple_code (gs
)],
1153 gs
->gsbase
.subcode
> 0
1154 ? get_tree_code_name ((enum tree_code
) gs
->gsbase
.subcode
)
1156 function
, trim_filename (file
), line
);
1158 #endif /* ENABLE_GIMPLE_CHECKING */
1161 /* Link gimple statement GS to the end of the sequence *SEQ_P. If
1162 *SEQ_P is NULL, a new sequence is allocated. */
1165 gimple_seq_add_stmt (gimple_seq
*seq_p
, gimple gs
)
1167 gimple_stmt_iterator si
;
1171 si
= gsi_last (*seq_p
);
1172 gsi_insert_after (&si
, gs
, GSI_NEW_STMT
);
1176 /* Append sequence SRC to the end of sequence *DST_P. If *DST_P is
1177 NULL, a new sequence is allocated. */
1180 gimple_seq_add_seq (gimple_seq
*dst_p
, gimple_seq src
)
1182 gimple_stmt_iterator si
;
1186 si
= gsi_last (*dst_p
);
1187 gsi_insert_seq_after (&si
, src
, GSI_NEW_STMT
);
1191 /* Helper function of empty_body_p. Return true if STMT is an empty
1195 empty_stmt_p (gimple stmt
)
1197 if (gimple_code (stmt
) == GIMPLE_NOP
)
1199 if (gimple_code (stmt
) == GIMPLE_BIND
)
1200 return empty_body_p (gimple_bind_body (stmt
));
1205 /* Return true if BODY contains nothing but empty statements. */
1208 empty_body_p (gimple_seq body
)
1210 gimple_stmt_iterator i
;
1212 if (gimple_seq_empty_p (body
))
1214 for (i
= gsi_start (body
); !gsi_end_p (i
); gsi_next (&i
))
1215 if (!empty_stmt_p (gsi_stmt (i
))
1216 && !is_gimple_debug (gsi_stmt (i
)))
1223 /* Perform a deep copy of sequence SRC and return the result. */
1226 gimple_seq_copy (gimple_seq src
)
1228 gimple_stmt_iterator gsi
;
1229 gimple_seq new_seq
= NULL
;
1232 for (gsi
= gsi_start (src
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1234 stmt
= gimple_copy (gsi_stmt (gsi
));
1235 gimple_seq_add_stmt (&new_seq
, stmt
);
1242 /* Walk all the statements in the sequence *PSEQ calling walk_gimple_stmt
1243 on each one. WI is as in walk_gimple_stmt.
1245 If walk_gimple_stmt returns non-NULL, the walk is stopped, and the
1246 value is stored in WI->CALLBACK_RESULT. Also, the statement that
1247 produced the value is returned if this statement has not been
1248 removed by a callback (wi->removed_stmt). If the statement has
1249 been removed, NULL is returned.
1251 Otherwise, all the statements are walked and NULL returned. */
1254 walk_gimple_seq_mod (gimple_seq
*pseq
, walk_stmt_fn callback_stmt
,
1255 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1257 gimple_stmt_iterator gsi
;
1259 for (gsi
= gsi_start (*pseq
); !gsi_end_p (gsi
); )
1261 tree ret
= walk_gimple_stmt (&gsi
, callback_stmt
, callback_op
, wi
);
1264 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
1267 wi
->callback_result
= ret
;
1269 return wi
->removed_stmt
? NULL
: gsi_stmt (gsi
);
1272 if (!wi
->removed_stmt
)
1277 wi
->callback_result
= NULL_TREE
;
1283 /* Like walk_gimple_seq_mod, but ensure that the head of SEQ isn't
1284 changed by the callbacks. */
1287 walk_gimple_seq (gimple_seq seq
, walk_stmt_fn callback_stmt
,
1288 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1290 gimple_seq seq2
= seq
;
1291 gimple ret
= walk_gimple_seq_mod (&seq2
, callback_stmt
, callback_op
, wi
);
1292 gcc_assert (seq2
== seq
);
1297 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
1300 walk_gimple_asm (gimple stmt
, walk_tree_fn callback_op
,
1301 struct walk_stmt_info
*wi
)
1305 const char **oconstraints
;
1307 const char *constraint
;
1308 bool allows_mem
, allows_reg
, is_inout
;
1310 noutputs
= gimple_asm_noutputs (stmt
);
1311 oconstraints
= (const char **) alloca ((noutputs
) * sizeof (const char *));
1316 for (i
= 0; i
< noutputs
; i
++)
1318 op
= gimple_asm_output_op (stmt
, i
);
1319 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1320 oconstraints
[i
] = constraint
;
1321 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
, &allows_reg
,
1324 wi
->val_only
= (allows_reg
|| !allows_mem
);
1325 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1330 n
= gimple_asm_ninputs (stmt
);
1331 for (i
= 0; i
< n
; i
++)
1333 op
= gimple_asm_input_op (stmt
, i
);
1334 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
1335 parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
1336 oconstraints
, &allows_mem
, &allows_reg
);
1339 wi
->val_only
= (allows_reg
|| !allows_mem
);
1340 /* Although input "m" is not really a LHS, we need a lvalue. */
1341 wi
->is_lhs
= !wi
->val_only
;
1343 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1351 wi
->val_only
= true;
1354 n
= gimple_asm_nlabels (stmt
);
1355 for (i
= 0; i
< n
; i
++)
1357 op
= gimple_asm_label_op (stmt
, i
);
1358 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
1367 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
1368 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
1370 CALLBACK_OP is called on each operand of STMT via walk_tree.
1371 Additional parameters to walk_tree must be stored in WI. For each operand
1372 OP, walk_tree is called as:
1374 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
1376 If CALLBACK_OP returns non-NULL for an operand, the remaining
1377 operands are not scanned.
1379 The return value is that returned by the last call to walk_tree, or
1380 NULL_TREE if no CALLBACK_OP is specified. */
1383 walk_gimple_op (gimple stmt
, walk_tree_fn callback_op
,
1384 struct walk_stmt_info
*wi
)
1386 struct pointer_set_t
*pset
= (wi
) ? wi
->pset
: NULL
;
1388 tree ret
= NULL_TREE
;
1390 switch (gimple_code (stmt
))
1393 /* Walk the RHS operands. If the LHS is of a non-renamable type or
1394 is a register variable, we may use a COMPONENT_REF on the RHS. */
1397 tree lhs
= gimple_assign_lhs (stmt
);
1399 = (is_gimple_reg_type (TREE_TYPE (lhs
)) && !is_gimple_reg (lhs
))
1400 || gimple_assign_rhs_class (stmt
) != GIMPLE_SINGLE_RHS
;
1403 for (i
= 1; i
< gimple_num_ops (stmt
); i
++)
1405 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
,
1411 /* Walk the LHS. If the RHS is appropriate for a memory, we
1412 may use a COMPONENT_REF on the LHS. */
1415 /* If the RHS is of a non-renamable type or is a register variable,
1416 we may use a COMPONENT_REF on the LHS. */
1417 tree rhs1
= gimple_assign_rhs1 (stmt
);
1419 = (is_gimple_reg_type (TREE_TYPE (rhs1
)) && !is_gimple_reg (rhs1
))
1420 || gimple_assign_rhs_class (stmt
) != GIMPLE_SINGLE_RHS
;
1424 ret
= walk_tree (gimple_op_ptr (stmt
, 0), callback_op
, wi
, pset
);
1430 wi
->val_only
= true;
1439 wi
->val_only
= true;
1442 ret
= walk_tree (gimple_call_chain_ptr (stmt
), callback_op
, wi
, pset
);
1446 ret
= walk_tree (gimple_call_fn_ptr (stmt
), callback_op
, wi
, pset
);
1450 for (i
= 0; i
< gimple_call_num_args (stmt
); i
++)
1454 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt
, i
)));
1455 ret
= walk_tree (gimple_call_arg_ptr (stmt
, i
), callback_op
, wi
,
1461 if (gimple_call_lhs (stmt
))
1467 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt
)));
1470 ret
= walk_tree (gimple_call_lhs_ptr (stmt
), callback_op
, wi
, pset
);
1478 wi
->val_only
= true;
1483 ret
= walk_tree (gimple_catch_types_ptr (stmt
), callback_op
, wi
,
1489 case GIMPLE_EH_FILTER
:
1490 ret
= walk_tree (gimple_eh_filter_types_ptr (stmt
), callback_op
, wi
,
1497 ret
= walk_gimple_asm (stmt
, callback_op
, wi
);
1502 case GIMPLE_OMP_CONTINUE
:
1503 ret
= walk_tree (gimple_omp_continue_control_def_ptr (stmt
),
1504 callback_op
, wi
, pset
);
1508 ret
= walk_tree (gimple_omp_continue_control_use_ptr (stmt
),
1509 callback_op
, wi
, pset
);
1514 case GIMPLE_OMP_CRITICAL
:
1515 ret
= walk_tree (gimple_omp_critical_name_ptr (stmt
), callback_op
, wi
,
1521 case GIMPLE_OMP_FOR
:
1522 ret
= walk_tree (gimple_omp_for_clauses_ptr (stmt
), callback_op
, wi
,
1526 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
1528 ret
= walk_tree (gimple_omp_for_index_ptr (stmt
, i
), callback_op
,
1532 ret
= walk_tree (gimple_omp_for_initial_ptr (stmt
, i
), callback_op
,
1536 ret
= walk_tree (gimple_omp_for_final_ptr (stmt
, i
), callback_op
,
1540 ret
= walk_tree (gimple_omp_for_incr_ptr (stmt
, i
), callback_op
,
1547 case GIMPLE_OMP_PARALLEL
:
1548 ret
= walk_tree (gimple_omp_parallel_clauses_ptr (stmt
), callback_op
,
1552 ret
= walk_tree (gimple_omp_parallel_child_fn_ptr (stmt
), callback_op
,
1556 ret
= walk_tree (gimple_omp_parallel_data_arg_ptr (stmt
), callback_op
,
1562 case GIMPLE_OMP_TASK
:
1563 ret
= walk_tree (gimple_omp_task_clauses_ptr (stmt
), callback_op
,
1567 ret
= walk_tree (gimple_omp_task_child_fn_ptr (stmt
), callback_op
,
1571 ret
= walk_tree (gimple_omp_task_data_arg_ptr (stmt
), callback_op
,
1575 ret
= walk_tree (gimple_omp_task_copy_fn_ptr (stmt
), callback_op
,
1579 ret
= walk_tree (gimple_omp_task_arg_size_ptr (stmt
), callback_op
,
1583 ret
= walk_tree (gimple_omp_task_arg_align_ptr (stmt
), callback_op
,
1589 case GIMPLE_OMP_SECTIONS
:
1590 ret
= walk_tree (gimple_omp_sections_clauses_ptr (stmt
), callback_op
,
1595 ret
= walk_tree (gimple_omp_sections_control_ptr (stmt
), callback_op
,
1602 case GIMPLE_OMP_SINGLE
:
1603 ret
= walk_tree (gimple_omp_single_clauses_ptr (stmt
), callback_op
, wi
,
1609 case GIMPLE_OMP_TARGET
:
1610 ret
= walk_tree (gimple_omp_target_clauses_ptr (stmt
), callback_op
, wi
,
1616 case GIMPLE_OMP_TEAMS
:
1617 ret
= walk_tree (gimple_omp_teams_clauses_ptr (stmt
), callback_op
, wi
,
1623 case GIMPLE_OMP_ATOMIC_LOAD
:
1624 ret
= walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt
), callback_op
, wi
,
1629 ret
= walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt
), callback_op
, wi
,
1635 case GIMPLE_OMP_ATOMIC_STORE
:
1636 ret
= walk_tree (gimple_omp_atomic_store_val_ptr (stmt
), callback_op
,
1642 case GIMPLE_TRANSACTION
:
1643 ret
= walk_tree (gimple_transaction_label_ptr (stmt
), callback_op
,
1649 case GIMPLE_OMP_RETURN
:
1650 ret
= walk_tree (gimple_omp_return_lhs_ptr (stmt
), callback_op
, wi
,
1656 /* Tuples that do not have operands. */
1659 case GIMPLE_PREDICT
:
1664 enum gimple_statement_structure_enum gss
;
1665 gss
= gimple_statement_structure (stmt
);
1666 if (gss
== GSS_WITH_OPS
|| gss
== GSS_WITH_MEM_OPS
)
1667 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
1669 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
, pset
);
1681 /* Walk the current statement in GSI (optionally using traversal state
1682 stored in WI). If WI is NULL, no state is kept during traversal.
1683 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
1684 that it has handled all the operands of the statement, its return
1685 value is returned. Otherwise, the return value from CALLBACK_STMT
1686 is discarded and its operands are scanned.
1688 If CALLBACK_STMT is NULL or it didn't handle the operands,
1689 CALLBACK_OP is called on each operand of the statement via
1690 walk_gimple_op. If walk_gimple_op returns non-NULL for any
1691 operand, the remaining operands are not scanned. In this case, the
1692 return value from CALLBACK_OP is returned.
1694 In any other case, NULL_TREE is returned. */
1697 walk_gimple_stmt (gimple_stmt_iterator
*gsi
, walk_stmt_fn callback_stmt
,
1698 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
1702 gimple stmt
= gsi_stmt (*gsi
);
1707 wi
->removed_stmt
= false;
1709 if (wi
->want_locations
&& gimple_has_location (stmt
))
1710 input_location
= gimple_location (stmt
);
1715 /* Invoke the statement callback. Return if the callback handled
1716 all of STMT operands by itself. */
1719 bool handled_ops
= false;
1720 tree_ret
= callback_stmt (gsi
, &handled_ops
, wi
);
1724 /* If CALLBACK_STMT did not handle operands, it should not have
1725 a value to return. */
1726 gcc_assert (tree_ret
== NULL
);
1728 if (wi
&& wi
->removed_stmt
)
1731 /* Re-read stmt in case the callback changed it. */
1732 stmt
= gsi_stmt (*gsi
);
1735 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
1738 tree_ret
= walk_gimple_op (stmt
, callback_op
, wi
);
1743 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
1744 switch (gimple_code (stmt
))
1747 ret
= walk_gimple_seq_mod (gimple_bind_body_ptr (stmt
), callback_stmt
,
1750 return wi
->callback_result
;
1754 ret
= walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt
), callback_stmt
,
1757 return wi
->callback_result
;
1760 case GIMPLE_EH_FILTER
:
1761 ret
= walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt
), callback_stmt
,
1764 return wi
->callback_result
;
1767 case GIMPLE_EH_ELSE
:
1768 ret
= walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (stmt
),
1769 callback_stmt
, callback_op
, wi
);
1771 return wi
->callback_result
;
1772 ret
= walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (stmt
),
1773 callback_stmt
, callback_op
, wi
);
1775 return wi
->callback_result
;
1779 ret
= walk_gimple_seq_mod (gimple_try_eval_ptr (stmt
), callback_stmt
, callback_op
,
1782 return wi
->callback_result
;
1784 ret
= walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt
), callback_stmt
,
1787 return wi
->callback_result
;
1790 case GIMPLE_OMP_FOR
:
1791 ret
= walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt
), callback_stmt
,
1794 return wi
->callback_result
;
1797 case GIMPLE_OMP_CRITICAL
:
1798 case GIMPLE_OMP_MASTER
:
1799 case GIMPLE_OMP_TASKGROUP
:
1800 case GIMPLE_OMP_ORDERED
:
1801 case GIMPLE_OMP_SECTION
:
1802 case GIMPLE_OMP_PARALLEL
:
1803 case GIMPLE_OMP_TASK
:
1804 case GIMPLE_OMP_SECTIONS
:
1805 case GIMPLE_OMP_SINGLE
:
1806 case GIMPLE_OMP_TARGET
:
1807 case GIMPLE_OMP_TEAMS
:
1808 ret
= walk_gimple_seq_mod (gimple_omp_body_ptr (stmt
), callback_stmt
,
1811 return wi
->callback_result
;
1814 case GIMPLE_WITH_CLEANUP_EXPR
:
1815 ret
= walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt
), callback_stmt
,
1818 return wi
->callback_result
;
1821 case GIMPLE_TRANSACTION
:
1822 ret
= walk_gimple_seq_mod (gimple_transaction_body_ptr (stmt
),
1823 callback_stmt
, callback_op
, wi
);
1825 return wi
->callback_result
;
1829 gcc_assert (!gimple_has_substatements (stmt
));
1837 /* Return true if calls C1 and C2 are known to go to the same function. */
1840 gimple_call_same_target_p (const_gimple c1
, const_gimple c2
)
1842 if (gimple_call_internal_p (c1
))
1843 return (gimple_call_internal_p (c2
)
1844 && gimple_call_internal_fn (c1
) == gimple_call_internal_fn (c2
));
1846 return (gimple_call_fn (c1
) == gimple_call_fn (c2
)
1847 || (gimple_call_fndecl (c1
)
1848 && gimple_call_fndecl (c1
) == gimple_call_fndecl (c2
)));
1851 /* Detect flags from a GIMPLE_CALL. This is just like
1852 call_expr_flags, but for gimple tuples. */
1855 gimple_call_flags (const_gimple stmt
)
1858 tree decl
= gimple_call_fndecl (stmt
);
1861 flags
= flags_from_decl_or_type (decl
);
1862 else if (gimple_call_internal_p (stmt
))
1863 flags
= internal_fn_flags (gimple_call_internal_fn (stmt
));
1865 flags
= flags_from_decl_or_type (gimple_call_fntype (stmt
));
1867 if (stmt
->gsbase
.subcode
& GF_CALL_NOTHROW
)
1868 flags
|= ECF_NOTHROW
;
1873 /* Return the "fn spec" string for call STMT. */
1876 gimple_call_fnspec (const_gimple stmt
)
1880 type
= gimple_call_fntype (stmt
);
1884 attr
= lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type
));
1888 return TREE_VALUE (TREE_VALUE (attr
));
1891 /* Detects argument flags for argument number ARG on call STMT. */
1894 gimple_call_arg_flags (const_gimple stmt
, unsigned arg
)
1896 tree attr
= gimple_call_fnspec (stmt
);
1898 if (!attr
|| 1 + arg
>= (unsigned) TREE_STRING_LENGTH (attr
))
1901 switch (TREE_STRING_POINTER (attr
)[1 + arg
])
1908 return EAF_DIRECT
| EAF_NOCLOBBER
| EAF_NOESCAPE
;
1911 return EAF_NOCLOBBER
| EAF_NOESCAPE
;
1914 return EAF_DIRECT
| EAF_NOESCAPE
;
1917 return EAF_NOESCAPE
;
1925 /* Detects return flags for the call STMT. */
1928 gimple_call_return_flags (const_gimple stmt
)
1932 if (gimple_call_flags (stmt
) & ECF_MALLOC
)
1935 attr
= gimple_call_fnspec (stmt
);
1936 if (!attr
|| TREE_STRING_LENGTH (attr
) < 1)
1939 switch (TREE_STRING_POINTER (attr
)[0])
1945 return ERF_RETURNS_ARG
| (TREE_STRING_POINTER (attr
)[0] - '1');
1957 /* Return true if GS is a copy assignment. */
1960 gimple_assign_copy_p (gimple gs
)
1962 return (gimple_assign_single_p (gs
)
1963 && is_gimple_val (gimple_op (gs
, 1)));
1967 /* Return true if GS is a SSA_NAME copy assignment. */
1970 gimple_assign_ssa_name_copy_p (gimple gs
)
1972 return (gimple_assign_single_p (gs
)
1973 && TREE_CODE (gimple_assign_lhs (gs
)) == SSA_NAME
1974 && TREE_CODE (gimple_assign_rhs1 (gs
)) == SSA_NAME
);
1978 /* Return true if GS is an assignment with a unary RHS, but the
1979 operator has no effect on the assigned value. The logic is adapted
1980 from STRIP_NOPS. This predicate is intended to be used in tuplifying
1981 instances in which STRIP_NOPS was previously applied to the RHS of
1984 NOTE: In the use cases that led to the creation of this function
1985 and of gimple_assign_single_p, it is typical to test for either
1986 condition and to proceed in the same manner. In each case, the
1987 assigned value is represented by the single RHS operand of the
1988 assignment. I suspect there may be cases where gimple_assign_copy_p,
1989 gimple_assign_single_p, or equivalent logic is used where a similar
1990 treatment of unary NOPs is appropriate. */
1993 gimple_assign_unary_nop_p (gimple gs
)
1995 return (is_gimple_assign (gs
)
1996 && (CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (gs
))
1997 || gimple_assign_rhs_code (gs
) == NON_LVALUE_EXPR
)
1998 && gimple_assign_rhs1 (gs
) != error_mark_node
1999 && (TYPE_MODE (TREE_TYPE (gimple_assign_lhs (gs
)))
2000 == TYPE_MODE (TREE_TYPE (gimple_assign_rhs1 (gs
)))));
2003 /* Set BB to be the basic block holding G. */
2006 gimple_set_bb (gimple stmt
, basic_block bb
)
2008 stmt
->gsbase
.bb
= bb
;
2010 /* If the statement is a label, add the label to block-to-labels map
2011 so that we can speed up edge creation for GIMPLE_GOTOs. */
2012 if (cfun
->cfg
&& gimple_code (stmt
) == GIMPLE_LABEL
)
2017 t
= gimple_label_label (stmt
);
2018 uid
= LABEL_DECL_UID (t
);
2021 unsigned old_len
= vec_safe_length (label_to_block_map
);
2022 LABEL_DECL_UID (t
) = uid
= cfun
->cfg
->last_label_uid
++;
2023 if (old_len
<= (unsigned) uid
)
2025 unsigned new_len
= 3 * uid
/ 2 + 1;
2027 vec_safe_grow_cleared (label_to_block_map
, new_len
);
2031 (*label_to_block_map
)[uid
] = bb
;
2036 /* Modify the RHS of the assignment pointed-to by GSI using the
2037 operands in the expression tree EXPR.
2039 NOTE: The statement pointed-to by GSI may be reallocated if it
2040 did not have enough operand slots.
2042 This function is useful to convert an existing tree expression into
2043 the flat representation used for the RHS of a GIMPLE assignment.
2044 It will reallocate memory as needed to expand or shrink the number
2045 of operand slots needed to represent EXPR.
2047 NOTE: If you find yourself building a tree and then calling this
2048 function, you are most certainly doing it the slow way. It is much
2049 better to build a new assignment or to use the function
2050 gimple_assign_set_rhs_with_ops, which does not require an
2051 expression tree to be built. */
2054 gimple_assign_set_rhs_from_tree (gimple_stmt_iterator
*gsi
, tree expr
)
2056 enum tree_code subcode
;
2059 extract_ops_from_tree_1 (expr
, &subcode
, &op1
, &op2
, &op3
);
2060 gimple_assign_set_rhs_with_ops_1 (gsi
, subcode
, op1
, op2
, op3
);
2064 /* Set the RHS of assignment statement pointed-to by GSI to CODE with
2065 operands OP1, OP2 and OP3.
2067 NOTE: The statement pointed-to by GSI may be reallocated if it
2068 did not have enough operand slots. */
2071 gimple_assign_set_rhs_with_ops_1 (gimple_stmt_iterator
*gsi
, enum tree_code code
,
2072 tree op1
, tree op2
, tree op3
)
2074 unsigned new_rhs_ops
= get_gimple_rhs_num_ops (code
);
2075 gimple stmt
= gsi_stmt (*gsi
);
2077 /* If the new CODE needs more operands, allocate a new statement. */
2078 if (gimple_num_ops (stmt
) < new_rhs_ops
+ 1)
2080 tree lhs
= gimple_assign_lhs (stmt
);
2081 gimple new_stmt
= gimple_alloc (gimple_code (stmt
), new_rhs_ops
+ 1);
2082 memcpy (new_stmt
, stmt
, gimple_size (gimple_code (stmt
)));
2083 gimple_init_singleton (new_stmt
);
2084 gsi_replace (gsi
, new_stmt
, true);
2087 /* The LHS needs to be reset as this also changes the SSA name
2089 gimple_assign_set_lhs (stmt
, lhs
);
2092 gimple_set_num_ops (stmt
, new_rhs_ops
+ 1);
2093 gimple_set_subcode (stmt
, code
);
2094 gimple_assign_set_rhs1 (stmt
, op1
);
2095 if (new_rhs_ops
> 1)
2096 gimple_assign_set_rhs2 (stmt
, op2
);
2097 if (new_rhs_ops
> 2)
2098 gimple_assign_set_rhs3 (stmt
, op3
);
2102 /* Return the LHS of a statement that performs an assignment,
2103 either a GIMPLE_ASSIGN or a GIMPLE_CALL. Returns NULL_TREE
2104 for a call to a function that returns no value, or for a
2105 statement other than an assignment or a call. */
2108 gimple_get_lhs (const_gimple stmt
)
2110 enum gimple_code code
= gimple_code (stmt
);
2112 if (code
== GIMPLE_ASSIGN
)
2113 return gimple_assign_lhs (stmt
);
2114 else if (code
== GIMPLE_CALL
)
2115 return gimple_call_lhs (stmt
);
2121 /* Set the LHS of a statement that performs an assignment,
2122 either a GIMPLE_ASSIGN or a GIMPLE_CALL. */
2125 gimple_set_lhs (gimple stmt
, tree lhs
)
2127 enum gimple_code code
= gimple_code (stmt
);
2129 if (code
== GIMPLE_ASSIGN
)
2130 gimple_assign_set_lhs (stmt
, lhs
);
2131 else if (code
== GIMPLE_CALL
)
2132 gimple_call_set_lhs (stmt
, lhs
);
2138 /* Return a deep copy of statement STMT. All the operands from STMT
2139 are reallocated and copied using unshare_expr. The DEF, USE, VDEF
2140 and VUSE operand arrays are set to empty in the new copy. The new
2141 copy isn't part of any sequence. */
2144 gimple_copy (gimple stmt
)
2146 enum gimple_code code
= gimple_code (stmt
);
2147 unsigned num_ops
= gimple_num_ops (stmt
);
2148 gimple copy
= gimple_alloc (code
, num_ops
);
2151 /* Shallow copy all the fields from STMT. */
2152 memcpy (copy
, stmt
, gimple_size (code
));
2153 gimple_init_singleton (copy
);
2155 /* If STMT has sub-statements, deep-copy them as well. */
2156 if (gimple_has_substatements (stmt
))
2161 switch (gimple_code (stmt
))
2164 new_seq
= gimple_seq_copy (gimple_bind_body (stmt
));
2165 gimple_bind_set_body (copy
, new_seq
);
2166 gimple_bind_set_vars (copy
, unshare_expr (gimple_bind_vars (stmt
)));
2167 gimple_bind_set_block (copy
, gimple_bind_block (stmt
));
2171 new_seq
= gimple_seq_copy (gimple_catch_handler (stmt
));
2172 gimple_catch_set_handler (copy
, new_seq
);
2173 t
= unshare_expr (gimple_catch_types (stmt
));
2174 gimple_catch_set_types (copy
, t
);
2177 case GIMPLE_EH_FILTER
:
2178 new_seq
= gimple_seq_copy (gimple_eh_filter_failure (stmt
));
2179 gimple_eh_filter_set_failure (copy
, new_seq
);
2180 t
= unshare_expr (gimple_eh_filter_types (stmt
));
2181 gimple_eh_filter_set_types (copy
, t
);
2184 case GIMPLE_EH_ELSE
:
2185 new_seq
= gimple_seq_copy (gimple_eh_else_n_body (stmt
));
2186 gimple_eh_else_set_n_body (copy
, new_seq
);
2187 new_seq
= gimple_seq_copy (gimple_eh_else_e_body (stmt
));
2188 gimple_eh_else_set_e_body (copy
, new_seq
);
2192 new_seq
= gimple_seq_copy (gimple_try_eval (stmt
));
2193 gimple_try_set_eval (copy
, new_seq
);
2194 new_seq
= gimple_seq_copy (gimple_try_cleanup (stmt
));
2195 gimple_try_set_cleanup (copy
, new_seq
);
2198 case GIMPLE_OMP_FOR
:
2199 new_seq
= gimple_seq_copy (gimple_omp_for_pre_body (stmt
));
2200 gimple_omp_for_set_pre_body (copy
, new_seq
);
2201 t
= unshare_expr (gimple_omp_for_clauses (stmt
));
2202 gimple_omp_for_set_clauses (copy
, t
);
2203 copy
->gimple_omp_for
.iter
2204 = ggc_alloc_vec_gimple_omp_for_iter
2205 (gimple_omp_for_collapse (stmt
));
2206 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
2208 gimple_omp_for_set_cond (copy
, i
,
2209 gimple_omp_for_cond (stmt
, i
));
2210 gimple_omp_for_set_index (copy
, i
,
2211 gimple_omp_for_index (stmt
, i
));
2212 t
= unshare_expr (gimple_omp_for_initial (stmt
, i
));
2213 gimple_omp_for_set_initial (copy
, i
, t
);
2214 t
= unshare_expr (gimple_omp_for_final (stmt
, i
));
2215 gimple_omp_for_set_final (copy
, i
, t
);
2216 t
= unshare_expr (gimple_omp_for_incr (stmt
, i
));
2217 gimple_omp_for_set_incr (copy
, i
, t
);
2221 case GIMPLE_OMP_PARALLEL
:
2222 t
= unshare_expr (gimple_omp_parallel_clauses (stmt
));
2223 gimple_omp_parallel_set_clauses (copy
, t
);
2224 t
= unshare_expr (gimple_omp_parallel_child_fn (stmt
));
2225 gimple_omp_parallel_set_child_fn (copy
, t
);
2226 t
= unshare_expr (gimple_omp_parallel_data_arg (stmt
));
2227 gimple_omp_parallel_set_data_arg (copy
, t
);
2230 case GIMPLE_OMP_TASK
:
2231 t
= unshare_expr (gimple_omp_task_clauses (stmt
));
2232 gimple_omp_task_set_clauses (copy
, t
);
2233 t
= unshare_expr (gimple_omp_task_child_fn (stmt
));
2234 gimple_omp_task_set_child_fn (copy
, t
);
2235 t
= unshare_expr (gimple_omp_task_data_arg (stmt
));
2236 gimple_omp_task_set_data_arg (copy
, t
);
2237 t
= unshare_expr (gimple_omp_task_copy_fn (stmt
));
2238 gimple_omp_task_set_copy_fn (copy
, t
);
2239 t
= unshare_expr (gimple_omp_task_arg_size (stmt
));
2240 gimple_omp_task_set_arg_size (copy
, t
);
2241 t
= unshare_expr (gimple_omp_task_arg_align (stmt
));
2242 gimple_omp_task_set_arg_align (copy
, t
);
2245 case GIMPLE_OMP_CRITICAL
:
2246 t
= unshare_expr (gimple_omp_critical_name (stmt
));
2247 gimple_omp_critical_set_name (copy
, t
);
2250 case GIMPLE_OMP_SECTIONS
:
2251 t
= unshare_expr (gimple_omp_sections_clauses (stmt
));
2252 gimple_omp_sections_set_clauses (copy
, t
);
2253 t
= unshare_expr (gimple_omp_sections_control (stmt
));
2254 gimple_omp_sections_set_control (copy
, t
);
2257 case GIMPLE_OMP_SINGLE
:
2258 case GIMPLE_OMP_TARGET
:
2259 case GIMPLE_OMP_TEAMS
:
2260 case GIMPLE_OMP_SECTION
:
2261 case GIMPLE_OMP_MASTER
:
2262 case GIMPLE_OMP_TASKGROUP
:
2263 case GIMPLE_OMP_ORDERED
:
2265 new_seq
= gimple_seq_copy (gimple_omp_body (stmt
));
2266 gimple_omp_set_body (copy
, new_seq
);
2269 case GIMPLE_TRANSACTION
:
2270 new_seq
= gimple_seq_copy (gimple_transaction_body (stmt
));
2271 gimple_transaction_set_body (copy
, new_seq
);
2274 case GIMPLE_WITH_CLEANUP_EXPR
:
2275 new_seq
= gimple_seq_copy (gimple_wce_cleanup (stmt
));
2276 gimple_wce_set_cleanup (copy
, new_seq
);
2284 /* Make copy of operands. */
2285 for (i
= 0; i
< num_ops
; i
++)
2286 gimple_set_op (copy
, i
, unshare_expr (gimple_op (stmt
, i
)));
2288 if (gimple_has_mem_ops (stmt
))
2290 gimple_set_vdef (copy
, gimple_vdef (stmt
));
2291 gimple_set_vuse (copy
, gimple_vuse (stmt
));
2294 /* Clear out SSA operand vectors on COPY. */
2295 if (gimple_has_ops (stmt
))
2297 gimple_set_use_ops (copy
, NULL
);
2299 /* SSA operands need to be updated. */
2300 gimple_set_modified (copy
, true);
2307 /* Return true if statement S has side-effects. We consider a
2308 statement to have side effects if:
2310 - It is a GIMPLE_CALL not marked with ECF_PURE or ECF_CONST.
2311 - Any of its operands are marked TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS. */
2314 gimple_has_side_effects (const_gimple s
)
2316 if (is_gimple_debug (s
))
2319 /* We don't have to scan the arguments to check for
2320 volatile arguments, though, at present, we still
2321 do a scan to check for TREE_SIDE_EFFECTS. */
2322 if (gimple_has_volatile_ops (s
))
2325 if (gimple_code (s
) == GIMPLE_ASM
2326 && gimple_asm_volatile_p (s
))
2329 if (is_gimple_call (s
))
2331 int flags
= gimple_call_flags (s
);
2333 /* An infinite loop is considered a side effect. */
2334 if (!(flags
& (ECF_CONST
| ECF_PURE
))
2335 || (flags
& ECF_LOOPING_CONST_OR_PURE
))
2344 /* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
2345 Return true if S can trap. When INCLUDE_MEM is true, check whether
2346 the memory operations could trap. When INCLUDE_STORES is true and
2347 S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
2350 gimple_could_trap_p_1 (gimple s
, bool include_mem
, bool include_stores
)
2352 tree t
, div
= NULL_TREE
;
2357 unsigned i
, start
= (is_gimple_assign (s
) && !include_stores
) ? 1 : 0;
2359 for (i
= start
; i
< gimple_num_ops (s
); i
++)
2360 if (tree_could_trap_p (gimple_op (s
, i
)))
2364 switch (gimple_code (s
))
2367 return gimple_asm_volatile_p (s
);
2370 t
= gimple_call_fndecl (s
);
2371 /* Assume that calls to weak functions may trap. */
2372 if (!t
|| !DECL_P (t
) || DECL_WEAK (t
))
2377 t
= gimple_expr_type (s
);
2378 op
= gimple_assign_rhs_code (s
);
2379 if (get_gimple_rhs_class (op
) == GIMPLE_BINARY_RHS
)
2380 div
= gimple_assign_rhs2 (s
);
2381 return (operation_could_trap_p (op
, FLOAT_TYPE_P (t
),
2382 (INTEGRAL_TYPE_P (t
)
2383 && TYPE_OVERFLOW_TRAPS (t
)),
2393 /* Return true if statement S can trap. */
2396 gimple_could_trap_p (gimple s
)
2398 return gimple_could_trap_p_1 (s
, true, true);
2401 /* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
2404 gimple_assign_rhs_could_trap_p (gimple s
)
2406 gcc_assert (is_gimple_assign (s
));
2407 return gimple_could_trap_p_1 (s
, true, false);
2411 /* Print debugging information for gimple stmts generated. */
2414 dump_gimple_statistics (void)
2416 int i
, total_tuples
= 0, total_bytes
= 0;
2418 if (! GATHER_STATISTICS
)
2420 fprintf (stderr
, "No gimple statistics\n");
2424 fprintf (stderr
, "\nGIMPLE statements\n");
2425 fprintf (stderr
, "Kind Stmts Bytes\n");
2426 fprintf (stderr
, "---------------------------------------\n");
2427 for (i
= 0; i
< (int) gimple_alloc_kind_all
; ++i
)
2429 fprintf (stderr
, "%-20s %7d %10d\n", gimple_alloc_kind_names
[i
],
2430 gimple_alloc_counts
[i
], gimple_alloc_sizes
[i
]);
2431 total_tuples
+= gimple_alloc_counts
[i
];
2432 total_bytes
+= gimple_alloc_sizes
[i
];
2434 fprintf (stderr
, "---------------------------------------\n");
2435 fprintf (stderr
, "%-20s %7d %10d\n", "Total", total_tuples
, total_bytes
);
2436 fprintf (stderr
, "---------------------------------------\n");
2440 /* Return the number of operands needed on the RHS of a GIMPLE
2441 assignment for an expression with tree code CODE. */
2444 get_gimple_rhs_num_ops (enum tree_code code
)
2446 enum gimple_rhs_class rhs_class
= get_gimple_rhs_class (code
);
2448 if (rhs_class
== GIMPLE_UNARY_RHS
|| rhs_class
== GIMPLE_SINGLE_RHS
)
2450 else if (rhs_class
== GIMPLE_BINARY_RHS
)
2452 else if (rhs_class
== GIMPLE_TERNARY_RHS
)
2458 #define DEFTREECODE(SYM, STRING, TYPE, NARGS) \
2460 ((TYPE) == tcc_unary ? GIMPLE_UNARY_RHS \
2461 : ((TYPE) == tcc_binary \
2462 || (TYPE) == tcc_comparison) ? GIMPLE_BINARY_RHS \
2463 : ((TYPE) == tcc_constant \
2464 || (TYPE) == tcc_declaration \
2465 || (TYPE) == tcc_reference) ? GIMPLE_SINGLE_RHS \
2466 : ((SYM) == TRUTH_AND_EXPR \
2467 || (SYM) == TRUTH_OR_EXPR \
2468 || (SYM) == TRUTH_XOR_EXPR) ? GIMPLE_BINARY_RHS \
2469 : (SYM) == TRUTH_NOT_EXPR ? GIMPLE_UNARY_RHS \
2470 : ((SYM) == COND_EXPR \
2471 || (SYM) == WIDEN_MULT_PLUS_EXPR \
2472 || (SYM) == WIDEN_MULT_MINUS_EXPR \
2473 || (SYM) == DOT_PROD_EXPR \
2474 || (SYM) == REALIGN_LOAD_EXPR \
2475 || (SYM) == VEC_COND_EXPR \
2476 || (SYM) == VEC_PERM_EXPR \
2477 || (SYM) == FMA_EXPR) ? GIMPLE_TERNARY_RHS \
2478 : ((SYM) == CONSTRUCTOR \
2479 || (SYM) == OBJ_TYPE_REF \
2480 || (SYM) == ASSERT_EXPR \
2481 || (SYM) == ADDR_EXPR \
2482 || (SYM) == WITH_SIZE_EXPR \
2483 || (SYM) == SSA_NAME) ? GIMPLE_SINGLE_RHS \
2484 : GIMPLE_INVALID_RHS),
2485 #define END_OF_BASE_TREE_CODES (unsigned char) GIMPLE_INVALID_RHS,
2487 const unsigned char gimple_rhs_class_table
[] = {
2488 #include "all-tree.def"
2492 #undef END_OF_BASE_TREE_CODES
2494 /* Given a memory reference expression T, return its base address.
2495 The base address of a memory reference expression is the main
2496 object being referenced. For instance, the base address for
2497 'array[i].fld[j]' is 'array'. You can think of this as stripping
2498 away the offset part from a memory address.
2500 This function calls handled_component_p to strip away all the inner
2501 parts of the memory reference until it reaches the base object. */
2504 get_base_address (tree t
)
2506 while (handled_component_p (t
))
2507 t
= TREE_OPERAND (t
, 0);
2509 if ((TREE_CODE (t
) == MEM_REF
2510 || TREE_CODE (t
) == TARGET_MEM_REF
)
2511 && TREE_CODE (TREE_OPERAND (t
, 0)) == ADDR_EXPR
)
2512 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
2514 /* ??? Either the alias oracle or all callers need to properly deal
2515 with WITH_SIZE_EXPRs before we can look through those. */
2516 if (TREE_CODE (t
) == WITH_SIZE_EXPR
)
2523 recalculate_side_effects (tree t
)
2525 enum tree_code code
= TREE_CODE (t
);
2526 int len
= TREE_OPERAND_LENGTH (t
);
2529 switch (TREE_CODE_CLASS (code
))
2531 case tcc_expression
:
2537 case PREDECREMENT_EXPR
:
2538 case PREINCREMENT_EXPR
:
2539 case POSTDECREMENT_EXPR
:
2540 case POSTINCREMENT_EXPR
:
2541 /* All of these have side-effects, no matter what their
2550 case tcc_comparison
: /* a comparison expression */
2551 case tcc_unary
: /* a unary arithmetic expression */
2552 case tcc_binary
: /* a binary arithmetic expression */
2553 case tcc_reference
: /* a reference */
2554 case tcc_vl_exp
: /* a function call */
2555 TREE_SIDE_EFFECTS (t
) = TREE_THIS_VOLATILE (t
);
2556 for (i
= 0; i
< len
; ++i
)
2558 tree op
= TREE_OPERAND (t
, i
);
2559 if (op
&& TREE_SIDE_EFFECTS (op
))
2560 TREE_SIDE_EFFECTS (t
) = 1;
2565 /* No side-effects. */
2573 /* Canonicalize a tree T for use in a COND_EXPR as conditional. Returns
2574 a canonicalized tree that is valid for a COND_EXPR or NULL_TREE, if
2575 we failed to create one. */
2578 canonicalize_cond_expr_cond (tree t
)
2580 /* Strip conversions around boolean operations. */
2581 if (CONVERT_EXPR_P (t
)
2582 && (truth_value_p (TREE_CODE (TREE_OPERAND (t
, 0)))
2583 || TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
2585 t
= TREE_OPERAND (t
, 0);
2587 /* For !x use x == 0. */
2588 if (TREE_CODE (t
) == TRUTH_NOT_EXPR
)
2590 tree top0
= TREE_OPERAND (t
, 0);
2591 t
= build2 (EQ_EXPR
, TREE_TYPE (t
),
2592 top0
, build_int_cst (TREE_TYPE (top0
), 0));
2594 /* For cmp ? 1 : 0 use cmp. */
2595 else if (TREE_CODE (t
) == COND_EXPR
2596 && COMPARISON_CLASS_P (TREE_OPERAND (t
, 0))
2597 && integer_onep (TREE_OPERAND (t
, 1))
2598 && integer_zerop (TREE_OPERAND (t
, 2)))
2600 tree top0
= TREE_OPERAND (t
, 0);
2601 t
= build2 (TREE_CODE (top0
), TREE_TYPE (t
),
2602 TREE_OPERAND (top0
, 0), TREE_OPERAND (top0
, 1));
2604 /* For x ^ y use x != y. */
2605 else if (TREE_CODE (t
) == BIT_XOR_EXPR
)
2606 t
= build2 (NE_EXPR
, TREE_TYPE (t
),
2607 TREE_OPERAND (t
, 0), TREE_OPERAND (t
, 1));
2609 if (is_gimple_condexpr (t
))
2615 /* Build a GIMPLE_CALL identical to STMT but skipping the arguments in
2616 the positions marked by the set ARGS_TO_SKIP. */
2619 gimple_call_copy_skip_args (gimple stmt
, bitmap args_to_skip
)
2622 int nargs
= gimple_call_num_args (stmt
);
2624 vargs
.create (nargs
);
2627 for (i
= 0; i
< nargs
; i
++)
2628 if (!bitmap_bit_p (args_to_skip
, i
))
2629 vargs
.quick_push (gimple_call_arg (stmt
, i
));
2631 if (gimple_call_internal_p (stmt
))
2632 new_stmt
= gimple_build_call_internal_vec (gimple_call_internal_fn (stmt
),
2635 new_stmt
= gimple_build_call_vec (gimple_call_fn (stmt
), vargs
);
2637 if (gimple_call_lhs (stmt
))
2638 gimple_call_set_lhs (new_stmt
, gimple_call_lhs (stmt
));
2640 gimple_set_vuse (new_stmt
, gimple_vuse (stmt
));
2641 gimple_set_vdef (new_stmt
, gimple_vdef (stmt
));
2643 if (gimple_has_location (stmt
))
2644 gimple_set_location (new_stmt
, gimple_location (stmt
));
2645 gimple_call_copy_flags (new_stmt
, stmt
);
2646 gimple_call_set_chain (new_stmt
, gimple_call_chain (stmt
));
2648 gimple_set_modified (new_stmt
, true);
2655 /* Return true if the field decls F1 and F2 are at the same offset.
2657 This is intended to be used on GIMPLE types only. */
2660 gimple_compare_field_offset (tree f1
, tree f2
)
2662 if (DECL_OFFSET_ALIGN (f1
) == DECL_OFFSET_ALIGN (f2
))
2664 tree offset1
= DECL_FIELD_OFFSET (f1
);
2665 tree offset2
= DECL_FIELD_OFFSET (f2
);
2666 return ((offset1
== offset2
2667 /* Once gimplification is done, self-referential offsets are
2668 instantiated as operand #2 of the COMPONENT_REF built for
2669 each access and reset. Therefore, they are not relevant
2670 anymore and fields are interchangeable provided that they
2671 represent the same access. */
2672 || (TREE_CODE (offset1
) == PLACEHOLDER_EXPR
2673 && TREE_CODE (offset2
) == PLACEHOLDER_EXPR
2674 && (DECL_SIZE (f1
) == DECL_SIZE (f2
)
2675 || (TREE_CODE (DECL_SIZE (f1
)) == PLACEHOLDER_EXPR
2676 && TREE_CODE (DECL_SIZE (f2
)) == PLACEHOLDER_EXPR
)
2677 || operand_equal_p (DECL_SIZE (f1
), DECL_SIZE (f2
), 0))
2678 && DECL_ALIGN (f1
) == DECL_ALIGN (f2
))
2679 || operand_equal_p (offset1
, offset2
, 0))
2680 && tree_int_cst_equal (DECL_FIELD_BIT_OFFSET (f1
),
2681 DECL_FIELD_BIT_OFFSET (f2
)));
2684 /* Fortran and C do not always agree on what DECL_OFFSET_ALIGN
2685 should be, so handle differing ones specially by decomposing
2686 the offset into a byte and bit offset manually. */
2687 if (host_integerp (DECL_FIELD_OFFSET (f1
), 0)
2688 && host_integerp (DECL_FIELD_OFFSET (f2
), 0))
2690 unsigned HOST_WIDE_INT byte_offset1
, byte_offset2
;
2691 unsigned HOST_WIDE_INT bit_offset1
, bit_offset2
;
2692 bit_offset1
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f1
));
2693 byte_offset1
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f1
))
2694 + bit_offset1
/ BITS_PER_UNIT
);
2695 bit_offset2
= TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (f2
));
2696 byte_offset2
= (TREE_INT_CST_LOW (DECL_FIELD_OFFSET (f2
))
2697 + bit_offset2
/ BITS_PER_UNIT
);
2698 if (byte_offset1
!= byte_offset2
)
2700 return bit_offset1
% BITS_PER_UNIT
== bit_offset2
% BITS_PER_UNIT
;
2707 /* Return a type the same as TYPE except unsigned or
2708 signed according to UNSIGNEDP. */
2711 gimple_signed_or_unsigned_type (bool unsignedp
, tree type
)
2715 type1
= TYPE_MAIN_VARIANT (type
);
2716 if (type1
== signed_char_type_node
2717 || type1
== char_type_node
2718 || type1
== unsigned_char_type_node
)
2719 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2720 if (type1
== integer_type_node
|| type1
== unsigned_type_node
)
2721 return unsignedp
? unsigned_type_node
: integer_type_node
;
2722 if (type1
== short_integer_type_node
|| type1
== short_unsigned_type_node
)
2723 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2724 if (type1
== long_integer_type_node
|| type1
== long_unsigned_type_node
)
2725 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2726 if (type1
== long_long_integer_type_node
2727 || type1
== long_long_unsigned_type_node
)
2729 ? long_long_unsigned_type_node
2730 : long_long_integer_type_node
;
2731 if (int128_integer_type_node
&& (type1
== int128_integer_type_node
|| type1
== int128_unsigned_type_node
))
2733 ? int128_unsigned_type_node
2734 : int128_integer_type_node
;
2735 #if HOST_BITS_PER_WIDE_INT >= 64
2736 if (type1
== intTI_type_node
|| type1
== unsigned_intTI_type_node
)
2737 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2739 if (type1
== intDI_type_node
|| type1
== unsigned_intDI_type_node
)
2740 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2741 if (type1
== intSI_type_node
|| type1
== unsigned_intSI_type_node
)
2742 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2743 if (type1
== intHI_type_node
|| type1
== unsigned_intHI_type_node
)
2744 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2745 if (type1
== intQI_type_node
|| type1
== unsigned_intQI_type_node
)
2746 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2748 #define GIMPLE_FIXED_TYPES(NAME) \
2749 if (type1 == short_ ## NAME ## _type_node \
2750 || type1 == unsigned_short_ ## NAME ## _type_node) \
2751 return unsignedp ? unsigned_short_ ## NAME ## _type_node \
2752 : short_ ## NAME ## _type_node; \
2753 if (type1 == NAME ## _type_node \
2754 || type1 == unsigned_ ## NAME ## _type_node) \
2755 return unsignedp ? unsigned_ ## NAME ## _type_node \
2756 : NAME ## _type_node; \
2757 if (type1 == long_ ## NAME ## _type_node \
2758 || type1 == unsigned_long_ ## NAME ## _type_node) \
2759 return unsignedp ? unsigned_long_ ## NAME ## _type_node \
2760 : long_ ## NAME ## _type_node; \
2761 if (type1 == long_long_ ## NAME ## _type_node \
2762 || type1 == unsigned_long_long_ ## NAME ## _type_node) \
2763 return unsignedp ? unsigned_long_long_ ## NAME ## _type_node \
2764 : long_long_ ## NAME ## _type_node;
2766 #define GIMPLE_FIXED_MODE_TYPES(NAME) \
2767 if (type1 == NAME ## _type_node \
2768 || type1 == u ## NAME ## _type_node) \
2769 return unsignedp ? u ## NAME ## _type_node \
2770 : NAME ## _type_node;
2772 #define GIMPLE_FIXED_TYPES_SAT(NAME) \
2773 if (type1 == sat_ ## short_ ## NAME ## _type_node \
2774 || type1 == sat_ ## unsigned_short_ ## NAME ## _type_node) \
2775 return unsignedp ? sat_ ## unsigned_short_ ## NAME ## _type_node \
2776 : sat_ ## short_ ## NAME ## _type_node; \
2777 if (type1 == sat_ ## NAME ## _type_node \
2778 || type1 == sat_ ## unsigned_ ## NAME ## _type_node) \
2779 return unsignedp ? sat_ ## unsigned_ ## NAME ## _type_node \
2780 : sat_ ## NAME ## _type_node; \
2781 if (type1 == sat_ ## long_ ## NAME ## _type_node \
2782 || type1 == sat_ ## unsigned_long_ ## NAME ## _type_node) \
2783 return unsignedp ? sat_ ## unsigned_long_ ## NAME ## _type_node \
2784 : sat_ ## long_ ## NAME ## _type_node; \
2785 if (type1 == sat_ ## long_long_ ## NAME ## _type_node \
2786 || type1 == sat_ ## unsigned_long_long_ ## NAME ## _type_node) \
2787 return unsignedp ? sat_ ## unsigned_long_long_ ## NAME ## _type_node \
2788 : sat_ ## long_long_ ## NAME ## _type_node;
2790 #define GIMPLE_FIXED_MODE_TYPES_SAT(NAME) \
2791 if (type1 == sat_ ## NAME ## _type_node \
2792 || type1 == sat_ ## u ## NAME ## _type_node) \
2793 return unsignedp ? sat_ ## u ## NAME ## _type_node \
2794 : sat_ ## NAME ## _type_node;
2796 GIMPLE_FIXED_TYPES (fract
);
2797 GIMPLE_FIXED_TYPES_SAT (fract
);
2798 GIMPLE_FIXED_TYPES (accum
);
2799 GIMPLE_FIXED_TYPES_SAT (accum
);
2801 GIMPLE_FIXED_MODE_TYPES (qq
);
2802 GIMPLE_FIXED_MODE_TYPES (hq
);
2803 GIMPLE_FIXED_MODE_TYPES (sq
);
2804 GIMPLE_FIXED_MODE_TYPES (dq
);
2805 GIMPLE_FIXED_MODE_TYPES (tq
);
2806 GIMPLE_FIXED_MODE_TYPES_SAT (qq
);
2807 GIMPLE_FIXED_MODE_TYPES_SAT (hq
);
2808 GIMPLE_FIXED_MODE_TYPES_SAT (sq
);
2809 GIMPLE_FIXED_MODE_TYPES_SAT (dq
);
2810 GIMPLE_FIXED_MODE_TYPES_SAT (tq
);
2811 GIMPLE_FIXED_MODE_TYPES (ha
);
2812 GIMPLE_FIXED_MODE_TYPES (sa
);
2813 GIMPLE_FIXED_MODE_TYPES (da
);
2814 GIMPLE_FIXED_MODE_TYPES (ta
);
2815 GIMPLE_FIXED_MODE_TYPES_SAT (ha
);
2816 GIMPLE_FIXED_MODE_TYPES_SAT (sa
);
2817 GIMPLE_FIXED_MODE_TYPES_SAT (da
);
2818 GIMPLE_FIXED_MODE_TYPES_SAT (ta
);
2820 /* For ENUMERAL_TYPEs in C++, must check the mode of the types, not
2821 the precision; they have precision set to match their range, but
2822 may use a wider mode to match an ABI. If we change modes, we may
2823 wind up with bad conversions. For INTEGER_TYPEs in C, must check
2824 the precision as well, so as to yield correct results for
2825 bit-field types. C++ does not have these separate bit-field
2826 types, and producing a signed or unsigned variant of an
2827 ENUMERAL_TYPE may cause other problems as well. */
2828 if (!INTEGRAL_TYPE_P (type
)
2829 || TYPE_UNSIGNED (type
) == unsignedp
)
2832 #define TYPE_OK(node) \
2833 (TYPE_MODE (type) == TYPE_MODE (node) \
2834 && TYPE_PRECISION (type) == TYPE_PRECISION (node))
2835 if (TYPE_OK (signed_char_type_node
))
2836 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
2837 if (TYPE_OK (integer_type_node
))
2838 return unsignedp
? unsigned_type_node
: integer_type_node
;
2839 if (TYPE_OK (short_integer_type_node
))
2840 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
2841 if (TYPE_OK (long_integer_type_node
))
2842 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
2843 if (TYPE_OK (long_long_integer_type_node
))
2845 ? long_long_unsigned_type_node
2846 : long_long_integer_type_node
);
2847 if (int128_integer_type_node
&& TYPE_OK (int128_integer_type_node
))
2849 ? int128_unsigned_type_node
2850 : int128_integer_type_node
);
2852 #if HOST_BITS_PER_WIDE_INT >= 64
2853 if (TYPE_OK (intTI_type_node
))
2854 return unsignedp
? unsigned_intTI_type_node
: intTI_type_node
;
2856 if (TYPE_OK (intDI_type_node
))
2857 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
2858 if (TYPE_OK (intSI_type_node
))
2859 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
2860 if (TYPE_OK (intHI_type_node
))
2861 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
2862 if (TYPE_OK (intQI_type_node
))
2863 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
2865 #undef GIMPLE_FIXED_TYPES
2866 #undef GIMPLE_FIXED_MODE_TYPES
2867 #undef GIMPLE_FIXED_TYPES_SAT
2868 #undef GIMPLE_FIXED_MODE_TYPES_SAT
2871 return build_nonstandard_integer_type (TYPE_PRECISION (type
), unsignedp
);
2875 /* Return an unsigned type the same as TYPE in other respects. */
2878 gimple_unsigned_type (tree type
)
2880 return gimple_signed_or_unsigned_type (true, type
);
2884 /* Return a signed type the same as TYPE in other respects. */
2887 gimple_signed_type (tree type
)
2889 return gimple_signed_or_unsigned_type (false, type
);
2893 /* Return the typed-based alias set for T, which may be an expression
2894 or a type. Return -1 if we don't do anything special. */
2897 gimple_get_alias_set (tree t
)
2901 /* Permit type-punning when accessing a union, provided the access
2902 is directly through the union. For example, this code does not
2903 permit taking the address of a union member and then storing
2904 through it. Even the type-punning allowed here is a GCC
2905 extension, albeit a common and useful one; the C standard says
2906 that such accesses have implementation-defined behavior. */
2908 TREE_CODE (u
) == COMPONENT_REF
|| TREE_CODE (u
) == ARRAY_REF
;
2909 u
= TREE_OPERAND (u
, 0))
2910 if (TREE_CODE (u
) == COMPONENT_REF
2911 && TREE_CODE (TREE_TYPE (TREE_OPERAND (u
, 0))) == UNION_TYPE
)
2914 /* That's all the expressions we handle specially. */
2918 /* For convenience, follow the C standard when dealing with
2919 character types. Any object may be accessed via an lvalue that
2920 has character type. */
2921 if (t
== char_type_node
2922 || t
== signed_char_type_node
2923 || t
== unsigned_char_type_node
)
2926 /* Allow aliasing between signed and unsigned variants of the same
2927 type. We treat the signed variant as canonical. */
2928 if (TREE_CODE (t
) == INTEGER_TYPE
&& TYPE_UNSIGNED (t
))
2930 tree t1
= gimple_signed_type (t
);
2932 /* t1 == t can happen for boolean nodes which are always unsigned. */
2934 return get_alias_set (t1
);
2941 /* From a tree operand OP return the base of a load or store operation
2942 or NULL_TREE if OP is not a load or a store. */
2945 get_base_loadstore (tree op
)
2947 while (handled_component_p (op
))
2948 op
= TREE_OPERAND (op
, 0);
2950 || INDIRECT_REF_P (op
)
2951 || TREE_CODE (op
) == MEM_REF
2952 || TREE_CODE (op
) == TARGET_MEM_REF
)
2957 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
2958 VISIT_ADDR if non-NULL on loads, store and address-taken operands
2959 passing the STMT, the base of the operand and DATA to it. The base
2960 will be either a decl, an indirect reference (including TARGET_MEM_REF)
2961 or the argument of an address expression.
2962 Returns the results of these callbacks or'ed. */
2965 walk_stmt_load_store_addr_ops (gimple stmt
, void *data
,
2966 bool (*visit_load
)(gimple
, tree
, void *),
2967 bool (*visit_store
)(gimple
, tree
, void *),
2968 bool (*visit_addr
)(gimple
, tree
, void *))
2972 if (gimple_assign_single_p (stmt
))
2977 lhs
= get_base_loadstore (gimple_assign_lhs (stmt
));
2979 ret
|= visit_store (stmt
, lhs
, data
);
2981 rhs
= gimple_assign_rhs1 (stmt
);
2982 while (handled_component_p (rhs
))
2983 rhs
= TREE_OPERAND (rhs
, 0);
2986 if (TREE_CODE (rhs
) == ADDR_EXPR
)
2987 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
2988 else if (TREE_CODE (rhs
) == TARGET_MEM_REF
2989 && TREE_CODE (TMR_BASE (rhs
)) == ADDR_EXPR
)
2990 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (rhs
), 0), data
);
2991 else if (TREE_CODE (rhs
) == OBJ_TYPE_REF
2992 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs
)) == ADDR_EXPR
)
2993 ret
|= visit_addr (stmt
, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs
),
2995 else if (TREE_CODE (rhs
) == CONSTRUCTOR
)
3000 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs
), ix
, val
)
3001 if (TREE_CODE (val
) == ADDR_EXPR
)
3002 ret
|= visit_addr (stmt
, TREE_OPERAND (val
, 0), data
);
3003 else if (TREE_CODE (val
) == OBJ_TYPE_REF
3004 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val
)) == ADDR_EXPR
)
3005 ret
|= visit_addr (stmt
,
3006 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val
),
3009 lhs
= gimple_assign_lhs (stmt
);
3010 if (TREE_CODE (lhs
) == TARGET_MEM_REF
3011 && TREE_CODE (TMR_BASE (lhs
)) == ADDR_EXPR
)
3012 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (lhs
), 0), data
);
3016 rhs
= get_base_loadstore (rhs
);
3018 ret
|= visit_load (stmt
, rhs
, data
);
3022 && (is_gimple_assign (stmt
)
3023 || gimple_code (stmt
) == GIMPLE_COND
))
3025 for (i
= 0; i
< gimple_num_ops (stmt
); ++i
)
3027 tree op
= gimple_op (stmt
, i
);
3028 if (op
== NULL_TREE
)
3030 else if (TREE_CODE (op
) == ADDR_EXPR
)
3031 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
3032 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
3033 tree with two operands. */
3034 else if (i
== 1 && COMPARISON_CLASS_P (op
))
3036 if (TREE_CODE (TREE_OPERAND (op
, 0)) == ADDR_EXPR
)
3037 ret
|= visit_addr (stmt
, TREE_OPERAND (TREE_OPERAND (op
, 0),
3039 if (TREE_CODE (TREE_OPERAND (op
, 1)) == ADDR_EXPR
)
3040 ret
|= visit_addr (stmt
, TREE_OPERAND (TREE_OPERAND (op
, 1),
3045 else if (is_gimple_call (stmt
))
3049 tree lhs
= gimple_call_lhs (stmt
);
3052 lhs
= get_base_loadstore (lhs
);
3054 ret
|= visit_store (stmt
, lhs
, data
);
3057 if (visit_load
|| visit_addr
)
3058 for (i
= 0; i
< gimple_call_num_args (stmt
); ++i
)
3060 tree rhs
= gimple_call_arg (stmt
, i
);
3062 && TREE_CODE (rhs
) == ADDR_EXPR
)
3063 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), data
);
3064 else if (visit_load
)
3066 rhs
= get_base_loadstore (rhs
);
3068 ret
|= visit_load (stmt
, rhs
, data
);
3072 && gimple_call_chain (stmt
)
3073 && TREE_CODE (gimple_call_chain (stmt
)) == ADDR_EXPR
)
3074 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_call_chain (stmt
), 0),
3077 && gimple_call_return_slot_opt_p (stmt
)
3078 && gimple_call_lhs (stmt
) != NULL_TREE
3079 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt
))))
3080 ret
|= visit_addr (stmt
, gimple_call_lhs (stmt
), data
);
3082 else if (gimple_code (stmt
) == GIMPLE_ASM
)
3085 const char *constraint
;
3086 const char **oconstraints
;
3087 bool allows_mem
, allows_reg
, is_inout
;
3088 noutputs
= gimple_asm_noutputs (stmt
);
3089 oconstraints
= XALLOCAVEC (const char *, noutputs
);
3090 if (visit_store
|| visit_addr
)
3091 for (i
= 0; i
< gimple_asm_noutputs (stmt
); ++i
)
3093 tree link
= gimple_asm_output_op (stmt
, i
);
3094 tree op
= get_base_loadstore (TREE_VALUE (link
));
3095 if (op
&& visit_store
)
3096 ret
|= visit_store (stmt
, op
, data
);
3099 constraint
= TREE_STRING_POINTER
3100 (TREE_VALUE (TREE_PURPOSE (link
)));
3101 oconstraints
[i
] = constraint
;
3102 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
,
3103 &allows_reg
, &is_inout
);
3104 if (op
&& !allows_reg
&& allows_mem
)
3105 ret
|= visit_addr (stmt
, op
, data
);
3108 if (visit_load
|| visit_addr
)
3109 for (i
= 0; i
< gimple_asm_ninputs (stmt
); ++i
)
3111 tree link
= gimple_asm_input_op (stmt
, i
);
3112 tree op
= TREE_VALUE (link
);
3114 && TREE_CODE (op
) == ADDR_EXPR
)
3115 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
3116 else if (visit_load
|| visit_addr
)
3118 op
= get_base_loadstore (op
);
3122 ret
|= visit_load (stmt
, op
, data
);
3125 constraint
= TREE_STRING_POINTER
3126 (TREE_VALUE (TREE_PURPOSE (link
)));
3127 parse_input_constraint (&constraint
, 0, 0, noutputs
,
3129 &allows_mem
, &allows_reg
);
3130 if (!allows_reg
&& allows_mem
)
3131 ret
|= visit_addr (stmt
, op
, data
);
3137 else if (gimple_code (stmt
) == GIMPLE_RETURN
)
3139 tree op
= gimple_return_retval (stmt
);
3143 && TREE_CODE (op
) == ADDR_EXPR
)
3144 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
3145 else if (visit_load
)
3147 op
= get_base_loadstore (op
);
3149 ret
|= visit_load (stmt
, op
, data
);
3154 && gimple_code (stmt
) == GIMPLE_PHI
)
3156 for (i
= 0; i
< gimple_phi_num_args (stmt
); ++i
)
3158 tree op
= gimple_phi_arg_def (stmt
, i
);
3159 if (TREE_CODE (op
) == ADDR_EXPR
)
3160 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
3164 && gimple_code (stmt
) == GIMPLE_GOTO
)
3166 tree op
= gimple_goto_dest (stmt
);
3167 if (TREE_CODE (op
) == ADDR_EXPR
)
3168 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), data
);
3174 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
3175 should make a faster clone for this case. */
3178 walk_stmt_load_store_ops (gimple stmt
, void *data
,
3179 bool (*visit_load
)(gimple
, tree
, void *),
3180 bool (*visit_store
)(gimple
, tree
, void *))
3182 return walk_stmt_load_store_addr_ops (stmt
, data
,
3183 visit_load
, visit_store
, NULL
);
3186 /* Helper for gimple_ior_addresses_taken_1. */
3189 gimple_ior_addresses_taken_1 (gimple stmt ATTRIBUTE_UNUSED
,
3190 tree addr
, void *data
)
3192 bitmap addresses_taken
= (bitmap
)data
;
3193 addr
= get_base_address (addr
);
3197 bitmap_set_bit (addresses_taken
, DECL_UID (addr
));
3203 /* Set the bit for the uid of all decls that have their address taken
3204 in STMT in the ADDRESSES_TAKEN bitmap. Returns true if there
3205 were any in this stmt. */
3208 gimple_ior_addresses_taken (bitmap addresses_taken
, gimple stmt
)
3210 return walk_stmt_load_store_addr_ops (stmt
, addresses_taken
, NULL
, NULL
,
3211 gimple_ior_addresses_taken_1
);
3215 /* Return TRUE iff stmt is a call to a built-in function. */
3218 is_gimple_builtin_call (gimple stmt
)
3222 if (is_gimple_call (stmt
)
3223 && (callee
= gimple_call_fndecl (stmt
))
3224 && is_builtin_fn (callee
)
3225 && DECL_BUILT_IN_CLASS (callee
) == BUILT_IN_NORMAL
)
3231 /* Return true when STMTs arguments match those of FNDECL. */
3234 validate_call (gimple stmt
, tree fndecl
)
3236 tree targs
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
3237 unsigned nargs
= gimple_call_num_args (stmt
);
3238 for (unsigned i
= 0; i
< nargs
; ++i
)
3240 /* Variadic args follow. */
3243 tree arg
= gimple_call_arg (stmt
, i
);
3244 if (INTEGRAL_TYPE_P (TREE_TYPE (arg
))
3245 && INTEGRAL_TYPE_P (TREE_VALUE (targs
)))
3247 else if (POINTER_TYPE_P (TREE_TYPE (arg
))
3248 && POINTER_TYPE_P (TREE_VALUE (targs
)))
3250 else if (TREE_CODE (TREE_TYPE (arg
))
3251 != TREE_CODE (TREE_VALUE (targs
)))
3253 targs
= TREE_CHAIN (targs
);
3255 if (targs
&& !VOID_TYPE_P (TREE_VALUE (targs
)))
3260 /* Return true when STMT is builtins call to CLASS. */
3263 gimple_call_builtin_p (gimple stmt
, enum built_in_class klass
)
3266 if (is_gimple_call (stmt
)
3267 && (fndecl
= gimple_call_fndecl (stmt
)) != NULL_TREE
3268 && DECL_BUILT_IN_CLASS (fndecl
) == klass
)
3269 return validate_call (stmt
, fndecl
);
3273 /* Return true when STMT is builtins call to CODE of CLASS. */
3276 gimple_call_builtin_p (gimple stmt
, enum built_in_function code
)
3279 if (is_gimple_call (stmt
)
3280 && (fndecl
= gimple_call_fndecl (stmt
)) != NULL_TREE
3281 && DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
3282 && DECL_FUNCTION_CODE (fndecl
) == code
)
3283 return validate_call (stmt
, fndecl
);
3287 /* Return true if STMT clobbers memory. STMT is required to be a
3291 gimple_asm_clobbers_memory_p (const_gimple stmt
)
3295 for (i
= 0; i
< gimple_asm_nclobbers (stmt
); i
++)
3297 tree op
= gimple_asm_clobber_op (stmt
, i
);
3298 if (strcmp (TREE_STRING_POINTER (TREE_VALUE (op
)), "memory") == 0)
3305 /* Dump bitmap SET (assumed to contain VAR_DECLs) to FILE. */
3308 dump_decl_set (FILE *file
, bitmap set
)
3315 fprintf (file
, "{ ");
3317 EXECUTE_IF_SET_IN_BITMAP (set
, 0, i
, bi
)
3319 fprintf (file
, "D.%u", i
);
3320 fprintf (file
, " ");
3323 fprintf (file
, "}");
3326 fprintf (file
, "NIL");
3329 /* Return true when CALL is a call stmt that definitely doesn't
3330 free any memory or makes it unavailable otherwise. */
3332 nonfreeing_call_p (gimple call
)
3334 if (gimple_call_builtin_p (call
, BUILT_IN_NORMAL
)
3335 && gimple_call_flags (call
) & ECF_LEAF
)
3336 switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call
)))
3338 /* Just in case these become ECF_LEAF in the future. */
3340 case BUILT_IN_TM_FREE
:
3341 case BUILT_IN_REALLOC
:
3342 case BUILT_IN_STACK_RESTORE
:
3351 /* Callback for walk_stmt_load_store_ops.
3353 Return TRUE if OP will dereference the tree stored in DATA, FALSE
3356 This routine only makes a superficial check for a dereference. Thus
3357 it must only be used if it is safe to return a false negative. */
3359 check_loadstore (gimple stmt ATTRIBUTE_UNUSED
, tree op
, void *data
)
3361 if ((TREE_CODE (op
) == MEM_REF
|| TREE_CODE (op
) == TARGET_MEM_REF
)
3362 && operand_equal_p (TREE_OPERAND (op
, 0), (tree
)data
, 0))
3367 /* If OP can be inferred to be non-zero after STMT executes, return true. */
3370 infer_nonnull_range (gimple stmt
, tree op
)
3372 /* We can only assume that a pointer dereference will yield
3373 non-NULL if -fdelete-null-pointer-checks is enabled. */
3374 if (!flag_delete_null_pointer_checks
3375 || !POINTER_TYPE_P (TREE_TYPE (op
))
3376 || gimple_code (stmt
) == GIMPLE_ASM
)
3379 if (walk_stmt_load_store_ops (stmt
, (void *)op
,
3380 check_loadstore
, check_loadstore
))
3383 if (is_gimple_call (stmt
) && !gimple_call_internal_p (stmt
))
3385 tree fntype
= gimple_call_fntype (stmt
);
3386 tree attrs
= TYPE_ATTRIBUTES (fntype
);
3387 for (; attrs
; attrs
= TREE_CHAIN (attrs
))
3389 attrs
= lookup_attribute ("nonnull", attrs
);
3391 /* If "nonnull" wasn't specified, we know nothing about
3393 if (attrs
== NULL_TREE
)
3396 /* If "nonnull" applies to all the arguments, then ARG
3397 is non-null if it's in the argument list. */
3398 if (TREE_VALUE (attrs
) == NULL_TREE
)
3400 for (unsigned int i
= 0; i
< gimple_call_num_args (stmt
); i
++)
3402 if (operand_equal_p (op
, gimple_call_arg (stmt
, i
), 0)
3403 && POINTER_TYPE_P (TREE_TYPE (gimple_call_arg (stmt
, i
))))
3409 /* Now see if op appears in the nonnull list. */
3410 for (tree t
= TREE_VALUE (attrs
); t
; t
= TREE_CHAIN (t
))
3412 int idx
= TREE_INT_CST_LOW (TREE_VALUE (t
)) - 1;
3413 tree arg
= gimple_call_arg (stmt
, idx
);
3414 if (operand_equal_p (op
, arg
, 0))
3420 /* If this function is marked as returning non-null, then we can
3421 infer OP is non-null if it is used in the return statement. */
3422 if (gimple_code (stmt
) == GIMPLE_RETURN
3423 && gimple_return_retval (stmt
)
3424 && operand_equal_p (gimple_return_retval (stmt
), op
, 0)
3425 && lookup_attribute ("returns_nonnull",
3426 TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl
))))