Introduce gimple_omp_continue
[official-gcc.git] / gcc / gimple-walk.c
blob39ffc5565491a0ad83713669666d41bf4c8ed3ce
1 /* Gimple walk support.
3 Copyright (C) 2007-2014 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
11 version.
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
16 for more details.
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/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "stmt.h"
28 #include "basic-block.h"
29 #include "tree-ssa-alias.h"
30 #include "internal-fn.h"
31 #include "gimple-expr.h"
32 #include "is-a.h"
33 #include "gimple.h"
34 #include "gimple-iterator.h"
35 #include "gimple-walk.h"
36 #include "gimple-walk.h"
37 #include "demangle.h"
39 /* Walk all the statements in the sequence *PSEQ calling walk_gimple_stmt
40 on each one. WI is as in walk_gimple_stmt.
42 If walk_gimple_stmt returns non-NULL, the walk is stopped, and the
43 value is stored in WI->CALLBACK_RESULT. Also, the statement that
44 produced the value is returned if this statement has not been
45 removed by a callback (wi->removed_stmt). If the statement has
46 been removed, NULL is returned.
48 Otherwise, all the statements are walked and NULL returned. */
50 gimple
51 walk_gimple_seq_mod (gimple_seq *pseq, walk_stmt_fn callback_stmt,
52 walk_tree_fn callback_op, struct walk_stmt_info *wi)
54 gimple_stmt_iterator gsi;
56 for (gsi = gsi_start (*pseq); !gsi_end_p (gsi); )
58 tree ret = walk_gimple_stmt (&gsi, callback_stmt, callback_op, wi);
59 if (ret)
61 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
62 to hold it. */
63 gcc_assert (wi);
64 wi->callback_result = ret;
66 return wi->removed_stmt ? NULL : gsi_stmt (gsi);
69 if (!wi->removed_stmt)
70 gsi_next (&gsi);
73 if (wi)
74 wi->callback_result = NULL_TREE;
76 return NULL;
80 /* Like walk_gimple_seq_mod, but ensure that the head of SEQ isn't
81 changed by the callbacks. */
83 gimple
84 walk_gimple_seq (gimple_seq seq, walk_stmt_fn callback_stmt,
85 walk_tree_fn callback_op, struct walk_stmt_info *wi)
87 gimple_seq seq2 = seq;
88 gimple ret = walk_gimple_seq_mod (&seq2, callback_stmt, callback_op, wi);
89 gcc_assert (seq2 == seq);
90 return ret;
94 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
96 static tree
97 walk_gimple_asm (gimple_asm stmt, walk_tree_fn callback_op,
98 struct walk_stmt_info *wi)
100 tree ret, op;
101 unsigned noutputs;
102 const char **oconstraints;
103 unsigned i, n;
104 const char *constraint;
105 bool allows_mem, allows_reg, is_inout;
107 noutputs = gimple_asm_noutputs (stmt);
108 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
110 if (wi)
111 wi->is_lhs = true;
113 for (i = 0; i < noutputs; i++)
115 op = gimple_asm_output_op (stmt, i);
116 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
117 oconstraints[i] = constraint;
118 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, &allows_reg,
119 &is_inout);
120 if (wi)
121 wi->val_only = (allows_reg || !allows_mem);
122 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
123 if (ret)
124 return ret;
127 n = gimple_asm_ninputs (stmt);
128 for (i = 0; i < n; i++)
130 op = gimple_asm_input_op (stmt, i);
131 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
132 parse_input_constraint (&constraint, 0, 0, noutputs, 0,
133 oconstraints, &allows_mem, &allows_reg);
134 if (wi)
136 wi->val_only = (allows_reg || !allows_mem);
137 /* Although input "m" is not really a LHS, we need a lvalue. */
138 wi->is_lhs = !wi->val_only;
140 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
141 if (ret)
142 return ret;
145 if (wi)
147 wi->is_lhs = false;
148 wi->val_only = true;
151 n = gimple_asm_nlabels (stmt);
152 for (i = 0; i < n; i++)
154 op = gimple_asm_label_op (stmt, i);
155 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
156 if (ret)
157 return ret;
160 return NULL_TREE;
164 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
165 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
167 CALLBACK_OP is called on each operand of STMT via walk_tree.
168 Additional parameters to walk_tree must be stored in WI. For each operand
169 OP, walk_tree is called as:
171 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
173 If CALLBACK_OP returns non-NULL for an operand, the remaining
174 operands are not scanned.
176 The return value is that returned by the last call to walk_tree, or
177 NULL_TREE if no CALLBACK_OP is specified. */
179 tree
180 walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
181 struct walk_stmt_info *wi)
183 hash_set<tree> *pset = (wi) ? wi->pset : NULL;
184 unsigned i;
185 tree ret = NULL_TREE;
187 switch (gimple_code (stmt))
189 case GIMPLE_ASSIGN:
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. */
192 if (wi)
194 tree lhs = gimple_assign_lhs (stmt);
195 wi->val_only
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,
203 pset);
204 if (ret)
205 return ret;
208 /* Walk the LHS. If the RHS is appropriate for a memory, we
209 may use a COMPONENT_REF on the LHS. */
210 if (wi)
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);
215 wi->val_only
216 = (is_gimple_reg_type (TREE_TYPE (rhs1)) && !is_gimple_reg (rhs1))
217 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
218 wi->is_lhs = true;
221 ret = walk_tree (gimple_op_ptr (stmt, 0), callback_op, wi, pset);
222 if (ret)
223 return ret;
225 if (wi)
227 wi->val_only = true;
228 wi->is_lhs = false;
230 break;
232 case GIMPLE_CALL:
233 if (wi)
235 wi->is_lhs = false;
236 wi->val_only = true;
239 ret = walk_tree (gimple_call_chain_ptr (as_a <gimple_call> (stmt)),
240 callback_op, wi, pset);
241 if (ret)
242 return ret;
244 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset);
245 if (ret)
246 return ret;
248 for (i = 0; i < gimple_call_num_args (stmt); i++)
250 if (wi)
251 wi->val_only
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,
254 pset);
255 if (ret)
256 return ret;
259 if (gimple_call_lhs (stmt))
261 if (wi)
263 wi->is_lhs = true;
264 wi->val_only
265 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt)));
268 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
269 if (ret)
270 return ret;
273 if (wi)
275 wi->is_lhs = false;
276 wi->val_only = true;
278 break;
280 case GIMPLE_CATCH:
281 ret = walk_tree (gimple_catch_types_ptr (as_a <gimple_catch> (stmt)),
282 callback_op, wi, pset);
283 if (ret)
284 return ret;
285 break;
287 case GIMPLE_EH_FILTER:
288 ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi,
289 pset);
290 if (ret)
291 return ret;
292 break;
294 case GIMPLE_ASM:
295 ret = walk_gimple_asm (as_a <gimple_asm> (stmt), callback_op, wi);
296 if (ret)
297 return ret;
298 break;
300 case GIMPLE_OMP_CONTINUE:
302 gimple_omp_continue cont_stmt = as_a <gimple_omp_continue> (stmt);
303 ret = walk_tree (gimple_omp_continue_control_def_ptr (cont_stmt),
304 callback_op, wi, pset);
305 if (ret)
306 return ret;
308 ret = walk_tree (gimple_omp_continue_control_use_ptr (cont_stmt),
309 callback_op, wi, pset);
310 if (ret)
311 return ret;
313 break;
315 case GIMPLE_OMP_CRITICAL:
316 ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi,
317 pset);
318 if (ret)
319 return ret;
320 break;
322 case GIMPLE_OMP_FOR:
323 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi,
324 pset);
325 if (ret)
326 return ret;
327 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
329 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op,
330 wi, pset);
331 if (ret)
332 return ret;
333 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op,
334 wi, pset);
335 if (ret)
336 return ret;
337 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op,
338 wi, pset);
339 if (ret)
340 return ret;
341 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
342 wi, pset);
344 if (ret)
345 return ret;
346 break;
348 case GIMPLE_OMP_PARALLEL:
349 ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
350 wi, pset);
351 if (ret)
352 return ret;
353 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
354 wi, pset);
355 if (ret)
356 return ret;
357 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
358 wi, pset);
359 if (ret)
360 return ret;
361 break;
363 case GIMPLE_OMP_TASK:
364 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op,
365 wi, pset);
366 if (ret)
367 return ret;
368 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op,
369 wi, pset);
370 if (ret)
371 return ret;
372 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op,
373 wi, pset);
374 if (ret)
375 return ret;
376 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op,
377 wi, pset);
378 if (ret)
379 return ret;
380 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op,
381 wi, pset);
382 if (ret)
383 return ret;
384 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op,
385 wi, pset);
386 if (ret)
387 return ret;
388 break;
390 case GIMPLE_OMP_SECTIONS:
391 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op,
392 wi, pset);
393 if (ret)
394 return ret;
396 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
397 wi, pset);
398 if (ret)
399 return ret;
401 break;
403 case GIMPLE_OMP_SINGLE:
404 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi,
405 pset);
406 if (ret)
407 return ret;
408 break;
410 case GIMPLE_OMP_TARGET:
411 ret = walk_tree (gimple_omp_target_clauses_ptr (stmt), callback_op, wi,
412 pset);
413 if (ret)
414 return ret;
415 break;
417 case GIMPLE_OMP_TEAMS:
418 ret = walk_tree (gimple_omp_teams_clauses_ptr (stmt), callback_op, wi,
419 pset);
420 if (ret)
421 return ret;
422 break;
424 case GIMPLE_OMP_ATOMIC_LOAD:
426 gimple_omp_atomic_load omp_stmt = as_a <gimple_omp_atomic_load> (stmt);
427 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (omp_stmt),
428 callback_op, wi, pset);
429 if (ret)
430 return ret;
432 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (omp_stmt),
433 callback_op, wi, pset);
434 if (ret)
435 return ret;
437 break;
439 case GIMPLE_OMP_ATOMIC_STORE:
440 ret = walk_tree (gimple_omp_atomic_store_val_ptr (
441 as_a <gimple_omp_atomic_store> (stmt)),
442 callback_op, wi, pset);
443 if (ret)
444 return ret;
445 break;
447 case GIMPLE_TRANSACTION:
448 ret = walk_tree (gimple_transaction_label_ptr (
449 as_a <gimple_transaction> (stmt)),
450 callback_op, wi, pset);
451 if (ret)
452 return ret;
453 break;
455 case GIMPLE_OMP_RETURN:
456 ret = walk_tree (gimple_omp_return_lhs_ptr (stmt), callback_op, wi,
457 pset);
458 if (ret)
459 return ret;
460 break;
462 /* Tuples that do not have operands. */
463 case GIMPLE_NOP:
464 case GIMPLE_RESX:
465 case GIMPLE_PREDICT:
466 break;
468 default:
470 enum gimple_statement_structure_enum gss;
471 gss = gimple_statement_structure (stmt);
472 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
473 for (i = 0; i < gimple_num_ops (stmt); i++)
475 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
476 if (ret)
477 return ret;
480 break;
483 return NULL_TREE;
487 /* Walk the current statement in GSI (optionally using traversal state
488 stored in WI). If WI is NULL, no state is kept during traversal.
489 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
490 that it has handled all the operands of the statement, its return
491 value is returned. Otherwise, the return value from CALLBACK_STMT
492 is discarded and its operands are scanned.
494 If CALLBACK_STMT is NULL or it didn't handle the operands,
495 CALLBACK_OP is called on each operand of the statement via
496 walk_gimple_op. If walk_gimple_op returns non-NULL for any
497 operand, the remaining operands are not scanned. In this case, the
498 return value from CALLBACK_OP is returned.
500 In any other case, NULL_TREE is returned. */
502 tree
503 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
504 walk_tree_fn callback_op, struct walk_stmt_info *wi)
506 gimple ret;
507 tree tree_ret;
508 gimple stmt = gsi_stmt (*gsi);
510 if (wi)
512 wi->gsi = *gsi;
513 wi->removed_stmt = false;
515 if (wi->want_locations && gimple_has_location (stmt))
516 input_location = gimple_location (stmt);
519 ret = NULL;
521 /* Invoke the statement callback. Return if the callback handled
522 all of STMT operands by itself. */
523 if (callback_stmt)
525 bool handled_ops = false;
526 tree_ret = callback_stmt (gsi, &handled_ops, wi);
527 if (handled_ops)
528 return tree_ret;
530 /* If CALLBACK_STMT did not handle operands, it should not have
531 a value to return. */
532 gcc_assert (tree_ret == NULL);
534 if (wi && wi->removed_stmt)
535 return NULL;
537 /* Re-read stmt in case the callback changed it. */
538 stmt = gsi_stmt (*gsi);
541 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
542 if (callback_op)
544 tree_ret = walk_gimple_op (stmt, callback_op, wi);
545 if (tree_ret)
546 return tree_ret;
549 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
550 switch (gimple_code (stmt))
552 case GIMPLE_BIND:
553 ret =
554 walk_gimple_seq_mod (gimple_bind_body_ptr (as_a <gimple_bind> (stmt)),
555 callback_stmt, callback_op, wi);
556 if (ret)
557 return wi->callback_result;
558 break;
560 case GIMPLE_CATCH:
561 ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (
562 as_a <gimple_catch> (stmt)),
563 callback_stmt, callback_op, wi);
564 if (ret)
565 return wi->callback_result;
566 break;
568 case GIMPLE_EH_FILTER:
569 ret = walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt), callback_stmt,
570 callback_op, wi);
571 if (ret)
572 return wi->callback_result;
573 break;
575 case GIMPLE_EH_ELSE:
577 gimple_eh_else eh_else_stmt = as_a <gimple_eh_else> (stmt);
578 ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (eh_else_stmt),
579 callback_stmt, callback_op, wi);
580 if (ret)
581 return wi->callback_result;
582 ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (eh_else_stmt),
583 callback_stmt, callback_op, wi);
584 if (ret)
585 return wi->callback_result;
587 break;
589 case GIMPLE_TRY:
590 ret = walk_gimple_seq_mod (gimple_try_eval_ptr (stmt), callback_stmt, callback_op,
591 wi);
592 if (ret)
593 return wi->callback_result;
595 ret = walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt), callback_stmt,
596 callback_op, wi);
597 if (ret)
598 return wi->callback_result;
599 break;
601 case GIMPLE_OMP_FOR:
602 ret = walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt), callback_stmt,
603 callback_op, wi);
604 if (ret)
605 return wi->callback_result;
607 /* FALL THROUGH. */
608 case GIMPLE_OMP_CRITICAL:
609 case GIMPLE_OMP_MASTER:
610 case GIMPLE_OMP_TASKGROUP:
611 case GIMPLE_OMP_ORDERED:
612 case GIMPLE_OMP_SECTION:
613 case GIMPLE_OMP_PARALLEL:
614 case GIMPLE_OMP_TASK:
615 case GIMPLE_OMP_SECTIONS:
616 case GIMPLE_OMP_SINGLE:
617 case GIMPLE_OMP_TARGET:
618 case GIMPLE_OMP_TEAMS:
619 ret = walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), callback_stmt,
620 callback_op, wi);
621 if (ret)
622 return wi->callback_result;
623 break;
625 case GIMPLE_WITH_CLEANUP_EXPR:
626 ret = walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt), callback_stmt,
627 callback_op, wi);
628 if (ret)
629 return wi->callback_result;
630 break;
632 case GIMPLE_TRANSACTION:
633 ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (
634 as_a <gimple_transaction> (stmt)),
635 callback_stmt, callback_op, wi);
636 if (ret)
637 return wi->callback_result;
638 break;
640 default:
641 gcc_assert (!gimple_has_substatements (stmt));
642 break;
645 return NULL;
648 /* From a tree operand OP return the base of a load or store operation
649 or NULL_TREE if OP is not a load or a store. */
651 static tree
652 get_base_loadstore (tree op)
654 while (handled_component_p (op))
655 op = TREE_OPERAND (op, 0);
656 if (DECL_P (op)
657 || INDIRECT_REF_P (op)
658 || TREE_CODE (op) == MEM_REF
659 || TREE_CODE (op) == TARGET_MEM_REF)
660 return op;
661 return NULL_TREE;
665 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
666 VISIT_ADDR if non-NULL on loads, store and address-taken operands
667 passing the STMT, the base of the operand, the operand itself containing
668 the base and DATA to it. The base will be either a decl, an indirect
669 reference (including TARGET_MEM_REF) or the argument of an address
670 expression.
671 Returns the results of these callbacks or'ed. */
673 bool
674 walk_stmt_load_store_addr_ops (gimple stmt, void *data,
675 walk_stmt_load_store_addr_fn visit_load,
676 walk_stmt_load_store_addr_fn visit_store,
677 walk_stmt_load_store_addr_fn visit_addr)
679 bool ret = false;
680 unsigned i;
681 if (gimple_assign_single_p (stmt))
683 tree lhs, rhs, arg;
684 if (visit_store)
686 arg = gimple_assign_lhs (stmt);
687 lhs = get_base_loadstore (arg);
688 if (lhs)
689 ret |= visit_store (stmt, lhs, arg, data);
691 arg = gimple_assign_rhs1 (stmt);
692 rhs = arg;
693 while (handled_component_p (rhs))
694 rhs = TREE_OPERAND (rhs, 0);
695 if (visit_addr)
697 if (TREE_CODE (rhs) == ADDR_EXPR)
698 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), arg, data);
699 else if (TREE_CODE (rhs) == TARGET_MEM_REF
700 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
701 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), arg,
702 data);
703 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
704 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
705 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
706 0), arg, data);
707 else if (TREE_CODE (rhs) == CONSTRUCTOR)
709 unsigned int ix;
710 tree val;
712 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
713 if (TREE_CODE (val) == ADDR_EXPR)
714 ret |= visit_addr (stmt, TREE_OPERAND (val, 0), arg, data);
715 else if (TREE_CODE (val) == OBJ_TYPE_REF
716 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
717 ret |= visit_addr (stmt,
718 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
719 0), arg, data);
721 lhs = gimple_assign_lhs (stmt);
722 if (TREE_CODE (lhs) == TARGET_MEM_REF
723 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
724 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), lhs, data);
726 if (visit_load)
728 rhs = get_base_loadstore (rhs);
729 if (rhs)
730 ret |= visit_load (stmt, rhs, arg, data);
733 else if (visit_addr
734 && (is_gimple_assign (stmt)
735 || gimple_code (stmt) == GIMPLE_COND))
737 for (i = 0; i < gimple_num_ops (stmt); ++i)
739 tree op = gimple_op (stmt, i);
740 if (op == NULL_TREE)
742 else if (TREE_CODE (op) == ADDR_EXPR)
743 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
744 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
745 tree with two operands. */
746 else if (i == 1 && COMPARISON_CLASS_P (op))
748 if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
749 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
750 0), op, data);
751 if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
752 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
753 0), op, data);
757 else if (is_gimple_call (stmt))
759 if (visit_store)
761 tree arg = gimple_call_lhs (stmt);
762 if (arg)
764 tree lhs = get_base_loadstore (arg);
765 if (lhs)
766 ret |= visit_store (stmt, lhs, arg, data);
769 if (visit_load || visit_addr)
770 for (i = 0; i < gimple_call_num_args (stmt); ++i)
772 tree arg = gimple_call_arg (stmt, i);
773 if (visit_addr
774 && TREE_CODE (arg) == ADDR_EXPR)
775 ret |= visit_addr (stmt, TREE_OPERAND (arg, 0), arg, data);
776 else if (visit_load)
778 tree rhs = get_base_loadstore (arg);
779 if (rhs)
780 ret |= visit_load (stmt, rhs, arg, data);
783 if (visit_addr
784 && gimple_call_chain (stmt)
785 && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
786 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
787 gimple_call_chain (stmt), data);
788 if (visit_addr
789 && gimple_call_return_slot_opt_p (stmt)
790 && gimple_call_lhs (stmt) != NULL_TREE
791 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
792 ret |= visit_addr (stmt, gimple_call_lhs (stmt),
793 gimple_call_lhs (stmt), data);
795 else if (gimple_asm asm_stmt = dyn_cast <gimple_asm> (stmt))
797 unsigned noutputs;
798 const char *constraint;
799 const char **oconstraints;
800 bool allows_mem, allows_reg, is_inout;
801 noutputs = gimple_asm_noutputs (asm_stmt);
802 oconstraints = XALLOCAVEC (const char *, noutputs);
803 if (visit_store || visit_addr)
804 for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
806 tree link = gimple_asm_output_op (asm_stmt, i);
807 tree op = get_base_loadstore (TREE_VALUE (link));
808 if (op && visit_store)
809 ret |= visit_store (stmt, op, TREE_VALUE (link), data);
810 if (visit_addr)
812 constraint = TREE_STRING_POINTER
813 (TREE_VALUE (TREE_PURPOSE (link)));
814 oconstraints[i] = constraint;
815 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
816 &allows_reg, &is_inout);
817 if (op && !allows_reg && allows_mem)
818 ret |= visit_addr (stmt, op, TREE_VALUE (link), data);
821 if (visit_load || visit_addr)
822 for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
824 tree link = gimple_asm_input_op (asm_stmt, i);
825 tree op = TREE_VALUE (link);
826 if (visit_addr
827 && TREE_CODE (op) == ADDR_EXPR)
828 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
829 else if (visit_load || visit_addr)
831 op = get_base_loadstore (op);
832 if (op)
834 if (visit_load)
835 ret |= visit_load (stmt, op, TREE_VALUE (link), data);
836 if (visit_addr)
838 constraint = TREE_STRING_POINTER
839 (TREE_VALUE (TREE_PURPOSE (link)));
840 parse_input_constraint (&constraint, 0, 0, noutputs,
841 0, oconstraints,
842 &allows_mem, &allows_reg);
843 if (!allows_reg && allows_mem)
844 ret |= visit_addr (stmt, op, TREE_VALUE (link),
845 data);
851 else if (gimple_code (stmt) == GIMPLE_RETURN)
853 tree op = gimple_return_retval (stmt);
854 if (op)
856 if (visit_addr
857 && TREE_CODE (op) == ADDR_EXPR)
858 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
859 else if (visit_load)
861 tree base = get_base_loadstore (op);
862 if (base)
863 ret |= visit_load (stmt, base, op, data);
867 else if (visit_addr
868 && gimple_code (stmt) == GIMPLE_PHI)
870 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
872 tree op = gimple_phi_arg_def (stmt, i);
873 if (TREE_CODE (op) == ADDR_EXPR)
874 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
877 else if (visit_addr
878 && gimple_code (stmt) == GIMPLE_GOTO)
880 tree op = gimple_goto_dest (stmt);
881 if (TREE_CODE (op) == ADDR_EXPR)
882 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
885 return ret;
888 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
889 should make a faster clone for this case. */
891 bool
892 walk_stmt_load_store_ops (gimple stmt, void *data,
893 walk_stmt_load_store_addr_fn visit_load,
894 walk_stmt_load_store_addr_fn visit_store)
896 return walk_stmt_load_store_addr_ops (stmt, data,
897 visit_load, visit_store, NULL);