Introduce gimple_omp_critical
[official-gcc.git] / gcc / gimple-walk.c
blob8293e0d13e3f3689c7796adce87e0e6fdc18e6cc
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 (
317 as_a <gimple_omp_critical> (stmt)),
318 callback_op, wi, pset);
319 if (ret)
320 return ret;
321 break;
323 case GIMPLE_OMP_FOR:
324 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi,
325 pset);
326 if (ret)
327 return ret;
328 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
330 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op,
331 wi, pset);
332 if (ret)
333 return ret;
334 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op,
335 wi, pset);
336 if (ret)
337 return ret;
338 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op,
339 wi, pset);
340 if (ret)
341 return ret;
342 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
343 wi, pset);
345 if (ret)
346 return ret;
347 break;
349 case GIMPLE_OMP_PARALLEL:
350 ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
351 wi, pset);
352 if (ret)
353 return ret;
354 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
355 wi, pset);
356 if (ret)
357 return ret;
358 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
359 wi, pset);
360 if (ret)
361 return ret;
362 break;
364 case GIMPLE_OMP_TASK:
365 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op,
366 wi, pset);
367 if (ret)
368 return ret;
369 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op,
370 wi, pset);
371 if (ret)
372 return ret;
373 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op,
374 wi, pset);
375 if (ret)
376 return ret;
377 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op,
378 wi, pset);
379 if (ret)
380 return ret;
381 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op,
382 wi, pset);
383 if (ret)
384 return ret;
385 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op,
386 wi, pset);
387 if (ret)
388 return ret;
389 break;
391 case GIMPLE_OMP_SECTIONS:
392 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op,
393 wi, pset);
394 if (ret)
395 return ret;
397 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
398 wi, pset);
399 if (ret)
400 return ret;
402 break;
404 case GIMPLE_OMP_SINGLE:
405 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi,
406 pset);
407 if (ret)
408 return ret;
409 break;
411 case GIMPLE_OMP_TARGET:
412 ret = walk_tree (gimple_omp_target_clauses_ptr (stmt), callback_op, wi,
413 pset);
414 if (ret)
415 return ret;
416 break;
418 case GIMPLE_OMP_TEAMS:
419 ret = walk_tree (gimple_omp_teams_clauses_ptr (stmt), callback_op, wi,
420 pset);
421 if (ret)
422 return ret;
423 break;
425 case GIMPLE_OMP_ATOMIC_LOAD:
427 gimple_omp_atomic_load omp_stmt = as_a <gimple_omp_atomic_load> (stmt);
428 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (omp_stmt),
429 callback_op, wi, pset);
430 if (ret)
431 return ret;
433 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (omp_stmt),
434 callback_op, wi, pset);
435 if (ret)
436 return ret;
438 break;
440 case GIMPLE_OMP_ATOMIC_STORE:
441 ret = walk_tree (gimple_omp_atomic_store_val_ptr (
442 as_a <gimple_omp_atomic_store> (stmt)),
443 callback_op, wi, pset);
444 if (ret)
445 return ret;
446 break;
448 case GIMPLE_TRANSACTION:
449 ret = walk_tree (gimple_transaction_label_ptr (
450 as_a <gimple_transaction> (stmt)),
451 callback_op, wi, pset);
452 if (ret)
453 return ret;
454 break;
456 case GIMPLE_OMP_RETURN:
457 ret = walk_tree (gimple_omp_return_lhs_ptr (stmt), callback_op, wi,
458 pset);
459 if (ret)
460 return ret;
461 break;
463 /* Tuples that do not have operands. */
464 case GIMPLE_NOP:
465 case GIMPLE_RESX:
466 case GIMPLE_PREDICT:
467 break;
469 default:
471 enum gimple_statement_structure_enum gss;
472 gss = gimple_statement_structure (stmt);
473 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
474 for (i = 0; i < gimple_num_ops (stmt); i++)
476 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
477 if (ret)
478 return ret;
481 break;
484 return NULL_TREE;
488 /* Walk the current statement in GSI (optionally using traversal state
489 stored in WI). If WI is NULL, no state is kept during traversal.
490 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
491 that it has handled all the operands of the statement, its return
492 value is returned. Otherwise, the return value from CALLBACK_STMT
493 is discarded and its operands are scanned.
495 If CALLBACK_STMT is NULL or it didn't handle the operands,
496 CALLBACK_OP is called on each operand of the statement via
497 walk_gimple_op. If walk_gimple_op returns non-NULL for any
498 operand, the remaining operands are not scanned. In this case, the
499 return value from CALLBACK_OP is returned.
501 In any other case, NULL_TREE is returned. */
503 tree
504 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
505 walk_tree_fn callback_op, struct walk_stmt_info *wi)
507 gimple ret;
508 tree tree_ret;
509 gimple stmt = gsi_stmt (*gsi);
511 if (wi)
513 wi->gsi = *gsi;
514 wi->removed_stmt = false;
516 if (wi->want_locations && gimple_has_location (stmt))
517 input_location = gimple_location (stmt);
520 ret = NULL;
522 /* Invoke the statement callback. Return if the callback handled
523 all of STMT operands by itself. */
524 if (callback_stmt)
526 bool handled_ops = false;
527 tree_ret = callback_stmt (gsi, &handled_ops, wi);
528 if (handled_ops)
529 return tree_ret;
531 /* If CALLBACK_STMT did not handle operands, it should not have
532 a value to return. */
533 gcc_assert (tree_ret == NULL);
535 if (wi && wi->removed_stmt)
536 return NULL;
538 /* Re-read stmt in case the callback changed it. */
539 stmt = gsi_stmt (*gsi);
542 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
543 if (callback_op)
545 tree_ret = walk_gimple_op (stmt, callback_op, wi);
546 if (tree_ret)
547 return tree_ret;
550 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
551 switch (gimple_code (stmt))
553 case GIMPLE_BIND:
554 ret =
555 walk_gimple_seq_mod (gimple_bind_body_ptr (as_a <gimple_bind> (stmt)),
556 callback_stmt, callback_op, wi);
557 if (ret)
558 return wi->callback_result;
559 break;
561 case GIMPLE_CATCH:
562 ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (
563 as_a <gimple_catch> (stmt)),
564 callback_stmt, callback_op, wi);
565 if (ret)
566 return wi->callback_result;
567 break;
569 case GIMPLE_EH_FILTER:
570 ret = walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt), callback_stmt,
571 callback_op, wi);
572 if (ret)
573 return wi->callback_result;
574 break;
576 case GIMPLE_EH_ELSE:
578 gimple_eh_else eh_else_stmt = as_a <gimple_eh_else> (stmt);
579 ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (eh_else_stmt),
580 callback_stmt, callback_op, wi);
581 if (ret)
582 return wi->callback_result;
583 ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (eh_else_stmt),
584 callback_stmt, callback_op, wi);
585 if (ret)
586 return wi->callback_result;
588 break;
590 case GIMPLE_TRY:
591 ret = walk_gimple_seq_mod (gimple_try_eval_ptr (stmt), callback_stmt, callback_op,
592 wi);
593 if (ret)
594 return wi->callback_result;
596 ret = walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt), callback_stmt,
597 callback_op, wi);
598 if (ret)
599 return wi->callback_result;
600 break;
602 case GIMPLE_OMP_FOR:
603 ret = walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt), callback_stmt,
604 callback_op, wi);
605 if (ret)
606 return wi->callback_result;
608 /* FALL THROUGH. */
609 case GIMPLE_OMP_CRITICAL:
610 case GIMPLE_OMP_MASTER:
611 case GIMPLE_OMP_TASKGROUP:
612 case GIMPLE_OMP_ORDERED:
613 case GIMPLE_OMP_SECTION:
614 case GIMPLE_OMP_PARALLEL:
615 case GIMPLE_OMP_TASK:
616 case GIMPLE_OMP_SECTIONS:
617 case GIMPLE_OMP_SINGLE:
618 case GIMPLE_OMP_TARGET:
619 case GIMPLE_OMP_TEAMS:
620 ret = walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), callback_stmt,
621 callback_op, wi);
622 if (ret)
623 return wi->callback_result;
624 break;
626 case GIMPLE_WITH_CLEANUP_EXPR:
627 ret = walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt), callback_stmt,
628 callback_op, wi);
629 if (ret)
630 return wi->callback_result;
631 break;
633 case GIMPLE_TRANSACTION:
634 ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (
635 as_a <gimple_transaction> (stmt)),
636 callback_stmt, callback_op, wi);
637 if (ret)
638 return wi->callback_result;
639 break;
641 default:
642 gcc_assert (!gimple_has_substatements (stmt));
643 break;
646 return NULL;
649 /* From a tree operand OP return the base of a load or store operation
650 or NULL_TREE if OP is not a load or a store. */
652 static tree
653 get_base_loadstore (tree op)
655 while (handled_component_p (op))
656 op = TREE_OPERAND (op, 0);
657 if (DECL_P (op)
658 || INDIRECT_REF_P (op)
659 || TREE_CODE (op) == MEM_REF
660 || TREE_CODE (op) == TARGET_MEM_REF)
661 return op;
662 return NULL_TREE;
666 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
667 VISIT_ADDR if non-NULL on loads, store and address-taken operands
668 passing the STMT, the base of the operand, the operand itself containing
669 the base and DATA to it. The base will be either a decl, an indirect
670 reference (including TARGET_MEM_REF) or the argument of an address
671 expression.
672 Returns the results of these callbacks or'ed. */
674 bool
675 walk_stmt_load_store_addr_ops (gimple stmt, void *data,
676 walk_stmt_load_store_addr_fn visit_load,
677 walk_stmt_load_store_addr_fn visit_store,
678 walk_stmt_load_store_addr_fn visit_addr)
680 bool ret = false;
681 unsigned i;
682 if (gimple_assign_single_p (stmt))
684 tree lhs, rhs, arg;
685 if (visit_store)
687 arg = gimple_assign_lhs (stmt);
688 lhs = get_base_loadstore (arg);
689 if (lhs)
690 ret |= visit_store (stmt, lhs, arg, data);
692 arg = gimple_assign_rhs1 (stmt);
693 rhs = arg;
694 while (handled_component_p (rhs))
695 rhs = TREE_OPERAND (rhs, 0);
696 if (visit_addr)
698 if (TREE_CODE (rhs) == ADDR_EXPR)
699 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), arg, data);
700 else if (TREE_CODE (rhs) == TARGET_MEM_REF
701 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
702 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), arg,
703 data);
704 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
705 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
706 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
707 0), arg, data);
708 else if (TREE_CODE (rhs) == CONSTRUCTOR)
710 unsigned int ix;
711 tree val;
713 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
714 if (TREE_CODE (val) == ADDR_EXPR)
715 ret |= visit_addr (stmt, TREE_OPERAND (val, 0), arg, data);
716 else if (TREE_CODE (val) == OBJ_TYPE_REF
717 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
718 ret |= visit_addr (stmt,
719 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
720 0), arg, data);
722 lhs = gimple_assign_lhs (stmt);
723 if (TREE_CODE (lhs) == TARGET_MEM_REF
724 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
725 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), lhs, data);
727 if (visit_load)
729 rhs = get_base_loadstore (rhs);
730 if (rhs)
731 ret |= visit_load (stmt, rhs, arg, data);
734 else if (visit_addr
735 && (is_gimple_assign (stmt)
736 || gimple_code (stmt) == GIMPLE_COND))
738 for (i = 0; i < gimple_num_ops (stmt); ++i)
740 tree op = gimple_op (stmt, i);
741 if (op == NULL_TREE)
743 else if (TREE_CODE (op) == ADDR_EXPR)
744 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
745 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
746 tree with two operands. */
747 else if (i == 1 && COMPARISON_CLASS_P (op))
749 if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
750 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
751 0), op, data);
752 if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
753 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
754 0), op, data);
758 else if (is_gimple_call (stmt))
760 if (visit_store)
762 tree arg = gimple_call_lhs (stmt);
763 if (arg)
765 tree lhs = get_base_loadstore (arg);
766 if (lhs)
767 ret |= visit_store (stmt, lhs, arg, data);
770 if (visit_load || visit_addr)
771 for (i = 0; i < gimple_call_num_args (stmt); ++i)
773 tree arg = gimple_call_arg (stmt, i);
774 if (visit_addr
775 && TREE_CODE (arg) == ADDR_EXPR)
776 ret |= visit_addr (stmt, TREE_OPERAND (arg, 0), arg, data);
777 else if (visit_load)
779 tree rhs = get_base_loadstore (arg);
780 if (rhs)
781 ret |= visit_load (stmt, rhs, arg, data);
784 if (visit_addr
785 && gimple_call_chain (stmt)
786 && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
787 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
788 gimple_call_chain (stmt), data);
789 if (visit_addr
790 && gimple_call_return_slot_opt_p (stmt)
791 && gimple_call_lhs (stmt) != NULL_TREE
792 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
793 ret |= visit_addr (stmt, gimple_call_lhs (stmt),
794 gimple_call_lhs (stmt), data);
796 else if (gimple_asm asm_stmt = dyn_cast <gimple_asm> (stmt))
798 unsigned noutputs;
799 const char *constraint;
800 const char **oconstraints;
801 bool allows_mem, allows_reg, is_inout;
802 noutputs = gimple_asm_noutputs (asm_stmt);
803 oconstraints = XALLOCAVEC (const char *, noutputs);
804 if (visit_store || visit_addr)
805 for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
807 tree link = gimple_asm_output_op (asm_stmt, i);
808 tree op = get_base_loadstore (TREE_VALUE (link));
809 if (op && visit_store)
810 ret |= visit_store (stmt, op, TREE_VALUE (link), data);
811 if (visit_addr)
813 constraint = TREE_STRING_POINTER
814 (TREE_VALUE (TREE_PURPOSE (link)));
815 oconstraints[i] = constraint;
816 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
817 &allows_reg, &is_inout);
818 if (op && !allows_reg && allows_mem)
819 ret |= visit_addr (stmt, op, TREE_VALUE (link), data);
822 if (visit_load || visit_addr)
823 for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
825 tree link = gimple_asm_input_op (asm_stmt, i);
826 tree op = TREE_VALUE (link);
827 if (visit_addr
828 && TREE_CODE (op) == ADDR_EXPR)
829 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
830 else if (visit_load || visit_addr)
832 op = get_base_loadstore (op);
833 if (op)
835 if (visit_load)
836 ret |= visit_load (stmt, op, TREE_VALUE (link), data);
837 if (visit_addr)
839 constraint = TREE_STRING_POINTER
840 (TREE_VALUE (TREE_PURPOSE (link)));
841 parse_input_constraint (&constraint, 0, 0, noutputs,
842 0, oconstraints,
843 &allows_mem, &allows_reg);
844 if (!allows_reg && allows_mem)
845 ret |= visit_addr (stmt, op, TREE_VALUE (link),
846 data);
852 else if (gimple_code (stmt) == GIMPLE_RETURN)
854 tree op = gimple_return_retval (stmt);
855 if (op)
857 if (visit_addr
858 && TREE_CODE (op) == ADDR_EXPR)
859 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
860 else if (visit_load)
862 tree base = get_base_loadstore (op);
863 if (base)
864 ret |= visit_load (stmt, base, op, data);
868 else if (visit_addr
869 && gimple_code (stmt) == GIMPLE_PHI)
871 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
873 tree op = gimple_phi_arg_def (stmt, i);
874 if (TREE_CODE (op) == ADDR_EXPR)
875 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
878 else if (visit_addr
879 && gimple_code (stmt) == GIMPLE_GOTO)
881 tree op = gimple_goto_dest (stmt);
882 if (TREE_CODE (op) == ADDR_EXPR)
883 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
886 return ret;
889 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
890 should make a faster clone for this case. */
892 bool
893 walk_stmt_load_store_ops (gimple stmt, void *data,
894 walk_stmt_load_store_addr_fn visit_load,
895 walk_stmt_load_store_addr_fn visit_store)
897 return walk_stmt_load_store_addr_ops (stmt, data,
898 visit_load, visit_store, NULL);