svn merge -r215707:216846 svn+ssh://gcc.gnu.org/svn/gcc/trunk
[official-gcc.git] / gcc / gimple-walk.c
blobcc74d34e1d57eb04874c80b8bf7d976881bbb83f
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 "predict.h"
29 #include "vec.h"
30 #include "hashtab.h"
31 #include "hash-set.h"
32 #include "machmode.h"
33 #include "hard-reg-set.h"
34 #include "input.h"
35 #include "function.h"
36 #include "basic-block.h"
37 #include "tree-ssa-alias.h"
38 #include "internal-fn.h"
39 #include "gimple-expr.h"
40 #include "is-a.h"
41 #include "gimple.h"
42 #include "gimple-iterator.h"
43 #include "gimple-walk.h"
44 #include "gimple-walk.h"
45 #include "demangle.h"
47 /* Walk all the statements in the sequence *PSEQ calling walk_gimple_stmt
48 on each one. WI is as in walk_gimple_stmt.
50 If walk_gimple_stmt returns non-NULL, the walk is stopped, and the
51 value is stored in WI->CALLBACK_RESULT. Also, the statement that
52 produced the value is returned if this statement has not been
53 removed by a callback (wi->removed_stmt). If the statement has
54 been removed, NULL is returned.
56 Otherwise, all the statements are walked and NULL returned. */
58 gimple
59 walk_gimple_seq_mod (gimple_seq *pseq, walk_stmt_fn callback_stmt,
60 walk_tree_fn callback_op, struct walk_stmt_info *wi)
62 gimple_stmt_iterator gsi;
64 for (gsi = gsi_start (*pseq); !gsi_end_p (gsi); )
66 tree ret = walk_gimple_stmt (&gsi, callback_stmt, callback_op, wi);
67 if (ret)
69 /* If CALLBACK_STMT or CALLBACK_OP return a value, WI must exist
70 to hold it. */
71 gcc_assert (wi);
72 wi->callback_result = ret;
74 return wi->removed_stmt ? NULL : gsi_stmt (gsi);
77 if (!wi->removed_stmt)
78 gsi_next (&gsi);
81 if (wi)
82 wi->callback_result = NULL_TREE;
84 return NULL;
88 /* Like walk_gimple_seq_mod, but ensure that the head of SEQ isn't
89 changed by the callbacks. */
91 gimple
92 walk_gimple_seq (gimple_seq seq, walk_stmt_fn callback_stmt,
93 walk_tree_fn callback_op, struct walk_stmt_info *wi)
95 gimple_seq seq2 = seq;
96 gimple ret = walk_gimple_seq_mod (&seq2, callback_stmt, callback_op, wi);
97 gcc_assert (seq2 == seq);
98 return ret;
102 /* Helper function for walk_gimple_stmt. Walk operands of a GIMPLE_ASM. */
104 static tree
105 walk_gimple_asm (gimple stmt, walk_tree_fn callback_op,
106 struct walk_stmt_info *wi)
108 tree ret, op;
109 unsigned noutputs;
110 const char **oconstraints;
111 unsigned i, n;
112 const char *constraint;
113 bool allows_mem, allows_reg, is_inout;
115 noutputs = gimple_asm_noutputs (stmt);
116 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *));
118 if (wi)
119 wi->is_lhs = true;
121 for (i = 0; i < noutputs; i++)
123 op = gimple_asm_output_op (stmt, i);
124 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
125 oconstraints[i] = constraint;
126 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, &allows_reg,
127 &is_inout);
128 if (wi)
129 wi->val_only = (allows_reg || !allows_mem);
130 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
131 if (ret)
132 return ret;
135 n = gimple_asm_ninputs (stmt);
136 for (i = 0; i < n; i++)
138 op = gimple_asm_input_op (stmt, i);
139 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (op)));
140 parse_input_constraint (&constraint, 0, 0, noutputs, 0,
141 oconstraints, &allows_mem, &allows_reg);
142 if (wi)
144 wi->val_only = (allows_reg || !allows_mem);
145 /* Although input "m" is not really a LHS, we need a lvalue. */
146 wi->is_lhs = !wi->val_only;
148 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
149 if (ret)
150 return ret;
153 if (wi)
155 wi->is_lhs = false;
156 wi->val_only = true;
159 n = gimple_asm_nlabels (stmt);
160 for (i = 0; i < n; i++)
162 op = gimple_asm_label_op (stmt, i);
163 ret = walk_tree (&TREE_VALUE (op), callback_op, wi, NULL);
164 if (ret)
165 return ret;
168 return NULL_TREE;
172 /* Helper function of WALK_GIMPLE_STMT. Walk every tree operand in
173 STMT. CALLBACK_OP and WI are as in WALK_GIMPLE_STMT.
175 CALLBACK_OP is called on each operand of STMT via walk_tree.
176 Additional parameters to walk_tree must be stored in WI. For each operand
177 OP, walk_tree is called as:
179 walk_tree (&OP, CALLBACK_OP, WI, WI->PSET)
181 If CALLBACK_OP returns non-NULL for an operand, the remaining
182 operands are not scanned.
184 The return value is that returned by the last call to walk_tree, or
185 NULL_TREE if no CALLBACK_OP is specified. */
187 tree
188 walk_gimple_op (gimple stmt, walk_tree_fn callback_op,
189 struct walk_stmt_info *wi)
191 hash_set<tree> *pset = (wi) ? wi->pset : NULL;
192 unsigned i;
193 tree ret = NULL_TREE;
195 switch (gimple_code (stmt))
197 case GIMPLE_ASSIGN:
198 /* Walk the RHS operands. If the LHS is of a non-renamable type or
199 is a register variable, we may use a COMPONENT_REF on the RHS. */
200 if (wi)
202 tree lhs = gimple_assign_lhs (stmt);
203 wi->val_only
204 = (is_gimple_reg_type (TREE_TYPE (lhs)) && !is_gimple_reg (lhs))
205 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
208 for (i = 1; i < gimple_num_ops (stmt); i++)
210 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi,
211 pset);
212 if (ret)
213 return ret;
216 /* Walk the LHS. If the RHS is appropriate for a memory, we
217 may use a COMPONENT_REF on the LHS. */
218 if (wi)
220 /* If the RHS is of a non-renamable type or is a register variable,
221 we may use a COMPONENT_REF on the LHS. */
222 tree rhs1 = gimple_assign_rhs1 (stmt);
223 wi->val_only
224 = (is_gimple_reg_type (TREE_TYPE (rhs1)) && !is_gimple_reg (rhs1))
225 || gimple_assign_rhs_class (stmt) != GIMPLE_SINGLE_RHS;
226 wi->is_lhs = true;
229 ret = walk_tree (gimple_op_ptr (stmt, 0), callback_op, wi, pset);
230 if (ret)
231 return ret;
233 if (wi)
235 wi->val_only = true;
236 wi->is_lhs = false;
238 break;
240 case GIMPLE_CALL:
241 if (wi)
243 wi->is_lhs = false;
244 wi->val_only = true;
247 ret = walk_tree (gimple_call_chain_ptr (stmt), callback_op, wi, pset);
248 if (ret)
249 return ret;
251 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset);
252 if (ret)
253 return ret;
255 for (i = 0; i < gimple_call_num_args (stmt); i++)
257 if (wi)
258 wi->val_only
259 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt, i)));
260 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi,
261 pset);
262 if (ret)
263 return ret;
266 if (gimple_call_lhs (stmt))
268 if (wi)
270 wi->is_lhs = true;
271 wi->val_only
272 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt)));
275 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
276 if (ret)
277 return ret;
280 if (wi)
282 wi->is_lhs = false;
283 wi->val_only = true;
285 break;
287 case GIMPLE_CATCH:
288 ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi,
289 pset);
290 if (ret)
291 return ret;
292 break;
294 case GIMPLE_EH_FILTER:
295 ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi,
296 pset);
297 if (ret)
298 return ret;
299 break;
301 case GIMPLE_ASM:
302 ret = walk_gimple_asm (stmt, callback_op, wi);
303 if (ret)
304 return ret;
305 break;
307 case GIMPLE_OACC_KERNELS:
308 ret = walk_tree (gimple_oacc_kernels_clauses_ptr (stmt), callback_op,
309 wi, pset);
310 if (ret)
311 return ret;
312 ret = walk_tree (gimple_oacc_kernels_child_fn_ptr (stmt), callback_op,
313 wi, pset);
314 if (ret)
315 return ret;
316 ret = walk_tree (gimple_oacc_kernels_data_arg_ptr (stmt), callback_op,
317 wi, pset);
318 if (ret)
319 return ret;
320 break;
322 case GIMPLE_OACC_PARALLEL:
323 ret = walk_tree (gimple_oacc_parallel_clauses_ptr (stmt), callback_op,
324 wi, pset);
325 if (ret)
326 return ret;
327 ret = walk_tree (gimple_oacc_parallel_child_fn_ptr (stmt), callback_op,
328 wi, pset);
329 if (ret)
330 return ret;
331 ret = walk_tree (gimple_oacc_parallel_data_arg_ptr (stmt), callback_op,
332 wi, pset);
333 if (ret)
334 return ret;
335 break;
337 case GIMPLE_OMP_CONTINUE:
338 ret = walk_tree (gimple_omp_continue_control_def_ptr (stmt),
339 callback_op, wi, pset);
340 if (ret)
341 return ret;
343 ret = walk_tree (gimple_omp_continue_control_use_ptr (stmt),
344 callback_op, wi, pset);
345 if (ret)
346 return ret;
347 break;
349 case GIMPLE_OMP_CRITICAL:
350 ret = walk_tree (gimple_omp_critical_name_ptr (stmt), callback_op, wi,
351 pset);
352 if (ret)
353 return ret;
354 break;
356 case GIMPLE_OMP_FOR:
357 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi,
358 pset);
359 if (ret)
360 return ret;
361 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
363 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op,
364 wi, pset);
365 if (ret)
366 return ret;
367 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op,
368 wi, pset);
369 if (ret)
370 return ret;
371 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op,
372 wi, pset);
373 if (ret)
374 return ret;
375 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
376 wi, pset);
378 if (ret)
379 return ret;
380 break;
382 case GIMPLE_OMP_PARALLEL:
383 ret = walk_tree (gimple_omp_parallel_clauses_ptr (stmt), callback_op,
384 wi, pset);
385 if (ret)
386 return ret;
387 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (stmt), callback_op,
388 wi, pset);
389 if (ret)
390 return ret;
391 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (stmt), callback_op,
392 wi, pset);
393 if (ret)
394 return ret;
395 break;
397 case GIMPLE_OMP_TASK:
398 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op,
399 wi, pset);
400 if (ret)
401 return ret;
402 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op,
403 wi, pset);
404 if (ret)
405 return ret;
406 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op,
407 wi, pset);
408 if (ret)
409 return ret;
410 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op,
411 wi, pset);
412 if (ret)
413 return ret;
414 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op,
415 wi, pset);
416 if (ret)
417 return ret;
418 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op,
419 wi, pset);
420 if (ret)
421 return ret;
422 break;
424 case GIMPLE_OMP_SECTIONS:
425 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op,
426 wi, pset);
427 if (ret)
428 return ret;
430 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
431 wi, pset);
432 if (ret)
433 return ret;
435 break;
437 case GIMPLE_OMP_SINGLE:
438 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi,
439 pset);
440 if (ret)
441 return ret;
442 break;
444 case GIMPLE_OMP_TARGET:
445 ret = walk_tree (gimple_omp_target_clauses_ptr (stmt), callback_op, wi,
446 pset);
447 if (ret)
448 return ret;
449 break;
451 case GIMPLE_OMP_TEAMS:
452 ret = walk_tree (gimple_omp_teams_clauses_ptr (stmt), callback_op, wi,
453 pset);
454 if (ret)
455 return ret;
456 break;
458 case GIMPLE_OMP_ATOMIC_LOAD:
459 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (stmt), callback_op, wi,
460 pset);
461 if (ret)
462 return ret;
464 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (stmt), callback_op, wi,
465 pset);
466 if (ret)
467 return ret;
468 break;
470 case GIMPLE_OMP_ATOMIC_STORE:
471 ret = walk_tree (gimple_omp_atomic_store_val_ptr (stmt), callback_op,
472 wi, pset);
473 if (ret)
474 return ret;
475 break;
477 case GIMPLE_TRANSACTION:
478 ret = walk_tree (gimple_transaction_label_ptr (stmt), callback_op,
479 wi, pset);
480 if (ret)
481 return ret;
482 break;
484 case GIMPLE_OMP_RETURN:
485 ret = walk_tree (gimple_omp_return_lhs_ptr (stmt), callback_op, wi,
486 pset);
487 if (ret)
488 return ret;
489 break;
491 /* Tuples that do not have operands. */
492 case GIMPLE_NOP:
493 case GIMPLE_RESX:
494 case GIMPLE_PREDICT:
495 break;
497 default:
499 enum gimple_statement_structure_enum gss;
500 gss = gimple_statement_structure (stmt);
501 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
502 for (i = 0; i < gimple_num_ops (stmt); i++)
504 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
505 if (ret)
506 return ret;
509 break;
512 return NULL_TREE;
516 /* Walk the current statement in GSI (optionally using traversal state
517 stored in WI). If WI is NULL, no state is kept during traversal.
518 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
519 that it has handled all the operands of the statement, its return
520 value is returned. Otherwise, the return value from CALLBACK_STMT
521 is discarded and its operands are scanned.
523 If CALLBACK_STMT is NULL or it didn't handle the operands,
524 CALLBACK_OP is called on each operand of the statement via
525 walk_gimple_op. If walk_gimple_op returns non-NULL for any
526 operand, the remaining operands are not scanned. In this case, the
527 return value from CALLBACK_OP is returned.
529 In any other case, NULL_TREE is returned. */
531 tree
532 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
533 walk_tree_fn callback_op, struct walk_stmt_info *wi)
535 gimple ret;
536 tree tree_ret;
537 gimple stmt = gsi_stmt (*gsi);
539 if (wi)
541 wi->gsi = *gsi;
542 wi->removed_stmt = false;
544 if (wi->want_locations && gimple_has_location (stmt))
545 input_location = gimple_location (stmt);
548 ret = NULL;
550 /* Invoke the statement callback. Return if the callback handled
551 all of STMT operands by itself. */
552 if (callback_stmt)
554 bool handled_ops = false;
555 tree_ret = callback_stmt (gsi, &handled_ops, wi);
556 if (handled_ops)
557 return tree_ret;
559 /* If CALLBACK_STMT did not handle operands, it should not have
560 a value to return. */
561 gcc_assert (tree_ret == NULL);
563 if (wi && wi->removed_stmt)
564 return NULL;
566 /* Re-read stmt in case the callback changed it. */
567 stmt = gsi_stmt (*gsi);
570 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
571 if (callback_op)
573 tree_ret = walk_gimple_op (stmt, callback_op, wi);
574 if (tree_ret)
575 return tree_ret;
578 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
579 switch (gimple_code (stmt))
581 case GIMPLE_BIND:
582 ret = walk_gimple_seq_mod (gimple_bind_body_ptr (stmt), callback_stmt,
583 callback_op, wi);
584 if (ret)
585 return wi->callback_result;
586 break;
588 case GIMPLE_CATCH:
589 ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt), callback_stmt,
590 callback_op, wi);
591 if (ret)
592 return wi->callback_result;
593 break;
595 case GIMPLE_EH_FILTER:
596 ret = walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt), callback_stmt,
597 callback_op, wi);
598 if (ret)
599 return wi->callback_result;
600 break;
602 case GIMPLE_EH_ELSE:
603 ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (stmt),
604 callback_stmt, callback_op, wi);
605 if (ret)
606 return wi->callback_result;
607 ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (stmt),
608 callback_stmt, callback_op, wi);
609 if (ret)
610 return wi->callback_result;
611 break;
613 case GIMPLE_TRY:
614 ret = walk_gimple_seq_mod (gimple_try_eval_ptr (stmt), callback_stmt, callback_op,
615 wi);
616 if (ret)
617 return wi->callback_result;
619 ret = walk_gimple_seq_mod (gimple_try_cleanup_ptr (stmt), callback_stmt,
620 callback_op, wi);
621 if (ret)
622 return wi->callback_result;
623 break;
625 case GIMPLE_OMP_FOR:
626 ret = walk_gimple_seq_mod (gimple_omp_for_pre_body_ptr (stmt), callback_stmt,
627 callback_op, wi);
628 if (ret)
629 return wi->callback_result;
631 /* FALL THROUGH. */
632 case GIMPLE_OACC_KERNELS:
633 case GIMPLE_OACC_PARALLEL:
634 case GIMPLE_OMP_CRITICAL:
635 case GIMPLE_OMP_MASTER:
636 case GIMPLE_OMP_TASKGROUP:
637 case GIMPLE_OMP_ORDERED:
638 case GIMPLE_OMP_SECTION:
639 case GIMPLE_OMP_PARALLEL:
640 case GIMPLE_OMP_TASK:
641 case GIMPLE_OMP_SECTIONS:
642 case GIMPLE_OMP_SINGLE:
643 case GIMPLE_OMP_TARGET:
644 case GIMPLE_OMP_TEAMS:
645 ret = walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), callback_stmt,
646 callback_op, wi);
647 if (ret)
648 return wi->callback_result;
649 break;
651 case GIMPLE_WITH_CLEANUP_EXPR:
652 ret = walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt), callback_stmt,
653 callback_op, wi);
654 if (ret)
655 return wi->callback_result;
656 break;
658 case GIMPLE_TRANSACTION:
659 ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (stmt),
660 callback_stmt, callback_op, wi);
661 if (ret)
662 return wi->callback_result;
663 break;
665 default:
666 gcc_assert (!gimple_has_substatements (stmt));
667 break;
670 return NULL;
673 /* From a tree operand OP return the base of a load or store operation
674 or NULL_TREE if OP is not a load or a store. */
676 static tree
677 get_base_loadstore (tree op)
679 while (handled_component_p (op))
680 op = TREE_OPERAND (op, 0);
681 if (DECL_P (op)
682 || INDIRECT_REF_P (op)
683 || TREE_CODE (op) == MEM_REF
684 || TREE_CODE (op) == TARGET_MEM_REF)
685 return op;
686 return NULL_TREE;
690 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
691 VISIT_ADDR if non-NULL on loads, store and address-taken operands
692 passing the STMT, the base of the operand, the operand itself containing
693 the base and DATA to it. The base will be either a decl, an indirect
694 reference (including TARGET_MEM_REF) or the argument of an address
695 expression.
696 Returns the results of these callbacks or'ed. */
698 bool
699 walk_stmt_load_store_addr_ops (gimple stmt, void *data,
700 walk_stmt_load_store_addr_fn visit_load,
701 walk_stmt_load_store_addr_fn visit_store,
702 walk_stmt_load_store_addr_fn visit_addr)
704 bool ret = false;
705 unsigned i;
706 if (gimple_assign_single_p (stmt))
708 tree lhs, rhs, arg;
709 if (visit_store)
711 arg = gimple_assign_lhs (stmt);
712 lhs = get_base_loadstore (arg);
713 if (lhs)
714 ret |= visit_store (stmt, lhs, arg, data);
716 arg = gimple_assign_rhs1 (stmt);
717 rhs = arg;
718 while (handled_component_p (rhs))
719 rhs = TREE_OPERAND (rhs, 0);
720 if (visit_addr)
722 if (TREE_CODE (rhs) == ADDR_EXPR)
723 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), arg, data);
724 else if (TREE_CODE (rhs) == TARGET_MEM_REF
725 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
726 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), arg,
727 data);
728 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
729 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
730 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
731 0), arg, data);
732 else if (TREE_CODE (rhs) == CONSTRUCTOR)
734 unsigned int ix;
735 tree val;
737 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
738 if (TREE_CODE (val) == ADDR_EXPR)
739 ret |= visit_addr (stmt, TREE_OPERAND (val, 0), arg, data);
740 else if (TREE_CODE (val) == OBJ_TYPE_REF
741 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
742 ret |= visit_addr (stmt,
743 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
744 0), arg, data);
746 lhs = gimple_assign_lhs (stmt);
747 if (TREE_CODE (lhs) == TARGET_MEM_REF
748 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
749 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), lhs, data);
751 if (visit_load)
753 rhs = get_base_loadstore (rhs);
754 if (rhs)
755 ret |= visit_load (stmt, rhs, arg, data);
758 else if (visit_addr
759 && (is_gimple_assign (stmt)
760 || gimple_code (stmt) == GIMPLE_COND))
762 for (i = 0; i < gimple_num_ops (stmt); ++i)
764 tree op = gimple_op (stmt, i);
765 if (op == NULL_TREE)
767 else if (TREE_CODE (op) == ADDR_EXPR)
768 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
769 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
770 tree with two operands. */
771 else if (i == 1 && COMPARISON_CLASS_P (op))
773 if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
774 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
775 0), op, data);
776 if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
777 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
778 0), op, data);
782 else if (is_gimple_call (stmt))
784 if (visit_store)
786 tree arg = gimple_call_lhs (stmt);
787 if (arg)
789 tree lhs = get_base_loadstore (arg);
790 if (lhs)
791 ret |= visit_store (stmt, lhs, arg, data);
794 if (visit_load || visit_addr)
795 for (i = 0; i < gimple_call_num_args (stmt); ++i)
797 tree arg = gimple_call_arg (stmt, i);
798 if (visit_addr
799 && TREE_CODE (arg) == ADDR_EXPR)
800 ret |= visit_addr (stmt, TREE_OPERAND (arg, 0), arg, data);
801 else if (visit_load)
803 tree rhs = get_base_loadstore (arg);
804 if (rhs)
805 ret |= visit_load (stmt, rhs, arg, data);
808 if (visit_addr
809 && gimple_call_chain (stmt)
810 && TREE_CODE (gimple_call_chain (stmt)) == ADDR_EXPR)
811 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (stmt), 0),
812 gimple_call_chain (stmt), data);
813 if (visit_addr
814 && gimple_call_return_slot_opt_p (stmt)
815 && gimple_call_lhs (stmt) != NULL_TREE
816 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (stmt))))
817 ret |= visit_addr (stmt, gimple_call_lhs (stmt),
818 gimple_call_lhs (stmt), data);
820 else if (gimple_code (stmt) == GIMPLE_ASM)
822 unsigned noutputs;
823 const char *constraint;
824 const char **oconstraints;
825 bool allows_mem, allows_reg, is_inout;
826 noutputs = gimple_asm_noutputs (stmt);
827 oconstraints = XALLOCAVEC (const char *, noutputs);
828 if (visit_store || visit_addr)
829 for (i = 0; i < gimple_asm_noutputs (stmt); ++i)
831 tree link = gimple_asm_output_op (stmt, i);
832 tree op = get_base_loadstore (TREE_VALUE (link));
833 if (op && visit_store)
834 ret |= visit_store (stmt, op, TREE_VALUE (link), data);
835 if (visit_addr)
837 constraint = TREE_STRING_POINTER
838 (TREE_VALUE (TREE_PURPOSE (link)));
839 oconstraints[i] = constraint;
840 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
841 &allows_reg, &is_inout);
842 if (op && !allows_reg && allows_mem)
843 ret |= visit_addr (stmt, op, TREE_VALUE (link), data);
846 if (visit_load || visit_addr)
847 for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
849 tree link = gimple_asm_input_op (stmt, i);
850 tree op = TREE_VALUE (link);
851 if (visit_addr
852 && TREE_CODE (op) == ADDR_EXPR)
853 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
854 else if (visit_load || visit_addr)
856 op = get_base_loadstore (op);
857 if (op)
859 if (visit_load)
860 ret |= visit_load (stmt, op, TREE_VALUE (link), data);
861 if (visit_addr)
863 constraint = TREE_STRING_POINTER
864 (TREE_VALUE (TREE_PURPOSE (link)));
865 parse_input_constraint (&constraint, 0, 0, noutputs,
866 0, oconstraints,
867 &allows_mem, &allows_reg);
868 if (!allows_reg && allows_mem)
869 ret |= visit_addr (stmt, op, TREE_VALUE (link),
870 data);
876 else if (gimple_code (stmt) == GIMPLE_RETURN)
878 tree op = gimple_return_retval (stmt);
879 if (op)
881 if (visit_addr
882 && TREE_CODE (op) == ADDR_EXPR)
883 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
884 else if (visit_load)
886 tree base = get_base_loadstore (op);
887 if (base)
888 ret |= visit_load (stmt, base, op, data);
892 else if (visit_addr
893 && gimple_code (stmt) == GIMPLE_PHI)
895 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
897 tree op = gimple_phi_arg_def (stmt, i);
898 if (TREE_CODE (op) == ADDR_EXPR)
899 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
902 else if (visit_addr
903 && gimple_code (stmt) == GIMPLE_GOTO)
905 tree op = gimple_goto_dest (stmt);
906 if (TREE_CODE (op) == ADDR_EXPR)
907 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
910 return ret;
913 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
914 should make a faster clone for this case. */
916 bool
917 walk_stmt_load_store_ops (gimple stmt, void *data,
918 walk_stmt_load_store_addr_fn visit_load,
919 walk_stmt_load_store_addr_fn visit_store)
921 return walk_stmt_load_store_addr_ops (stmt, data,
922 visit_load, visit_store, NULL);