Introduce gimple_call
[official-gcc.git] / gcc / gimple-walk.c
blob661a69ec43c340926604182b0ee4f0da58ac3a56
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 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 (stmt), callback_op, wi,
282 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 (stmt, callback_op, wi);
296 if (ret)
297 return ret;
298 break;
300 case GIMPLE_OMP_CONTINUE:
301 ret = walk_tree (gimple_omp_continue_control_def_ptr (stmt),
302 callback_op, wi, pset);
303 if (ret)
304 return ret;
306 ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt),
307 callback_op, wi, pset);
308 if (ret)
309 return ret;
310 break;
312 case GIMPLE_OMP_CRITICAL:
313 ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi,
314 pset);
315 if (ret)
316 return ret;
317 break;
319 case GIMPLE_OMP_FOR:
320 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi,
321 pset);
322 if (ret)
323 return ret;
324 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
326 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op,
327 wi, pset);
328 if (ret)
329 return ret;
330 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op,
331 wi, pset);
332 if (ret)
333 return ret;
334 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op,
335 wi, pset);
336 if (ret)
337 return ret;
338 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
339 wi, pset);
341 if (ret)
342 return ret;
343 break;
345 case GIMPLE_OMP_PARALLEL:
346 ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
347 wi, pset);
348 if (ret)
349 return ret;
350 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
351 wi, pset);
352 if (ret)
353 return ret;
354 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
355 wi, pset);
356 if (ret)
357 return ret;
358 break;
360 case GIMPLE_OMP_TASK:
361 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op,
362 wi, pset);
363 if (ret)
364 return ret;
365 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op,
366 wi, pset);
367 if (ret)
368 return ret;
369 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op,
370 wi, pset);
371 if (ret)
372 return ret;
373 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op,
374 wi, pset);
375 if (ret)
376 return ret;
377 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op,
378 wi, pset);
379 if (ret)
380 return ret;
381 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op,
382 wi, pset);
383 if (ret)
384 return ret;
385 break;
387 case GIMPLE_OMP_SECTIONS:
388 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op,
389 wi, pset);
390 if (ret)
391 return ret;
393 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
394 wi, pset);
395 if (ret)
396 return ret;
398 break;
400 case GIMPLE_OMP_SINGLE:
401 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi,
402 pset);
403 if (ret)
404 return ret;
405 break;
407 case GIMPLE_OMP_TARGET:
408 ret = walk_tree (gimple_omp_target_clauses_ptr (stmt), callback_op, wi,
409 pset);
410 if (ret)
411 return ret;
412 break;
414 case GIMPLE_OMP_TEAMS:
415 ret = walk_tree (gimple_omp_teams_clauses_ptr (stmt), callback_op, wi,
416 pset);
417 if (ret)
418 return ret;
419 break;
421 case GIMPLE_OMP_ATOMIC_LOAD:
422 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi,
423 pset);
424 if (ret)
425 return ret;
427 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi,
428 pset);
429 if (ret)
430 return ret;
431 break;
433 case GIMPLE_OMP_ATOMIC_STORE:
434 ret = walk_tree (gimple_omp_atomic_store_val_ptr (stmt), callback_op,
435 wi, pset);
436 if (ret)
437 return ret;
438 break;
440 case GIMPLE_TRANSACTION:
441 ret = walk_tree (gimple_transaction_label_ptr (stmt), callback_op,
442 wi, pset);
443 if (ret)
444 return ret;
445 break;
447 case GIMPLE_OMP_RETURN:
448 ret = walk_tree (gimple_omp_return_lhs_ptr (stmt), callback_op, wi,
449 pset);
450 if (ret)
451 return ret;
452 break;
454 /* Tuples that do not have operands. */
455 case GIMPLE_NOP:
456 case GIMPLE_RESX:
457 case GIMPLE_PREDICT:
458 break;
460 default:
462 enum gimple_statement_structure_enum gss;
463 gss = gimple_statement_structure (stmt);
464 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
465 for (i = 0; i < gimple_num_ops (stmt); i++)
467 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
468 if (ret)
469 return ret;
472 break;
475 return NULL_TREE;
479 /* Walk the current statement in GSI (optionally using traversal state
480 stored in WI). If WI is NULL, no state is kept during traversal.
481 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
482 that it has handled all the operands of the statement, its return
483 value is returned. Otherwise, the return value from CALLBACK_STMT
484 is discarded and its operands are scanned.
486 If CALLBACK_STMT is NULL or it didn't handle the operands,
487 CALLBACK_OP is called on each operand of the statement via
488 walk_gimple_op. If walk_gimple_op returns non-NULL for any
489 operand, the remaining operands are not scanned. In this case, the
490 return value from CALLBACK_OP is returned.
492 In any other case, NULL_TREE is returned. */
494 tree
495 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
496 walk_tree_fn callback_op, struct walk_stmt_info *wi)
498 gimple ret;
499 tree tree_ret;
500 gimple stmt = gsi_stmt (*gsi);
502 if (wi)
504 wi->gsi = *gsi;
505 wi->removed_stmt = false;
507 if (wi->want_locations && gimple_has_location (stmt))
508 input_location = gimple_location (stmt);
511 ret = NULL;
513 /* Invoke the statement callback. Return if the callback handled
514 all of STMT operands by itself. */
515 if (callback_stmt)
517 bool handled_ops = false;
518 tree_ret = callback_stmt (gsi, &handled_ops, wi);
519 if (handled_ops)
520 return tree_ret;
522 /* If CALLBACK_STMT did not handle operands, it should not have
523 a value to return. */
524 gcc_assert (tree_ret == NULL);
526 if (wi && wi->removed_stmt)
527 return NULL;
529 /* Re-read stmt in case the callback changed it. */
530 stmt = gsi_stmt (*gsi);
533 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
534 if (callback_op)
536 tree_ret = walk_gimple_op (stmt, callback_op, wi);
537 if (tree_ret)
538 return tree_ret;
541 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
542 switch (gimple_code (stmt))
544 case GIMPLE_BIND:
545 ret =
546 walk_gimple_seq_mod (gimple_bind_body_ptr (as_a <gimple_bind> (stmt)),
547 callback_stmt, callback_op, wi);
548 if (ret)
549 return wi->callback_result;
550 break;
552 case GIMPLE_CATCH:
553 ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt), callback_stmt,
554 callback_op, wi);
555 if (ret)
556 return wi->callback_result;
557 break;
559 case GIMPLE_EH_FILTER:
560 ret = walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt), callback_stmt,
561 callback_op, wi);
562 if (ret)
563 return wi->callback_result;
564 break;
566 case GIMPLE_EH_ELSE:
567 ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (stmt),
568 callback_stmt, callback_op, wi);
569 if (ret)
570 return wi->callback_result;
571 ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (stmt),
572 callback_stmt, callback_op, wi);
573 if (ret)
574 return wi->callback_result;
575 break;
577 case GIMPLE_TRY:
578 ret = walk_gimple_seq_mod (gimple_try_eval_ptr (stmt), callback_stmt, callback_op,
579 wi);
580 if (ret)
581 return wi->callback_result;
583 ret = walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt), callback_stmt,
584 callback_op, wi);
585 if (ret)
586 return wi->callback_result;
587 break;
589 case GIMPLE_OMP_FOR:
590 ret = walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt), callback_stmt,
591 callback_op, wi);
592 if (ret)
593 return wi->callback_result;
595 /* FALL THROUGH. */
596 case GIMPLE_OMP_CRITICAL:
597 case GIMPLE_OMP_MASTER:
598 case GIMPLE_OMP_TASKGROUP:
599 case GIMPLE_OMP_ORDERED:
600 case GIMPLE_OMP_SECTION:
601 case GIMPLE_OMP_PARALLEL:
602 case GIMPLE_OMP_TASK:
603 case GIMPLE_OMP_SECTIONS:
604 case GIMPLE_OMP_SINGLE:
605 case GIMPLE_OMP_TARGET:
606 case GIMPLE_OMP_TEAMS:
607 ret = walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), callback_stmt,
608 callback_op, wi);
609 if (ret)
610 return wi->callback_result;
611 break;
613 case GIMPLE_WITH_CLEANUP_EXPR:
614 ret = walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt), callback_stmt,
615 callback_op, wi);
616 if (ret)
617 return wi->callback_result;
618 break;
620 case GIMPLE_TRANSACTION:
621 ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (stmt),
622 callback_stmt, callback_op, wi);
623 if (ret)
624 return wi->callback_result;
625 break;
627 default:
628 gcc_assert (!gimple_has_substatements (stmt));
629 break;
632 return NULL;
635 /* From a tree operand OP return the base of a load or store operation
636 or NULL_TREE if OP is not a load or a store. */
638 static tree
639 get_base_loadstore (tree op)
641 while (handled_component_p (op))
642 op = TREE_OPERAND (op, 0);
643 if (DECL_P (op)
644 || INDIRECT_REF_P (op)
645 || TREE_CODE (op) == MEM_REF
646 || TREE_CODE (op) == TARGET_MEM_REF)
647 return op;
648 return NULL_TREE;
652 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
653 VISIT_ADDR if non-NULL on loads, store and address-taken operands
654 passing the STMT, the base of the operand, the operand itself containing
655 the base and DATA to it. The base will be either a decl, an indirect
656 reference (including TARGET_MEM_REF) or the argument of an address
657 expression.
658 Returns the results of these callbacks or'ed. */
660 bool
661 walk_stmt_load_store_addr_ops (gimple stmt, void *data,
662 walk_stmt_load_store_addr_fn visit_load,
663 walk_stmt_load_store_addr_fn visit_store,
664 walk_stmt_load_store_addr_fn visit_addr)
666 bool ret = false;
667 unsigned i;
668 if (gimple_assign_single_p (stmt))
670 tree lhs, rhs, arg;
671 if (visit_store)
673 arg = gimple_assign_lhs (stmt);
674 lhs = get_base_loadstore (arg);
675 if (lhs)
676 ret |= visit_store (stmt, lhs, arg, data);
678 arg = gimple_assign_rhs1 (stmt);
679 rhs = arg;
680 while (handled_component_p (rhs))
681 rhs = TREE_OPERAND (rhs, 0);
682 if (visit_addr)
684 if (TREE_CODE (rhs) == ADDR_EXPR)
685 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), arg, data);
686 else if (TREE_CODE (rhs) == TARGET_MEM_REF
687 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
688 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), arg,
689 data);
690 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
691 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
692 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
693 0), arg, data);
694 else if (TREE_CODE (rhs) == CONSTRUCTOR)
696 unsigned int ix;
697 tree val;
699 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
700 if (TREE_CODE (val) == ADDR_EXPR)
701 ret |= visit_addr (stmt, TREE_OPERAND (val, 0), arg, data);
702 else if (TREE_CODE (val) == OBJ_TYPE_REF
703 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
704 ret |= visit_addr (stmt,
705 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
706 0), arg, data);
708 lhs = gimple_assign_lhs (stmt);
709 if (TREE_CODE (lhs) == TARGET_MEM_REF
710 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
711 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), lhs, data);
713 if (visit_load)
715 rhs = get_base_loadstore (rhs);
716 if (rhs)
717 ret |= visit_load (stmt, rhs, arg, data);
720 else if (visit_addr
721 && (is_gimple_assign (stmt)
722 || gimple_code (stmt) == GIMPLE_COND))
724 for (i = 0; i < gimple_num_ops (stmt); ++i)
726 tree op = gimple_op (stmt, i);
727 if (op == NULL_TREE)
729 else if (TREE_CODE (op) == ADDR_EXPR)
730 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
731 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
732 tree with two operands. */
733 else if (i == 1 && COMPARISON_CLASS_P (op))
735 if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
736 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
737 0), op, data);
738 if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
739 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
740 0), op, data);
744 else if (is_gimple_call (stmt))
746 if (visit_store)
748 tree arg = gimple_call_lhs (stmt);
749 if (arg)
751 tree lhs = get_base_loadstore (arg);
752 if (lhs)
753 ret |= visit_store (stmt, lhs, arg, data);
756 if (visit_load || visit_addr)
757 for (i = 0; i < gimple_call_num_args (stmt); ++i)
759 tree arg = gimple_call_arg (stmt, i);
760 if (visit_addr
761 && TREE_CODE (arg) == ADDR_EXPR)
762 ret |= visit_addr (stmt, TREE_OPERAND (arg, 0), arg, data);
763 else if (visit_load)
765 tree rhs = get_base_loadstore (arg);
766 if (rhs)
767 ret |= visit_load (stmt, rhs, arg, data);
770 if (visit_addr
771 && gimple_call_chain (stmt)
772 && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
773 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
774 gimple_call_chain (stmt), data);
775 if (visit_addr
776 && gimple_call_return_slot_opt_p (stmt)
777 && gimple_call_lhs (stmt) != NULL_TREE
778 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
779 ret |= visit_addr (stmt, gimple_call_lhs (stmt),
780 gimple_call_lhs (stmt), data);
782 else if (gimple_code (stmt) == GIMPLE_ASM)
784 unsigned noutputs;
785 const char *constraint;
786 const char **oconstraints;
787 bool allows_mem, allows_reg, is_inout;
788 noutputs = gimple_asm_noutputs (stmt);
789 oconstraints = XALLOCAVEC (const char *, noutputs);
790 if (visit_store || visit_addr)
791 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
793 tree link = gimple_asm_output_op (stmt, i);
794 tree op = get_base_loadstore (TREE_VALUE (link));
795 if (op && visit_store)
796 ret |= visit_store (stmt, op, TREE_VALUE (link), data);
797 if (visit_addr)
799 constraint = TREE_STRING_POINTER
800 (TREE_VALUE (TREE_PURPOSE (link)));
801 oconstraints[i] = constraint;
802 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
803 &allows_reg, &is_inout);
804 if (op && !allows_reg && allows_mem)
805 ret |= visit_addr (stmt, op, TREE_VALUE (link), data);
808 if (visit_load || visit_addr)
809 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
811 tree link = gimple_asm_input_op (stmt, i);
812 tree op = TREE_VALUE (link);
813 if (visit_addr
814 && TREE_CODE (op) == ADDR_EXPR)
815 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
816 else if (visit_load || visit_addr)
818 op = get_base_loadstore (op);
819 if (op)
821 if (visit_load)
822 ret |= visit_load (stmt, op, TREE_VALUE (link), data);
823 if (visit_addr)
825 constraint = TREE_STRING_POINTER
826 (TREE_VALUE (TREE_PURPOSE (link)));
827 parse_input_constraint (&constraint, 0, 0, noutputs,
828 0, oconstraints,
829 &allows_mem, &allows_reg);
830 if (!allows_reg && allows_mem)
831 ret |= visit_addr (stmt, op, TREE_VALUE (link),
832 data);
838 else if (gimple_code (stmt) == GIMPLE_RETURN)
840 tree op = gimple_return_retval (stmt);
841 if (op)
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)
848 tree base = get_base_loadstore (op);
849 if (base)
850 ret |= visit_load (stmt, base, op, data);
854 else if (visit_addr
855 && gimple_code (stmt) == GIMPLE_PHI)
857 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
859 tree op = gimple_phi_arg_def (stmt, i);
860 if (TREE_CODE (op) == ADDR_EXPR)
861 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
864 else if (visit_addr
865 && gimple_code (stmt) == GIMPLE_GOTO)
867 tree op = gimple_goto_dest (stmt);
868 if (TREE_CODE (op) == ADDR_EXPR)
869 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
872 return ret;
875 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
876 should make a faster clone for this case. */
878 bool
879 walk_stmt_load_store_ops (gimple stmt, void *data,
880 walk_stmt_load_store_addr_fn visit_load,
881 walk_stmt_load_store_addr_fn visit_store)
883 return walk_stmt_load_store_addr_ops (stmt, data,
884 visit_load, visit_store, NULL);