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"
31 #include "langhooks.h"
34 #include "tree-pretty-print.h"
35 #include "tree-dump.h"
37 #include "tree-flow.h"
38 #include "tree-inline.h"
39 #include "tree-pass.h"
42 #include "ipa-type-escape.h"
46 #include "pointer-set.h"
47 #include "alloc-pool.h"
48 #include "tree-ssa-alias.h"
50 /* Broad overview of how alias analysis on gimple works:
52 Statements clobbering or using memory are linked through the
53 virtual operand factored use-def chain. The virtual operand
54 is unique per function, its symbol is accessible via gimple_vop (cfun).
55 Virtual operands are used for efficiently walking memory statements
56 in the gimple IL and are useful for things like value-numbering as
57 a generation count for memory references.
59 SSA_NAME pointers may have associated points-to information
60 accessible via the SSA_NAME_PTR_INFO macro. Flow-insensitive
61 points-to information is (re-)computed by the TODO_rebuild_alias
62 pass manager todo. Points-to information is also used for more
63 precise tracking of call-clobbered and call-used variables and
64 related disambiguations.
66 This file contains functions for disambiguating memory references,
67 the so called alias-oracle and tools for walking of the gimple IL.
69 The main alias-oracle entry-points are
71 bool stmt_may_clobber_ref_p (gimple, tree)
73 This function queries if a statement may invalidate (parts of)
74 the memory designated by the reference tree argument.
76 bool ref_maybe_used_by_stmt_p (gimple, tree)
78 This function queries if a statement may need (parts of) the
79 memory designated by the reference tree argument.
81 There are variants of these functions that only handle the call
82 part of a statement, call_may_clobber_ref_p and ref_maybe_used_by_call_p.
83 Note that these do not disambiguate against a possible call lhs.
85 bool refs_may_alias_p (tree, tree)
87 This function tries to disambiguate two reference trees.
89 bool ptr_deref_may_alias_global_p (tree)
91 This function queries if dereferencing a pointer variable may
94 More low-level disambiguators are available and documented in
95 this file. Low-level disambiguators dealing with points-to
96 information are in tree-ssa-structalias.c. */
99 /* Query statistics for the different low-level disambiguators.
100 A high-level query may trigger multiple of them. */
103 unsigned HOST_WIDE_INT refs_may_alias_p_may_alias;
104 unsigned HOST_WIDE_INT refs_may_alias_p_no_alias;
105 unsigned HOST_WIDE_INT ref_maybe_used_by_call_p_may_alias;
106 unsigned HOST_WIDE_INT ref_maybe_used_by_call_p_no_alias;
107 unsigned HOST_WIDE_INT call_may_clobber_ref_p_may_alias;
108 unsigned HOST_WIDE_INT call_may_clobber_ref_p_no_alias;
112 dump_alias_stats (FILE *s)
114 fprintf (s, "\nAlias oracle query stats:\n");
115 fprintf (s, " refs_may_alias_p: "
116 HOST_WIDE_INT_PRINT_DEC" disambiguations, "
117 HOST_WIDE_INT_PRINT_DEC" queries\n",
118 alias_stats.refs_may_alias_p_no_alias,
119 alias_stats.refs_may_alias_p_no_alias
120 + alias_stats.refs_may_alias_p_may_alias);
121 fprintf (s, " ref_maybe_used_by_call_p: "
122 HOST_WIDE_INT_PRINT_DEC" disambiguations, "
123 HOST_WIDE_INT_PRINT_DEC" queries\n",
124 alias_stats.ref_maybe_used_by_call_p_no_alias,
125 alias_stats.refs_may_alias_p_no_alias
126 + alias_stats.ref_maybe_used_by_call_p_may_alias);
127 fprintf (s, " call_may_clobber_ref_p: "
128 HOST_WIDE_INT_PRINT_DEC" disambiguations, "
129 HOST_WIDE_INT_PRINT_DEC" queries\n",
130 alias_stats.call_may_clobber_ref_p_no_alias,
131 alias_stats.call_may_clobber_ref_p_no_alias
132 + alias_stats.call_may_clobber_ref_p_may_alias);
136 /* Return true, if dereferencing PTR may alias with a global variable. */
139 ptr_deref_may_alias_global_p (tree ptr)
141 struct ptr_info_def *pi;
143 /* If we end up with a pointer constant here that may point
145 if (TREE_CODE (ptr) != SSA_NAME)
148 pi = SSA_NAME_PTR_INFO (ptr);
150 /* If we do not have points-to information for this variable,
155 /* ??? This does not use TBAA to prune globals ptr may not access. */
156 return pt_solution_includes_global (&pi->pt);
159 /* Return true if dereferencing PTR may alias DECL.
160 The caller is responsible for applying TBAA to see if PTR
161 may access DECL at all. */
164 ptr_deref_may_alias_decl_p (tree ptr, tree decl)
166 struct ptr_info_def *pi;
168 gcc_assert ((TREE_CODE (ptr) == SSA_NAME
169 || TREE_CODE (ptr) == ADDR_EXPR
170 || TREE_CODE (ptr) == INTEGER_CST)
171 && (TREE_CODE (decl) == VAR_DECL
172 || TREE_CODE (decl) == PARM_DECL
173 || TREE_CODE (decl) == RESULT_DECL));
175 /* Non-aliased variables can not be pointed to. */
176 if (!may_be_aliased (decl))
179 /* ADDR_EXPR pointers either just offset another pointer or directly
180 specify the pointed-to set. */
181 if (TREE_CODE (ptr) == ADDR_EXPR)
183 tree base = get_base_address (TREE_OPERAND (ptr, 0));
185 && INDIRECT_REF_P (base))
186 ptr = TREE_OPERAND (base, 0);
191 && CONSTANT_CLASS_P (base))
197 /* We can end up with dereferencing constant pointers.
198 Just bail out in this case. */
199 if (TREE_CODE (ptr) == INTEGER_CST)
202 /* If we do not have useful points-to information for this pointer
203 we cannot disambiguate anything else. */
204 pi = SSA_NAME_PTR_INFO (ptr);
208 /* If the decl can be used as a restrict tag and we have a restrict
209 pointer and that pointers points-to set doesn't contain this decl
210 then they can't alias. */
211 if (DECL_RESTRICTED_P (decl)
212 && TYPE_RESTRICT (TREE_TYPE (ptr))
213 && pi->pt.vars_contains_restrict)
214 return bitmap_bit_p (pi->pt.vars, DECL_PT_UID (decl));
216 return pt_solution_includes (&pi->pt, decl);
219 /* Return true if dereferenced PTR1 and PTR2 may alias.
220 The caller is responsible for applying TBAA to see if accesses
221 through PTR1 and PTR2 may conflict at all. */
224 ptr_derefs_may_alias_p (tree ptr1, tree ptr2)
226 struct ptr_info_def *pi1, *pi2;
228 gcc_assert ((TREE_CODE (ptr1) == SSA_NAME
229 || TREE_CODE (ptr1) == ADDR_EXPR
230 || TREE_CODE (ptr1) == INTEGER_CST)
231 && (TREE_CODE (ptr2) == SSA_NAME
232 || TREE_CODE (ptr2) == ADDR_EXPR
233 || TREE_CODE (ptr2) == INTEGER_CST));
235 /* ADDR_EXPR pointers either just offset another pointer or directly
236 specify the pointed-to set. */
237 if (TREE_CODE (ptr1) == ADDR_EXPR)
239 tree base = get_base_address (TREE_OPERAND (ptr1, 0));
241 && INDIRECT_REF_P (base))
242 ptr1 = TREE_OPERAND (base, 0);
245 return ptr_deref_may_alias_decl_p (ptr2, base);
249 if (TREE_CODE (ptr2) == ADDR_EXPR)
251 tree base = get_base_address (TREE_OPERAND (ptr2, 0));
253 && INDIRECT_REF_P (base))
254 ptr2 = TREE_OPERAND (base, 0);
257 return ptr_deref_may_alias_decl_p (ptr1, base);
262 /* We can end up with dereferencing constant pointers.
263 Just bail out in this case. */
264 if (TREE_CODE (ptr1) == INTEGER_CST
265 || TREE_CODE (ptr2) == INTEGER_CST)
268 /* We may end up with two empty points-to solutions for two same pointers.
269 In this case we still want to say both pointers alias, so shortcut
274 /* If we do not have useful points-to information for either pointer
275 we cannot disambiguate anything else. */
276 pi1 = SSA_NAME_PTR_INFO (ptr1);
277 pi2 = SSA_NAME_PTR_INFO (ptr2);
281 /* If both pointers are restrict-qualified try to disambiguate
282 with restrict information. */
283 if (TYPE_RESTRICT (TREE_TYPE (ptr1))
284 && TYPE_RESTRICT (TREE_TYPE (ptr2))
285 && !pt_solutions_same_restrict_base (&pi1->pt, &pi2->pt))
288 /* ??? This does not use TBAA to prune decls from the intersection
289 that not both pointers may access. */
290 return pt_solutions_intersect (&pi1->pt, &pi2->pt);
293 /* Return true if dereferencing PTR may alias *REF.
294 The caller is responsible for applying TBAA to see if PTR
295 may access *REF at all. */
298 ptr_deref_may_alias_ref_p_1 (tree ptr, ao_ref *ref)
300 tree base = ao_ref_base (ref);
302 if (INDIRECT_REF_P (base))
303 return ptr_derefs_may_alias_p (ptr, TREE_OPERAND (base, 0));
304 else if (SSA_VAR_P (base))
305 return ptr_deref_may_alias_decl_p (ptr, base);
311 /* Dump alias information on FILE. */
314 dump_alias_info (FILE *file)
318 = lang_hooks.decl_printable_name (current_function_decl, 2);
319 referenced_var_iterator rvi;
322 fprintf (file, "\n\nAlias information for %s\n\n", funcname);
324 fprintf (file, "Aliased symbols\n\n");
326 FOR_EACH_REFERENCED_VAR (var, rvi)
328 if (may_be_aliased (var))
329 dump_variable (file, var);
332 fprintf (file, "\nCall clobber information\n");
334 fprintf (file, "\nESCAPED");
335 dump_points_to_solution (file, &cfun->gimple_df->escaped);
337 fprintf (file, "\n\nFlow-insensitive points-to information\n\n");
339 for (i = 1; i < num_ssa_names; i++)
341 tree ptr = ssa_name (i);
342 struct ptr_info_def *pi;
345 || SSA_NAME_IN_FREE_LIST (ptr))
348 pi = SSA_NAME_PTR_INFO (ptr);
350 dump_points_to_info_for (file, ptr);
353 fprintf (file, "\n");
357 /* Dump alias information on stderr. */
360 debug_alias_info (void)
362 dump_alias_info (stderr);
366 /* Return the alias information associated with pointer T. It creates a
367 new instance if none existed. */
369 struct ptr_info_def *
370 get_ptr_info (tree t)
372 struct ptr_info_def *pi;
374 gcc_assert (POINTER_TYPE_P (TREE_TYPE (t)));
376 pi = SSA_NAME_PTR_INFO (t);
379 pi = ggc_alloc_cleared_ptr_info_def ();
380 pt_solution_reset (&pi->pt);
381 SSA_NAME_PTR_INFO (t) = pi;
387 /* Dump the points-to set *PT into FILE. */
390 dump_points_to_solution (FILE *file, struct pt_solution *pt)
393 fprintf (file, ", points-to anything");
396 fprintf (file, ", points-to non-local");
399 fprintf (file, ", points-to escaped");
402 fprintf (file, ", points-to unit escaped");
405 fprintf (file, ", points-to NULL");
409 fprintf (file, ", points-to vars: ");
410 dump_decl_set (file, pt->vars);
411 if (pt->vars_contains_global)
412 fprintf (file, " (includes global vars)");
413 if (pt->vars_contains_restrict)
414 fprintf (file, " (includes restrict tags)");
418 /* Dump points-to information for SSA_NAME PTR into FILE. */
421 dump_points_to_info_for (FILE *file, tree ptr)
423 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr);
425 print_generic_expr (file, ptr, dump_flags);
428 dump_points_to_solution (file, &pi->pt);
430 fprintf (file, ", points-to anything");
432 fprintf (file, "\n");
436 /* Dump points-to information for VAR into stderr. */
439 debug_points_to_info_for (tree var)
441 dump_points_to_info_for (stderr, var);
445 /* Initializes the alias-oracle reference representation *R from REF. */
448 ao_ref_init (ao_ref *r, tree ref)
455 r->ref_alias_set = -1;
456 r->base_alias_set = -1;
459 /* Returns the base object of the memory reference *REF. */
462 ao_ref_base (ao_ref *ref)
466 ref->base = get_ref_base_and_extent (ref->ref, &ref->offset, &ref->size,
471 /* Returns the base object alias set of the memory reference *REF. */
473 static alias_set_type ATTRIBUTE_UNUSED
474 ao_ref_base_alias_set (ao_ref *ref)
476 if (ref->base_alias_set != -1)
477 return ref->base_alias_set;
478 ref->base_alias_set = get_alias_set (ao_ref_base (ref));
479 return ref->base_alias_set;
482 /* Returns the reference alias set of the memory reference *REF. */
485 ao_ref_alias_set (ao_ref *ref)
487 if (ref->ref_alias_set != -1)
488 return ref->ref_alias_set;
489 ref->ref_alias_set = get_alias_set (ref->ref);
490 return ref->ref_alias_set;
493 /* Init an alias-oracle reference representation from a gimple pointer
494 PTR and a gimple size SIZE in bytes. If SIZE is NULL_TREE the the
495 size is assumed to be unknown. The access is assumed to be only
496 to or after of the pointer target, not before it. */
499 ao_ref_init_from_ptr_and_size (ao_ref *ref, tree ptr, tree size)
501 HOST_WIDE_INT t1, t2;
502 ref->ref = NULL_TREE;
503 if (TREE_CODE (ptr) == ADDR_EXPR)
504 ref->base = get_ref_base_and_extent (TREE_OPERAND (ptr, 0),
505 &ref->offset, &t1, &t2);
508 ref->base = build1 (INDIRECT_REF, char_type_node, ptr);
512 && host_integerp (size, 0)
513 && TREE_INT_CST_LOW (size) * 8 / 8 == TREE_INT_CST_LOW (size))
514 ref->max_size = ref->size = TREE_INT_CST_LOW (size) * 8;
516 ref->max_size = ref->size = -1;
517 ref->ref_alias_set = 0;
518 ref->base_alias_set = 0;
521 /* Return 1 if TYPE1 and TYPE2 are to be considered equivalent for the
522 purpose of TBAA. Return 0 if they are distinct and -1 if we cannot
526 same_type_for_tbaa (tree type1, tree type2)
528 type1 = TYPE_MAIN_VARIANT (type1);
529 type2 = TYPE_MAIN_VARIANT (type2);
531 /* If we would have to do structural comparison bail out. */
532 if (TYPE_STRUCTURAL_EQUALITY_P (type1)
533 || TYPE_STRUCTURAL_EQUALITY_P (type2))
536 /* Compare the canonical types. */
537 if (TYPE_CANONICAL (type1) == TYPE_CANONICAL (type2))
540 /* ??? Array types are not properly unified in all cases as we have
541 spurious changes in the index types for example. Removing this
542 causes all sorts of problems with the Fortran frontend. */
543 if (TREE_CODE (type1) == ARRAY_TYPE
544 && TREE_CODE (type2) == ARRAY_TYPE)
547 /* ??? In Ada, an lvalue of an unconstrained type can be used to access an
548 object of one of its constrained subtypes, e.g. when a function with an
549 unconstrained parameter passed by reference is called on an object and
550 inlined. But, even in the case of a fixed size, type and subtypes are
551 not equivalent enough as to share the same TYPE_CANONICAL, since this
552 would mean that conversions between them are useless, whereas they are
553 not (e.g. type and subtypes can have different modes). So, in the end,
554 they are only guaranteed to have the same alias set. */
555 if (get_alias_set (type1) == get_alias_set (type2))
558 /* The types are known to be not equal. */
562 /* Determine if the two component references REF1 and REF2 which are
563 based on access types TYPE1 and TYPE2 and of which at least one is based
564 on an indirect reference may alias. REF2 is the only one that can
565 be a decl in which case REF2_IS_DECL is true.
566 REF1_ALIAS_SET, BASE1_ALIAS_SET, REF2_ALIAS_SET and BASE2_ALIAS_SET
567 are the respective alias sets. */
570 aliasing_component_refs_p (tree ref1, tree type1,
571 alias_set_type ref1_alias_set,
572 alias_set_type base1_alias_set,
573 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
574 tree ref2, tree type2,
575 alias_set_type ref2_alias_set,
576 alias_set_type base2_alias_set,
577 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
580 /* If one reference is a component references through pointers try to find a
581 common base and apply offset based disambiguation. This handles
583 struct A { int i; int j; } *q;
584 struct B { struct A a; int k; } *p;
585 disambiguating q->i and p->a.j. */
589 /* Now search for the type1 in the access path of ref2. This
590 would be a common base for doing offset based disambiguation on. */
592 while (handled_component_p (*refp)
593 && same_type_for_tbaa (TREE_TYPE (*refp), type1) == 0)
594 refp = &TREE_OPERAND (*refp, 0);
595 same_p = same_type_for_tbaa (TREE_TYPE (*refp), type1);
596 /* If we couldn't compare types we have to bail out. */
599 else if (same_p == 1)
601 HOST_WIDE_INT offadj, sztmp, msztmp;
602 get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp);
604 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
606 /* If we didn't find a common base, try the other way around. */
608 while (handled_component_p (*refp)
609 && same_type_for_tbaa (TREE_TYPE (*refp), type2) == 0)
610 refp = &TREE_OPERAND (*refp, 0);
611 same_p = same_type_for_tbaa (TREE_TYPE (*refp), type2);
612 /* If we couldn't compare types we have to bail out. */
615 else if (same_p == 1)
617 HOST_WIDE_INT offadj, sztmp, msztmp;
618 get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp);
620 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
623 /* If we have two type access paths B1.path1 and B2.path2 they may
624 only alias if either B1 is in B2.path2 or B2 is in B1.path1.
625 But we can still have a path that goes B1.path1...B2.path2 with
626 a part that we do not see. So we can only disambiguate now
627 if there is no B2 in the tail of path1 and no B1 on the
629 if (base1_alias_set == ref2_alias_set
630 || alias_set_subset_of (base1_alias_set, ref2_alias_set))
632 /* If this is ptr vs. decl then we know there is no ptr ... decl path. */
634 return (base2_alias_set == ref1_alias_set
635 || alias_set_subset_of (base2_alias_set, ref1_alias_set));
639 /* Return true if two memory references based on the variables BASE1
640 and BASE2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and
641 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. */
644 decl_refs_may_alias_p (tree base1,
645 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
647 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2)
649 gcc_assert (SSA_VAR_P (base1) && SSA_VAR_P (base2));
651 /* If both references are based on different variables, they cannot alias. */
655 /* If both references are based on the same variable, they cannot alias if
656 the accesses do not overlap. */
657 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
660 /* Return true if an indirect reference based on *PTR1 constrained
661 to [OFFSET1, OFFSET1 + MAX_SIZE1) may alias a variable based on BASE2
662 constrained to [OFFSET2, OFFSET2 + MAX_SIZE2). *PTR1 and BASE2 have
663 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
664 in which case they are computed on-demand. REF1 and REF2
665 if non-NULL are the complete memory reference trees. */
668 indirect_ref_may_alias_decl_p (tree ref1, tree ptr1,
669 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
670 alias_set_type ref1_alias_set,
671 alias_set_type base1_alias_set,
672 tree ref2, tree base2,
673 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
674 alias_set_type ref2_alias_set,
675 alias_set_type base2_alias_set)
677 /* If only one reference is based on a variable, they cannot alias if
678 the pointer access is beyond the extent of the variable access.
679 (the pointer base cannot validly point to an offset less than zero
681 They also cannot alias if the pointer may not point to the decl. */
683 && !ranges_overlap_p (offset1, max_size1, 0, offset2 + max_size2))
685 if (!ptr_deref_may_alias_decl_p (ptr1, base2))
688 /* Disambiguations that rely on strict aliasing rules follow. */
689 if (!flag_strict_aliasing)
692 /* If the alias set for a pointer access is zero all bets are off. */
693 if (base1_alias_set == -1)
694 base1_alias_set = get_deref_alias_set (ptr1);
695 if (base1_alias_set == 0)
697 if (base2_alias_set == -1)
698 base2_alias_set = get_alias_set (base2);
700 /* If both references are through the same type, they do not alias
701 if the accesses do not overlap. This does extra disambiguation
702 for mixed/pointer accesses but requires strict aliasing. */
703 if (same_type_for_tbaa (TREE_TYPE (TREE_TYPE (ptr1)),
704 TREE_TYPE (base2)) == 1)
705 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
707 /* The only way to access a variable is through a pointer dereference
708 of the same alias set or a subset of it. */
709 if (base1_alias_set != base2_alias_set
710 && !alias_set_subset_of (base1_alias_set, base2_alias_set))
713 /* Do access-path based disambiguation. */
715 && handled_component_p (ref1)
716 && handled_component_p (ref2))
717 return aliasing_component_refs_p (ref1, TREE_TYPE (TREE_TYPE (ptr1)),
718 ref1_alias_set, base1_alias_set,
720 ref2, TREE_TYPE (base2),
721 ref2_alias_set, base2_alias_set,
722 offset2, max_size2, true);
727 /* Return true if two indirect references based on *PTR1
728 and *PTR2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and
729 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. *PTR1 and *PTR2 have
730 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
731 in which case they are computed on-demand. REF1 and REF2
732 if non-NULL are the complete memory reference trees. */
735 indirect_refs_may_alias_p (tree ref1, tree ptr1,
736 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
737 alias_set_type ref1_alias_set,
738 alias_set_type base1_alias_set,
739 tree ref2, tree ptr2,
740 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
741 alias_set_type ref2_alias_set,
742 alias_set_type base2_alias_set)
744 /* If both bases are based on pointers they cannot alias if they may not
745 point to the same memory object or if they point to the same object
746 and the accesses do not overlap. */
747 if (operand_equal_p (ptr1, ptr2, 0))
748 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
749 if (!ptr_derefs_may_alias_p (ptr1, ptr2))
752 /* Disambiguations that rely on strict aliasing rules follow. */
753 if (!flag_strict_aliasing)
756 /* If the alias set for a pointer access is zero all bets are off. */
757 if (base1_alias_set == -1)
758 base1_alias_set = get_deref_alias_set (ptr1);
759 if (base1_alias_set == 0)
761 if (base2_alias_set == -1)
762 base2_alias_set = get_deref_alias_set (ptr2);
763 if (base2_alias_set == 0)
766 /* If both references are through the same type, they do not alias
767 if the accesses do not overlap. This does extra disambiguation
768 for mixed/pointer accesses but requires strict aliasing. */
769 if (same_type_for_tbaa (TREE_TYPE (TREE_TYPE (ptr1)),
770 TREE_TYPE (TREE_TYPE (ptr2))) == 1)
771 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
773 /* Do type-based disambiguation. */
774 if (base1_alias_set != base2_alias_set
775 && !alias_sets_conflict_p (base1_alias_set, base2_alias_set))
778 /* Do access-path based disambiguation. */
780 && handled_component_p (ref1)
781 && handled_component_p (ref2))
782 return aliasing_component_refs_p (ref1, TREE_TYPE (TREE_TYPE (ptr1)),
783 ref1_alias_set, base1_alias_set,
785 ref2, TREE_TYPE (TREE_TYPE (ptr2)),
786 ref2_alias_set, base2_alias_set,
787 offset2, max_size2, false);
792 /* Return true, if the two memory references REF1 and REF2 may alias. */
795 refs_may_alias_p_1 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
798 HOST_WIDE_INT offset1 = 0, offset2 = 0;
799 HOST_WIDE_INT max_size1 = -1, max_size2 = -1;
800 bool var1_p, var2_p, ind1_p, ind2_p;
803 gcc_checking_assert ((!ref1->ref
804 || TREE_CODE (ref1->ref) == SSA_NAME
805 || DECL_P (ref1->ref)
806 || handled_component_p (ref1->ref)
807 || INDIRECT_REF_P (ref1->ref)
808 || TREE_CODE (ref1->ref) == TARGET_MEM_REF)
810 || TREE_CODE (ref2->ref) == SSA_NAME
811 || DECL_P (ref2->ref)
812 || handled_component_p (ref2->ref)
813 || INDIRECT_REF_P (ref2->ref)
814 || TREE_CODE (ref2->ref) == TARGET_MEM_REF));
816 /* Decompose the references into their base objects and the access. */
817 base1 = ao_ref_base (ref1);
818 offset1 = ref1->offset;
819 max_size1 = ref1->max_size;
820 base2 = ao_ref_base (ref2);
821 offset2 = ref2->offset;
822 max_size2 = ref2->max_size;
824 /* We can end up with registers or constants as bases for example from
825 *D.1663_44 = VIEW_CONVERT_EXPR<struct DB_LSN>(__tmp$B0F64_59);
826 which is seen as a struct copy. */
827 if (TREE_CODE (base1) == SSA_NAME
828 || TREE_CODE (base2) == SSA_NAME
829 || TREE_CODE (base1) == CONST_DECL
830 || TREE_CODE (base2) == CONST_DECL
831 || is_gimple_min_invariant (base1)
832 || is_gimple_min_invariant (base2))
835 /* We can end up refering to code via function and label decls.
836 As we likely do not properly track code aliases conservatively
838 if (TREE_CODE (base1) == FUNCTION_DECL
839 || TREE_CODE (base2) == FUNCTION_DECL
840 || TREE_CODE (base1) == LABEL_DECL
841 || TREE_CODE (base2) == LABEL_DECL)
844 /* Defer to simple offset based disambiguation if we have
845 references based on two decls. Do this before defering to
846 TBAA to handle must-alias cases in conformance with the
847 GCC extension of allowing type-punning through unions. */
848 var1_p = SSA_VAR_P (base1);
849 var2_p = SSA_VAR_P (base2);
850 if (var1_p && var2_p)
851 return decl_refs_may_alias_p (base1, offset1, max_size1,
852 base2, offset2, max_size2);
854 ind1_p = INDIRECT_REF_P (base1);
855 ind2_p = INDIRECT_REF_P (base2);
856 /* Canonicalize the pointer-vs-decl case. */
857 if (ind1_p && var2_p)
862 tmp1 = offset1; offset1 = offset2; offset2 = tmp1;
863 tmp1 = max_size1; max_size1 = max_size2; max_size2 = tmp1;
864 tmp2 = base1; base1 = base2; base2 = tmp2;
865 tmp3 = ref1; ref1 = ref2; ref2 = tmp3;
872 /* If we are about to disambiguate pointer-vs-decl try harder to
873 see must-aliases and give leeway to some invalid cases.
874 This covers a pretty minimal set of cases only and does not
875 when called from the RTL oracle. It handles cases like
880 and also fixes gfortran.dg/lto/pr40725. */
883 && gimple_in_ssa_p (cfun)
884 && TREE_CODE (TREE_OPERAND (base2, 0)) == SSA_NAME)
886 gimple def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (base2, 0));
887 while (is_gimple_assign (def_stmt)
888 && (gimple_assign_rhs_code (def_stmt) == SSA_NAME
889 || CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))))
891 tree rhs = gimple_assign_rhs1 (def_stmt);
892 HOST_WIDE_INT offset, size, max_size;
894 /* Look through SSA name copies and pointer conversions. */
895 if (TREE_CODE (rhs) == SSA_NAME
896 && POINTER_TYPE_P (TREE_TYPE (rhs)))
898 def_stmt = SSA_NAME_DEF_STMT (rhs);
901 if (TREE_CODE (rhs) != ADDR_EXPR)
904 /* If the pointer is defined as an address based on a decl
905 use plain offset disambiguation and ignore TBAA. */
906 rhs = TREE_OPERAND (rhs, 0);
907 rhs = get_ref_base_and_extent (rhs, &offset, &size, &max_size);
915 return decl_refs_may_alias_p (base1, offset1, max_size1,
916 base2, offset2, max_size2);
919 /* Do not continue looking through &p->x to limit time
925 /* First defer to TBAA if possible. */
927 && flag_strict_aliasing
928 && !alias_sets_conflict_p (ao_ref_alias_set (ref1),
929 ao_ref_alias_set (ref2)))
932 /* If one reference is a TARGET_MEM_REF weird things are allowed. Still
933 TBAA disambiguation based on the access type is possible, so bail
934 out only after that check. */
935 if ((ref1->ref && TREE_CODE (ref1->ref) == TARGET_MEM_REF)
936 || (ref2->ref && TREE_CODE (ref2->ref) == TARGET_MEM_REF))
939 /* Dispatch to the pointer-vs-decl or pointer-vs-pointer disambiguators. */
940 set = tbaa_p ? -1 : 0;
941 if (var1_p && ind2_p)
942 return indirect_ref_may_alias_decl_p (ref2->ref, TREE_OPERAND (base2, 0),
944 ao_ref_alias_set (ref2), set,
947 ao_ref_alias_set (ref1), set);
948 else if (ind1_p && ind2_p)
949 return indirect_refs_may_alias_p (ref1->ref, TREE_OPERAND (base1, 0),
951 ao_ref_alias_set (ref1), set,
952 ref2->ref, TREE_OPERAND (base2, 0),
954 ao_ref_alias_set (ref2), set);
960 refs_may_alias_p (tree ref1, tree ref2)
964 ao_ref_init (&r1, ref1);
965 ao_ref_init (&r2, ref2);
966 res = refs_may_alias_p_1 (&r1, &r2, true);
968 ++alias_stats.refs_may_alias_p_may_alias;
970 ++alias_stats.refs_may_alias_p_no_alias;
974 /* Returns true if there is a anti-dependence for the STORE that
975 executes after the LOAD. */
978 refs_anti_dependent_p (tree load, tree store)
981 ao_ref_init (&r1, load);
982 ao_ref_init (&r2, store);
983 return refs_may_alias_p_1 (&r1, &r2, false);
986 /* Returns true if there is a output dependence for the stores
987 STORE1 and STORE2. */
990 refs_output_dependent_p (tree store1, tree store2)
993 ao_ref_init (&r1, store1);
994 ao_ref_init (&r2, store2);
995 return refs_may_alias_p_1 (&r1, &r2, false);
998 /* If the call CALL may use the memory reference REF return true,
999 otherwise return false. */
1002 ref_maybe_used_by_call_p_1 (gimple call, ao_ref *ref)
1006 int flags = gimple_call_flags (call);
1008 /* Const functions without a static chain do not implicitly use memory. */
1009 if (!gimple_call_chain (call)
1010 && (flags & (ECF_CONST|ECF_NOVOPS)))
1013 base = ao_ref_base (ref);
1017 /* If the reference is based on a decl that is not aliased the call
1018 cannot possibly use it. */
1020 && !may_be_aliased (base)
1021 /* But local statics can be used through recursion. */
1022 && !is_global_var (base))
1025 callee = gimple_call_fndecl (call);
1027 /* Handle those builtin functions explicitly that do not act as
1028 escape points. See tree-ssa-structalias.c:find_func_aliases
1029 for the list of builtins we might need to handle here. */
1030 if (callee != NULL_TREE
1031 && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
1032 switch (DECL_FUNCTION_CODE (callee))
1034 /* All the following functions clobber memory pointed to by
1035 their first argument. */
1036 case BUILT_IN_STRCPY:
1037 case BUILT_IN_STRNCPY:
1038 case BUILT_IN_MEMCPY:
1039 case BUILT_IN_MEMMOVE:
1040 case BUILT_IN_MEMPCPY:
1041 case BUILT_IN_STPCPY:
1042 case BUILT_IN_STPNCPY:
1043 case BUILT_IN_STRCAT:
1044 case BUILT_IN_STRNCAT:
1047 tree size = NULL_TREE;
1048 if (gimple_call_num_args (call) == 3)
1049 size = gimple_call_arg (call, 2);
1050 ao_ref_init_from_ptr_and_size (&dref,
1051 gimple_call_arg (call, 1),
1053 return refs_may_alias_p_1 (&dref, ref, false);
1055 case BUILT_IN_BCOPY:
1058 tree size = gimple_call_arg (call, 2);
1059 ao_ref_init_from_ptr_and_size (&dref,
1060 gimple_call_arg (call, 0),
1062 return refs_may_alias_p_1 (&dref, ref, false);
1064 /* The following builtins do not read from memory. */
1066 case BUILT_IN_MALLOC:
1067 case BUILT_IN_CALLOC:
1068 case BUILT_IN_MEMSET:
1069 case BUILT_IN_FREXP:
1070 case BUILT_IN_FREXPF:
1071 case BUILT_IN_FREXPL:
1072 case BUILT_IN_GAMMA_R:
1073 case BUILT_IN_GAMMAF_R:
1074 case BUILT_IN_GAMMAL_R:
1075 case BUILT_IN_LGAMMA_R:
1076 case BUILT_IN_LGAMMAF_R:
1077 case BUILT_IN_LGAMMAL_R:
1079 case BUILT_IN_MODFF:
1080 case BUILT_IN_MODFL:
1081 case BUILT_IN_REMQUO:
1082 case BUILT_IN_REMQUOF:
1083 case BUILT_IN_REMQUOL:
1084 case BUILT_IN_SINCOS:
1085 case BUILT_IN_SINCOSF:
1086 case BUILT_IN_SINCOSL:
1090 /* Fallthru to general call handling. */;
1093 /* Check if base is a global static variable that is not read
1095 if (TREE_CODE (base) == VAR_DECL
1096 && TREE_STATIC (base))
1100 if (callee != NULL_TREE
1102 = ipa_reference_get_not_read_global (cgraph_node (callee)))
1103 && bitmap_bit_p (not_read, DECL_UID (base)))
1107 /* Check if the base variable is call-used. */
1110 if (pt_solution_includes (gimple_call_use_set (call), base))
1113 else if (INDIRECT_REF_P (base)
1114 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
1116 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0));
1120 if (pt_solutions_intersect (gimple_call_use_set (call), &pi->pt))
1126 /* Inspect call arguments for passed-by-value aliases. */
1128 for (i = 0; i < gimple_call_num_args (call); ++i)
1130 tree op = gimple_call_arg (call, i);
1131 int flags = gimple_call_arg_flags (call, i);
1133 if (flags & EAF_UNUSED)
1136 if (TREE_CODE (op) == WITH_SIZE_EXPR)
1137 op = TREE_OPERAND (op, 0);
1139 if (TREE_CODE (op) != SSA_NAME
1140 && !is_gimple_min_invariant (op))
1143 ao_ref_init (&r, op);
1144 if (refs_may_alias_p_1 (&r, ref, true))
1153 ref_maybe_used_by_call_p (gimple call, tree ref)
1157 ao_ref_init (&r, ref);
1158 res = ref_maybe_used_by_call_p_1 (call, &r);
1160 ++alias_stats.ref_maybe_used_by_call_p_may_alias;
1162 ++alias_stats.ref_maybe_used_by_call_p_no_alias;
1167 /* If the statement STMT may use the memory reference REF return
1168 true, otherwise return false. */
1171 ref_maybe_used_by_stmt_p (gimple stmt, tree ref)
1173 if (is_gimple_assign (stmt))
1177 /* All memory assign statements are single. */
1178 if (!gimple_assign_single_p (stmt))
1181 rhs = gimple_assign_rhs1 (stmt);
1182 if (is_gimple_reg (rhs)
1183 || is_gimple_min_invariant (rhs)
1184 || gimple_assign_rhs_code (stmt) == CONSTRUCTOR)
1187 return refs_may_alias_p (rhs, ref);
1189 else if (is_gimple_call (stmt))
1190 return ref_maybe_used_by_call_p (stmt, ref);
1195 /* If the call in statement CALL may clobber the memory reference REF
1196 return true, otherwise return false. */
1199 call_may_clobber_ref_p_1 (gimple call, ao_ref *ref)
1204 /* If the call is pure or const it cannot clobber anything. */
1205 if (gimple_call_flags (call)
1206 & (ECF_PURE|ECF_CONST|ECF_LOOPING_CONST_OR_PURE|ECF_NOVOPS))
1209 base = ao_ref_base (ref);
1213 if (TREE_CODE (base) == SSA_NAME
1214 || CONSTANT_CLASS_P (base))
1217 /* If the reference is based on a decl that is not aliased the call
1218 cannot possibly clobber it. */
1220 && !may_be_aliased (base)
1221 /* But local non-readonly statics can be modified through recursion
1222 or the call may implement a threading barrier which we must
1223 treat as may-def. */
1224 && (TREE_READONLY (base)
1225 || !is_global_var (base)))
1228 callee = gimple_call_fndecl (call);
1230 /* Handle those builtin functions explicitly that do not act as
1231 escape points. See tree-ssa-structalias.c:find_func_aliases
1232 for the list of builtins we might need to handle here. */
1233 if (callee != NULL_TREE
1234 && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
1235 switch (DECL_FUNCTION_CODE (callee))
1237 /* All the following functions clobber memory pointed to by
1238 their first argument. */
1239 case BUILT_IN_STRCPY:
1240 case BUILT_IN_STRNCPY:
1241 case BUILT_IN_MEMCPY:
1242 case BUILT_IN_MEMMOVE:
1243 case BUILT_IN_MEMPCPY:
1244 case BUILT_IN_STPCPY:
1245 case BUILT_IN_STPNCPY:
1246 case BUILT_IN_STRCAT:
1247 case BUILT_IN_STRNCAT:
1248 case BUILT_IN_MEMSET:
1251 tree size = NULL_TREE;
1252 if (gimple_call_num_args (call) == 3)
1253 size = gimple_call_arg (call, 2);
1254 ao_ref_init_from_ptr_and_size (&dref,
1255 gimple_call_arg (call, 0),
1257 return refs_may_alias_p_1 (&dref, ref, false);
1259 case BUILT_IN_BCOPY:
1262 tree size = gimple_call_arg (call, 2);
1263 ao_ref_init_from_ptr_and_size (&dref,
1264 gimple_call_arg (call, 1),
1266 return refs_may_alias_p_1 (&dref, ref, false);
1268 /* Allocating memory does not have any side-effects apart from
1269 being the definition point for the pointer. */
1270 case BUILT_IN_MALLOC:
1271 case BUILT_IN_CALLOC:
1272 /* Unix98 specifies that errno is set on allocation failure.
1273 Until we properly can track the errno location assume it
1274 is not a local decl but external or anonymous storage in
1275 a different translation unit. Also assume it is of
1276 type int as required by the standard. */
1278 && TREE_TYPE (base) == integer_type_node)
1280 struct ptr_info_def *pi;
1282 && !TREE_STATIC (base))
1284 else if (INDIRECT_REF_P (base)
1285 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME
1286 && (pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0))))
1287 return pi->pt.anything || pi->pt.nonlocal;
1290 /* Freeing memory kills the pointed-to memory. More importantly
1291 the call has to serve as a barrier for moving loads and stores
1295 tree ptr = gimple_call_arg (call, 0);
1296 return ptr_deref_may_alias_ref_p_1 (ptr, ref);
1298 case BUILT_IN_GAMMA_R:
1299 case BUILT_IN_GAMMAF_R:
1300 case BUILT_IN_GAMMAL_R:
1301 case BUILT_IN_LGAMMA_R:
1302 case BUILT_IN_LGAMMAF_R:
1303 case BUILT_IN_LGAMMAL_R:
1305 tree out = gimple_call_arg (call, 1);
1306 if (ptr_deref_may_alias_ref_p_1 (out, ref))
1308 if (flag_errno_math)
1312 case BUILT_IN_FREXP:
1313 case BUILT_IN_FREXPF:
1314 case BUILT_IN_FREXPL:
1316 case BUILT_IN_MODFF:
1317 case BUILT_IN_MODFL:
1319 tree out = gimple_call_arg (call, 1);
1320 return ptr_deref_may_alias_ref_p_1 (out, ref);
1322 case BUILT_IN_REMQUO:
1323 case BUILT_IN_REMQUOF:
1324 case BUILT_IN_REMQUOL:
1326 tree out = gimple_call_arg (call, 2);
1327 if (ptr_deref_may_alias_ref_p_1 (out, ref))
1329 if (flag_errno_math)
1333 case BUILT_IN_SINCOS:
1334 case BUILT_IN_SINCOSF:
1335 case BUILT_IN_SINCOSL:
1337 tree sin = gimple_call_arg (call, 1);
1338 tree cos = gimple_call_arg (call, 2);
1339 return (ptr_deref_may_alias_ref_p_1 (sin, ref)
1340 || ptr_deref_may_alias_ref_p_1 (cos, ref));
1343 /* Fallthru to general call handling. */;
1346 /* Check if base is a global static variable that is not written
1348 if (callee != NULL_TREE
1349 && TREE_CODE (base) == VAR_DECL
1350 && TREE_STATIC (base))
1355 = ipa_reference_get_not_written_global (cgraph_node (callee)))
1356 && bitmap_bit_p (not_written, DECL_UID (base)))
1360 /* Check if the base variable is call-clobbered. */
1362 return pt_solution_includes (gimple_call_clobber_set (call), base);
1363 else if (INDIRECT_REF_P (base)
1364 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
1366 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0));
1370 return pt_solutions_intersect (gimple_call_clobber_set (call), &pi->pt);
1376 /* If the call in statement CALL may clobber the memory reference REF
1377 return true, otherwise return false. */
1380 call_may_clobber_ref_p (gimple call, tree ref)
1384 ao_ref_init (&r, ref);
1385 res = call_may_clobber_ref_p_1 (call, &r);
1387 ++alias_stats.call_may_clobber_ref_p_may_alias;
1389 ++alias_stats.call_may_clobber_ref_p_no_alias;
1394 /* If the statement STMT may clobber the memory reference REF return true,
1395 otherwise return false. */
1398 stmt_may_clobber_ref_p_1 (gimple stmt, ao_ref *ref)
1400 if (is_gimple_call (stmt))
1402 tree lhs = gimple_call_lhs (stmt);
1404 && !is_gimple_reg (lhs))
1407 ao_ref_init (&r, lhs);
1408 if (refs_may_alias_p_1 (ref, &r, true))
1412 return call_may_clobber_ref_p_1 (stmt, ref);
1414 else if (gimple_assign_single_p (stmt))
1416 tree lhs = gimple_assign_lhs (stmt);
1417 if (!is_gimple_reg (lhs))
1420 ao_ref_init (&r, gimple_assign_lhs (stmt));
1421 return refs_may_alias_p_1 (ref, &r, true);
1424 else if (gimple_code (stmt) == GIMPLE_ASM)
1431 stmt_may_clobber_ref_p (gimple stmt, tree ref)
1434 ao_ref_init (&r, ref);
1435 return stmt_may_clobber_ref_p_1 (stmt, &r);
1439 /* Walk the virtual use-def chain of VUSE until hitting the virtual operand
1440 TARGET or a statement clobbering the memory reference REF in which
1441 case false is returned. The walk starts with VUSE, one argument of PHI. */
1444 maybe_skip_until (gimple phi, tree target, ao_ref *ref,
1445 tree vuse, bitmap *visited)
1448 *visited = BITMAP_ALLOC (NULL);
1450 bitmap_set_bit (*visited, SSA_NAME_VERSION (PHI_RESULT (phi)));
1452 /* Walk until we hit the target. */
1453 while (vuse != target)
1455 gimple def_stmt = SSA_NAME_DEF_STMT (vuse);
1456 /* Recurse for PHI nodes. */
1457 if (gimple_code (def_stmt) == GIMPLE_PHI)
1459 /* An already visited PHI node ends the walk successfully. */
1460 if (bitmap_bit_p (*visited, SSA_NAME_VERSION (PHI_RESULT (def_stmt))))
1462 vuse = get_continuation_for_phi (def_stmt, ref, visited);
1467 /* A clobbering statement or the end of the IL ends it failing. */
1468 else if (gimple_nop_p (def_stmt)
1469 || stmt_may_clobber_ref_p_1 (def_stmt, ref))
1471 vuse = gimple_vuse (def_stmt);
1476 /* Starting from a PHI node for the virtual operand of the memory reference
1477 REF find a continuation virtual operand that allows to continue walking
1478 statements dominating PHI skipping only statements that cannot possibly
1479 clobber REF. Returns NULL_TREE if no suitable virtual operand can
1483 get_continuation_for_phi (gimple phi, ao_ref *ref, bitmap *visited)
1485 unsigned nargs = gimple_phi_num_args (phi);
1487 /* Through a single-argument PHI we can simply look through. */
1489 return PHI_ARG_DEF (phi, 0);
1491 /* For two arguments try to skip non-aliasing code until we hit
1492 the phi argument definition that dominates the other one. */
1495 tree arg0 = PHI_ARG_DEF (phi, 0);
1496 tree arg1 = PHI_ARG_DEF (phi, 1);
1497 gimple def0 = SSA_NAME_DEF_STMT (arg0);
1498 gimple def1 = SSA_NAME_DEF_STMT (arg1);
1503 else if (gimple_nop_p (def0)
1504 || (!gimple_nop_p (def1)
1505 && dominated_by_p (CDI_DOMINATORS,
1506 gimple_bb (def1), gimple_bb (def0))))
1508 if (maybe_skip_until (phi, arg0, ref, arg1, visited))
1511 else if (gimple_nop_p (def1)
1512 || dominated_by_p (CDI_DOMINATORS,
1513 gimple_bb (def0), gimple_bb (def1)))
1515 if (maybe_skip_until (phi, arg1, ref, arg0, visited))
1518 /* Special case of a diamond:
1520 goto (cond) ? L1 : L2
1521 L1: store1 = ... #MEM_2 = vuse(MEM_1)
1523 L2: store2 = ... #MEM_3 = vuse(MEM_1)
1524 L3: MEM_4 = PHI<MEM_2, MEM_3>
1525 We were called with the PHI at L3, MEM_2 and MEM_3 don't
1526 dominate each other, but still we can easily skip this PHI node
1527 if we recognize that the vuse MEM operand is the same for both,
1528 and that we can skip both statements (they don't clobber us).
1529 This is still linear. Don't use maybe_skip_until, that might
1530 potentially be slow. */
1531 else if ((common_vuse = gimple_vuse (def0))
1532 && common_vuse == gimple_vuse (def1))
1534 if (!stmt_may_clobber_ref_p_1 (def0, ref)
1535 && !stmt_may_clobber_ref_p_1 (def1, ref))
1543 /* Based on the memory reference REF and its virtual use VUSE call
1544 WALKER for each virtual use that is equivalent to VUSE, including VUSE
1545 itself. That is, for each virtual use for which its defining statement
1546 does not clobber REF.
1548 WALKER is called with REF, the current virtual use and DATA. If
1549 WALKER returns non-NULL the walk stops and its result is returned.
1550 At the end of a non-successful walk NULL is returned.
1552 TRANSLATE if non-NULL is called with a pointer to REF, the virtual
1553 use which definition is a statement that may clobber REF and DATA.
1554 If TRANSLATE returns (void *)-1 the walk stops and NULL is returned.
1555 If TRANSLATE returns non-NULL the walk stops and its result is returned.
1556 If TRANSLATE returns NULL the walk continues and TRANSLATE is supposed
1557 to adjust REF and *DATA to make that valid.
1559 TODO: Cache the vector of equivalent vuses per ref, vuse pair. */
1562 walk_non_aliased_vuses (ao_ref *ref, tree vuse,
1563 void *(*walker)(ao_ref *, tree, void *),
1564 void *(*translate)(ao_ref *, tree, void *), void *data)
1566 bitmap visited = NULL;
1569 timevar_push (TV_ALIAS_STMT_WALK);
1575 /* ??? Do we want to account this to TV_ALIAS_STMT_WALK? */
1576 res = (*walker) (ref, vuse, data);
1580 def_stmt = SSA_NAME_DEF_STMT (vuse);
1581 if (gimple_nop_p (def_stmt))
1583 else if (gimple_code (def_stmt) == GIMPLE_PHI)
1584 vuse = get_continuation_for_phi (def_stmt, ref, &visited);
1587 if (stmt_may_clobber_ref_p_1 (def_stmt, ref))
1591 res = (*translate) (ref, vuse, data);
1592 /* Failed lookup and translation. */
1593 if (res == (void *)-1)
1598 /* Lookup succeeded. */
1599 else if (res != NULL)
1601 /* Translation succeeded, continue walking. */
1603 vuse = gimple_vuse (def_stmt);
1609 BITMAP_FREE (visited);
1611 timevar_pop (TV_ALIAS_STMT_WALK);
1617 /* Based on the memory reference REF call WALKER for each vdef which
1618 defining statement may clobber REF, starting with VDEF. If REF
1619 is NULL_TREE, each defining statement is visited.
1621 WALKER is called with REF, the current vdef and DATA. If WALKER
1622 returns true the walk is stopped, otherwise it continues.
1624 At PHI nodes walk_aliased_vdefs forks into one walk for reach
1625 PHI argument (but only one walk continues on merge points), the
1626 return value is true if any of the walks was successful.
1628 The function returns the number of statements walked. */
1631 walk_aliased_vdefs_1 (ao_ref *ref, tree vdef,
1632 bool (*walker)(ao_ref *, tree, void *), void *data,
1633 bitmap *visited, unsigned int cnt)
1637 gimple def_stmt = SSA_NAME_DEF_STMT (vdef);
1640 && !bitmap_set_bit (*visited, SSA_NAME_VERSION (vdef)))
1643 if (gimple_nop_p (def_stmt))
1645 else if (gimple_code (def_stmt) == GIMPLE_PHI)
1649 *visited = BITMAP_ALLOC (NULL);
1650 for (i = 0; i < gimple_phi_num_args (def_stmt); ++i)
1651 cnt += walk_aliased_vdefs_1 (ref, gimple_phi_arg_def (def_stmt, i),
1652 walker, data, visited, 0);
1656 /* ??? Do we want to account this to TV_ALIAS_STMT_WALK? */
1659 || stmt_may_clobber_ref_p_1 (def_stmt, ref))
1660 && (*walker) (ref, vdef, data))
1663 vdef = gimple_vuse (def_stmt);
1669 walk_aliased_vdefs (ao_ref *ref, tree vdef,
1670 bool (*walker)(ao_ref *, tree, void *), void *data,
1673 bitmap local_visited = NULL;
1676 timevar_push (TV_ALIAS_STMT_WALK);
1678 ret = walk_aliased_vdefs_1 (ref, vdef, walker, data,
1679 visited ? visited : &local_visited, 0);
1681 BITMAP_FREE (local_visited);
1683 timevar_pop (TV_ALIAS_STMT_WALK);