N3778: Sized Deallocation
[official-gcc.git] / gcc / gimple-walk.c
blob959d68eca28d7e574cecbec5d57facaa38ae46a9
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 (gasm *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 (as_a <gcall *> (stmt)),
248 callback_op, wi, pset);
249 if (ret)
250 return ret;
252 ret = walk_tree (gimple_call_fn_ptr (stmt), callback_op, wi, pset);
253 if (ret)
254 return ret;
256 for (i = 0; i < gimple_call_num_args (stmt); i++)
258 if (wi)
259 wi->val_only
260 = is_gimple_reg_type (TREE_TYPE (gimple_call_arg (stmt, i)));
261 ret = walk_tree (gimple_call_arg_ptr (stmt, i), callback_op, wi,
262 pset);
263 if (ret)
264 return ret;
267 if (gimple_call_lhs (stmt))
269 if (wi)
271 wi->is_lhs = true;
272 wi->val_only
273 = is_gimple_reg_type (TREE_TYPE (gimple_call_lhs (stmt)));
276 ret = walk_tree (gimple_call_lhs_ptr (stmt), callback_op, wi, pset);
277 if (ret)
278 return ret;
281 if (wi)
283 wi->is_lhs = false;
284 wi->val_only = true;
286 break;
288 case GIMPLE_CATCH:
289 ret = walk_tree (gimple_catch_types_ptr (as_a <gcatch *> (stmt)),
290 callback_op, wi, pset);
291 if (ret)
292 return ret;
293 break;
295 case GIMPLE_EH_FILTER:
296 ret = walk_tree (gimple_eh_filter_types_ptr (stmt), callback_op, wi,
297 pset);
298 if (ret)
299 return ret;
300 break;
302 case GIMPLE_ASM:
303 ret = walk_gimple_asm (as_a <gasm *> (stmt), callback_op, wi);
304 if (ret)
305 return ret;
306 break;
308 case GIMPLE_OMP_CONTINUE:
310 gomp_continue *cont_stmt = as_a <gomp_continue *> (stmt);
311 ret = walk_tree (gimple_omp_continue_control_def_ptr (cont_stmt),
312 callback_op, wi, pset);
313 if (ret)
314 return ret;
316 ret = walk_tree (gimple_omp_continue_control_use_ptr (cont_stmt),
317 callback_op, wi, pset);
318 if (ret)
319 return ret;
321 break;
323 case GIMPLE_OMP_CRITICAL:
325 gomp_critical *omp_stmt = as_a <gomp_critical *> (stmt);
326 ret = walk_tree (gimple_omp_critical_name_ptr (omp_stmt),
327 callback_op, wi, pset);
328 if (ret)
329 return ret;
331 break;
333 case GIMPLE_OMP_FOR:
334 ret = walk_tree (gimple_omp_for_clauses_ptr (stmt), callback_op, wi,
335 pset);
336 if (ret)
337 return ret;
338 for (i = 0; i < gimple_omp_for_collapse (stmt); i++)
340 ret = walk_tree (gimple_omp_for_index_ptr (stmt, i), callback_op,
341 wi, pset);
342 if (ret)
343 return ret;
344 ret = walk_tree (gimple_omp_for_initial_ptr (stmt, i), callback_op,
345 wi, pset);
346 if (ret)
347 return ret;
348 ret = walk_tree (gimple_omp_for_final_ptr (stmt, i), callback_op,
349 wi, pset);
350 if (ret)
351 return ret;
352 ret = walk_tree (gimple_omp_for_incr_ptr (stmt, i), callback_op,
353 wi, pset);
354 if (ret)
355 return ret;
357 break;
359 case GIMPLE_OMP_PARALLEL:
361 gomp_parallel *omp_par_stmt = as_a <gomp_parallel *> (stmt);
362 ret = walk_tree (gimple_omp_parallel_clauses_ptr (omp_par_stmt),
363 callback_op, wi, pset);
364 if (ret)
365 return ret;
366 ret = walk_tree (gimple_omp_parallel_child_fn_ptr (omp_par_stmt),
367 callback_op, wi, pset);
368 if (ret)
369 return ret;
370 ret = walk_tree (gimple_omp_parallel_data_arg_ptr (omp_par_stmt),
371 callback_op, wi, pset);
372 if (ret)
373 return ret;
375 break;
377 case GIMPLE_OMP_TASK:
378 ret = walk_tree (gimple_omp_task_clauses_ptr (stmt), callback_op,
379 wi, pset);
380 if (ret)
381 return ret;
382 ret = walk_tree (gimple_omp_task_child_fn_ptr (stmt), callback_op,
383 wi, pset);
384 if (ret)
385 return ret;
386 ret = walk_tree (gimple_omp_task_data_arg_ptr (stmt), callback_op,
387 wi, pset);
388 if (ret)
389 return ret;
390 ret = walk_tree (gimple_omp_task_copy_fn_ptr (stmt), callback_op,
391 wi, pset);
392 if (ret)
393 return ret;
394 ret = walk_tree (gimple_omp_task_arg_size_ptr (stmt), callback_op,
395 wi, pset);
396 if (ret)
397 return ret;
398 ret = walk_tree (gimple_omp_task_arg_align_ptr (stmt), callback_op,
399 wi, pset);
400 if (ret)
401 return ret;
402 break;
404 case GIMPLE_OMP_SECTIONS:
405 ret = walk_tree (gimple_omp_sections_clauses_ptr (stmt), callback_op,
406 wi, pset);
407 if (ret)
408 return ret;
409 ret = walk_tree (gimple_omp_sections_control_ptr (stmt), callback_op,
410 wi, pset);
411 if (ret)
412 return ret;
414 break;
416 case GIMPLE_OMP_SINGLE:
417 ret = walk_tree (gimple_omp_single_clauses_ptr (stmt), callback_op, wi,
418 pset);
419 if (ret)
420 return ret;
421 break;
423 case GIMPLE_OMP_TARGET:
425 gomp_target *omp_stmt = as_a <gomp_target *> (stmt);
426 ret = walk_tree (gimple_omp_target_clauses_ptr (omp_stmt),
427 callback_op, wi, pset);
428 if (ret)
429 return ret;
430 ret = walk_tree (gimple_omp_target_child_fn_ptr (omp_stmt),
431 callback_op, wi, pset);
432 if (ret)
433 return ret;
434 ret = walk_tree (gimple_omp_target_data_arg_ptr (omp_stmt),
435 callback_op, wi, pset);
436 if (ret)
437 return ret;
439 break;
441 case GIMPLE_OMP_TEAMS:
442 ret = walk_tree (gimple_omp_teams_clauses_ptr (stmt), callback_op, wi,
443 pset);
444 if (ret)
445 return ret;
446 break;
448 case GIMPLE_OMP_ATOMIC_LOAD:
450 gomp_atomic_load *omp_stmt = as_a <gomp_atomic_load *> (stmt);
451 ret = walk_tree (gimple_omp_atomic_load_lhs_ptr (omp_stmt),
452 callback_op, wi, pset);
453 if (ret)
454 return ret;
455 ret = walk_tree (gimple_omp_atomic_load_rhs_ptr (omp_stmt),
456 callback_op, wi, pset);
457 if (ret)
458 return ret;
460 break;
462 case GIMPLE_OMP_ATOMIC_STORE:
464 gomp_atomic_store *omp_stmt = as_a <gomp_atomic_store *> (stmt);
465 ret = walk_tree (gimple_omp_atomic_store_val_ptr (omp_stmt),
466 callback_op, wi, pset);
467 if (ret)
468 return ret;
470 break;
472 case GIMPLE_TRANSACTION:
473 ret = walk_tree (gimple_transaction_label_ptr (
474 as_a <gtransaction *> (stmt)),
475 callback_op, wi, pset);
476 if (ret)
477 return ret;
478 break;
480 case GIMPLE_OMP_RETURN:
481 ret = walk_tree (gimple_omp_return_lhs_ptr (stmt), callback_op, wi,
482 pset);
483 if (ret)
484 return ret;
485 break;
487 /* Tuples that do not have operands. */
488 case GIMPLE_NOP:
489 case GIMPLE_RESX:
490 case GIMPLE_PREDICT:
491 break;
493 default:
495 enum gimple_statement_structure_enum gss;
496 gss = gimple_statement_structure (stmt);
497 if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
498 for (i = 0; i < gimple_num_ops (stmt); i++)
500 ret = walk_tree (gimple_op_ptr (stmt, i), callback_op, wi, pset);
501 if (ret)
502 return ret;
505 break;
508 return NULL_TREE;
512 /* Walk the current statement in GSI (optionally using traversal state
513 stored in WI). If WI is NULL, no state is kept during traversal.
514 The callback CALLBACK_STMT is called. If CALLBACK_STMT indicates
515 that it has handled all the operands of the statement, its return
516 value is returned. Otherwise, the return value from CALLBACK_STMT
517 is discarded and its operands are scanned.
519 If CALLBACK_STMT is NULL or it didn't handle the operands,
520 CALLBACK_OP is called on each operand of the statement via
521 walk_gimple_op. If walk_gimple_op returns non-NULL for any
522 operand, the remaining operands are not scanned. In this case, the
523 return value from CALLBACK_OP is returned.
525 In any other case, NULL_TREE is returned. */
527 tree
528 walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
529 walk_tree_fn callback_op, struct walk_stmt_info *wi)
531 gimple ret;
532 tree tree_ret;
533 gimple stmt = gsi_stmt (*gsi);
535 if (wi)
537 wi->gsi = *gsi;
538 wi->removed_stmt = false;
540 if (wi->want_locations && gimple_has_location (stmt))
541 input_location = gimple_location (stmt);
544 ret = NULL;
546 /* Invoke the statement callback. Return if the callback handled
547 all of STMT operands by itself. */
548 if (callback_stmt)
550 bool handled_ops = false;
551 tree_ret = callback_stmt (gsi, &handled_ops, wi);
552 if (handled_ops)
553 return tree_ret;
555 /* If CALLBACK_STMT did not handle operands, it should not have
556 a value to return. */
557 gcc_assert (tree_ret == NULL);
559 if (wi && wi->removed_stmt)
560 return NULL;
562 /* Re-read stmt in case the callback changed it. */
563 stmt = gsi_stmt (*gsi);
566 /* If CALLBACK_OP is defined, invoke it on every operand of STMT. */
567 if (callback_op)
569 tree_ret = walk_gimple_op (stmt, callback_op, wi);
570 if (tree_ret)
571 return tree_ret;
574 /* If STMT can have statements inside (e.g. GIMPLE_BIND), walk them. */
575 switch (gimple_code (stmt))
577 case GIMPLE_BIND:
578 ret = walk_gimple_seq_mod (gimple_bind_body_ptr (as_a <gbind *> (stmt)),
579 callback_stmt, callback_op, wi);
580 if (ret)
581 return wi->callback_result;
582 break;
584 case GIMPLE_CATCH:
585 ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (
586 as_a <gcatch *> (stmt)),
587 callback_stmt, callback_op, wi);
588 if (ret)
589 return wi->callback_result;
590 break;
592 case GIMPLE_EH_FILTER:
593 ret = walk_gimple_seq_mod (gimple_eh_filter_failure_ptr (stmt), callback_stmt,
594 callback_op, wi);
595 if (ret)
596 return wi->callback_result;
597 break;
599 case GIMPLE_EH_ELSE:
601 geh_else *eh_else_stmt = as_a <geh_else *> (stmt);
602 ret = walk_gimple_seq_mod (gimple_eh_else_n_body_ptr (eh_else_stmt),
603 callback_stmt, callback_op, wi);
604 if (ret)
605 return wi->callback_result;
606 ret = walk_gimple_seq_mod (gimple_eh_else_e_body_ptr (eh_else_stmt),
607 callback_stmt, callback_op, wi);
608 if (ret)
609 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_OMP_CRITICAL:
633 case GIMPLE_OMP_MASTER:
634 case GIMPLE_OMP_TASKGROUP:
635 case GIMPLE_OMP_ORDERED:
636 case GIMPLE_OMP_SECTION:
637 case GIMPLE_OMP_PARALLEL:
638 case GIMPLE_OMP_TASK:
639 case GIMPLE_OMP_SECTIONS:
640 case GIMPLE_OMP_SINGLE:
641 case GIMPLE_OMP_TARGET:
642 case GIMPLE_OMP_TEAMS:
643 ret = walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), callback_stmt,
644 callback_op, wi);
645 if (ret)
646 return wi->callback_result;
647 break;
649 case GIMPLE_WITH_CLEANUP_EXPR:
650 ret = walk_gimple_seq_mod (gimple_wce_cleanup_ptr (stmt), callback_stmt,
651 callback_op, wi);
652 if (ret)
653 return wi->callback_result;
654 break;
656 case GIMPLE_TRANSACTION:
657 ret = walk_gimple_seq_mod (gimple_transaction_body_ptr (
658 as_a <gtransaction *> (stmt)),
659 callback_stmt, callback_op, wi);
660 if (ret)
661 return wi->callback_result;
662 break;
664 default:
665 gcc_assert (!gimple_has_substatements (stmt));
666 break;
669 return NULL;
672 /* From a tree operand OP return the base of a load or store operation
673 or NULL_TREE if OP is not a load or a store. */
675 static tree
676 get_base_loadstore (tree op)
678 while (handled_component_p (op))
679 op = TREE_OPERAND (op, 0);
680 if (DECL_P (op)
681 || INDIRECT_REF_P (op)
682 || TREE_CODE (op) == MEM_REF
683 || TREE_CODE (op) == TARGET_MEM_REF)
684 return op;
685 return NULL_TREE;
689 /* For the statement STMT call the callbacks VISIT_LOAD, VISIT_STORE and
690 VISIT_ADDR if non-NULL on loads, store and address-taken operands
691 passing the STMT, the base of the operand, the operand itself containing
692 the base and DATA to it. The base will be either a decl, an indirect
693 reference (including TARGET_MEM_REF) or the argument of an address
694 expression.
695 Returns the results of these callbacks or'ed. */
697 bool
698 walk_stmt_load_store_addr_ops (gimple stmt, void *data,
699 walk_stmt_load_store_addr_fn visit_load,
700 walk_stmt_load_store_addr_fn visit_store,
701 walk_stmt_load_store_addr_fn visit_addr)
703 bool ret = false;
704 unsigned i;
705 if (gimple_assign_single_p (stmt))
707 tree lhs, rhs, arg;
708 if (visit_store)
710 arg = gimple_assign_lhs (stmt);
711 lhs = get_base_loadstore (arg);
712 if (lhs)
713 ret |= visit_store (stmt, lhs, arg, data);
715 arg = gimple_assign_rhs1 (stmt);
716 rhs = arg;
717 while (handled_component_p (rhs))
718 rhs = TREE_OPERAND (rhs, 0);
719 if (visit_addr)
721 if (TREE_CODE (rhs) == ADDR_EXPR)
722 ret |= visit_addr (stmt, TREE_OPERAND (rhs, 0), arg, data);
723 else if (TREE_CODE (rhs) == TARGET_MEM_REF
724 && TREE_CODE (TMR_BASE (rhs)) == ADDR_EXPR)
725 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (rhs), 0), arg,
726 data);
727 else if (TREE_CODE (rhs) == OBJ_TYPE_REF
728 && TREE_CODE (OBJ_TYPE_REF_OBJECT (rhs)) == ADDR_EXPR)
729 ret |= visit_addr (stmt, TREE_OPERAND (OBJ_TYPE_REF_OBJECT (rhs),
730 0), arg, data);
731 else if (TREE_CODE (rhs) == CONSTRUCTOR)
733 unsigned int ix;
734 tree val;
736 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (rhs), ix, val)
737 if (TREE_CODE (val) == ADDR_EXPR)
738 ret |= visit_addr (stmt, TREE_OPERAND (val, 0), arg, data);
739 else if (TREE_CODE (val) == OBJ_TYPE_REF
740 && TREE_CODE (OBJ_TYPE_REF_OBJECT (val)) == ADDR_EXPR)
741 ret |= visit_addr (stmt,
742 TREE_OPERAND (OBJ_TYPE_REF_OBJECT (val),
743 0), arg, data);
745 lhs = gimple_assign_lhs (stmt);
746 if (TREE_CODE (lhs) == TARGET_MEM_REF
747 && TREE_CODE (TMR_BASE (lhs)) == ADDR_EXPR)
748 ret |= visit_addr (stmt, TREE_OPERAND (TMR_BASE (lhs), 0), lhs, data);
750 if (visit_load)
752 rhs = get_base_loadstore (rhs);
753 if (rhs)
754 ret |= visit_load (stmt, rhs, arg, data);
757 else if (visit_addr
758 && (is_gimple_assign (stmt)
759 || gimple_code (stmt) == GIMPLE_COND))
761 for (i = 0; i < gimple_num_ops (stmt); ++i)
763 tree op = gimple_op (stmt, i);
764 if (op == NULL_TREE)
766 else if (TREE_CODE (op) == ADDR_EXPR)
767 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
768 /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
769 tree with two operands. */
770 else if (i == 1 && COMPARISON_CLASS_P (op))
772 if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
773 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
774 0), op, data);
775 if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
776 ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
777 0), op, data);
781 else if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
783 if (visit_store)
785 tree arg = gimple_call_lhs (call_stmt);
786 if (arg)
788 tree lhs = get_base_loadstore (arg);
789 if (lhs)
790 ret |= visit_store (stmt, lhs, arg, data);
793 if (visit_load || visit_addr)
794 for (i = 0; i < gimple_call_num_args (call_stmt); ++i)
796 tree arg = gimple_call_arg (call_stmt, i);
797 if (visit_addr
798 && TREE_CODE (arg) == ADDR_EXPR)
799 ret |= visit_addr (stmt, TREE_OPERAND (arg, 0), arg, data);
800 else if (visit_load)
802 tree rhs = get_base_loadstore (arg);
803 if (rhs)
804 ret |= visit_load (stmt, rhs, arg, data);
807 if (visit_addr
808 && gimple_call_chain (call_stmt)
809 && TREE_CODE (gimple_call_chain (call_stmt)) == ADDR_EXPR)
810 ret |= visit_addr (stmt, TREE_OPERAND (gimple_call_chain (call_stmt), 0),
811 gimple_call_chain (call_stmt), data);
812 if (visit_addr
813 && gimple_call_return_slot_opt_p (call_stmt)
814 && gimple_call_lhs (call_stmt) != NULL_TREE
815 && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (call_stmt))))
816 ret |= visit_addr (stmt, gimple_call_lhs (call_stmt),
817 gimple_call_lhs (call_stmt), data);
819 else if (gasm *asm_stmt = dyn_cast <gasm *> (stmt))
821 unsigned noutputs;
822 const char *constraint;
823 const char **oconstraints;
824 bool allows_mem, allows_reg, is_inout;
825 noutputs = gimple_asm_noutputs (asm_stmt);
826 oconstraints = XALLOCAVEC (const char *, noutputs);
827 if (visit_store || visit_addr)
828 for (i = 0; i < gimple_asm_noutputs (asm_stmt); ++i)
830 tree link = gimple_asm_output_op (asm_stmt, i);
831 tree op = get_base_loadstore (TREE_VALUE (link));
832 if (op && visit_store)
833 ret |= visit_store (stmt, op, TREE_VALUE (link), data);
834 if (visit_addr)
836 constraint = TREE_STRING_POINTER
837 (TREE_VALUE (TREE_PURPOSE (link)));
838 oconstraints[i] = constraint;
839 parse_output_constraint (&constraint, i, 0, 0, &allows_mem,
840 &allows_reg, &is_inout);
841 if (op && !allows_reg && allows_mem)
842 ret |= visit_addr (stmt, op, TREE_VALUE (link), data);
845 if (visit_load || visit_addr)
846 for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
848 tree link = gimple_asm_input_op (asm_stmt, i);
849 tree op = TREE_VALUE (link);
850 if (visit_addr
851 && TREE_CODE (op) == ADDR_EXPR)
852 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
853 else if (visit_load || visit_addr)
855 op = get_base_loadstore (op);
856 if (op)
858 if (visit_load)
859 ret |= visit_load (stmt, op, TREE_VALUE (link), data);
860 if (visit_addr)
862 constraint = TREE_STRING_POINTER
863 (TREE_VALUE (TREE_PURPOSE (link)));
864 parse_input_constraint (&constraint, 0, 0, noutputs,
865 0, oconstraints,
866 &allows_mem, &allows_reg);
867 if (!allows_reg && allows_mem)
868 ret |= visit_addr (stmt, op, TREE_VALUE (link),
869 data);
875 else if (greturn *return_stmt = dyn_cast <greturn *> (stmt))
877 tree op = gimple_return_retval (return_stmt);
878 if (op)
880 if (visit_addr
881 && TREE_CODE (op) == ADDR_EXPR)
882 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
883 else if (visit_load)
885 tree base = get_base_loadstore (op);
886 if (base)
887 ret |= visit_load (stmt, base, op, data);
891 else if (visit_addr
892 && gimple_code (stmt) == GIMPLE_PHI)
894 for (i = 0; i < gimple_phi_num_args (stmt); ++i)
896 tree op = gimple_phi_arg_def (stmt, i);
897 if (TREE_CODE (op) == ADDR_EXPR)
898 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
901 else if (visit_addr
902 && gimple_code (stmt) == GIMPLE_GOTO)
904 tree op = gimple_goto_dest (stmt);
905 if (TREE_CODE (op) == ADDR_EXPR)
906 ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
909 return ret;
912 /* Like walk_stmt_load_store_addr_ops but with NULL visit_addr. IPA-CP
913 should make a faster clone for this case. */
915 bool
916 walk_stmt_load_store_ops (gimple stmt, void *data,
917 walk_stmt_load_store_addr_fn visit_load,
918 walk_stmt_load_store_addr_fn visit_store)
920 return walk_stmt_load_store_addr_ops (stmt, data,
921 visit_load, visit_store, NULL);