2013-11-21 Edward Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / gcc / gimple-walk.c
blob22f4584a673ee7533355cf78b288bb10fc5450aa
1 /* Gimple walk support.
3 Copyright (C) 2007-2013 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 "gimple.h"
29 #include "gimple-iterator.h"
30 #include "gimple-walk.h"
31 #include "gimple-walk.h"
32 #include "demangle.h"
34 /* Walk all the statements in the sequence *PSEQ calling walk_gimple_stmt
35 on each one. WI is as in walk_gimple_stmt.
37 If walk_gimple_stmt returns non-NULL, the walk is stopped, and the
38 value is stored in WI->CALLBACK_RESULT. Also, the statement that
39 produced the value is returned if this statement has not been
40 removed by a callback (wi->removed_stmt). If the statement has
41 been removed, NULL is returned.
43 Otherwise, all the statements are walked and NULL returned. */
45 gimple
46 walk_gimple_seq_mod (gimple_seq *pseq, walk_stmt_fn callback_stmt,
47 walk_tree_fn callback_op, struct walk_stmt_info *wi)
49 gimple_stmt_iterator gsi;
51 for (gsi = gsi_start (*pseq); !gsi_end_p (gsi); )
53 tree ret = walk_gimple_stmt (&gsi, callback_stmt, callback_op, wi);
54 if (ret)
56 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
57 to hold it. */
58 gcc_assert (wi);
59 wi->callback_result = ret;
61 return wi->removed_stmt ? NULL : gsi_stmt (gsi);
64 if (!wi->removed_stmt)
65 gsi_next (&gsi);
68 if (wi)
69 wi->callback_result = NULL_TREE;
71 return NULL;
75 /* Like walk_gimple_seq_mod, but ensure that the head of SEQ isn't
76 changed by the callbacks. */
78 gimple
79 walk_gimple_seq (gimple_seq seq, walk_stmt_fn callback_stmt,
80 walk_tree_fn callback_op, struct walk_stmt_info *wi)
82 gimple_seq seq2 = seq;
83 gimple ret = walk_gimple_seq_mod (&seq2, callback_stmt, callback_op, wi);
84 gcc_assert (seq2 == seq);
85 return ret;
89 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
91 static tree
92 walk_gimple_asm (gimple stmt, walk_tree_fn callback_op,
93 struct walk_stmt_info *wi)
95 tree ret, op;
96 unsigned noutputs;
97 const char **oconstraints;
98 unsigned i, n;
99 const char *constraint;
100 bool allows_mem, allows_reg, is_inout;
102 noutputs = gimple_asm_noutputs (stmt);
103 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
105 if (wi)
106 wi->is_lhs = true;
108 for (i = 0; i < noutputs; i++)
110 op = gimple_asm_output_op (stmt, i);
111 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
112 oconstraints[i] = constraint;
113 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, &allows_reg,
114 &is_inout);
115 if (wi)
116 wi->val_only = (allows_reg || !allows_mem);
117 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
118 if (ret)
119 return ret;
122 n = gimple_asm_ninputs (stmt);
123 for (i = 0; i < n; i++)
125 op = gimple_asm_input_op (stmt, i);
126 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
127 parse_input_constraint (&constraint, 0, 0, noutputs, 0,
128 oconstraints, &allows_mem, &allows_reg);
129 if (wi)
131 wi->val_only = (allows_reg || !allows_mem);
132 /* Although input "m" is not really a LHS, we need a lvalue. */
133 wi->is_lhs = !wi->val_only;
135 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
136 if (ret)
137 return ret;
140 if (wi)
142 wi->is_lhs = false;
143 wi->val_only = true;
146 n = gimple_asm_nlabels (stmt);
147 for (i = 0; i < n; i++)
149 op = gimple_asm_label_op (stmt, i);
150 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
151 if (ret)
152 return ret;
155 return NULL_TREE;
159 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
160 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
162 CALLBACK_OP is called on each operand of STMT via walk_tree.
163 Additional parameters to walk_tree must be stored in WI. For each operand
164 OP, walk_tree is called as:
166 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
168 If CALLBACK_OP returns non-NULL for an operand, the remaining
169 operands are not scanned.
171 The return value is that returned by the last call to walk_tree, or
172 NULL_TREE if no CALLBACK_OP is specified. */
174 tree
175 walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
176 struct walk_stmt_info *wi)
178 struct pointer_set_t *pset = (wi) ? wi->pset : NULL;
179 unsigned i;
180 tree ret = NULL_TREE;
182 switch (gimple_code (stmt))
184 case GIMPLE_ASSIGN:
185 /* Walk the RHS operands. If the LHS is of a non-renamable type or
186 is a register variable, we may use a COMPONENT_REF on the RHS. */
187 if (wi)
189 tree lhs = gimple_assign_lhs (stmt);
190 wi->val_only
191 = (is_gimple_reg_type (TREE_TYPE (lhs)) && !is_gimple_reg (lhs))
192 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
195 for (i = 1; i < gimple_num_ops (stmt); i++)
197 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi,
198 pset);
199 if (ret)
200 return ret;
203 /* Walk the LHS. If the RHS is appropriate for a memory, we
204 may use a COMPONENT_REF on the LHS. */
205 if (wi)
207 /* If the RHS is of a non-renamable type or is a register variable,
208 we may use a COMPONENT_REF on the LHS. */
209 tree rhs1 = gimple_assign_rhs1 (stmt);
210 wi->val_only
211 = (is_gimple_reg_type (TREE_TYPE (rhs1)) && !is_gimple_reg (rhs1))
212 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
213 wi->is_lhs = true;
216 ret = walk_tree (gimple_op_ptr (stmt, 0), callback_op, wi, pset);
217 if (ret)
218 return ret;
220 if (wi)
222 wi->val_only = true;
223 wi->is_lhs = false;
225 break;
227 case GIMPLE_CALL:
228 if (wi)
230 wi->is_lhs = false;
231 wi->val_only = true;
234 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset);
235 if (ret)
236 return ret;
238 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset);
239 if (ret)
240 return ret;
242 for (i = 0; i < gimple_call_num_args (stmt); i++)
244 if (wi)
245 wi->val_only
246 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt, i)));
247 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi,
248 pset);
249 if (ret)
250 return ret;
253 if (gimple_call_lhs (stmt))
255 if (wi)
257 wi->is_lhs = true;
258 wi->val_only
259 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt)));
262 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
263 if (ret)
264 return ret;
267 if (wi)
269 wi->is_lhs = false;
270 wi->val_only = true;
272 break;
274 case GIMPLE_CATCH:
275 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi,
276 pset);
277 if (ret)
278 return ret;
279 break;
281 case GIMPLE_EH_FILTER:
282 ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi,
283 pset);
284 if (ret)
285 return ret;
286 break;
288 case GIMPLE_ASM:
289 ret = walk_gimple_asm (stmt, callback_op, wi);
290 if (ret)
291 return ret;
292 break;
294 case GIMPLE_OMP_CONTINUE:
295 ret = walk_tree (gimple_omp_continue_control_def_ptr (stmt),
296 callback_op, wi, pset);
297 if (ret)
298 return ret;
300 ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt),
301 callback_op, wi, pset);
302 if (ret)
303 return ret;
304 break;
306 case GIMPLE_OMP_CRITICAL:
307 ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi,
308 pset);
309 if (ret)
310 return ret;
311 break;
313 case GIMPLE_OMP_FOR:
314 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi,
315 pset);
316 if (ret)
317 return ret;
318 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
320 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op,
321 wi, pset);
322 if (ret)
323 return ret;
324 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op,
325 wi, pset);
326 if (ret)
327 return ret;
328 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op,
329 wi, pset);
330 if (ret)
331 return ret;
332 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
333 wi, pset);
335 if (ret)
336 return ret;
337 break;
339 case GIMPLE_OMP_PARALLEL:
340 ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
341 wi, pset);
342 if (ret)
343 return ret;
344 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
345 wi, pset);
346 if (ret)
347 return ret;
348 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
349 wi, pset);
350 if (ret)
351 return ret;
352 break;
354 case GIMPLE_OMP_TASK:
355 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op,
356 wi, pset);
357 if (ret)
358 return ret;
359 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op,
360 wi, pset);
361 if (ret)
362 return ret;
363 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op,
364 wi, pset);
365 if (ret)
366 return ret;
367 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op,
368 wi, pset);
369 if (ret)
370 return ret;
371 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op,
372 wi, pset);
373 if (ret)
374 return ret;
375 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op,
376 wi, pset);
377 if (ret)
378 return ret;
379 break;
381 case GIMPLE_OMP_SECTIONS:
382 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op,
383 wi, pset);
384 if (ret)
385 return ret;
387 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
388 wi, pset);
389 if (ret)
390 return ret;
392 break;
394 case GIMPLE_OMP_SINGLE:
395 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi,
396 pset);
397 if (ret)
398 return ret;
399 break;
401 case GIMPLE_OMP_TARGET:
402 ret = walk_tree (gimple_omp_target_clauses_ptr (stmt), callback_op, wi,
403 pset);
404 if (ret)
405 return ret;
406 break;
408 case GIMPLE_OMP_TEAMS:
409 ret = walk_tree (gimple_omp_teams_clauses_ptr (stmt), callback_op, wi,
410 pset);
411 if (ret)
412 return ret;
413 break;
415 case GIMPLE_OMP_ATOMIC_LOAD:
416 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi,
417 pset);
418 if (ret)
419 return ret;
421 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi,
422 pset);
423 if (ret)
424 return ret;
425 break;
427 case GIMPLE_OMP_ATOMIC_STORE:
428 ret = walk_tree (gimple_omp_atomic_store_val_ptr (stmt), callback_op,
429 wi, pset);
430 if (ret)
431 return ret;
432 break;
434 case GIMPLE_TRANSACTION:
435 ret = walk_tree (gimple_transaction_label_ptr (stmt), callback_op,
436 wi, pset);
437 if (ret)
438 return ret;
439 break;
441 case GIMPLE_OMP_RETURN:
442 ret = walk_tree (gimple_omp_return_lhs_ptr (stmt), callback_op, wi,
443 pset);
444 if (ret)
445 return ret;
446 break;
448 /* Tuples that do not have operands. */
449 case GIMPLE_NOP:
450 case GIMPLE_RESX:
451 case GIMPLE_PREDICT:
452 break;
454 default:
456 enum gimple_statement_structure_enum gss;
457 gss = gimple_statement_structure (stmt);
458 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
459 for (i = 0; i < gimple_num_ops (stmt); i++)
461 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
462 if (ret)
463 return ret;
466 break;
469 return NULL_TREE;
473 /* Walk the current statement in GSI (optionally using traversal state
474 stored in WI). If WI is NULL, no state is kept during traversal.
475 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
476 that it has handled all the operands of the statement, its return
477 value is returned. Otherwise, the return value from CALLBACK_STMT
478 is discarded and its operands are scanned.
480 If CALLBACK_STMT is NULL or it didn't handle the operands,
481 CALLBACK_OP is called on each operand of the statement via
482 walk_gimple_op. If walk_gimple_op returns non-NULL for any
483 operand, the remaining operands are not scanned. In this case, the
484 return value from CALLBACK_OP is returned.
486 In any other case, NULL_TREE is returned. */
488 tree
489 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
490 walk_tree_fn callback_op, struct walk_stmt_info *wi)
492 gimple ret;
493 tree tree_ret;
494 gimple stmt = gsi_stmt (*gsi);
496 if (wi)
498 wi->gsi = *gsi;
499 wi->removed_stmt = false;
501 if (wi->want_locations && gimple_has_location (stmt))
502 input_location = gimple_location (stmt);
505 ret = NULL;
507 /* Invoke the statement callback. Return if the callback handled
508 all of STMT operands by itself. */
509 if (callback_stmt)
511 bool handled_ops = false;
512 tree_ret = callback_stmt (gsi, &handled_ops, wi);
513 if (handled_ops)
514 return tree_ret;
516 /* If CALLBACK_STMT did not handle operands, it should not have
517 a value to return. */
518 gcc_assert (tree_ret == NULL);
520 if (wi && wi->removed_stmt)
521 return NULL;
523 /* Re-read stmt in case the callback changed it. */
524 stmt = gsi_stmt (*gsi);
527 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
528 if (callback_op)
530 tree_ret = walk_gimple_op (stmt, callback_op, wi);
531 if (tree_ret)
532 return tree_ret;
535 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
536 switch (gimple_code (stmt))
538 case GIMPLE_BIND:
539 ret = walk_gimple_seq_mod (gimple_bind_body_ptr (stmt), callback_stmt,
540 callback_op, wi);
541 if (ret)
542 return wi->callback_result;
543 break;
545 case GIMPLE_CATCH:
546 ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt), callback_stmt,
547 callback_op, wi);
548 if (ret)
549 return wi->callback_result;
550 break;
552 case GIMPLE_EH_FILTER:
553 ret = walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt), callback_stmt,
554 callback_op, wi);
555 if (ret)
556 return wi->callback_result;
557 break;
559 case GIMPLE_EH_ELSE:
560 ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (stmt),
561 callback_stmt, callback_op, wi);
562 if (ret)
563 return wi->callback_result;
564 ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (stmt),
565 callback_stmt, callback_op, wi);
566 if (ret)
567 return wi->callback_result;
568 break;
570 case GIMPLE_TRY:
571 ret = walk_gimple_seq_mod (gimple_try_eval_ptr (stmt), callback_stmt, callback_op,
572 wi);
573 if (ret)
574 return wi->callback_result;
576 ret = walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt), callback_stmt,
577 callback_op, wi);
578 if (ret)
579 return wi->callback_result;
580 break;
582 case GIMPLE_OMP_FOR:
583 ret = walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt), callback_stmt,
584 callback_op, wi);
585 if (ret)
586 return wi->callback_result;
588 /* FALL THROUGH. */
589 case GIMPLE_OMP_CRITICAL:
590 case GIMPLE_OMP_MASTER:
591 case GIMPLE_OMP_TASKGROUP:
592 case GIMPLE_OMP_ORDERED:
593 case GIMPLE_OMP_SECTION:
594 case GIMPLE_OMP_PARALLEL:
595 case GIMPLE_OMP_TASK:
596 case GIMPLE_OMP_SECTIONS:
597 case GIMPLE_OMP_SINGLE:
598 case GIMPLE_OMP_TARGET:
599 case GIMPLE_OMP_TEAMS:
600 ret = walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), callback_stmt,
601 callback_op, wi);
602 if (ret)
603 return wi->callback_result;
604 break;
606 case GIMPLE_WITH_CLEANUP_EXPR:
607 ret = walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt), callback_stmt,
608 callback_op, wi);
609 if (ret)
610 return wi->callback_result;
611 break;
613 case GIMPLE_TRANSACTION:
614 ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (stmt),
615 callback_stmt, callback_op, wi);
616 if (ret)
617 return wi->callback_result;
618 break;
620 default:
621 gcc_assert (!gimple_has_substatements (stmt));
622 break;
625 return NULL;
628 /* From a tree operand OP return the base of a load or store operation
629 or NULL_TREE if OP is not a load or a store. */
631 static tree
632 get_base_loadstore (tree op)
634 while (handled_component_p (op))
635 op = TREE_OPERAND (op, 0);
636 if (DECL_P (op)
637 || INDIRECT_REF_P (op)
638 || TREE_CODE (op) == MEM_REF
639 || TREE_CODE (op) == TARGET_MEM_REF)
640 return op;
641 return NULL_TREE;
645 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
646 VISIT_ADDR if non-NULL on loads, store and address-taken operands
647 passing the STMT, the base of the operand and DATA to it. The base
648 will be either a decl, an indirect reference (including TARGET_MEM_REF)
649 or the argument of an address expression.
650 Returns the results of these callbacks or'ed. */
652 bool
653 walk_stmt_load_store_addr_ops (gimple stmt, void *data,
654 bool (*visit_load)(gimple, tree, void *),
655 bool (*visit_store)(gimple, tree, void *),
656 bool (*visit_addr)(gimple, tree, void *))
658 bool ret = false;
659 unsigned i;
660 if (gimple_assign_single_p (stmt))
662 tree lhs, rhs;
663 if (visit_store)
665 lhs = get_base_loadstore (gimple_assign_lhs (stmt));
666 if (lhs)
667 ret |= visit_store (stmt, lhs, data);
669 rhs = gimple_assign_rhs1 (stmt);
670 while (handled_component_p (rhs))
671 rhs = TREE_OPERAND (rhs, 0);
672 if (visit_addr)
674 if (TREE_CODE (rhs) == ADDR_EXPR)
675 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
676 else if (TREE_CODE (rhs) == TARGET_MEM_REF
677 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
678 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data);
679 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
680 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
681 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
682 0), data);
683 else if (TREE_CODE (rhs) == CONSTRUCTOR)
685 unsigned int ix;
686 tree val;
688 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
689 if (TREE_CODE (val) == ADDR_EXPR)
690 ret |= visit_addr (stmt, TREE_OPERAND (val, 0), data);
691 else if (TREE_CODE (val) == OBJ_TYPE_REF
692 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
693 ret |= visit_addr (stmt,
694 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
695 0), data);
697 lhs = gimple_assign_lhs (stmt);
698 if (TREE_CODE (lhs) == TARGET_MEM_REF
699 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
700 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data);
702 if (visit_load)
704 rhs = get_base_loadstore (rhs);
705 if (rhs)
706 ret |= visit_load (stmt, rhs, data);
709 else if (visit_addr
710 && (is_gimple_assign (stmt)
711 || gimple_code (stmt) == GIMPLE_COND))
713 for (i = 0; i < gimple_num_ops (stmt); ++i)
715 tree op = gimple_op (stmt, i);
716 if (op == NULL_TREE)
718 else if (TREE_CODE (op) == ADDR_EXPR)
719 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
720 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
721 tree with two operands. */
722 else if (i == 1 && COMPARISON_CLASS_P (op))
724 if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
725 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
726 0), data);
727 if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
728 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
729 0), data);
733 else if (is_gimple_call (stmt))
735 if (visit_store)
737 tree lhs = gimple_call_lhs (stmt);
738 if (lhs)
740 lhs = get_base_loadstore (lhs);
741 if (lhs)
742 ret |= visit_store (stmt, lhs, data);
745 if (visit_load || visit_addr)
746 for (i = 0; i < gimple_call_num_args (stmt); ++i)
748 tree rhs = gimple_call_arg (stmt, i);
749 if (visit_addr
750 && TREE_CODE (rhs) == ADDR_EXPR)
751 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
752 else if (visit_load)
754 rhs = get_base_loadstore (rhs);
755 if (rhs)
756 ret |= visit_load (stmt, rhs, data);
759 if (visit_addr
760 && gimple_call_chain (stmt)
761 && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
762 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
763 data);
764 if (visit_addr
765 && gimple_call_return_slot_opt_p (stmt)
766 && gimple_call_lhs (stmt) != NULL_TREE
767 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
768 ret |= visit_addr (stmt, gimple_call_lhs (stmt), data);
770 else if (gimple_code (stmt) == GIMPLE_ASM)
772 unsigned noutputs;
773 const char *constraint;
774 const char **oconstraints;
775 bool allows_mem, allows_reg, is_inout;
776 noutputs = gimple_asm_noutputs (stmt);
777 oconstraints = XALLOCAVEC (const char *, noutputs);
778 if (visit_store || visit_addr)
779 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
781 tree link = gimple_asm_output_op (stmt, i);
782 tree op = get_base_loadstore (TREE_VALUE (link));
783 if (op && visit_store)
784 ret |= visit_store (stmt, op, data);
785 if (visit_addr)
787 constraint = TREE_STRING_POINTER
788 (TREE_VALUE (TREE_PURPOSE (link)));
789 oconstraints[i] = constraint;
790 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
791 &allows_reg, &is_inout);
792 if (op && !allows_reg && allows_mem)
793 ret |= visit_addr (stmt, op, data);
796 if (visit_load || visit_addr)
797 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
799 tree link = gimple_asm_input_op (stmt, i);
800 tree op = TREE_VALUE (link);
801 if (visit_addr
802 && TREE_CODE (op) == ADDR_EXPR)
803 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
804 else if (visit_load || visit_addr)
806 op = get_base_loadstore (op);
807 if (op)
809 if (visit_load)
810 ret |= visit_load (stmt, op, data);
811 if (visit_addr)
813 constraint = TREE_STRING_POINTER
814 (TREE_VALUE (TREE_PURPOSE (link)));
815 parse_input_constraint (&constraint, 0, 0, noutputs,
816 0, oconstraints,
817 &allows_mem, &allows_reg);
818 if (!allows_reg && allows_mem)
819 ret |= visit_addr (stmt, op, data);
825 else if (gimple_code (stmt) == GIMPLE_RETURN)
827 tree op = gimple_return_retval (stmt);
828 if (op)
830 if (visit_addr
831 && TREE_CODE (op) == ADDR_EXPR)
832 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
833 else if (visit_load)
835 op = get_base_loadstore (op);
836 if (op)
837 ret |= visit_load (stmt, op, data);
841 else if (visit_addr
842 && gimple_code (stmt) == GIMPLE_PHI)
844 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
846 tree op = gimple_phi_arg_def (stmt, i);
847 if (TREE_CODE (op) == ADDR_EXPR)
848 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
851 else if (visit_addr
852 && gimple_code (stmt) == GIMPLE_GOTO)
854 tree op = gimple_goto_dest (stmt);
855 if (TREE_CODE (op) == ADDR_EXPR)
856 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
859 return ret;
862 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
863 should make a faster clone for this case. */
865 bool
866 walk_stmt_load_store_ops (gimple stmt, void *data,
867 bool (*visit_load)(gimple, tree, void *),
868 bool (*visit_store)(gimple, tree, void *))
870 return walk_stmt_load_store_addr_ops (stmt, data,
871 visit_load, visit_store, NULL);