1 /* Gimple walk support.
3 Copyright (C) 2007-2019 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"
28 #include "gimple-iterator.h"
29 #include "gimple-walk.h"
32 /* Walk all the statements in the sequence *PSEQ calling walk_gimple_stmt
33 on each one. WI is as in walk_gimple_stmt.
35 If walk_gimple_stmt returns non-NULL, the walk is stopped, and the
36 value is stored in WI->CALLBACK_RESULT. Also, the statement that
37 produced the value is returned if this statement has not been
38 removed by a callback (wi->removed_stmt). If the statement has
39 been removed, NULL is returned.
41 Otherwise, all the statements are walked and NULL returned. */
44 walk_gimple_seq_mod (gimple_seq
*pseq
, walk_stmt_fn callback_stmt
,
45 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
47 gimple_stmt_iterator gsi
;
49 for (gsi
= gsi_start (*pseq
); !gsi_end_p (gsi
); )
51 tree ret
= walk_gimple_stmt (&gsi
, callback_stmt
, callback_op
, wi
);
54 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
57 wi
->callback_result
= ret
;
59 return wi
->removed_stmt
? NULL
: gsi_stmt (gsi
);
62 if (!wi
->removed_stmt
)
67 wi
->callback_result
= NULL_TREE
;
73 /* Like walk_gimple_seq_mod, but ensure that the head of SEQ isn't
74 changed by the callbacks. */
77 walk_gimple_seq (gimple_seq seq
, walk_stmt_fn callback_stmt
,
78 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
80 gimple_seq seq2
= seq
;
81 gimple
*ret
= walk_gimple_seq_mod (&seq2
, callback_stmt
, callback_op
, wi
);
82 gcc_assert (seq2
== seq
);
87 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
90 walk_gimple_asm (gasm
*stmt
, walk_tree_fn callback_op
,
91 struct walk_stmt_info
*wi
)
95 const char **oconstraints
;
97 const char *constraint
;
98 bool allows_mem
, allows_reg
, is_inout
;
100 noutputs
= gimple_asm_noutputs (stmt
);
101 oconstraints
= (const char **) alloca ((noutputs
) * sizeof (const char *));
103 for (i
= 0; i
< noutputs
; i
++)
105 op
= gimple_asm_output_op (stmt
, i
);
106 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
107 oconstraints
[i
] = constraint
;
110 if (parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
,
111 &allows_reg
, &is_inout
))
112 wi
->val_only
= (allows_reg
|| !allows_mem
);
116 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
121 n
= gimple_asm_ninputs (stmt
);
122 for (i
= 0; i
< n
; i
++)
124 op
= gimple_asm_input_op (stmt
, i
);
125 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op
)));
129 if (parse_input_constraint (&constraint
, 0, 0, noutputs
, 0,
130 oconstraints
, &allows_mem
, &allows_reg
))
132 wi
->val_only
= (allows_reg
|| !allows_mem
);
133 /* Although input "m" is not really a LHS, we need a lvalue. */
134 wi
->is_lhs
= !wi
->val_only
;
137 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
148 n
= gimple_asm_nlabels (stmt
);
149 for (i
= 0; i
< n
; i
++)
151 op
= gimple_asm_label_op (stmt
, i
);
152 ret
= walk_tree (&TREE_VALUE (op
), callback_op
, wi
, NULL
);
161 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
162 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
164 CALLBACK_OP is called on each operand of STMT via walk_tree.
165 Additional parameters to walk_tree must be stored in WI. For each operand
166 OP, walk_tree is called as:
168 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
170 If CALLBACK_OP returns non-NULL for an operand, the remaining
171 operands are not scanned.
173 The return value is that returned by the last call to walk_tree, or
174 NULL_TREE if no CALLBACK_OP is specified. */
177 walk_gimple_op (gimple
*stmt
, walk_tree_fn callback_op
,
178 struct walk_stmt_info
*wi
)
180 hash_set
<tree
> *pset
= (wi
) ? wi
->pset
: NULL
;
182 tree ret
= NULL_TREE
;
187 switch (gimple_code (stmt
))
190 /* Walk the RHS operands. If the LHS is of a non-renamable type or
191 is a register variable, we may use a COMPONENT_REF on the RHS. */
194 tree lhs
= gimple_assign_lhs (stmt
);
196 = (is_gimple_reg_type (TREE_TYPE (lhs
)) && !is_gimple_reg (lhs
))
197 || gimple_assign_rhs_class (stmt
) != GIMPLE_SINGLE_RHS
;
200 for (i
= 1; i
< gimple_num_ops (stmt
); i
++)
202 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
,
208 /* Walk the LHS. If the RHS is appropriate for a memory, we
209 may use a COMPONENT_REF on the LHS. */
212 /* If the RHS is of a non-renamable type or is a register variable,
213 we may use a COMPONENT_REF on the LHS. */
214 tree rhs1
= gimple_assign_rhs1 (stmt
);
216 = (is_gimple_reg_type (TREE_TYPE (rhs1
)) && !is_gimple_reg (rhs1
))
217 || gimple_assign_rhs_class (stmt
) != GIMPLE_SINGLE_RHS
;
221 ret
= walk_tree (gimple_op_ptr (stmt
, 0), callback_op
, wi
, pset
);
239 ret
= walk_tree (gimple_call_chain_ptr (as_a
<gcall
*> (stmt
)),
240 callback_op
, wi
, pset
);
244 ret
= walk_tree (gimple_call_fn_ptr (stmt
), callback_op
, wi
, pset
);
248 for (i
= 0; i
< gimple_call_num_args (stmt
); i
++)
252 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt
, i
)));
253 ret
= walk_tree (gimple_call_arg_ptr (stmt
, i
), callback_op
, wi
,
259 if (gimple_call_lhs (stmt
))
265 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt
)));
268 ret
= walk_tree (gimple_call_lhs_ptr (stmt
), callback_op
, wi
, pset
);
281 ret
= walk_tree (gimple_catch_types_ptr (as_a
<gcatch
*> (stmt
)),
282 callback_op
, wi
, pset
);
287 case GIMPLE_EH_FILTER
:
288 ret
= walk_tree (gimple_eh_filter_types_ptr (stmt
), callback_op
, wi
,
295 ret
= walk_gimple_asm (as_a
<gasm
*> (stmt
), callback_op
, wi
);
300 case GIMPLE_OMP_CONTINUE
:
302 gomp_continue
*cont_stmt
= as_a
<gomp_continue
*> (stmt
);
303 ret
= walk_tree (gimple_omp_continue_control_def_ptr (cont_stmt
),
304 callback_op
, wi
, pset
);
308 ret
= walk_tree (gimple_omp_continue_control_use_ptr (cont_stmt
),
309 callback_op
, wi
, pset
);
315 case GIMPLE_OMP_CRITICAL
:
317 gomp_critical
*omp_stmt
= as_a
<gomp_critical
*> (stmt
);
318 ret
= walk_tree (gimple_omp_critical_name_ptr (omp_stmt
),
319 callback_op
, wi
, pset
);
322 ret
= walk_tree (gimple_omp_critical_clauses_ptr (omp_stmt
),
323 callback_op
, wi
, pset
);
329 case GIMPLE_OMP_ORDERED
:
331 gomp_ordered
*omp_stmt
= as_a
<gomp_ordered
*> (stmt
);
332 ret
= walk_tree (gimple_omp_ordered_clauses_ptr (omp_stmt
),
333 callback_op
, wi
, pset
);
339 case GIMPLE_OMP_SCAN
:
341 gomp_scan
*scan_stmt
= as_a
<gomp_scan
*> (stmt
);
342 ret
= walk_tree (gimple_omp_scan_clauses_ptr (scan_stmt
),
343 callback_op
, wi
, pset
);
350 ret
= walk_tree (gimple_omp_for_clauses_ptr (stmt
), callback_op
, wi
,
354 for (i
= 0; i
< gimple_omp_for_collapse (stmt
); i
++)
356 ret
= walk_tree (gimple_omp_for_index_ptr (stmt
, i
), callback_op
,
360 ret
= walk_tree (gimple_omp_for_initial_ptr (stmt
, i
), callback_op
,
364 ret
= walk_tree (gimple_omp_for_final_ptr (stmt
, i
), callback_op
,
368 ret
= walk_tree (gimple_omp_for_incr_ptr (stmt
, i
), callback_op
,
375 case GIMPLE_OMP_PARALLEL
:
377 gomp_parallel
*omp_par_stmt
= as_a
<gomp_parallel
*> (stmt
);
378 ret
= walk_tree (gimple_omp_parallel_clauses_ptr (omp_par_stmt
),
379 callback_op
, wi
, pset
);
382 ret
= walk_tree (gimple_omp_parallel_child_fn_ptr (omp_par_stmt
),
383 callback_op
, wi
, pset
);
386 ret
= walk_tree (gimple_omp_parallel_data_arg_ptr (omp_par_stmt
),
387 callback_op
, wi
, pset
);
393 case GIMPLE_OMP_TASK
:
394 ret
= walk_tree (gimple_omp_task_clauses_ptr (stmt
), callback_op
,
398 ret
= walk_tree (gimple_omp_task_child_fn_ptr (stmt
), callback_op
,
402 ret
= walk_tree (gimple_omp_task_data_arg_ptr (stmt
), callback_op
,
406 ret
= walk_tree (gimple_omp_task_copy_fn_ptr (stmt
), callback_op
,
410 ret
= walk_tree (gimple_omp_task_arg_size_ptr (stmt
), callback_op
,
414 ret
= walk_tree (gimple_omp_task_arg_align_ptr (stmt
), callback_op
,
420 case GIMPLE_OMP_SECTIONS
:
421 ret
= walk_tree (gimple_omp_sections_clauses_ptr (stmt
), callback_op
,
425 ret
= walk_tree (gimple_omp_sections_control_ptr (stmt
), callback_op
,
432 case GIMPLE_OMP_SINGLE
:
433 ret
= walk_tree (gimple_omp_single_clauses_ptr (stmt
), callback_op
, wi
,
439 case GIMPLE_OMP_TARGET
:
441 gomp_target
*omp_stmt
= as_a
<gomp_target
*> (stmt
);
442 ret
= walk_tree (gimple_omp_target_clauses_ptr (omp_stmt
),
443 callback_op
, wi
, pset
);
446 ret
= walk_tree (gimple_omp_target_child_fn_ptr (omp_stmt
),
447 callback_op
, wi
, pset
);
450 ret
= walk_tree (gimple_omp_target_data_arg_ptr (omp_stmt
),
451 callback_op
, wi
, pset
);
457 case GIMPLE_OMP_TEAMS
:
458 ret
= walk_tree (gimple_omp_teams_clauses_ptr (stmt
), callback_op
, wi
,
464 case GIMPLE_OMP_ATOMIC_LOAD
:
466 gomp_atomic_load
*omp_stmt
= as_a
<gomp_atomic_load
*> (stmt
);
467 ret
= walk_tree (gimple_omp_atomic_load_lhs_ptr (omp_stmt
),
468 callback_op
, wi
, pset
);
471 ret
= walk_tree (gimple_omp_atomic_load_rhs_ptr (omp_stmt
),
472 callback_op
, wi
, pset
);
478 case GIMPLE_OMP_ATOMIC_STORE
:
480 gomp_atomic_store
*omp_stmt
= as_a
<gomp_atomic_store
*> (stmt
);
481 ret
= walk_tree (gimple_omp_atomic_store_val_ptr (omp_stmt
),
482 callback_op
, wi
, pset
);
488 case GIMPLE_TRANSACTION
:
490 gtransaction
*txn
= as_a
<gtransaction
*> (stmt
);
492 ret
= walk_tree (gimple_transaction_label_norm_ptr (txn
),
493 callback_op
, wi
, pset
);
496 ret
= walk_tree (gimple_transaction_label_uninst_ptr (txn
),
497 callback_op
, wi
, pset
);
500 ret
= walk_tree (gimple_transaction_label_over_ptr (txn
),
501 callback_op
, wi
, pset
);
507 case GIMPLE_OMP_RETURN
:
508 ret
= walk_tree (gimple_omp_return_lhs_ptr (stmt
), callback_op
, wi
,
514 /* Tuples that do not have operands. */
522 enum gimple_statement_structure_enum gss
;
523 gss
= gimple_statement_structure (stmt
);
524 if (gss
== GSS_WITH_OPS
|| gss
== GSS_WITH_MEM_OPS
)
525 for (i
= 0; i
< gimple_num_ops (stmt
); i
++)
527 ret
= walk_tree (gimple_op_ptr (stmt
, i
), callback_op
, wi
, pset
);
539 /* Walk the current statement in GSI (optionally using traversal state
540 stored in WI). If WI is NULL, no state is kept during traversal.
541 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
542 that it has handled all the operands of the statement, its return
543 value is returned. Otherwise, the return value from CALLBACK_STMT
544 is discarded and its operands are scanned.
546 If CALLBACK_STMT is NULL or it didn't handle the operands,
547 CALLBACK_OP is called on each operand of the statement via
548 walk_gimple_op. If walk_gimple_op returns non-NULL for any
549 operand, the remaining operands are not scanned. In this case, the
550 return value from CALLBACK_OP is returned.
552 In any other case, NULL_TREE is returned. */
555 walk_gimple_stmt (gimple_stmt_iterator
*gsi
, walk_stmt_fn callback_stmt
,
556 walk_tree_fn callback_op
, struct walk_stmt_info
*wi
)
560 gimple
*stmt
= gsi_stmt (*gsi
);
565 wi
->removed_stmt
= false;
567 if (wi
->want_locations
&& gimple_has_location (stmt
))
568 input_location
= gimple_location (stmt
);
573 /* Invoke the statement callback. Return if the callback handled
574 all of STMT operands by itself. */
577 bool handled_ops
= false;
578 tree_ret
= callback_stmt (gsi
, &handled_ops
, wi
);
582 /* If CALLBACK_STMT did not handle operands, it should not have
583 a value to return. */
584 gcc_assert (tree_ret
== NULL
);
586 if (wi
&& wi
->removed_stmt
)
589 /* Re-read stmt in case the callback changed it. */
590 stmt
= gsi_stmt (*gsi
);
593 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
596 tree_ret
= walk_gimple_op (stmt
, callback_op
, wi
);
601 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
602 switch (gimple_code (stmt
))
605 ret
= walk_gimple_seq_mod (gimple_bind_body_ptr (as_a
<gbind
*> (stmt
)),
606 callback_stmt
, callback_op
, wi
);
608 return wi
->callback_result
;
612 ret
= walk_gimple_seq_mod (gimple_catch_handler_ptr (
613 as_a
<gcatch
*> (stmt
)),
614 callback_stmt
, callback_op
, wi
);
616 return wi
->callback_result
;
619 case GIMPLE_EH_FILTER
:
620 ret
= walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt
), callback_stmt
,
623 return wi
->callback_result
;
628 geh_else
*eh_else_stmt
= as_a
<geh_else
*> (stmt
);
629 ret
= walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (eh_else_stmt
),
630 callback_stmt
, callback_op
, wi
);
632 return wi
->callback_result
;
633 ret
= walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (eh_else_stmt
),
634 callback_stmt
, callback_op
, wi
);
636 return wi
->callback_result
;
641 ret
= walk_gimple_seq_mod (gimple_try_eval_ptr (stmt
), callback_stmt
, callback_op
,
644 return wi
->callback_result
;
646 ret
= walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt
), callback_stmt
,
649 return wi
->callback_result
;
653 ret
= walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt
), callback_stmt
,
656 return wi
->callback_result
;
659 case GIMPLE_OMP_CRITICAL
:
660 case GIMPLE_OMP_MASTER
:
661 case GIMPLE_OMP_TASKGROUP
:
662 case GIMPLE_OMP_ORDERED
:
663 case GIMPLE_OMP_SCAN
:
664 case GIMPLE_OMP_SECTION
:
665 case GIMPLE_OMP_PARALLEL
:
666 case GIMPLE_OMP_TASK
:
667 case GIMPLE_OMP_SECTIONS
:
668 case GIMPLE_OMP_SINGLE
:
669 case GIMPLE_OMP_TARGET
:
670 case GIMPLE_OMP_TEAMS
:
671 case GIMPLE_OMP_GRID_BODY
:
672 ret
= walk_gimple_seq_mod (gimple_omp_body_ptr (stmt
), callback_stmt
,
675 return wi
->callback_result
;
678 case GIMPLE_WITH_CLEANUP_EXPR
:
679 ret
= walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt
), callback_stmt
,
682 return wi
->callback_result
;
685 case GIMPLE_TRANSACTION
:
686 ret
= walk_gimple_seq_mod (gimple_transaction_body_ptr (
687 as_a
<gtransaction
*> (stmt
)),
688 callback_stmt
, callback_op
, wi
);
690 return wi
->callback_result
;
694 gcc_assert (!gimple_has_substatements (stmt
));
701 /* From a tree operand OP return the base of a load or store operation
702 or NULL_TREE if OP is not a load or a store. */
705 get_base_loadstore (tree op
)
707 while (handled_component_p (op
))
708 op
= TREE_OPERAND (op
, 0);
710 || INDIRECT_REF_P (op
)
711 || TREE_CODE (op
) == MEM_REF
712 || TREE_CODE (op
) == TARGET_MEM_REF
)
718 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
719 VISIT_ADDR if non-NULL on loads, store and address-taken operands
720 passing the STMT, the base of the operand, the operand itself containing
721 the base and DATA to it. The base will be either a decl, an indirect
722 reference (including TARGET_MEM_REF) or the argument of an address
724 Returns the results of these callbacks or'ed. */
727 walk_stmt_load_store_addr_ops (gimple
*stmt
, void *data
,
728 walk_stmt_load_store_addr_fn visit_load
,
729 walk_stmt_load_store_addr_fn visit_store
,
730 walk_stmt_load_store_addr_fn visit_addr
)
734 if (gimple_assign_single_p (stmt
))
739 arg
= gimple_assign_lhs (stmt
);
740 lhs
= get_base_loadstore (arg
);
742 ret
|= visit_store (stmt
, lhs
, arg
, data
);
744 arg
= gimple_assign_rhs1 (stmt
);
746 while (handled_component_p (rhs
))
747 rhs
= TREE_OPERAND (rhs
, 0);
750 if (TREE_CODE (rhs
) == ADDR_EXPR
)
751 ret
|= visit_addr (stmt
, TREE_OPERAND (rhs
, 0), arg
, data
);
752 else if (TREE_CODE (rhs
) == TARGET_MEM_REF
753 && TREE_CODE (TMR_BASE (rhs
)) == ADDR_EXPR
)
754 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (rhs
), 0), arg
,
756 else if (TREE_CODE (rhs
) == OBJ_TYPE_REF
757 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs
)) == ADDR_EXPR
)
758 ret
|= visit_addr (stmt
, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs
),
760 else if (TREE_CODE (rhs
) == CONSTRUCTOR
)
765 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs
), ix
, val
)
766 if (TREE_CODE (val
) == ADDR_EXPR
)
767 ret
|= visit_addr (stmt
, TREE_OPERAND (val
, 0), arg
, data
);
768 else if (TREE_CODE (val
) == OBJ_TYPE_REF
769 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val
)) == ADDR_EXPR
)
770 ret
|= visit_addr (stmt
,
771 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val
),
774 lhs
= gimple_assign_lhs (stmt
);
775 if (TREE_CODE (lhs
) == TARGET_MEM_REF
776 && TREE_CODE (TMR_BASE (lhs
)) == ADDR_EXPR
)
777 ret
|= visit_addr (stmt
, TREE_OPERAND (TMR_BASE (lhs
), 0), lhs
, data
);
781 rhs
= get_base_loadstore (rhs
);
783 ret
|= visit_load (stmt
, rhs
, arg
, data
);
787 && (is_gimple_assign (stmt
)
788 || gimple_code (stmt
) == GIMPLE_COND
))
790 for (i
= 0; i
< gimple_num_ops (stmt
); ++i
)
792 tree op
= gimple_op (stmt
, i
);
795 else if (TREE_CODE (op
) == ADDR_EXPR
)
796 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), op
, data
);
797 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
798 tree with two operands. */
799 else if (i
== 1 && COMPARISON_CLASS_P (op
))
801 if (TREE_CODE (TREE_OPERAND (op
, 0)) == ADDR_EXPR
)
802 ret
|= visit_addr (stmt
, TREE_OPERAND (TREE_OPERAND (op
, 0),
804 if (TREE_CODE (TREE_OPERAND (op
, 1)) == ADDR_EXPR
)
805 ret
|= visit_addr (stmt
, TREE_OPERAND (TREE_OPERAND (op
, 1),
810 else if (gcall
*call_stmt
= dyn_cast
<gcall
*> (stmt
))
814 tree arg
= gimple_call_lhs (call_stmt
);
817 tree lhs
= get_base_loadstore (arg
);
819 ret
|= visit_store (stmt
, lhs
, arg
, data
);
822 if (visit_load
|| visit_addr
)
823 for (i
= 0; i
< gimple_call_num_args (call_stmt
); ++i
)
825 tree arg
= gimple_call_arg (call_stmt
, i
);
827 && TREE_CODE (arg
) == ADDR_EXPR
)
828 ret
|= visit_addr (stmt
, TREE_OPERAND (arg
, 0), arg
, data
);
831 tree rhs
= get_base_loadstore (arg
);
833 ret
|= visit_load (stmt
, rhs
, arg
, data
);
837 && gimple_call_chain (call_stmt
)
838 && TREE_CODE (gimple_call_chain (call_stmt
)) == ADDR_EXPR
)
839 ret
|= visit_addr (stmt
, TREE_OPERAND (gimple_call_chain (call_stmt
), 0),
840 gimple_call_chain (call_stmt
), data
);
842 && gimple_call_return_slot_opt_p (call_stmt
)
843 && gimple_call_lhs (call_stmt
) != NULL_TREE
844 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (call_stmt
))))
845 ret
|= visit_addr (stmt
, gimple_call_lhs (call_stmt
),
846 gimple_call_lhs (call_stmt
), data
);
848 else if (gasm
*asm_stmt
= dyn_cast
<gasm
*> (stmt
))
851 const char *constraint
;
852 const char **oconstraints
;
853 bool allows_mem
, allows_reg
, is_inout
;
854 noutputs
= gimple_asm_noutputs (asm_stmt
);
855 oconstraints
= XALLOCAVEC (const char *, noutputs
);
856 if (visit_store
|| visit_addr
)
857 for (i
= 0; i
< gimple_asm_noutputs (asm_stmt
); ++i
)
859 tree link
= gimple_asm_output_op (asm_stmt
, i
);
860 tree op
= get_base_loadstore (TREE_VALUE (link
));
861 if (op
&& visit_store
)
862 ret
|= visit_store (stmt
, op
, TREE_VALUE (link
), data
);
865 constraint
= TREE_STRING_POINTER
866 (TREE_VALUE (TREE_PURPOSE (link
)));
867 oconstraints
[i
] = constraint
;
868 parse_output_constraint (&constraint
, i
, 0, 0, &allows_mem
,
869 &allows_reg
, &is_inout
);
870 if (op
&& !allows_reg
&& allows_mem
)
871 ret
|= visit_addr (stmt
, op
, TREE_VALUE (link
), data
);
874 if (visit_load
|| visit_addr
)
875 for (i
= 0; i
< gimple_asm_ninputs (asm_stmt
); ++i
)
877 tree link
= gimple_asm_input_op (asm_stmt
, i
);
878 tree op
= TREE_VALUE (link
);
880 && TREE_CODE (op
) == ADDR_EXPR
)
881 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), op
, data
);
882 else if (visit_load
|| visit_addr
)
884 op
= get_base_loadstore (op
);
888 ret
|= visit_load (stmt
, op
, TREE_VALUE (link
), data
);
891 constraint
= TREE_STRING_POINTER
892 (TREE_VALUE (TREE_PURPOSE (link
)));
893 parse_input_constraint (&constraint
, 0, 0, noutputs
,
895 &allows_mem
, &allows_reg
);
896 if (!allows_reg
&& allows_mem
)
897 ret
|= visit_addr (stmt
, op
, TREE_VALUE (link
),
904 else if (greturn
*return_stmt
= dyn_cast
<greturn
*> (stmt
))
906 tree op
= gimple_return_retval (return_stmt
);
910 && TREE_CODE (op
) == ADDR_EXPR
)
911 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), op
, data
);
914 tree base
= get_base_loadstore (op
);
916 ret
|= visit_load (stmt
, base
, op
, data
);
921 && gimple_code (stmt
) == GIMPLE_PHI
)
923 for (i
= 0; i
< gimple_phi_num_args (stmt
); ++i
)
925 tree op
= gimple_phi_arg_def (stmt
, i
);
926 if (TREE_CODE (op
) == ADDR_EXPR
)
927 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), op
, data
);
931 && gimple_code (stmt
) == GIMPLE_GOTO
)
933 tree op
= gimple_goto_dest (stmt
);
934 if (TREE_CODE (op
) == ADDR_EXPR
)
935 ret
|= visit_addr (stmt
, TREE_OPERAND (op
, 0), op
, data
);
941 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
942 should make a faster clone for this case. */
945 walk_stmt_load_store_ops (gimple
*stmt
, void *data
,
946 walk_stmt_load_store_addr_fn visit_load
,
947 walk_stmt_load_store_addr_fn visit_store
)
949 return walk_stmt_load_store_addr_ops (stmt
, data
,
950 visit_load
, visit_store
, NULL
);