Reverting merge from trunk
[official-gcc.git] / gcc / gimple-walk.c
blobdeb4673354a661de3e7fa35c930777c6ea53b505
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 "gimple.h"
28 #include "gimple-iterator.h"
29 #include "gimple-walk.h"
30 #include "gimple-walk.h"
31 #include "demangle.h"
33 /* Walk all the statements in the sequence *PSEQ calling walk_gimple_stmt
34 on each one. WI is as in walk_gimple_stmt.
36 If walk_gimple_stmt returns non-NULL, the walk is stopped, and the
37 value is stored in WI->CALLBACK_RESULT. Also, the statement that
38 produced the value is returned if this statement has not been
39 removed by a callback (wi->removed_stmt). If the statement has
40 been removed, NULL is returned.
42 Otherwise, all the statements are walked and NULL returned. */
44 gimple
45 walk_gimple_seq_mod (gimple_seq *pseq, walk_stmt_fn callback_stmt,
46 walk_tree_fn callback_op, struct walk_stmt_info *wi)
48 gimple_stmt_iterator gsi;
50 for (gsi = gsi_start (*pseq); !gsi_end_p (gsi); )
52 tree ret = walk_gimple_stmt (&gsi, callback_stmt, callback_op, wi);
53 if (ret)
55 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
56 to hold it. */
57 gcc_assert (wi);
58 wi->callback_result = ret;
60 return wi->removed_stmt ? NULL : gsi_stmt (gsi);
63 if (!wi->removed_stmt)
64 gsi_next (&gsi);
67 if (wi)
68 wi->callback_result = NULL_TREE;
70 return NULL;
74 /* Like walk_gimple_seq_mod, but ensure that the head of SEQ isn't
75 changed by the callbacks. */
77 gimple
78 walk_gimple_seq (gimple_seq seq, walk_stmt_fn callback_stmt,
79 walk_tree_fn callback_op, struct walk_stmt_info *wi)
81 gimple_seq seq2 = seq;
82 gimple ret = walk_gimple_seq_mod (&seq2, callback_stmt, callback_op, wi);
83 gcc_assert (seq2 == seq);
84 return ret;
88 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
90 static tree
91 walk_gimple_asm (gimple stmt, walk_tree_fn callback_op,
92 struct walk_stmt_info *wi)
94 tree ret, op;
95 unsigned noutputs;
96 const char **oconstraints;
97 unsigned i, n;
98 const char *constraint;
99 bool allows_mem, allows_reg, is_inout;
101 noutputs = gimple_asm_noutputs (stmt);
102 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
104 if (wi)
105 wi->is_lhs = true;
107 for (i = 0; i < noutputs; i++)
109 op = gimple_asm_output_op (stmt, i);
110 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
111 oconstraints[i] = constraint;
112 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, &allows_reg,
113 &is_inout);
114 if (wi)
115 wi->val_only = (allows_reg || !allows_mem);
116 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
117 if (ret)
118 return ret;
121 n = gimple_asm_ninputs (stmt);
122 for (i = 0; i < n; i++)
124 op = gimple_asm_input_op (stmt, i);
125 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
126 parse_input_constraint (&constraint, 0, 0, noutputs, 0,
127 oconstraints, &allows_mem, &allows_reg);
128 if (wi)
130 wi->val_only = (allows_reg || !allows_mem);
131 /* Although input "m" is not really a LHS, we need a lvalue. */
132 wi->is_lhs = !wi->val_only;
134 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
135 if (ret)
136 return ret;
139 if (wi)
141 wi->is_lhs = false;
142 wi->val_only = true;
145 n = gimple_asm_nlabels (stmt);
146 for (i = 0; i < n; i++)
148 op = gimple_asm_label_op (stmt, i);
149 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
150 if (ret)
151 return ret;
154 return NULL_TREE;
158 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
159 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
161 CALLBACK_OP is called on each operand of STMT via walk_tree.
162 Additional parameters to walk_tree must be stored in WI. For each operand
163 OP, walk_tree is called as:
165 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
167 If CALLBACK_OP returns non-NULL for an operand, the remaining
168 operands are not scanned.
170 The return value is that returned by the last call to walk_tree, or
171 NULL_TREE if no CALLBACK_OP is specified. */
173 tree
174 walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
175 struct walk_stmt_info *wi)
177 struct pointer_set_t *pset = (wi) ? wi->pset : NULL;
178 unsigned i;
179 tree ret = NULL_TREE;
181 switch (gimple_code (stmt))
183 case GIMPLE_ASSIGN:
184 /* Walk the RHS operands. If the LHS is of a non-renamable type or
185 is a register variable, we may use a COMPONENT_REF on the RHS. */
186 if (wi)
188 tree lhs = gimple_assign_lhs (stmt);
189 wi->val_only
190 = (is_gimple_reg_type (TREE_TYPE (lhs)) && !is_gimple_reg (lhs))
191 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
194 for (i = 1; i < gimple_num_ops (stmt); i++)
196 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi,
197 pset);
198 if (ret)
199 return ret;
202 /* Walk the LHS. If the RHS is appropriate for a memory, we
203 may use a COMPONENT_REF on the LHS. */
204 if (wi)
206 /* If the RHS is of a non-renamable type or is a register variable,
207 we may use a COMPONENT_REF on the LHS. */
208 tree rhs1 = gimple_assign_rhs1 (stmt);
209 wi->val_only
210 = (is_gimple_reg_type (TREE_TYPE (rhs1)) && !is_gimple_reg (rhs1))
211 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
212 wi->is_lhs = true;
215 ret = walk_tree (gimple_op_ptr (stmt, 0), callback_op, wi, pset);
216 if (ret)
217 return ret;
219 if (wi)
221 wi->val_only = true;
222 wi->is_lhs = false;
224 break;
226 case GIMPLE_CALL:
227 if (wi)
229 wi->is_lhs = false;
230 wi->val_only = true;
233 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset);
234 if (ret)
235 return ret;
237 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset);
238 if (ret)
239 return ret;
241 for (i = 0; i < gimple_call_num_args (stmt); i++)
243 if (wi)
244 wi->val_only
245 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt, i)));
246 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi,
247 pset);
248 if (ret)
249 return ret;
252 if (gimple_call_lhs (stmt))
254 if (wi)
256 wi->is_lhs = true;
257 wi->val_only
258 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt)));
261 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
262 if (ret)
263 return ret;
266 if (wi)
268 wi->is_lhs = false;
269 wi->val_only = true;
271 break;
273 case GIMPLE_CATCH:
274 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi,
275 pset);
276 if (ret)
277 return ret;
278 break;
280 case GIMPLE_EH_FILTER:
281 ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi,
282 pset);
283 if (ret)
284 return ret;
285 break;
287 case GIMPLE_ASM:
288 ret = walk_gimple_asm (stmt, callback_op, wi);
289 if (ret)
290 return ret;
291 break;
293 case GIMPLE_OMP_CONTINUE:
294 ret = walk_tree (gimple_omp_continue_control_def_ptr (stmt),
295 callback_op, wi, pset);
296 if (ret)
297 return ret;
299 ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt),
300 callback_op, wi, pset);
301 if (ret)
302 return ret;
303 break;
305 case GIMPLE_OMP_CRITICAL:
306 ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi,
307 pset);
308 if (ret)
309 return ret;
310 break;
312 case GIMPLE_OMP_FOR:
313 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi,
314 pset);
315 if (ret)
316 return ret;
317 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
319 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op,
320 wi, pset);
321 if (ret)
322 return ret;
323 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op,
324 wi, pset);
325 if (ret)
326 return ret;
327 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op,
328 wi, pset);
329 if (ret)
330 return ret;
331 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
332 wi, pset);
334 if (ret)
335 return ret;
336 break;
338 case GIMPLE_OMP_PARALLEL:
339 ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
340 wi, pset);
341 if (ret)
342 return ret;
343 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
344 wi, pset);
345 if (ret)
346 return ret;
347 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
348 wi, pset);
349 if (ret)
350 return ret;
351 break;
353 case GIMPLE_OMP_TASK:
354 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op,
355 wi, pset);
356 if (ret)
357 return ret;
358 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op,
359 wi, pset);
360 if (ret)
361 return ret;
362 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op,
363 wi, pset);
364 if (ret)
365 return ret;
366 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op,
367 wi, pset);
368 if (ret)
369 return ret;
370 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op,
371 wi, pset);
372 if (ret)
373 return ret;
374 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op,
375 wi, pset);
376 if (ret)
377 return ret;
378 break;
380 case GIMPLE_OMP_SECTIONS:
381 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op,
382 wi, pset);
383 if (ret)
384 return ret;
386 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
387 wi, pset);
388 if (ret)
389 return ret;
391 break;
393 case GIMPLE_OMP_SINGLE:
394 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi,
395 pset);
396 if (ret)
397 return ret;
398 break;
400 case GIMPLE_OMP_TARGET:
401 ret = walk_tree (gimple_omp_target_clauses_ptr (stmt), callback_op, wi,
402 pset);
403 if (ret)
404 return ret;
405 break;
407 case GIMPLE_OMP_TEAMS:
408 ret = walk_tree (gimple_omp_teams_clauses_ptr (stmt), callback_op, wi,
409 pset);
410 if (ret)
411 return ret;
412 break;
414 case GIMPLE_OMP_ATOMIC_LOAD:
415 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi,
416 pset);
417 if (ret)
418 return ret;
420 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi,
421 pset);
422 if (ret)
423 return ret;
424 break;
426 case GIMPLE_OMP_ATOMIC_STORE:
427 ret = walk_tree (gimple_omp_atomic_store_val_ptr (stmt), callback_op,
428 wi, pset);
429 if (ret)
430 return ret;
431 break;
433 case GIMPLE_TRANSACTION:
434 ret = walk_tree (gimple_transaction_label_ptr (stmt), callback_op,
435 wi, pset);
436 if (ret)
437 return ret;
438 break;
440 case GIMPLE_OMP_RETURN:
441 ret = walk_tree (gimple_omp_return_lhs_ptr (stmt), callback_op, wi,
442 pset);
443 if (ret)
444 return ret;
445 break;
447 /* Tuples that do not have operands. */
448 case GIMPLE_NOP:
449 case GIMPLE_RESX:
450 case GIMPLE_PREDICT:
451 break;
453 default:
455 enum gimple_statement_structure_enum gss;
456 gss = gimple_statement_structure (stmt);
457 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
458 for (i = 0; i < gimple_num_ops (stmt); i++)
460 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
461 if (ret)
462 return ret;
465 break;
468 return NULL_TREE;
472 /* Walk the current statement in GSI (optionally using traversal state
473 stored in WI). If WI is NULL, no state is kept during traversal.
474 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
475 that it has handled all the operands of the statement, its return
476 value is returned. Otherwise, the return value from CALLBACK_STMT
477 is discarded and its operands are scanned.
479 If CALLBACK_STMT is NULL or it didn't handle the operands,
480 CALLBACK_OP is called on each operand of the statement via
481 walk_gimple_op. If walk_gimple_op returns non-NULL for any
482 operand, the remaining operands are not scanned. In this case, the
483 return value from CALLBACK_OP is returned.
485 In any other case, NULL_TREE is returned. */
487 tree
488 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
489 walk_tree_fn callback_op, struct walk_stmt_info *wi)
491 gimple ret;
492 tree tree_ret;
493 gimple stmt = gsi_stmt (*gsi);
495 if (wi)
497 wi->gsi = *gsi;
498 wi->removed_stmt = false;
500 if (wi->want_locations && gimple_has_location (stmt))
501 input_location = gimple_location (stmt);
504 ret = NULL;
506 /* Invoke the statement callback. Return if the callback handled
507 all of STMT operands by itself. */
508 if (callback_stmt)
510 bool handled_ops = false;
511 tree_ret = callback_stmt (gsi, &handled_ops, wi);
512 if (handled_ops)
513 return tree_ret;
515 /* If CALLBACK_STMT did not handle operands, it should not have
516 a value to return. */
517 gcc_assert (tree_ret == NULL);
519 if (wi && wi->removed_stmt)
520 return NULL;
522 /* Re-read stmt in case the callback changed it. */
523 stmt = gsi_stmt (*gsi);
526 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
527 if (callback_op)
529 tree_ret = walk_gimple_op (stmt, callback_op, wi);
530 if (tree_ret)
531 return tree_ret;
534 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
535 switch (gimple_code (stmt))
537 case GIMPLE_BIND:
538 ret = walk_gimple_seq_mod (gimple_bind_body_ptr (stmt), callback_stmt,
539 callback_op, wi);
540 if (ret)
541 return wi->callback_result;
542 break;
544 case GIMPLE_CATCH:
545 ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt), callback_stmt,
546 callback_op, wi);
547 if (ret)
548 return wi->callback_result;
549 break;
551 case GIMPLE_EH_FILTER:
552 ret = walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt), callback_stmt,
553 callback_op, wi);
554 if (ret)
555 return wi->callback_result;
556 break;
558 case GIMPLE_EH_ELSE:
559 ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (stmt),
560 callback_stmt, callback_op, wi);
561 if (ret)
562 return wi->callback_result;
563 ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (stmt),
564 callback_stmt, callback_op, wi);
565 if (ret)
566 return wi->callback_result;
567 break;
569 case GIMPLE_TRY:
570 ret = walk_gimple_seq_mod (gimple_try_eval_ptr (stmt), callback_stmt, callback_op,
571 wi);
572 if (ret)
573 return wi->callback_result;
575 ret = walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt), callback_stmt,
576 callback_op, wi);
577 if (ret)
578 return wi->callback_result;
579 break;
581 case GIMPLE_OMP_FOR:
582 ret = walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt), callback_stmt,
583 callback_op, wi);
584 if (ret)
585 return wi->callback_result;
587 /* FALL THROUGH. */
588 case GIMPLE_OMP_CRITICAL:
589 case GIMPLE_OMP_MASTER:
590 case GIMPLE_OMP_TASKGROUP:
591 case GIMPLE_OMP_ORDERED:
592 case GIMPLE_OMP_SECTION:
593 case GIMPLE_OMP_PARALLEL:
594 case GIMPLE_OMP_TASK:
595 case GIMPLE_OMP_SECTIONS:
596 case GIMPLE_OMP_SINGLE:
597 case GIMPLE_OMP_TARGET:
598 case GIMPLE_OMP_TEAMS:
599 ret = walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), callback_stmt,
600 callback_op, wi);
601 if (ret)
602 return wi->callback_result;
603 break;
605 case GIMPLE_WITH_CLEANUP_EXPR:
606 ret = walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt), callback_stmt,
607 callback_op, wi);
608 if (ret)
609 return wi->callback_result;
610 break;
612 case GIMPLE_TRANSACTION:
613 ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (stmt),
614 callback_stmt, callback_op, wi);
615 if (ret)
616 return wi->callback_result;
617 break;
619 default:
620 gcc_assert (!gimple_has_substatements (stmt));
621 break;
624 return NULL;
627 /* From a tree operand OP return the base of a load or store operation
628 or NULL_TREE if OP is not a load or a store. */
630 static tree
631 get_base_loadstore (tree op)
633 while (handled_component_p (op))
634 op = TREE_OPERAND (op, 0);
635 if (DECL_P (op)
636 || INDIRECT_REF_P (op)
637 || TREE_CODE (op) == MEM_REF
638 || TREE_CODE (op) == TARGET_MEM_REF)
639 return op;
640 return NULL_TREE;
644 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
645 VISIT_ADDR if non-NULL on loads, store and address-taken operands
646 passing the STMT, the base of the operand and DATA to it. The base
647 will be either a decl, an indirect reference (including TARGET_MEM_REF)
648 or the argument of an address expression.
649 Returns the results of these callbacks or'ed. */
651 bool
652 walk_stmt_load_store_addr_ops (gimple stmt, void *data,
653 bool (*visit_load)(gimple, tree, void *),
654 bool (*visit_store)(gimple, tree, void *),
655 bool (*visit_addr)(gimple, tree, void *))
657 bool ret = false;
658 unsigned i;
659 if (gimple_assign_single_p (stmt))
661 tree lhs, rhs;
662 if (visit_store)
664 lhs = get_base_loadstore (gimple_assign_lhs (stmt));
665 if (lhs)
666 ret |= visit_store (stmt, lhs, data);
668 rhs = gimple_assign_rhs1 (stmt);
669 while (handled_component_p (rhs))
670 rhs = TREE_OPERAND (rhs, 0);
671 if (visit_addr)
673 if (TREE_CODE (rhs) == ADDR_EXPR)
674 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
675 else if (TREE_CODE (rhs) == TARGET_MEM_REF
676 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
677 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), data);
678 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
679 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
680 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
681 0), data);
682 else if (TREE_CODE (rhs) == CONSTRUCTOR)
684 unsigned int ix;
685 tree val;
687 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
688 if (TREE_CODE (val) == ADDR_EXPR)
689 ret |= visit_addr (stmt, TREE_OPERAND (val, 0), data);
690 else if (TREE_CODE (val) == OBJ_TYPE_REF
691 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
692 ret |= visit_addr (stmt,
693 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
694 0), data);
696 lhs = gimple_assign_lhs (stmt);
697 if (TREE_CODE (lhs) == TARGET_MEM_REF
698 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
699 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), data);
701 if (visit_load)
703 rhs = get_base_loadstore (rhs);
704 if (rhs)
705 ret |= visit_load (stmt, rhs, data);
708 else if (visit_addr
709 && (is_gimple_assign (stmt)
710 || gimple_code (stmt) == GIMPLE_COND))
712 for (i = 0; i < gimple_num_ops (stmt); ++i)
714 tree op = gimple_op (stmt, i);
715 if (op == NULL_TREE)
717 else if (TREE_CODE (op) == ADDR_EXPR)
718 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
719 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
720 tree with two operands. */
721 else if (i == 1 && COMPARISON_CLASS_P (op))
723 if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
724 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
725 0), data);
726 if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
727 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
728 0), data);
732 else if (is_gimple_call (stmt))
734 if (visit_store)
736 tree lhs = gimple_call_lhs (stmt);
737 if (lhs)
739 lhs = get_base_loadstore (lhs);
740 if (lhs)
741 ret |= visit_store (stmt, lhs, data);
744 if (visit_load || visit_addr)
745 for (i = 0; i < gimple_call_num_args (stmt); ++i)
747 tree rhs = gimple_call_arg (stmt, i);
748 if (visit_addr
749 && TREE_CODE (rhs) == ADDR_EXPR)
750 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), data);
751 else if (visit_load)
753 rhs = get_base_loadstore (rhs);
754 if (rhs)
755 ret |= visit_load (stmt, rhs, data);
758 if (visit_addr
759 && gimple_call_chain (stmt)
760 && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
761 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
762 data);
763 if (visit_addr
764 && gimple_call_return_slot_opt_p (stmt)
765 && gimple_call_lhs (stmt) != NULL_TREE
766 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
767 ret |= visit_addr (stmt, gimple_call_lhs (stmt), data);
769 else if (gimple_code (stmt) == GIMPLE_ASM)
771 unsigned noutputs;
772 const char *constraint;
773 const char **oconstraints;
774 bool allows_mem, allows_reg, is_inout;
775 noutputs = gimple_asm_noutputs (stmt);
776 oconstraints = XALLOCAVEC (const char *, noutputs);
777 if (visit_store || visit_addr)
778 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
780 tree link = gimple_asm_output_op (stmt, i);
781 tree op = get_base_loadstore (TREE_VALUE (link));
782 if (op && visit_store)
783 ret |= visit_store (stmt, op, data);
784 if (visit_addr)
786 constraint = TREE_STRING_POINTER
787 (TREE_VALUE (TREE_PURPOSE (link)));
788 oconstraints[i] = constraint;
789 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
790 &allows_reg, &is_inout);
791 if (op && !allows_reg && allows_mem)
792 ret |= visit_addr (stmt, op, data);
795 if (visit_load || visit_addr)
796 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
798 tree link = gimple_asm_input_op (stmt, i);
799 tree op = TREE_VALUE (link);
800 if (visit_addr
801 && TREE_CODE (op) == ADDR_EXPR)
802 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
803 else if (visit_load || visit_addr)
805 op = get_base_loadstore (op);
806 if (op)
808 if (visit_load)
809 ret |= visit_load (stmt, op, data);
810 if (visit_addr)
812 constraint = TREE_STRING_POINTER
813 (TREE_VALUE (TREE_PURPOSE (link)));
814 parse_input_constraint (&constraint, 0, 0, noutputs,
815 0, oconstraints,
816 &allows_mem, &allows_reg);
817 if (!allows_reg && allows_mem)
818 ret |= visit_addr (stmt, op, data);
824 else if (gimple_code (stmt) == GIMPLE_RETURN)
826 tree op = gimple_return_retval (stmt);
827 if (op)
829 if (visit_addr
830 && TREE_CODE (op) == ADDR_EXPR)
831 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
832 else if (visit_load)
834 op = get_base_loadstore (op);
835 if (op)
836 ret |= visit_load (stmt, op, data);
840 else if (visit_addr
841 && gimple_code (stmt) == GIMPLE_PHI)
843 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
845 tree op = gimple_phi_arg_def (stmt, i);
846 if (TREE_CODE (op) == ADDR_EXPR)
847 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
850 else if (visit_addr
851 && gimple_code (stmt) == GIMPLE_GOTO)
853 tree op = gimple_goto_dest (stmt);
854 if (TREE_CODE (op) == ADDR_EXPR)
855 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), data);
858 return ret;
861 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
862 should make a faster clone for this case. */
864 bool
865 walk_stmt_load_store_ops (gimple stmt, void *data,
866 bool (*visit_load)(gimple, tree, void *),
867 bool (*visit_store)(gimple, tree, void *))
869 return walk_stmt_load_store_addr_ops (stmt, data,
870 visit_load, visit_store, NULL);