Just enumerate all GF_OMP_FOR_KIND_* and GF_OMP_TARGET_KIND_*.
[official-gcc.git] / gcc / gimple-walk.c
blobb5b4095f2ffe1b558a10da179cc067cfad014ee3
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 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 struct pointer_set_t *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 (stmt), callback_op, wi, pset);
240 if (ret)
241 return ret;
243 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset);
244 if (ret)
245 return ret;
247 for (i = 0; i < gimple_call_num_args (stmt); i++)
249 if (wi)
250 wi->val_only
251 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt, i)));
252 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi,
253 pset);
254 if (ret)
255 return ret;
258 if (gimple_call_lhs (stmt))
260 if (wi)
262 wi->is_lhs = true;
263 wi->val_only
264 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt)));
267 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
268 if (ret)
269 return ret;
272 if (wi)
274 wi->is_lhs = false;
275 wi->val_only = true;
277 break;
279 case GIMPLE_CATCH:
280 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi,
281 pset);
282 if (ret)
283 return ret;
284 break;
286 case GIMPLE_EH_FILTER:
287 ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi,
288 pset);
289 if (ret)
290 return ret;
291 break;
293 case GIMPLE_ASM:
294 ret = walk_gimple_asm (stmt, callback_op, wi);
295 if (ret)
296 return ret;
297 break;
299 case GIMPLE_OACC_KERNELS:
300 ret = walk_tree (gimple_oacc_kernels_clauses_ptr (stmt), callback_op,
301 wi, pset);
302 if (ret)
303 return ret;
304 ret = walk_tree (gimple_oacc_kernels_child_fn_ptr (stmt), callback_op,
305 wi, pset);
306 if (ret)
307 return ret;
308 ret = walk_tree (gimple_oacc_kernels_data_arg_ptr (stmt), callback_op,
309 wi, pset);
310 if (ret)
311 return ret;
312 break;
314 case GIMPLE_OACC_PARALLEL:
315 ret = walk_tree (gimple_oacc_parallel_clauses_ptr (stmt), callback_op,
316 wi, pset);
317 if (ret)
318 return ret;
319 ret = walk_tree (gimple_oacc_parallel_child_fn_ptr (stmt), callback_op,
320 wi, pset);
321 if (ret)
322 return ret;
323 ret = walk_tree (gimple_oacc_parallel_data_arg_ptr (stmt), callback_op,
324 wi, pset);
325 if (ret)
326 return ret;
327 break;
329 case GIMPLE_OMP_CONTINUE:
330 ret = walk_tree (gimple_omp_continue_control_def_ptr (stmt),
331 callback_op, wi, pset);
332 if (ret)
333 return ret;
335 ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt),
336 callback_op, wi, pset);
337 if (ret)
338 return ret;
339 break;
341 case GIMPLE_OMP_CRITICAL:
342 ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi,
343 pset);
344 if (ret)
345 return ret;
346 break;
348 case GIMPLE_OMP_FOR:
349 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi,
350 pset);
351 if (ret)
352 return ret;
353 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
355 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op,
356 wi, pset);
357 if (ret)
358 return ret;
359 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op,
360 wi, pset);
361 if (ret)
362 return ret;
363 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op,
364 wi, pset);
365 if (ret)
366 return ret;
367 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
368 wi, pset);
370 if (ret)
371 return ret;
372 break;
374 case GIMPLE_OMP_PARALLEL:
375 ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
376 wi, pset);
377 if (ret)
378 return ret;
379 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
380 wi, pset);
381 if (ret)
382 return ret;
383 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
384 wi, pset);
385 if (ret)
386 return ret;
387 break;
389 case GIMPLE_OMP_TASK:
390 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op,
391 wi, pset);
392 if (ret)
393 return ret;
394 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op,
395 wi, pset);
396 if (ret)
397 return ret;
398 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op,
399 wi, pset);
400 if (ret)
401 return ret;
402 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op,
403 wi, pset);
404 if (ret)
405 return ret;
406 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op,
407 wi, pset);
408 if (ret)
409 return ret;
410 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op,
411 wi, pset);
412 if (ret)
413 return ret;
414 break;
416 case GIMPLE_OMP_SECTIONS:
417 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op,
418 wi, pset);
419 if (ret)
420 return ret;
422 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
423 wi, pset);
424 if (ret)
425 return ret;
427 break;
429 case GIMPLE_OMP_SINGLE:
430 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi,
431 pset);
432 if (ret)
433 return ret;
434 break;
436 case GIMPLE_OMP_TARGET:
437 ret = walk_tree (gimple_omp_target_clauses_ptr (stmt), callback_op, wi,
438 pset);
439 if (ret)
440 return ret;
441 break;
443 case GIMPLE_OMP_TEAMS:
444 ret = walk_tree (gimple_omp_teams_clauses_ptr (stmt), callback_op, wi,
445 pset);
446 if (ret)
447 return ret;
448 break;
450 case GIMPLE_OMP_ATOMIC_LOAD:
451 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi,
452 pset);
453 if (ret)
454 return ret;
456 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi,
457 pset);
458 if (ret)
459 return ret;
460 break;
462 case GIMPLE_OMP_ATOMIC_STORE:
463 ret = walk_tree (gimple_omp_atomic_store_val_ptr (stmt), callback_op,
464 wi, pset);
465 if (ret)
466 return ret;
467 break;
469 case GIMPLE_TRANSACTION:
470 ret = walk_tree (gimple_transaction_label_ptr (stmt), callback_op,
471 wi, pset);
472 if (ret)
473 return ret;
474 break;
476 case GIMPLE_OMP_RETURN:
477 ret = walk_tree (gimple_omp_return_lhs_ptr (stmt), callback_op, wi,
478 pset);
479 if (ret)
480 return ret;
481 break;
483 /* Tuples that do not have operands. */
484 case GIMPLE_NOP:
485 case GIMPLE_RESX:
486 case GIMPLE_PREDICT:
487 break;
489 default:
491 enum gimple_statement_structure_enum gss;
492 gss = gimple_statement_structure (stmt);
493 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
494 for (i = 0; i < gimple_num_ops (stmt); i++)
496 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
497 if (ret)
498 return ret;
501 break;
504 return NULL_TREE;
508 /* Walk the current statement in GSI (optionally using traversal state
509 stored in WI). If WI is NULL, no state is kept during traversal.
510 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
511 that it has handled all the operands of the statement, its return
512 value is returned. Otherwise, the return value from CALLBACK_STMT
513 is discarded and its operands are scanned.
515 If CALLBACK_STMT is NULL or it didn't handle the operands,
516 CALLBACK_OP is called on each operand of the statement via
517 walk_gimple_op. If walk_gimple_op returns non-NULL for any
518 operand, the remaining operands are not scanned. In this case, the
519 return value from CALLBACK_OP is returned.
521 In any other case, NULL_TREE is returned. */
523 tree
524 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
525 walk_tree_fn callback_op, struct walk_stmt_info *wi)
527 gimple ret;
528 tree tree_ret;
529 gimple stmt = gsi_stmt (*gsi);
531 if (wi)
533 wi->gsi = *gsi;
534 wi->removed_stmt = false;
536 if (wi->want_locations && gimple_has_location (stmt))
537 input_location = gimple_location (stmt);
540 ret = NULL;
542 /* Invoke the statement callback. Return if the callback handled
543 all of STMT operands by itself. */
544 if (callback_stmt)
546 bool handled_ops = false;
547 tree_ret = callback_stmt (gsi, &handled_ops, wi);
548 if (handled_ops)
549 return tree_ret;
551 /* If CALLBACK_STMT did not handle operands, it should not have
552 a value to return. */
553 gcc_assert (tree_ret == NULL);
555 if (wi && wi->removed_stmt)
556 return NULL;
558 /* Re-read stmt in case the callback changed it. */
559 stmt = gsi_stmt (*gsi);
562 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
563 if (callback_op)
565 tree_ret = walk_gimple_op (stmt, callback_op, wi);
566 if (tree_ret)
567 return tree_ret;
570 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
571 switch (gimple_code (stmt))
573 case GIMPLE_BIND:
574 ret = walk_gimple_seq_mod (gimple_bind_body_ptr (stmt), callback_stmt,
575 callback_op, wi);
576 if (ret)
577 return wi->callback_result;
578 break;
580 case GIMPLE_CATCH:
581 ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt), callback_stmt,
582 callback_op, wi);
583 if (ret)
584 return wi->callback_result;
585 break;
587 case GIMPLE_EH_FILTER:
588 ret = walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt), callback_stmt,
589 callback_op, wi);
590 if (ret)
591 return wi->callback_result;
592 break;
594 case GIMPLE_EH_ELSE:
595 ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (stmt),
596 callback_stmt, callback_op, wi);
597 if (ret)
598 return wi->callback_result;
599 ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (stmt),
600 callback_stmt, callback_op, wi);
601 if (ret)
602 return wi->callback_result;
603 break;
605 case GIMPLE_TRY:
606 ret = walk_gimple_seq_mod (gimple_try_eval_ptr (stmt), callback_stmt, callback_op,
607 wi);
608 if (ret)
609 return wi->callback_result;
611 ret = walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt), callback_stmt,
612 callback_op, wi);
613 if (ret)
614 return wi->callback_result;
615 break;
617 case GIMPLE_OMP_FOR:
618 ret = walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt), callback_stmt,
619 callback_op, wi);
620 if (ret)
621 return wi->callback_result;
623 /* FALL THROUGH. */
624 case GIMPLE_OACC_KERNELS:
625 case GIMPLE_OACC_PARALLEL:
626 case GIMPLE_OMP_CRITICAL:
627 case GIMPLE_OMP_MASTER:
628 case GIMPLE_OMP_TASKGROUP:
629 case GIMPLE_OMP_ORDERED:
630 case GIMPLE_OMP_SECTION:
631 case GIMPLE_OMP_PARALLEL:
632 case GIMPLE_OMP_TASK:
633 case GIMPLE_OMP_SECTIONS:
634 case GIMPLE_OMP_SINGLE:
635 case GIMPLE_OMP_TARGET:
636 case GIMPLE_OMP_TEAMS:
637 ret = walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), callback_stmt,
638 callback_op, wi);
639 if (ret)
640 return wi->callback_result;
641 break;
643 case GIMPLE_WITH_CLEANUP_EXPR:
644 ret = walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt), callback_stmt,
645 callback_op, wi);
646 if (ret)
647 return wi->callback_result;
648 break;
650 case GIMPLE_TRANSACTION:
651 ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (stmt),
652 callback_stmt, callback_op, wi);
653 if (ret)
654 return wi->callback_result;
655 break;
657 default:
658 gcc_assert (!gimple_has_substatements (stmt));
659 break;
662 return NULL;
665 /* From a tree operand OP return the base of a load or store operation
666 or NULL_TREE if OP is not a load or a store. */
668 static tree
669 get_base_loadstore (tree op)
671 while (handled_component_p (op))
672 op = TREE_OPERAND (op, 0);
673 if (DECL_P (op)
674 || INDIRECT_REF_P (op)
675 || TREE_CODE (op) == MEM_REF
676 || TREE_CODE (op) == TARGET_MEM_REF)
677 return op;
678 return NULL_TREE;
682 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
683 VISIT_ADDR if non-NULL on loads, store and address-taken operands
684 passing the STMT, the base of the operand, the operand itself containing
685 the base and DATA to it. The base will be either a decl, an indirect
686 reference (including TARGET_MEM_REF) or the argument of an address
687 expression.
688 Returns the results of these callbacks or'ed. */
690 bool
691 walk_stmt_load_store_addr_ops (gimple stmt, void *data,
692 walk_stmt_load_store_addr_fn visit_load,
693 walk_stmt_load_store_addr_fn visit_store,
694 walk_stmt_load_store_addr_fn visit_addr)
696 bool ret = false;
697 unsigned i;
698 if (gimple_assign_single_p (stmt))
700 tree lhs, rhs, arg;
701 if (visit_store)
703 arg = gimple_assign_lhs (stmt);
704 lhs = get_base_loadstore (arg);
705 if (lhs)
706 ret |= visit_store (stmt, lhs, arg, data);
708 arg = gimple_assign_rhs1 (stmt);
709 rhs = arg;
710 while (handled_component_p (rhs))
711 rhs = TREE_OPERAND (rhs, 0);
712 if (visit_addr)
714 if (TREE_CODE (rhs) == ADDR_EXPR)
715 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), arg, data);
716 else if (TREE_CODE (rhs) == TARGET_MEM_REF
717 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
718 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), arg,
719 data);
720 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
721 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
722 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
723 0), arg, data);
724 else if (TREE_CODE (rhs) == CONSTRUCTOR)
726 unsigned int ix;
727 tree val;
729 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
730 if (TREE_CODE (val) == ADDR_EXPR)
731 ret |= visit_addr (stmt, TREE_OPERAND (val, 0), arg, data);
732 else if (TREE_CODE (val) == OBJ_TYPE_REF
733 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
734 ret |= visit_addr (stmt,
735 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
736 0), arg, data);
738 lhs = gimple_assign_lhs (stmt);
739 if (TREE_CODE (lhs) == TARGET_MEM_REF
740 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
741 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), lhs, data);
743 if (visit_load)
745 rhs = get_base_loadstore (rhs);
746 if (rhs)
747 ret |= visit_load (stmt, rhs, arg, data);
750 else if (visit_addr
751 && (is_gimple_assign (stmt)
752 || gimple_code (stmt) == GIMPLE_COND))
754 for (i = 0; i < gimple_num_ops (stmt); ++i)
756 tree op = gimple_op (stmt, i);
757 if (op == NULL_TREE)
759 else if (TREE_CODE (op) == ADDR_EXPR)
760 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
761 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
762 tree with two operands. */
763 else if (i == 1 && COMPARISON_CLASS_P (op))
765 if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
766 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
767 0), op, data);
768 if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
769 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
770 0), op, data);
774 else if (is_gimple_call (stmt))
776 if (visit_store)
778 tree arg = gimple_call_lhs (stmt);
779 if (arg)
781 tree lhs = get_base_loadstore (arg);
782 if (lhs)
783 ret |= visit_store (stmt, lhs, arg, data);
786 if (visit_load || visit_addr)
787 for (i = 0; i < gimple_call_num_args (stmt); ++i)
789 tree arg = gimple_call_arg (stmt, i);
790 if (visit_addr
791 && TREE_CODE (arg) == ADDR_EXPR)
792 ret |= visit_addr (stmt, TREE_OPERAND (arg, 0), arg, data);
793 else if (visit_load)
795 tree rhs = get_base_loadstore (arg);
796 if (rhs)
797 ret |= visit_load (stmt, rhs, arg, data);
800 if (visit_addr
801 && gimple_call_chain (stmt)
802 && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
803 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
804 gimple_call_chain (stmt), data);
805 if (visit_addr
806 && gimple_call_return_slot_opt_p (stmt)
807 && gimple_call_lhs (stmt) != NULL_TREE
808 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
809 ret |= visit_addr (stmt, gimple_call_lhs (stmt),
810 gimple_call_lhs (stmt), data);
812 else if (gimple_code (stmt) == GIMPLE_ASM)
814 unsigned noutputs;
815 const char *constraint;
816 const char **oconstraints;
817 bool allows_mem, allows_reg, is_inout;
818 noutputs = gimple_asm_noutputs (stmt);
819 oconstraints = XALLOCAVEC (const char *, noutputs);
820 if (visit_store || visit_addr)
821 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
823 tree link = gimple_asm_output_op (stmt, i);
824 tree op = get_base_loadstore (TREE_VALUE (link));
825 if (op && visit_store)
826 ret |= visit_store (stmt, op, TREE_VALUE (link), data);
827 if (visit_addr)
829 constraint = TREE_STRING_POINTER
830 (TREE_VALUE (TREE_PURPOSE (link)));
831 oconstraints[i] = constraint;
832 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
833 &allows_reg, &is_inout);
834 if (op && !allows_reg && allows_mem)
835 ret |= visit_addr (stmt, op, TREE_VALUE (link), data);
838 if (visit_load || visit_addr)
839 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
841 tree link = gimple_asm_input_op (stmt, i);
842 tree op = TREE_VALUE (link);
843 if (visit_addr
844 && TREE_CODE (op) == ADDR_EXPR)
845 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
846 else if (visit_load || visit_addr)
848 op = get_base_loadstore (op);
849 if (op)
851 if (visit_load)
852 ret |= visit_load (stmt, op, TREE_VALUE (link), data);
853 if (visit_addr)
855 constraint = TREE_STRING_POINTER
856 (TREE_VALUE (TREE_PURPOSE (link)));
857 parse_input_constraint (&constraint, 0, 0, noutputs,
858 0, oconstraints,
859 &allows_mem, &allows_reg);
860 if (!allows_reg && allows_mem)
861 ret |= visit_addr (stmt, op, TREE_VALUE (link),
862 data);
868 else if (gimple_code (stmt) == GIMPLE_RETURN)
870 tree op = gimple_return_retval (stmt);
871 if (op)
873 if (visit_addr
874 && TREE_CODE (op) == ADDR_EXPR)
875 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
876 else if (visit_load)
878 tree base = get_base_loadstore (op);
879 if (base)
880 ret |= visit_load (stmt, base, op, data);
884 else if (visit_addr
885 && gimple_code (stmt) == GIMPLE_PHI)
887 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
889 tree op = gimple_phi_arg_def (stmt, i);
890 if (TREE_CODE (op) == ADDR_EXPR)
891 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
894 else if (visit_addr
895 && gimple_code (stmt) == GIMPLE_GOTO)
897 tree op = gimple_goto_dest (stmt);
898 if (TREE_CODE (op) == ADDR_EXPR)
899 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
902 return ret;
905 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
906 should make a faster clone for this case. */
908 bool
909 walk_stmt_load_store_ops (gimple stmt, void *data,
910 walk_stmt_load_store_addr_fn visit_load,
911 walk_stmt_load_store_addr_fn visit_store)
913 return walk_stmt_load_store_addr_ops (stmt, data,
914 visit_load, visit_store, NULL);