1 /* Alias analysis for trees.
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Diego Novillo <dnovillo@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License 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/>. */
24 #include "coretypes.h"
28 #include "basic-block.h"
32 #include "langhooks.h"
35 #include "diagnostic.h"
36 #include "tree-pretty-print.h"
37 #include "tree-dump.h"
39 #include "tree-flow.h"
40 #include "tree-inline.h"
41 #include "tree-pass.h"
44 #include "ipa-type-escape.h"
48 #include "pointer-set.h"
49 #include "alloc-pool.h"
50 #include "tree-ssa-alias.h"
52 /* Broad overview of how alias analysis on gimple works:
54 Statements clobbering or using memory are linked through the
55 virtual operand factored use-def chain. The virtual operand
56 is unique per function, its symbol is accessible via gimple_vop (cfun).
57 Virtual operands are used for efficiently walking memory statements
58 in the gimple IL and are useful for things like value-numbering as
59 a generation count for memory references.
61 SSA_NAME pointers may have associated points-to information
62 accessible via the SSA_NAME_PTR_INFO macro. Flow-insensitive
63 points-to information is (re-)computed by the TODO_rebuild_alias
64 pass manager todo. Points-to information is also used for more
65 precise tracking of call-clobbered and call-used variables and
66 related disambiguations.
68 This file contains functions for disambiguating memory references,
69 the so called alias-oracle and tools for walking of the gimple IL.
71 The main alias-oracle entry-points are
73 bool stmt_may_clobber_ref_p (gimple, tree)
75 This function queries if a statement may invalidate (parts of)
76 the memory designated by the reference tree argument.
78 bool ref_maybe_used_by_stmt_p (gimple, tree)
80 This function queries if a statement may need (parts of) the
81 memory designated by the reference tree argument.
83 There are variants of these functions that only handle the call
84 part of a statement, call_may_clobber_ref_p and ref_maybe_used_by_call_p.
85 Note that these do not disambiguate against a possible call lhs.
87 bool refs_may_alias_p (tree, tree)
89 This function tries to disambiguate two reference trees.
91 bool ptr_deref_may_alias_global_p (tree)
93 This function queries if dereferencing a pointer variable may
96 More low-level disambiguators are available and documented in
97 this file. Low-level disambiguators dealing with points-to
98 information are in tree-ssa-structalias.c. */
101 /* Query statistics for the different low-level disambiguators.
102 A high-level query may trigger multiple of them. */
105 unsigned HOST_WIDE_INT refs_may_alias_p_may_alias;
106 unsigned HOST_WIDE_INT refs_may_alias_p_no_alias;
107 unsigned HOST_WIDE_INT ref_maybe_used_by_call_p_may_alias;
108 unsigned HOST_WIDE_INT ref_maybe_used_by_call_p_no_alias;
109 unsigned HOST_WIDE_INT call_may_clobber_ref_p_may_alias;
110 unsigned HOST_WIDE_INT call_may_clobber_ref_p_no_alias;
114 dump_alias_stats (FILE *s)
116 fprintf (s, "\nAlias oracle query stats:\n");
117 fprintf (s, " refs_may_alias_p: "
118 HOST_WIDE_INT_PRINT_DEC" disambiguations, "
119 HOST_WIDE_INT_PRINT_DEC" queries\n",
120 alias_stats.refs_may_alias_p_no_alias,
121 alias_stats.refs_may_alias_p_no_alias
122 + alias_stats.refs_may_alias_p_may_alias);
123 fprintf (s, " ref_maybe_used_by_call_p: "
124 HOST_WIDE_INT_PRINT_DEC" disambiguations, "
125 HOST_WIDE_INT_PRINT_DEC" queries\n",
126 alias_stats.ref_maybe_used_by_call_p_no_alias,
127 alias_stats.refs_may_alias_p_no_alias
128 + alias_stats.ref_maybe_used_by_call_p_may_alias);
129 fprintf (s, " call_may_clobber_ref_p: "
130 HOST_WIDE_INT_PRINT_DEC" disambiguations, "
131 HOST_WIDE_INT_PRINT_DEC" queries\n",
132 alias_stats.call_may_clobber_ref_p_no_alias,
133 alias_stats.call_may_clobber_ref_p_no_alias
134 + alias_stats.call_may_clobber_ref_p_may_alias);
138 /* Return true, if dereferencing PTR may alias with a global variable. */
141 ptr_deref_may_alias_global_p (tree ptr)
143 struct ptr_info_def *pi;
145 /* If we end up with a pointer constant here that may point
147 if (TREE_CODE (ptr) != SSA_NAME)
150 pi = SSA_NAME_PTR_INFO (ptr);
152 /* If we do not have points-to information for this variable,
157 /* ??? This does not use TBAA to prune globals ptr may not access. */
158 return pt_solution_includes_global (&pi->pt);
161 /* Return true if dereferencing PTR may alias DECL.
162 The caller is responsible for applying TBAA to see if PTR
163 may access DECL at all. */
166 ptr_deref_may_alias_decl_p (tree ptr, tree decl)
168 struct ptr_info_def *pi;
170 gcc_assert ((TREE_CODE (ptr) == SSA_NAME
171 || TREE_CODE (ptr) == ADDR_EXPR
172 || TREE_CODE (ptr) == INTEGER_CST)
173 && (TREE_CODE (decl) == VAR_DECL
174 || TREE_CODE (decl) == PARM_DECL
175 || TREE_CODE (decl) == RESULT_DECL));
177 /* Non-aliased variables can not be pointed to. */
178 if (!may_be_aliased (decl))
181 /* ADDR_EXPR pointers either just offset another pointer or directly
182 specify the pointed-to set. */
183 if (TREE_CODE (ptr) == ADDR_EXPR)
185 tree base = get_base_address (TREE_OPERAND (ptr, 0));
187 && INDIRECT_REF_P (base))
188 ptr = TREE_OPERAND (base, 0);
193 && CONSTANT_CLASS_P (base))
199 /* We can end up with dereferencing constant pointers.
200 Just bail out in this case. */
201 if (TREE_CODE (ptr) == INTEGER_CST)
204 /* If we do not have useful points-to information for this pointer
205 we cannot disambiguate anything else. */
206 pi = SSA_NAME_PTR_INFO (ptr);
210 /* If the decl can be used as a restrict tag and we have a restrict
211 pointer and that pointers points-to set doesn't contain this decl
212 then they can't alias. */
213 if (DECL_RESTRICTED_P (decl)
214 && TYPE_RESTRICT (TREE_TYPE (ptr))
215 && pi->pt.vars_contains_restrict)
216 return bitmap_bit_p (pi->pt.vars, DECL_PT_UID (decl));
218 return pt_solution_includes (&pi->pt, decl);
221 /* Return true if dereferenced PTR1 and PTR2 may alias.
222 The caller is responsible for applying TBAA to see if accesses
223 through PTR1 and PTR2 may conflict at all. */
226 ptr_derefs_may_alias_p (tree ptr1, tree ptr2)
228 struct ptr_info_def *pi1, *pi2;
230 gcc_assert ((TREE_CODE (ptr1) == SSA_NAME
231 || TREE_CODE (ptr1) == ADDR_EXPR
232 || TREE_CODE (ptr1) == INTEGER_CST)
233 && (TREE_CODE (ptr2) == SSA_NAME
234 || TREE_CODE (ptr2) == ADDR_EXPR
235 || TREE_CODE (ptr2) == INTEGER_CST));
237 /* ADDR_EXPR pointers either just offset another pointer or directly
238 specify the pointed-to set. */
239 if (TREE_CODE (ptr1) == ADDR_EXPR)
241 tree base = get_base_address (TREE_OPERAND (ptr1, 0));
243 && INDIRECT_REF_P (base))
244 ptr1 = TREE_OPERAND (base, 0);
247 return ptr_deref_may_alias_decl_p (ptr2, base);
251 if (TREE_CODE (ptr2) == ADDR_EXPR)
253 tree base = get_base_address (TREE_OPERAND (ptr2, 0));
255 && INDIRECT_REF_P (base))
256 ptr2 = TREE_OPERAND (base, 0);
259 return ptr_deref_may_alias_decl_p (ptr1, base);
264 /* We can end up with dereferencing constant pointers.
265 Just bail out in this case. */
266 if (TREE_CODE (ptr1) == INTEGER_CST
267 || TREE_CODE (ptr2) == INTEGER_CST)
270 /* We may end up with two empty points-to solutions for two same pointers.
271 In this case we still want to say both pointers alias, so shortcut
276 /* If we do not have useful points-to information for either pointer
277 we cannot disambiguate anything else. */
278 pi1 = SSA_NAME_PTR_INFO (ptr1);
279 pi2 = SSA_NAME_PTR_INFO (ptr2);
283 /* If both pointers are restrict-qualified try to disambiguate
284 with restrict information. */
285 if (TYPE_RESTRICT (TREE_TYPE (ptr1))
286 && TYPE_RESTRICT (TREE_TYPE (ptr2))
287 && !pt_solutions_same_restrict_base (&pi1->pt, &pi2->pt))
290 /* ??? This does not use TBAA to prune decls from the intersection
291 that not both pointers may access. */
292 return pt_solutions_intersect (&pi1->pt, &pi2->pt);
295 /* Return true if dereferencing PTR may alias *REF.
296 The caller is responsible for applying TBAA to see if PTR
297 may access *REF at all. */
300 ptr_deref_may_alias_ref_p_1 (tree ptr, ao_ref *ref)
302 tree base = ao_ref_base (ref);
304 if (INDIRECT_REF_P (base))
305 return ptr_derefs_may_alias_p (ptr, TREE_OPERAND (base, 0));
306 else if (SSA_VAR_P (base))
307 return ptr_deref_may_alias_decl_p (ptr, base);
313 /* Dump alias information on FILE. */
316 dump_alias_info (FILE *file)
320 = lang_hooks.decl_printable_name (current_function_decl, 2);
321 referenced_var_iterator rvi;
324 fprintf (file, "\n\nAlias information for %s\n\n", funcname);
326 fprintf (file, "Aliased symbols\n\n");
328 FOR_EACH_REFERENCED_VAR (var, rvi)
330 if (may_be_aliased (var))
331 dump_variable (file, var);
334 fprintf (file, "\nCall clobber information\n");
336 fprintf (file, "\nESCAPED");
337 dump_points_to_solution (file, &cfun->gimple_df->escaped);
339 fprintf (file, "\n\nFlow-insensitive points-to information\n\n");
341 for (i = 1; i < num_ssa_names; i++)
343 tree ptr = ssa_name (i);
344 struct ptr_info_def *pi;
347 || SSA_NAME_IN_FREE_LIST (ptr))
350 pi = SSA_NAME_PTR_INFO (ptr);
352 dump_points_to_info_for (file, ptr);
355 fprintf (file, "\n");
359 /* Dump alias information on stderr. */
362 debug_alias_info (void)
364 dump_alias_info (stderr);
368 /* Return the alias information associated with pointer T. It creates a
369 new instance if none existed. */
371 struct ptr_info_def *
372 get_ptr_info (tree t)
374 struct ptr_info_def *pi;
376 gcc_assert (POINTER_TYPE_P (TREE_TYPE (t)));
378 pi = SSA_NAME_PTR_INFO (t);
381 pi = GGC_CNEW (struct ptr_info_def);
382 pt_solution_reset (&pi->pt);
383 SSA_NAME_PTR_INFO (t) = pi;
389 /* Dump the points-to set *PT into FILE. */
392 dump_points_to_solution (FILE *file, struct pt_solution *pt)
395 fprintf (file, ", points-to anything");
398 fprintf (file, ", points-to non-local");
401 fprintf (file, ", points-to escaped");
404 fprintf (file, ", points-to unit escaped");
407 fprintf (file, ", points-to NULL");
411 fprintf (file, ", points-to vars: ");
412 dump_decl_set (file, pt->vars);
413 if (pt->vars_contains_global)
414 fprintf (file, " (includes global vars)");
415 if (pt->vars_contains_restrict)
416 fprintf (file, " (includes restrict tags)");
420 /* Dump points-to information for SSA_NAME PTR into FILE. */
423 dump_points_to_info_for (FILE *file, tree ptr)
425 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr);
427 print_generic_expr (file, ptr, dump_flags);
430 dump_points_to_solution (file, &pi->pt);
432 fprintf (file, ", points-to anything");
434 fprintf (file, "\n");
438 /* Dump points-to information for VAR into stderr. */
441 debug_points_to_info_for (tree var)
443 dump_points_to_info_for (stderr, var);
447 /* Initializes the alias-oracle reference representation *R from REF. */
450 ao_ref_init (ao_ref *r, tree ref)
457 r->ref_alias_set = -1;
458 r->base_alias_set = -1;
461 /* Returns the base object of the memory reference *REF. */
464 ao_ref_base (ao_ref *ref)
468 ref->base = get_ref_base_and_extent (ref->ref, &ref->offset, &ref->size,
473 /* Returns the base object alias set of the memory reference *REF. */
475 static alias_set_type ATTRIBUTE_UNUSED
476 ao_ref_base_alias_set (ao_ref *ref)
478 if (ref->base_alias_set != -1)
479 return ref->base_alias_set;
480 ref->base_alias_set = get_alias_set (ao_ref_base (ref));
481 return ref->base_alias_set;
484 /* Returns the reference alias set of the memory reference *REF. */
487 ao_ref_alias_set (ao_ref *ref)
489 if (ref->ref_alias_set != -1)
490 return ref->ref_alias_set;
491 ref->ref_alias_set = get_alias_set (ref->ref);
492 return ref->ref_alias_set;
495 /* Init an alias-oracle reference representation from a gimple pointer
496 PTR and a gimple size SIZE in bytes. If SIZE is NULL_TREE the the
497 size is assumed to be unknown. The access is assumed to be only
498 to or after of the pointer target, not before it. */
501 ao_ref_init_from_ptr_and_size (ao_ref *ref, tree ptr, tree size)
503 HOST_WIDE_INT t1, t2;
504 ref->ref = NULL_TREE;
505 if (TREE_CODE (ptr) == ADDR_EXPR)
506 ref->base = get_ref_base_and_extent (TREE_OPERAND (ptr, 0),
507 &ref->offset, &t1, &t2);
510 ref->base = build1 (INDIRECT_REF, char_type_node, ptr);
514 && host_integerp (size, 0)
515 && TREE_INT_CST_LOW (size) * 8 / 8 == TREE_INT_CST_LOW (size))
516 ref->max_size = ref->size = TREE_INT_CST_LOW (size) * 8;
518 ref->max_size = ref->size = -1;
519 ref->ref_alias_set = 0;
520 ref->base_alias_set = 0;
523 /* Return 1 if TYPE1 and TYPE2 are to be considered equivalent for the
524 purpose of TBAA. Return 0 if they are distinct and -1 if we cannot
528 same_type_for_tbaa (tree type1, tree type2)
530 type1 = TYPE_MAIN_VARIANT (type1);
531 type2 = TYPE_MAIN_VARIANT (type2);
533 /* If we would have to do structural comparison bail out. */
534 if (TYPE_STRUCTURAL_EQUALITY_P (type1)
535 || TYPE_STRUCTURAL_EQUALITY_P (type2))
538 /* Compare the canonical types. */
539 if (TYPE_CANONICAL (type1) == TYPE_CANONICAL (type2))
542 /* ??? Array types are not properly unified in all cases as we have
543 spurious changes in the index types for example. Removing this
544 causes all sorts of problems with the Fortran frontend. */
545 if (TREE_CODE (type1) == ARRAY_TYPE
546 && TREE_CODE (type2) == ARRAY_TYPE)
549 /* ??? In Ada, an lvalue of an unconstrained type can be used to access an
550 object of one of its constrained subtypes, e.g. when a function with an
551 unconstrained parameter passed by reference is called on an object and
552 inlined. But, even in the case of a fixed size, type and subtypes are
553 not equivalent enough as to share the same TYPE_CANONICAL, since this
554 would mean that conversions between them are useless, whereas they are
555 not (e.g. type and subtypes can have different modes). So, in the end,
556 they are only guaranteed to have the same alias set. */
557 if (get_alias_set (type1) == get_alias_set (type2))
560 /* The types are known to be not equal. */
564 /* Determine if the two component references REF1 and REF2 which are
565 based on access types TYPE1 and TYPE2 and of which at least one is based
566 on an indirect reference may alias. */
569 aliasing_component_refs_p (tree ref1, tree type1,
570 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
571 tree ref2, tree type2,
572 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2)
574 /* If one reference is a component references through pointers try to find a
575 common base and apply offset based disambiguation. This handles
577 struct A { int i; int j; } *q;
578 struct B { struct A a; int k; } *p;
579 disambiguating q->i and p->a.j. */
583 /* Now search for the type1 in the access path of ref2. This
584 would be a common base for doing offset based disambiguation on. */
586 while (handled_component_p (*refp)
587 && same_type_for_tbaa (TREE_TYPE (*refp), type1) == 0)
588 refp = &TREE_OPERAND (*refp, 0);
589 same_p = same_type_for_tbaa (TREE_TYPE (*refp), type1);
590 /* If we couldn't compare types we have to bail out. */
593 else if (same_p == 1)
595 HOST_WIDE_INT offadj, sztmp, msztmp;
596 get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp);
598 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
600 /* If we didn't find a common base, try the other way around. */
602 while (handled_component_p (*refp)
603 && same_type_for_tbaa (TREE_TYPE (*refp), type2) == 0)
604 refp = &TREE_OPERAND (*refp, 0);
605 same_p = same_type_for_tbaa (TREE_TYPE (*refp), type2);
606 /* If we couldn't compare types we have to bail out. */
609 else if (same_p == 1)
611 HOST_WIDE_INT offadj, sztmp, msztmp;
612 get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp);
614 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
616 /* If we have two type access paths B1.path1 and B2.path2 they may
617 only alias if either B1 is in B2.path2 or B2 is in B1.path1. */
621 /* Return true if two memory references based on the variables BASE1
622 and BASE2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and
623 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. */
626 decl_refs_may_alias_p (tree base1,
627 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
629 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2)
631 gcc_assert (SSA_VAR_P (base1) && SSA_VAR_P (base2));
633 /* If both references are based on different variables, they cannot alias. */
637 /* If both references are based on the same variable, they cannot alias if
638 the accesses do not overlap. */
639 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
642 /* Return true if an indirect reference based on *PTR1 constrained
643 to [OFFSET1, OFFSET1 + MAX_SIZE1) may alias a variable based on BASE2
644 constrained to [OFFSET2, OFFSET2 + MAX_SIZE2). *PTR1 and BASE2 have
645 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
646 in which case they are computed on-demand. REF1 and REF2
647 if non-NULL are the complete memory reference trees. */
650 indirect_ref_may_alias_decl_p (tree ref1, tree ptr1,
651 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
652 alias_set_type base1_alias_set,
653 tree ref2, tree base2,
654 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
655 alias_set_type base2_alias_set)
657 /* If only one reference is based on a variable, they cannot alias if
658 the pointer access is beyond the extent of the variable access.
659 (the pointer base cannot validly point to an offset less than zero
661 They also cannot alias if the pointer may not point to the decl. */
663 && !ranges_overlap_p (offset1, max_size1, 0, offset2 + max_size2))
665 if (!ptr_deref_may_alias_decl_p (ptr1, base2))
668 /* Disambiguations that rely on strict aliasing rules follow. */
669 if (!flag_strict_aliasing)
672 /* If the alias set for a pointer access is zero all bets are off. */
673 if (base1_alias_set == -1)
674 base1_alias_set = get_deref_alias_set (ptr1);
675 if (base1_alias_set == 0)
677 if (base2_alias_set == -1)
678 base2_alias_set = get_alias_set (base2);
680 /* If both references are through the same type, they do not alias
681 if the accesses do not overlap. This does extra disambiguation
682 for mixed/pointer accesses but requires strict aliasing. */
683 if (same_type_for_tbaa (TREE_TYPE (TREE_TYPE (ptr1)),
684 TREE_TYPE (base2)) == 1)
685 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
687 /* The only way to access a variable is through a pointer dereference
688 of the same alias set or a subset of it. */
689 if (base1_alias_set != base2_alias_set
690 && !alias_set_subset_of (base1_alias_set, base2_alias_set))
693 /* Do access-path based disambiguation. */
695 && handled_component_p (ref1)
696 && handled_component_p (ref2))
697 return aliasing_component_refs_p (ref1, TREE_TYPE (TREE_TYPE (ptr1)),
699 ref2, TREE_TYPE (base2),
705 /* Return true if two indirect references based on *PTR1
706 and *PTR2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and
707 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. *PTR1 and *PTR2 have
708 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
709 in which case they are computed on-demand. REF1 and REF2
710 if non-NULL are the complete memory reference trees. */
713 indirect_refs_may_alias_p (tree ref1, tree ptr1,
714 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
715 alias_set_type base1_alias_set,
716 tree ref2, tree ptr2,
717 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
718 alias_set_type base2_alias_set)
720 /* If both bases are based on pointers they cannot alias if they may not
721 point to the same memory object or if they point to the same object
722 and the accesses do not overlap. */
723 if (operand_equal_p (ptr1, ptr2, 0))
724 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
725 if (!ptr_derefs_may_alias_p (ptr1, ptr2))
728 /* Disambiguations that rely on strict aliasing rules follow. */
729 if (!flag_strict_aliasing)
732 /* If the alias set for a pointer access is zero all bets are off. */
733 if (base1_alias_set == -1)
734 base1_alias_set = get_deref_alias_set (ptr1);
735 if (base1_alias_set == 0)
737 if (base2_alias_set == -1)
738 base2_alias_set = get_deref_alias_set (ptr2);
739 if (base2_alias_set == 0)
742 /* If both references are through the same type, they do not alias
743 if the accesses do not overlap. This does extra disambiguation
744 for mixed/pointer accesses but requires strict aliasing. */
745 if (same_type_for_tbaa (TREE_TYPE (TREE_TYPE (ptr1)),
746 TREE_TYPE (TREE_TYPE (ptr2))) == 1)
747 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
749 /* Do type-based disambiguation. */
750 if (base1_alias_set != base2_alias_set
751 && !alias_sets_conflict_p (base1_alias_set, base2_alias_set))
754 /* Do access-path based disambiguation. */
756 && handled_component_p (ref1)
757 && handled_component_p (ref2))
758 return aliasing_component_refs_p (ref1, TREE_TYPE (TREE_TYPE (ptr1)),
760 ref2, TREE_TYPE (TREE_TYPE (ptr2)),
766 /* Return true, if the two memory references REF1 and REF2 may alias. */
769 refs_may_alias_p_1 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
772 HOST_WIDE_INT offset1 = 0, offset2 = 0;
773 HOST_WIDE_INT max_size1 = -1, max_size2 = -1;
774 bool var1_p, var2_p, ind1_p, ind2_p;
777 gcc_assert ((!ref1->ref
778 || SSA_VAR_P (ref1->ref)
779 || handled_component_p (ref1->ref)
780 || INDIRECT_REF_P (ref1->ref)
781 || TREE_CODE (ref1->ref) == TARGET_MEM_REF
782 || TREE_CODE (ref1->ref) == CONST_DECL)
784 || SSA_VAR_P (ref2->ref)
785 || handled_component_p (ref2->ref)
786 || INDIRECT_REF_P (ref2->ref)
787 || TREE_CODE (ref2->ref) == TARGET_MEM_REF
788 || TREE_CODE (ref2->ref) == CONST_DECL));
790 /* Decompose the references into their base objects and the access. */
791 base1 = ao_ref_base (ref1);
792 offset1 = ref1->offset;
793 max_size1 = ref1->max_size;
794 base2 = ao_ref_base (ref2);
795 offset2 = ref2->offset;
796 max_size2 = ref2->max_size;
798 /* We can end up with registers or constants as bases for example from
799 *D.1663_44 = VIEW_CONVERT_EXPR<struct DB_LSN>(__tmp$B0F64_59);
800 which is seen as a struct copy. */
801 if (TREE_CODE (base1) == SSA_NAME
802 || TREE_CODE (base2) == SSA_NAME
803 || TREE_CODE (base1) == CONST_DECL
804 || TREE_CODE (base2) == CONST_DECL
805 || is_gimple_min_invariant (base1)
806 || is_gimple_min_invariant (base2))
809 /* We can end up refering to code via function decls. As we likely
810 do not properly track code aliases conservatively bail out. */
811 if (TREE_CODE (base1) == FUNCTION_DECL
812 || TREE_CODE (base2) == FUNCTION_DECL)
815 /* Defer to simple offset based disambiguation if we have
816 references based on two decls. Do this before defering to
817 TBAA to handle must-alias cases in conformance with the
818 GCC extension of allowing type-punning through unions. */
819 var1_p = SSA_VAR_P (base1);
820 var2_p = SSA_VAR_P (base2);
821 if (var1_p && var2_p)
822 return decl_refs_may_alias_p (base1, offset1, max_size1,
823 base2, offset2, max_size2);
825 ind1_p = INDIRECT_REF_P (base1);
826 ind2_p = INDIRECT_REF_P (base2);
827 /* Canonicalize the pointer-vs-decl case. */
828 if (ind1_p && var2_p)
833 tmp1 = offset1; offset1 = offset2; offset2 = tmp1;
834 tmp1 = max_size1; max_size1 = max_size2; max_size2 = tmp1;
835 tmp2 = base1; base1 = base2; base2 = tmp2;
836 tmp3 = ref1; ref1 = ref2; ref2 = tmp3;
843 /* If we are about to disambiguate pointer-vs-decl try harder to
844 see must-aliases and give leeway to some invalid cases.
845 This covers a pretty minimal set of cases only and does not
846 when called from the RTL oracle. It handles cases like
851 and also fixes gfortran.dg/lto/pr40725. */
854 && gimple_in_ssa_p (cfun)
855 && TREE_CODE (TREE_OPERAND (base2, 0)) == SSA_NAME)
857 gimple def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (base2, 0));
858 while (is_gimple_assign (def_stmt)
859 && (gimple_assign_rhs_code (def_stmt) == SSA_NAME
860 || CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))))
862 tree rhs = gimple_assign_rhs1 (def_stmt);
863 HOST_WIDE_INT offset, size, max_size;
865 /* Look through SSA name copies and pointer conversions. */
866 if (TREE_CODE (rhs) == SSA_NAME
867 && POINTER_TYPE_P (TREE_TYPE (rhs)))
869 def_stmt = SSA_NAME_DEF_STMT (rhs);
872 if (TREE_CODE (rhs) != ADDR_EXPR)
875 /* If the pointer is defined as an address based on a decl
876 use plain offset disambiguation and ignore TBAA. */
877 rhs = TREE_OPERAND (rhs, 0);
878 rhs = get_ref_base_and_extent (rhs, &offset, &size, &max_size);
886 return decl_refs_may_alias_p (base1, offset1, max_size1,
887 base2, offset2, max_size2);
890 /* Do not continue looking through &p->x to limit time
896 /* First defer to TBAA if possible. */
898 && flag_strict_aliasing
899 && !alias_sets_conflict_p (ao_ref_alias_set (ref1),
900 ao_ref_alias_set (ref2)))
903 /* If one reference is a TARGET_MEM_REF weird things are allowed. Still
904 TBAA disambiguation based on the access type is possible, so bail
905 out only after that check. */
906 if ((ref1->ref && TREE_CODE (ref1->ref) == TARGET_MEM_REF)
907 || (ref2->ref && TREE_CODE (ref2->ref) == TARGET_MEM_REF))
910 /* Dispatch to the pointer-vs-decl or pointer-vs-pointer disambiguators. */
911 set = tbaa_p ? -1 : 0;
912 if (var1_p && ind2_p)
913 return indirect_ref_may_alias_decl_p (ref2->ref, TREE_OPERAND (base2, 0),
914 offset2, max_size2, set,
916 offset1, max_size1, set);
917 else if (ind1_p && ind2_p)
918 return indirect_refs_may_alias_p (ref1->ref, TREE_OPERAND (base1, 0),
919 offset1, max_size1, set,
920 ref2->ref, TREE_OPERAND (base2, 0),
921 offset2, max_size2, set);
927 refs_may_alias_p (tree ref1, tree ref2)
931 ao_ref_init (&r1, ref1);
932 ao_ref_init (&r2, ref2);
933 res = refs_may_alias_p_1 (&r1, &r2, true);
935 ++alias_stats.refs_may_alias_p_may_alias;
937 ++alias_stats.refs_may_alias_p_no_alias;
941 /* Returns true if there is a anti-dependence for the STORE that
942 executes after the LOAD. */
945 refs_anti_dependent_p (tree load, tree store)
948 ao_ref_init (&r1, load);
949 ao_ref_init (&r2, store);
950 return refs_may_alias_p_1 (&r1, &r2, false);
953 /* Returns true if there is a output dependence for the stores
954 STORE1 and STORE2. */
957 refs_output_dependent_p (tree store1, tree store2)
960 ao_ref_init (&r1, store1);
961 ao_ref_init (&r2, store2);
962 return refs_may_alias_p_1 (&r1, &r2, false);
965 /* If the call CALL may use the memory reference REF return true,
966 otherwise return false. */
969 ref_maybe_used_by_call_p_1 (gimple call, ao_ref *ref)
973 int flags = gimple_call_flags (call);
975 /* Const functions without a static chain do not implicitly use memory. */
976 if (!gimple_call_chain (call)
977 && (flags & (ECF_CONST|ECF_NOVOPS)))
980 base = ao_ref_base (ref);
984 /* If the reference is based on a decl that is not aliased the call
985 cannot possibly use it. */
987 && !may_be_aliased (base)
988 /* But local statics can be used through recursion. */
989 && !is_global_var (base))
992 callee = gimple_call_fndecl (call);
994 /* Handle those builtin functions explicitly that do not act as
995 escape points. See tree-ssa-structalias.c:find_func_aliases
996 for the list of builtins we might need to handle here. */
997 if (callee != NULL_TREE
998 && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
999 switch (DECL_FUNCTION_CODE (callee))
1001 /* All the following functions clobber memory pointed to by
1002 their first argument. */
1003 case BUILT_IN_STRCPY:
1004 case BUILT_IN_STRNCPY:
1005 case BUILT_IN_MEMCPY:
1006 case BUILT_IN_MEMMOVE:
1007 case BUILT_IN_MEMPCPY:
1008 case BUILT_IN_STPCPY:
1009 case BUILT_IN_STPNCPY:
1010 case BUILT_IN_STRCAT:
1011 case BUILT_IN_STRNCAT:
1014 tree size = NULL_TREE;
1015 if (gimple_call_num_args (call) == 3)
1016 size = gimple_call_arg (call, 2);
1017 ao_ref_init_from_ptr_and_size (&dref,
1018 gimple_call_arg (call, 1),
1020 return refs_may_alias_p_1 (&dref, ref, false);
1022 case BUILT_IN_BCOPY:
1025 tree size = gimple_call_arg (call, 2);
1026 ao_ref_init_from_ptr_and_size (&dref,
1027 gimple_call_arg (call, 0),
1029 return refs_may_alias_p_1 (&dref, ref, false);
1031 /* The following builtins do not read from memory. */
1033 case BUILT_IN_MALLOC:
1034 case BUILT_IN_CALLOC:
1035 case BUILT_IN_MEMSET:
1036 case BUILT_IN_FREXP:
1037 case BUILT_IN_FREXPF:
1038 case BUILT_IN_FREXPL:
1039 case BUILT_IN_GAMMA_R:
1040 case BUILT_IN_GAMMAF_R:
1041 case BUILT_IN_GAMMAL_R:
1042 case BUILT_IN_LGAMMA_R:
1043 case BUILT_IN_LGAMMAF_R:
1044 case BUILT_IN_LGAMMAL_R:
1046 case BUILT_IN_MODFF:
1047 case BUILT_IN_MODFL:
1048 case BUILT_IN_REMQUO:
1049 case BUILT_IN_REMQUOF:
1050 case BUILT_IN_REMQUOL:
1051 case BUILT_IN_SINCOS:
1052 case BUILT_IN_SINCOSF:
1053 case BUILT_IN_SINCOSL:
1057 /* Fallthru to general call handling. */;
1060 /* Check if base is a global static variable that is not read
1062 if (TREE_CODE (base) == VAR_DECL
1063 && TREE_STATIC (base))
1067 if (callee != NULL_TREE
1069 = ipa_reference_get_not_read_global (cgraph_node (callee)))
1070 && bitmap_bit_p (not_read, DECL_UID (base)))
1074 /* Check if the base variable is call-used. */
1077 if (pt_solution_includes (gimple_call_use_set (call), base))
1080 else if (INDIRECT_REF_P (base)
1081 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
1083 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0));
1087 if (pt_solutions_intersect (gimple_call_use_set (call), &pi->pt))
1093 /* Inspect call arguments for passed-by-value aliases. */
1095 for (i = 0; i < gimple_call_num_args (call); ++i)
1097 tree op = gimple_call_arg (call, i);
1098 int flags = gimple_call_arg_flags (call, i);
1100 if (flags & EAF_UNUSED)
1103 if (TREE_CODE (op) == WITH_SIZE_EXPR)
1104 op = TREE_OPERAND (op, 0);
1106 if (TREE_CODE (op) != SSA_NAME
1107 && !is_gimple_min_invariant (op))
1110 ao_ref_init (&r, op);
1111 if (refs_may_alias_p_1 (&r, ref, true))
1120 ref_maybe_used_by_call_p (gimple call, tree ref)
1124 ao_ref_init (&r, ref);
1125 res = ref_maybe_used_by_call_p_1 (call, &r);
1127 ++alias_stats.ref_maybe_used_by_call_p_may_alias;
1129 ++alias_stats.ref_maybe_used_by_call_p_no_alias;
1134 /* If the statement STMT may use the memory reference REF return
1135 true, otherwise return false. */
1138 ref_maybe_used_by_stmt_p (gimple stmt, tree ref)
1140 if (is_gimple_assign (stmt))
1144 /* All memory assign statements are single. */
1145 if (!gimple_assign_single_p (stmt))
1148 rhs = gimple_assign_rhs1 (stmt);
1149 if (is_gimple_reg (rhs)
1150 || is_gimple_min_invariant (rhs)
1151 || gimple_assign_rhs_code (stmt) == CONSTRUCTOR)
1154 return refs_may_alias_p (rhs, ref);
1156 else if (is_gimple_call (stmt))
1157 return ref_maybe_used_by_call_p (stmt, ref);
1162 /* If the call in statement CALL may clobber the memory reference REF
1163 return true, otherwise return false. */
1166 call_may_clobber_ref_p_1 (gimple call, ao_ref *ref)
1171 /* If the call is pure or const it cannot clobber anything. */
1172 if (gimple_call_flags (call)
1173 & (ECF_PURE|ECF_CONST|ECF_LOOPING_CONST_OR_PURE|ECF_NOVOPS))
1176 base = ao_ref_base (ref);
1180 if (TREE_CODE (base) == SSA_NAME
1181 || CONSTANT_CLASS_P (base))
1184 /* If the reference is based on a decl that is not aliased the call
1185 cannot possibly clobber it. */
1187 && !may_be_aliased (base)
1188 /* But local non-readonly statics can be modified through recursion
1189 or the call may implement a threading barrier which we must
1190 treat as may-def. */
1191 && (TREE_READONLY (base)
1192 || !is_global_var (base)))
1195 callee = gimple_call_fndecl (call);
1197 /* Handle those builtin functions explicitly that do not act as
1198 escape points. See tree-ssa-structalias.c:find_func_aliases
1199 for the list of builtins we might need to handle here. */
1200 if (callee != NULL_TREE
1201 && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
1202 switch (DECL_FUNCTION_CODE (callee))
1204 /* All the following functions clobber memory pointed to by
1205 their first argument. */
1206 case BUILT_IN_STRCPY:
1207 case BUILT_IN_STRNCPY:
1208 case BUILT_IN_MEMCPY:
1209 case BUILT_IN_MEMMOVE:
1210 case BUILT_IN_MEMPCPY:
1211 case BUILT_IN_STPCPY:
1212 case BUILT_IN_STPNCPY:
1213 case BUILT_IN_STRCAT:
1214 case BUILT_IN_STRNCAT:
1215 case BUILT_IN_MEMSET:
1218 tree size = NULL_TREE;
1219 if (gimple_call_num_args (call) == 3)
1220 size = gimple_call_arg (call, 2);
1221 ao_ref_init_from_ptr_and_size (&dref,
1222 gimple_call_arg (call, 0),
1224 return refs_may_alias_p_1 (&dref, ref, false);
1226 case BUILT_IN_BCOPY:
1229 tree size = gimple_call_arg (call, 2);
1230 ao_ref_init_from_ptr_and_size (&dref,
1231 gimple_call_arg (call, 1),
1233 return refs_may_alias_p_1 (&dref, ref, false);
1235 /* Allocating memory does not have any side-effects apart from
1236 being the definition point for the pointer. */
1237 case BUILT_IN_MALLOC:
1238 case BUILT_IN_CALLOC:
1239 /* Unix98 specifies that errno is set on allocation failure.
1240 Until we properly can track the errno location assume it
1241 is not a local decl but external or anonymous storage in
1242 a different translation unit. Also assume it is of
1243 type int as required by the standard. */
1245 && TREE_TYPE (base) == integer_type_node)
1247 struct ptr_info_def *pi;
1249 && !TREE_STATIC (base))
1251 else if (INDIRECT_REF_P (base)
1252 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME
1253 && (pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0))))
1254 return pi->pt.anything || pi->pt.nonlocal;
1257 /* Freeing memory kills the pointed-to memory. More importantly
1258 the call has to serve as a barrier for moving loads and stores
1262 tree ptr = gimple_call_arg (call, 0);
1263 return ptr_deref_may_alias_ref_p_1 (ptr, ref);
1265 case BUILT_IN_GAMMA_R:
1266 case BUILT_IN_GAMMAF_R:
1267 case BUILT_IN_GAMMAL_R:
1268 case BUILT_IN_LGAMMA_R:
1269 case BUILT_IN_LGAMMAF_R:
1270 case BUILT_IN_LGAMMAL_R:
1272 tree out = gimple_call_arg (call, 1);
1273 if (ptr_deref_may_alias_ref_p_1 (out, ref))
1275 if (flag_errno_math)
1279 case BUILT_IN_FREXP:
1280 case BUILT_IN_FREXPF:
1281 case BUILT_IN_FREXPL:
1283 case BUILT_IN_MODFF:
1284 case BUILT_IN_MODFL:
1286 tree out = gimple_call_arg (call, 1);
1287 return ptr_deref_may_alias_ref_p_1 (out, ref);
1289 case BUILT_IN_REMQUO:
1290 case BUILT_IN_REMQUOF:
1291 case BUILT_IN_REMQUOL:
1293 tree out = gimple_call_arg (call, 2);
1294 if (ptr_deref_may_alias_ref_p_1 (out, ref))
1296 if (flag_errno_math)
1300 case BUILT_IN_SINCOS:
1301 case BUILT_IN_SINCOSF:
1302 case BUILT_IN_SINCOSL:
1304 tree sin = gimple_call_arg (call, 1);
1305 tree cos = gimple_call_arg (call, 2);
1306 return (ptr_deref_may_alias_ref_p_1 (sin, ref)
1307 || ptr_deref_may_alias_ref_p_1 (cos, ref));
1310 /* Fallthru to general call handling. */;
1313 /* Check if base is a global static variable that is not written
1315 if (callee != NULL_TREE
1316 && TREE_CODE (base) == VAR_DECL
1317 && TREE_STATIC (base))
1322 = ipa_reference_get_not_written_global (cgraph_node (callee)))
1323 && bitmap_bit_p (not_written, DECL_UID (base)))
1327 /* Check if the base variable is call-clobbered. */
1329 return pt_solution_includes (gimple_call_clobber_set (call), base);
1330 else if (INDIRECT_REF_P (base)
1331 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
1333 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0));
1337 return pt_solutions_intersect (gimple_call_clobber_set (call), &pi->pt);
1343 /* If the call in statement CALL may clobber the memory reference REF
1344 return true, otherwise return false. */
1347 call_may_clobber_ref_p (gimple call, tree ref)
1351 ao_ref_init (&r, ref);
1352 res = call_may_clobber_ref_p_1 (call, &r);
1354 ++alias_stats.call_may_clobber_ref_p_may_alias;
1356 ++alias_stats.call_may_clobber_ref_p_no_alias;
1361 /* If the statement STMT may clobber the memory reference REF return true,
1362 otherwise return false. */
1365 stmt_may_clobber_ref_p_1 (gimple stmt, ao_ref *ref)
1367 if (is_gimple_call (stmt))
1369 tree lhs = gimple_call_lhs (stmt);
1371 && !is_gimple_reg (lhs))
1374 ao_ref_init (&r, lhs);
1375 if (refs_may_alias_p_1 (ref, &r, true))
1379 return call_may_clobber_ref_p_1 (stmt, ref);
1381 else if (is_gimple_assign (stmt))
1384 ao_ref_init (&r, gimple_assign_lhs (stmt));
1385 return refs_may_alias_p_1 (ref, &r, true);
1387 else if (gimple_code (stmt) == GIMPLE_ASM)
1394 stmt_may_clobber_ref_p (gimple stmt, tree ref)
1397 ao_ref_init (&r, ref);
1398 return stmt_may_clobber_ref_p_1 (stmt, &r);
1402 /* Walk the virtual use-def chain of VUSE until hitting the virtual operand
1403 TARGET or a statement clobbering the memory reference REF in which
1404 case false is returned. The walk starts with VUSE, one argument of PHI. */
1407 maybe_skip_until (gimple phi, tree target, ao_ref *ref,
1408 tree vuse, bitmap *visited)
1411 *visited = BITMAP_ALLOC (NULL);
1413 bitmap_set_bit (*visited, SSA_NAME_VERSION (PHI_RESULT (phi)));
1415 /* Walk until we hit the target. */
1416 while (vuse != target)
1418 gimple def_stmt = SSA_NAME_DEF_STMT (vuse);
1419 /* Recurse for PHI nodes. */
1420 if (gimple_code (def_stmt) == GIMPLE_PHI)
1422 /* An already visited PHI node ends the walk successfully. */
1423 if (bitmap_bit_p (*visited, SSA_NAME_VERSION (PHI_RESULT (def_stmt))))
1425 vuse = get_continuation_for_phi (def_stmt, ref, visited);
1430 /* A clobbering statement or the end of the IL ends it failing. */
1431 else if (gimple_nop_p (def_stmt)
1432 || stmt_may_clobber_ref_p_1 (def_stmt, ref))
1434 vuse = gimple_vuse (def_stmt);
1439 /* Starting from a PHI node for the virtual operand of the memory reference
1440 REF find a continuation virtual operand that allows to continue walking
1441 statements dominating PHI skipping only statements that cannot possibly
1442 clobber REF. Returns NULL_TREE if no suitable virtual operand can
1446 get_continuation_for_phi (gimple phi, ao_ref *ref, bitmap *visited)
1448 unsigned nargs = gimple_phi_num_args (phi);
1450 /* Through a single-argument PHI we can simply look through. */
1452 return PHI_ARG_DEF (phi, 0);
1454 /* For two arguments try to skip non-aliasing code until we hit
1455 the phi argument definition that dominates the other one. */
1458 tree arg0 = PHI_ARG_DEF (phi, 0);
1459 tree arg1 = PHI_ARG_DEF (phi, 1);
1460 gimple def0 = SSA_NAME_DEF_STMT (arg0);
1461 gimple def1 = SSA_NAME_DEF_STMT (arg1);
1466 else if (gimple_nop_p (def0)
1467 || (!gimple_nop_p (def1)
1468 && dominated_by_p (CDI_DOMINATORS,
1469 gimple_bb (def1), gimple_bb (def0))))
1471 if (maybe_skip_until (phi, arg0, ref, arg1, visited))
1474 else if (gimple_nop_p (def1)
1475 || dominated_by_p (CDI_DOMINATORS,
1476 gimple_bb (def0), gimple_bb (def1)))
1478 if (maybe_skip_until (phi, arg1, ref, arg0, visited))
1481 /* Special case of a diamond:
1483 goto (cond) ? L1 : L2
1484 L1: store1 = ... #MEM_2 = vuse(MEM_1)
1486 L2: store2 = ... #MEM_3 = vuse(MEM_1)
1487 L3: MEM_4 = PHI<MEM_2, MEM_3>
1488 We were called with the PHI at L3, MEM_2 and MEM_3 don't
1489 dominate each other, but still we can easily skip this PHI node
1490 if we recognize that the vuse MEM operand is the same for both,
1491 and that we can skip both statements (they don't clobber us).
1492 This is still linear. Don't use maybe_skip_until, that might
1493 potentially be slow. */
1494 else if ((common_vuse = gimple_vuse (def0))
1495 && common_vuse == gimple_vuse (def1))
1497 if (!stmt_may_clobber_ref_p_1 (def0, ref)
1498 && !stmt_may_clobber_ref_p_1 (def1, ref))
1506 /* Based on the memory reference REF and its virtual use VUSE call
1507 WALKER for each virtual use that is equivalent to VUSE, including VUSE
1508 itself. That is, for each virtual use for which its defining statement
1509 does not clobber REF.
1511 WALKER is called with REF, the current virtual use and DATA. If
1512 WALKER returns non-NULL the walk stops and its result is returned.
1513 At the end of a non-successful walk NULL is returned.
1515 TRANSLATE if non-NULL is called with a pointer to REF, the virtual
1516 use which definition is a statement that may clobber REF and DATA.
1517 If TRANSLATE returns (void *)-1 the walk stops and NULL is returned.
1518 If TRANSLATE returns non-NULL the walk stops and its result is returned.
1519 If TRANSLATE returns NULL the walk continues and TRANSLATE is supposed
1520 to adjust REF and *DATA to make that valid.
1522 TODO: Cache the vector of equivalent vuses per ref, vuse pair. */
1525 walk_non_aliased_vuses (ao_ref *ref, tree vuse,
1526 void *(*walker)(ao_ref *, tree, void *),
1527 void *(*translate)(ao_ref *, tree, void *), void *data)
1529 bitmap visited = NULL;
1532 timevar_push (TV_ALIAS_STMT_WALK);
1538 /* ??? Do we want to account this to TV_ALIAS_STMT_WALK? */
1539 res = (*walker) (ref, vuse, data);
1543 def_stmt = SSA_NAME_DEF_STMT (vuse);
1544 if (gimple_nop_p (def_stmt))
1546 else if (gimple_code (def_stmt) == GIMPLE_PHI)
1547 vuse = get_continuation_for_phi (def_stmt, ref, &visited);
1550 if (stmt_may_clobber_ref_p_1 (def_stmt, ref))
1554 res = (*translate) (ref, vuse, data);
1555 /* Failed lookup and translation. */
1556 if (res == (void *)-1)
1561 /* Lookup succeeded. */
1562 else if (res != NULL)
1564 /* Translation succeeded, continue walking. */
1566 vuse = gimple_vuse (def_stmt);
1572 BITMAP_FREE (visited);
1574 timevar_pop (TV_ALIAS_STMT_WALK);
1580 /* Based on the memory reference REF call WALKER for each vdef which
1581 defining statement may clobber REF, starting with VDEF. If REF
1582 is NULL_TREE, each defining statement is visited.
1584 WALKER is called with REF, the current vdef and DATA. If WALKER
1585 returns true the walk is stopped, otherwise it continues.
1587 At PHI nodes walk_aliased_vdefs forks into one walk for reach
1588 PHI argument (but only one walk continues on merge points), the
1589 return value is true if any of the walks was successful.
1591 The function returns the number of statements walked. */
1594 walk_aliased_vdefs_1 (ao_ref *ref, tree vdef,
1595 bool (*walker)(ao_ref *, tree, void *), void *data,
1596 bitmap *visited, unsigned int cnt)
1600 gimple def_stmt = SSA_NAME_DEF_STMT (vdef);
1603 && !bitmap_set_bit (*visited, SSA_NAME_VERSION (vdef)))
1606 if (gimple_nop_p (def_stmt))
1608 else if (gimple_code (def_stmt) == GIMPLE_PHI)
1612 *visited = BITMAP_ALLOC (NULL);
1613 for (i = 0; i < gimple_phi_num_args (def_stmt); ++i)
1614 cnt += walk_aliased_vdefs_1 (ref, gimple_phi_arg_def (def_stmt, i),
1615 walker, data, visited, 0);
1619 /* ??? Do we want to account this to TV_ALIAS_STMT_WALK? */
1622 || stmt_may_clobber_ref_p_1 (def_stmt, ref))
1623 && (*walker) (ref, vdef, data))
1626 vdef = gimple_vuse (def_stmt);
1632 walk_aliased_vdefs (ao_ref *ref, tree vdef,
1633 bool (*walker)(ao_ref *, tree, void *), void *data,
1636 bitmap local_visited = NULL;
1639 timevar_push (TV_ALIAS_STMT_WALK);
1641 ret = walk_aliased_vdefs_1 (ref, vdef, walker, data,
1642 visited ? visited : &local_visited, 0);
1644 BITMAP_FREE (local_visited);
1646 timevar_pop (TV_ALIAS_STMT_WALK);