1 /* Alias analysis for trees.
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
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"
29 #include "hard-reg-set.h"
30 #include "basic-block.h"
34 #include "langhooks.h"
37 #include "diagnostic.h"
38 #include "tree-dump.h"
40 #include "tree-flow.h"
41 #include "tree-inline.h"
42 #include "tree-pass.h"
45 #include "ipa-type-escape.h"
49 #include "pointer-set.h"
50 #include "alloc-pool.h"
51 #include "tree-ssa-alias.h"
53 /* Broad overview of how alias analysis on gimple works:
55 Statements clobbering or using memory are linked through the
56 virtual operand factored use-def chain. The virtual operand
57 is unique per function, its symbol is accessible via gimple_vop (cfun).
58 Virtual operands are used for efficiently walking memory statements
59 in the gimple IL and are useful for things like value-numbering as
60 a generation count for memory references.
62 SSA_NAME pointers may have associated points-to information
63 accessible via the SSA_NAME_PTR_INFO macro. Flow-insensitive
64 points-to information is (re-)computed by the TODO_rebuild_alias
65 pass manager todo. Points-to information is also used for more
66 precise tracking of call-clobbered and call-used variables and
67 related disambiguations.
69 This file contains functions for disambiguating memory references,
70 the so called alias-oracle and tools for walking of the gimple IL.
72 The main alias-oracle entry-points are
74 bool stmt_may_clobber_ref_p (gimple, tree)
76 This function queries if a statement may invalidate (parts of)
77 the memory designated by the reference tree argument.
79 bool ref_maybe_used_by_stmt_p (gimple, tree)
81 This function queries if a statement may need (parts of) the
82 memory designated by the reference tree argument.
84 There are variants of these functions that only handle the call
85 part of a statement, call_may_clobber_ref_p and ref_maybe_used_by_call_p.
86 Note that these do not disambiguate against a possible call lhs.
88 bool refs_may_alias_p (tree, tree)
90 This function tries to disambiguate two reference trees.
92 bool ptr_deref_may_alias_global_p (tree)
94 This function queries if dereferencing a pointer variable may
97 More low-level disambiguators are available and documented in
98 this file. Low-level disambiguators dealing with points-to
99 information are in tree-ssa-structalias.c. */
102 /* Query statistics for the different low-level disambiguators.
103 A high-level query may trigger multiple of them. */
106 unsigned HOST_WIDE_INT refs_may_alias_p_may_alias
;
107 unsigned HOST_WIDE_INT refs_may_alias_p_no_alias
;
108 unsigned HOST_WIDE_INT ref_maybe_used_by_call_p_may_alias
;
109 unsigned HOST_WIDE_INT ref_maybe_used_by_call_p_no_alias
;
110 unsigned HOST_WIDE_INT call_may_clobber_ref_p_may_alias
;
111 unsigned HOST_WIDE_INT call_may_clobber_ref_p_no_alias
;
115 dump_alias_stats (FILE *s
)
117 fprintf (s
, "\nAlias oracle query stats:\n");
118 fprintf (s
, " refs_may_alias_p: "
119 HOST_WIDE_INT_PRINT_DEC
" disambiguations, "
120 HOST_WIDE_INT_PRINT_DEC
" queries\n",
121 alias_stats
.refs_may_alias_p_no_alias
,
122 alias_stats
.refs_may_alias_p_no_alias
123 + alias_stats
.refs_may_alias_p_may_alias
);
124 fprintf (s
, " ref_maybe_used_by_call_p: "
125 HOST_WIDE_INT_PRINT_DEC
" disambiguations, "
126 HOST_WIDE_INT_PRINT_DEC
" queries\n",
127 alias_stats
.ref_maybe_used_by_call_p_no_alias
,
128 alias_stats
.refs_may_alias_p_no_alias
129 + alias_stats
.ref_maybe_used_by_call_p_may_alias
);
130 fprintf (s
, " call_may_clobber_ref_p: "
131 HOST_WIDE_INT_PRINT_DEC
" disambiguations, "
132 HOST_WIDE_INT_PRINT_DEC
" queries\n",
133 alias_stats
.call_may_clobber_ref_p_no_alias
,
134 alias_stats
.call_may_clobber_ref_p_no_alias
135 + alias_stats
.call_may_clobber_ref_p_may_alias
);
139 /* Return true, if dereferencing PTR may alias with a global variable. */
142 ptr_deref_may_alias_global_p (tree ptr
)
144 struct ptr_info_def
*pi
;
146 /* If we end up with a pointer constant here that may point
148 if (TREE_CODE (ptr
) != SSA_NAME
)
151 pi
= SSA_NAME_PTR_INFO (ptr
);
153 /* If we do not have points-to information for this variable,
158 /* ??? This does not use TBAA to prune globals ptr may not access. */
159 return pt_solution_includes_global (&pi
->pt
);
162 /* Return true if dereferencing PTR may alias DECL.
163 The caller is responsible for applying TBAA to see if PTR
164 may access DECL at all. */
167 ptr_deref_may_alias_decl_p (tree ptr
, tree decl
)
169 struct ptr_info_def
*pi
;
171 gcc_assert ((TREE_CODE (ptr
) == SSA_NAME
172 || TREE_CODE (ptr
) == ADDR_EXPR
173 || TREE_CODE (ptr
) == INTEGER_CST
)
174 && (TREE_CODE (decl
) == VAR_DECL
175 || TREE_CODE (decl
) == PARM_DECL
176 || TREE_CODE (decl
) == RESULT_DECL
));
178 /* Non-aliased variables can not be pointed to. */
179 if (!may_be_aliased (decl
))
182 /* ADDR_EXPR pointers either just offset another pointer or directly
183 specify the pointed-to set. */
184 if (TREE_CODE (ptr
) == ADDR_EXPR
)
186 tree base
= get_base_address (TREE_OPERAND (ptr
, 0));
188 && INDIRECT_REF_P (base
))
189 ptr
= TREE_OPERAND (base
, 0);
192 return operand_equal_p (base
, decl
, 0);
194 && CONSTANT_CLASS_P (base
))
200 /* We can end up with dereferencing constant pointers.
201 Just bail out in this case. */
202 if (TREE_CODE (ptr
) == INTEGER_CST
)
205 /* If we do not have useful points-to information for this pointer
206 we cannot disambiguate anything else. */
207 pi
= SSA_NAME_PTR_INFO (ptr
);
211 /* If the decl can be used as a restrict tag and we have a restrict
212 pointer and that pointers points-to set doesn't contain this decl
213 then they can't alias. */
214 if (DECL_RESTRICTED_P (decl
)
215 && TYPE_RESTRICT (TREE_TYPE (ptr
))
216 && pi
->pt
.vars_contains_restrict
)
217 return bitmap_bit_p (pi
->pt
.vars
, DECL_UID (decl
));
219 return pt_solution_includes (&pi
->pt
, decl
);
222 /* Return true if dereferenced PTR1 and PTR2 may alias.
223 The caller is responsible for applying TBAA to see if accesses
224 through PTR1 and PTR2 may conflict at all. */
227 ptr_derefs_may_alias_p (tree ptr1
, tree ptr2
)
229 struct ptr_info_def
*pi1
, *pi2
;
231 gcc_assert ((TREE_CODE (ptr1
) == SSA_NAME
232 || TREE_CODE (ptr1
) == ADDR_EXPR
233 || TREE_CODE (ptr1
) == INTEGER_CST
)
234 && (TREE_CODE (ptr2
) == SSA_NAME
235 || TREE_CODE (ptr2
) == ADDR_EXPR
236 || TREE_CODE (ptr2
) == INTEGER_CST
));
238 /* ADDR_EXPR pointers either just offset another pointer or directly
239 specify the pointed-to set. */
240 if (TREE_CODE (ptr1
) == ADDR_EXPR
)
242 tree base
= get_base_address (TREE_OPERAND (ptr1
, 0));
244 && INDIRECT_REF_P (base
))
245 ptr1
= TREE_OPERAND (base
, 0);
248 return ptr_deref_may_alias_decl_p (ptr2
, base
);
252 if (TREE_CODE (ptr2
) == ADDR_EXPR
)
254 tree base
= get_base_address (TREE_OPERAND (ptr2
, 0));
256 && INDIRECT_REF_P (base
))
257 ptr2
= TREE_OPERAND (base
, 0);
260 return ptr_deref_may_alias_decl_p (ptr1
, base
);
265 /* We can end up with dereferencing constant pointers.
266 Just bail out in this case. */
267 if (TREE_CODE (ptr1
) == INTEGER_CST
268 || TREE_CODE (ptr2
) == INTEGER_CST
)
271 /* We may end up with two empty points-to solutions for two same pointers.
272 In this case we still want to say both pointers alias, so shortcut
277 /* If we do not have useful points-to information for either pointer
278 we cannot disambiguate anything else. */
279 pi1
= SSA_NAME_PTR_INFO (ptr1
);
280 pi2
= SSA_NAME_PTR_INFO (ptr2
);
284 /* If both pointers are restrict-qualified try to disambiguate
285 with restrict information. */
286 if (TYPE_RESTRICT (TREE_TYPE (ptr1
))
287 && TYPE_RESTRICT (TREE_TYPE (ptr2
))
288 && !pt_solutions_same_restrict_base (&pi1
->pt
, &pi2
->pt
))
291 /* ??? This does not use TBAA to prune decls from the intersection
292 that not both pointers may access. */
293 return pt_solutions_intersect (&pi1
->pt
, &pi2
->pt
);
296 /* Return true if dereferencing PTR may alias *REF.
297 The caller is responsible for applying TBAA to see if PTR
298 may access *REF at all. */
301 ptr_deref_may_alias_ref_p_1 (tree ptr
, ao_ref
*ref
)
303 tree base
= ao_ref_base (ref
);
305 if (INDIRECT_REF_P (base
))
306 return ptr_derefs_may_alias_p (ptr
, TREE_OPERAND (base
, 0));
307 else if (SSA_VAR_P (base
))
308 return ptr_deref_may_alias_decl_p (ptr
, base
);
314 /* Dump alias information on FILE. */
317 dump_alias_info (FILE *file
)
321 = lang_hooks
.decl_printable_name (current_function_decl
, 2);
322 referenced_var_iterator rvi
;
325 fprintf (file
, "\n\nAlias information for %s\n\n", funcname
);
327 fprintf (file
, "Aliased symbols\n\n");
329 FOR_EACH_REFERENCED_VAR (var
, rvi
)
331 if (may_be_aliased (var
))
332 dump_variable (file
, var
);
335 fprintf (file
, "\nCall clobber information\n");
337 fprintf (file
, "\nESCAPED");
338 dump_points_to_solution (file
, &cfun
->gimple_df
->escaped
);
339 fprintf (file
, "\nCALLUSED");
340 dump_points_to_solution (file
, &cfun
->gimple_df
->callused
);
342 fprintf (file
, "\n\nFlow-insensitive points-to information\n\n");
344 for (i
= 1; i
< num_ssa_names
; i
++)
346 tree ptr
= ssa_name (i
);
347 struct ptr_info_def
*pi
;
350 || SSA_NAME_IN_FREE_LIST (ptr
))
353 pi
= SSA_NAME_PTR_INFO (ptr
);
355 dump_points_to_info_for (file
, ptr
);
358 fprintf (file
, "\n");
362 /* Dump alias information on stderr. */
365 debug_alias_info (void)
367 dump_alias_info (stderr
);
371 /* Return the alias information associated with pointer T. It creates a
372 new instance if none existed. */
374 struct ptr_info_def
*
375 get_ptr_info (tree t
)
377 struct ptr_info_def
*pi
;
379 gcc_assert (POINTER_TYPE_P (TREE_TYPE (t
)));
381 pi
= SSA_NAME_PTR_INFO (t
);
384 pi
= GGC_CNEW (struct ptr_info_def
);
385 pt_solution_reset (&pi
->pt
);
386 SSA_NAME_PTR_INFO (t
) = pi
;
392 /* Dump the points-to set *PT into FILE. */
395 dump_points_to_solution (FILE *file
, struct pt_solution
*pt
)
398 fprintf (file
, ", points-to anything");
401 fprintf (file
, ", points-to non-local");
404 fprintf (file
, ", points-to 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)");
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 unconstrained type can be used to access an object
548 of one of its constrained subtypes, for example when a function with an
549 unconstrained parameter passed by reference is called on a constrained
550 object and inlined. In this case, the types have the same alias set. */
551 if (TYPE_SIZE (type1
) && TYPE_SIZE (type2
)
552 && TREE_CONSTANT (TYPE_SIZE (type1
)) != TREE_CONSTANT (TYPE_SIZE (type2
))
553 && get_alias_set (type1
) == get_alias_set (type2
))
556 /* The types are known to be not equal. */
560 /* Determine if the two component references REF1 and REF2 which are
561 based on access types TYPE1 and TYPE2 and of which at least one is based
562 on an indirect reference may alias. */
565 aliasing_component_refs_p (tree ref1
, tree type1
,
566 HOST_WIDE_INT offset1
, HOST_WIDE_INT max_size1
,
567 tree ref2
, tree type2
,
568 HOST_WIDE_INT offset2
, HOST_WIDE_INT max_size2
)
570 /* If one reference is a component references through pointers try to find a
571 common base and apply offset based disambiguation. This handles
573 struct A { int i; int j; } *q;
574 struct B { struct A a; int k; } *p;
575 disambiguating q->i and p->a.j. */
579 /* Now search for the type1 in the access path of ref2. This
580 would be a common base for doing offset based disambiguation on. */
582 while (handled_component_p (*refp
)
583 && same_type_for_tbaa (TREE_TYPE (*refp
), type1
) == 0)
584 refp
= &TREE_OPERAND (*refp
, 0);
585 same_p
= same_type_for_tbaa (TREE_TYPE (*refp
), type1
);
586 /* If we couldn't compare types we have to bail out. */
589 else if (same_p
== 1)
591 HOST_WIDE_INT offadj
, sztmp
, msztmp
;
592 get_ref_base_and_extent (*refp
, &offadj
, &sztmp
, &msztmp
);
594 return ranges_overlap_p (offset1
, max_size1
, offset2
, max_size2
);
596 /* If we didn't find a common base, try the other way around. */
598 while (handled_component_p (*refp
)
599 && same_type_for_tbaa (TREE_TYPE (*refp
), type2
) == 0)
600 refp
= &TREE_OPERAND (*refp
, 0);
601 same_p
= same_type_for_tbaa (TREE_TYPE (*refp
), type2
);
602 /* If we couldn't compare types we have to bail out. */
605 else if (same_p
== 1)
607 HOST_WIDE_INT offadj
, sztmp
, msztmp
;
608 get_ref_base_and_extent (*refp
, &offadj
, &sztmp
, &msztmp
);
610 return ranges_overlap_p (offset1
, max_size1
, offset2
, max_size2
);
612 /* If we have two type access paths B1.path1 and B2.path2 they may
613 only alias if either B1 is in B2.path2 or B2 is in B1.path1. */
617 /* Return true if two memory references based on the variables BASE1
618 and BASE2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and
619 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. */
622 decl_refs_may_alias_p (tree base1
,
623 HOST_WIDE_INT offset1
, HOST_WIDE_INT max_size1
,
625 HOST_WIDE_INT offset2
, HOST_WIDE_INT max_size2
)
627 gcc_assert (SSA_VAR_P (base1
) && SSA_VAR_P (base2
));
629 /* If both references are based on different variables, they cannot alias. */
630 if (!operand_equal_p (base1
, base2
, 0))
633 /* If both references are based on the same variable, they cannot alias if
634 the accesses do not overlap. */
635 return ranges_overlap_p (offset1
, max_size1
, offset2
, max_size2
);
638 /* Return true if an indirect reference based on *PTR1 constrained
639 to [OFFSET1, OFFSET1 + MAX_SIZE1) may alias a variable based on BASE2
640 constrained to [OFFSET2, OFFSET2 + MAX_SIZE2). *PTR1 and BASE2 have
641 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
642 in which case they are computed on-demand. REF1 and REF2
643 if non-NULL are the complete memory reference trees. */
646 indirect_ref_may_alias_decl_p (tree ref1
, tree ptr1
,
647 HOST_WIDE_INT offset1
, HOST_WIDE_INT max_size1
,
648 alias_set_type base1_alias_set
,
649 tree ref2
, tree base2
,
650 HOST_WIDE_INT offset2
, HOST_WIDE_INT max_size2
,
651 alias_set_type base2_alias_set
)
653 /* If only one reference is based on a variable, they cannot alias if
654 the pointer access is beyond the extent of the variable access.
655 (the pointer base cannot validly point to an offset less than zero
657 They also cannot alias if the pointer may not point to the decl. */
659 && !ranges_overlap_p (offset1
, max_size1
, 0, offset2
+ max_size2
))
661 if (!ptr_deref_may_alias_decl_p (ptr1
, base2
))
664 /* Disambiguations that rely on strict aliasing rules follow. */
665 if (!flag_strict_aliasing
)
668 /* If the alias set for a pointer access is zero all bets are off. */
669 if (base1_alias_set
== -1)
670 base1_alias_set
= get_deref_alias_set (ptr1
);
671 if (base1_alias_set
== 0)
673 if (base2_alias_set
== -1)
674 base2_alias_set
= get_alias_set (base2
);
676 /* If both references are through the same type, they do not alias
677 if the accesses do not overlap. This does extra disambiguation
678 for mixed/pointer accesses but requires strict aliasing. */
679 if (same_type_for_tbaa (TREE_TYPE (TREE_TYPE (ptr1
)),
680 TREE_TYPE (base2
)) == 1)
681 return ranges_overlap_p (offset1
, max_size1
, offset2
, max_size2
);
683 /* The only way to access a variable is through a pointer dereference
684 of the same alias set or a subset of it. */
685 if (base1_alias_set
!= base2_alias_set
686 && !alias_set_subset_of (base1_alias_set
, base2_alias_set
))
689 /* Do access-path based disambiguation. */
691 && handled_component_p (ref1
)
692 && handled_component_p (ref2
))
693 return aliasing_component_refs_p (ref1
, TREE_TYPE (TREE_TYPE (ptr1
)),
695 ref2
, TREE_TYPE (base2
),
701 /* Return true if two indirect references based on *PTR1
702 and *PTR2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and
703 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. *PTR1 and *PTR2 have
704 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
705 in which case they are computed on-demand. REF1 and REF2
706 if non-NULL are the complete memory reference trees. */
709 indirect_refs_may_alias_p (tree ref1
, tree ptr1
,
710 HOST_WIDE_INT offset1
, HOST_WIDE_INT max_size1
,
711 alias_set_type base1_alias_set
,
712 tree ref2
, tree ptr2
,
713 HOST_WIDE_INT offset2
, HOST_WIDE_INT max_size2
,
714 alias_set_type base2_alias_set
)
716 /* If both bases are based on pointers they cannot alias if they may not
717 point to the same memory object or if they point to the same object
718 and the accesses do not overlap. */
719 if (operand_equal_p (ptr1
, ptr2
, 0))
720 return ranges_overlap_p (offset1
, max_size1
, offset2
, max_size2
);
721 if (!ptr_derefs_may_alias_p (ptr1
, ptr2
))
724 /* Disambiguations that rely on strict aliasing rules follow. */
725 if (!flag_strict_aliasing
)
728 /* If the alias set for a pointer access is zero all bets are off. */
729 if (base1_alias_set
== -1)
730 base1_alias_set
= get_deref_alias_set (ptr1
);
731 if (base1_alias_set
== 0)
733 if (base2_alias_set
== -1)
734 base2_alias_set
= get_deref_alias_set (ptr2
);
735 if (base2_alias_set
== 0)
738 /* If both references are through the same type, they do not alias
739 if the accesses do not overlap. This does extra disambiguation
740 for mixed/pointer accesses but requires strict aliasing. */
741 if (same_type_for_tbaa (TREE_TYPE (TREE_TYPE (ptr1
)),
742 TREE_TYPE (TREE_TYPE (ptr2
))) == 1)
743 return ranges_overlap_p (offset1
, max_size1
, offset2
, max_size2
);
745 /* Do type-based disambiguation. */
746 if (base1_alias_set
!= base2_alias_set
747 && !alias_sets_conflict_p (base1_alias_set
, base2_alias_set
))
750 /* Do access-path based disambiguation. */
752 && handled_component_p (ref1
)
753 && handled_component_p (ref2
))
754 return aliasing_component_refs_p (ref1
, TREE_TYPE (TREE_TYPE (ptr1
)),
756 ref2
, TREE_TYPE (TREE_TYPE (ptr2
)),
762 /* Return true, if the two memory references REF1 and REF2 may alias. */
765 refs_may_alias_p_1 (ao_ref
*ref1
, ao_ref
*ref2
, bool tbaa_p
)
768 HOST_WIDE_INT offset1
= 0, offset2
= 0;
769 HOST_WIDE_INT max_size1
= -1, max_size2
= -1;
770 bool var1_p
, var2_p
, ind1_p
, ind2_p
;
773 gcc_assert ((!ref1
->ref
774 || SSA_VAR_P (ref1
->ref
)
775 || handled_component_p (ref1
->ref
)
776 || INDIRECT_REF_P (ref1
->ref
)
777 || TREE_CODE (ref1
->ref
) == TARGET_MEM_REF
778 || TREE_CODE (ref1
->ref
) == CONST_DECL
)
780 || SSA_VAR_P (ref2
->ref
)
781 || handled_component_p (ref2
->ref
)
782 || INDIRECT_REF_P (ref2
->ref
)
783 || TREE_CODE (ref2
->ref
) == TARGET_MEM_REF
784 || TREE_CODE (ref2
->ref
) == CONST_DECL
));
786 /* Decompose the references into their base objects and the access. */
787 base1
= ao_ref_base (ref1
);
788 offset1
= ref1
->offset
;
789 max_size1
= ref1
->max_size
;
790 base2
= ao_ref_base (ref2
);
791 offset2
= ref2
->offset
;
792 max_size2
= ref2
->max_size
;
794 /* We can end up with registers or constants as bases for example from
795 *D.1663_44 = VIEW_CONVERT_EXPR<struct DB_LSN>(__tmp$B0F64_59);
796 which is seen as a struct copy. */
797 if (TREE_CODE (base1
) == SSA_NAME
798 || TREE_CODE (base2
) == SSA_NAME
799 || TREE_CODE (base1
) == CONST_DECL
800 || TREE_CODE (base2
) == CONST_DECL
801 || is_gimple_min_invariant (base1
)
802 || is_gimple_min_invariant (base2
))
805 /* We can end up refering to code via function decls. As we likely
806 do not properly track code aliases conservatively bail out. */
807 if (TREE_CODE (base1
) == FUNCTION_DECL
808 || TREE_CODE (base2
) == FUNCTION_DECL
)
811 /* Defer to simple offset based disambiguation if we have
812 references based on two decls. Do this before defering to
813 TBAA to handle must-alias cases in conformance with the
814 GCC extension of allowing type-punning through unions. */
815 var1_p
= SSA_VAR_P (base1
);
816 var2_p
= SSA_VAR_P (base2
);
817 if (var1_p
&& var2_p
)
818 return decl_refs_may_alias_p (base1
, offset1
, max_size1
,
819 base2
, offset2
, max_size2
);
821 /* First defer to TBAA if possible. */
823 && flag_strict_aliasing
824 && !alias_sets_conflict_p (ao_ref_alias_set (ref1
),
825 ao_ref_alias_set (ref2
)))
828 /* If one reference is a TARGET_MEM_REF weird things are allowed. Still
829 TBAA disambiguation based on the access type is possible, so bail
830 out only after that check. */
831 if ((ref1
->ref
&& TREE_CODE (ref1
->ref
) == TARGET_MEM_REF
)
832 || (ref2
->ref
&& TREE_CODE (ref2
->ref
) == TARGET_MEM_REF
))
835 /* Dispatch to the pointer-vs-decl or pointer-vs-pointer disambiguators. */
836 ind1_p
= INDIRECT_REF_P (base1
);
837 ind2_p
= INDIRECT_REF_P (base2
);
838 set
= tbaa_p
? -1 : 0;
839 if (var1_p
&& ind2_p
)
840 return indirect_ref_may_alias_decl_p (ref2
->ref
, TREE_OPERAND (base2
, 0),
841 offset2
, max_size2
, set
,
843 offset1
, max_size1
, set
);
844 else if (ind1_p
&& var2_p
)
845 return indirect_ref_may_alias_decl_p (ref1
->ref
, TREE_OPERAND (base1
, 0),
846 offset1
, max_size1
, set
,
848 offset2
, max_size2
, set
);
849 else if (ind1_p
&& ind2_p
)
850 return indirect_refs_may_alias_p (ref1
->ref
, TREE_OPERAND (base1
, 0),
851 offset1
, max_size1
, set
,
852 ref2
->ref
, TREE_OPERAND (base2
, 0),
853 offset2
, max_size2
, set
);
859 refs_may_alias_p (tree ref1
, tree ref2
)
863 ao_ref_init (&r1
, ref1
);
864 ao_ref_init (&r2
, ref2
);
865 res
= refs_may_alias_p_1 (&r1
, &r2
, true);
867 ++alias_stats
.refs_may_alias_p_may_alias
;
869 ++alias_stats
.refs_may_alias_p_no_alias
;
873 /* Returns true if there is a anti-dependence for the STORE that
874 executes after the LOAD. */
877 refs_anti_dependent_p (tree load
, tree store
)
880 ao_ref_init (&r1
, load
);
881 ao_ref_init (&r2
, store
);
882 return refs_may_alias_p_1 (&r1
, &r2
, false);
885 /* Returns true if there is a output dependence for the stores
886 STORE1 and STORE2. */
889 refs_output_dependent_p (tree store1
, tree store2
)
892 ao_ref_init (&r1
, store1
);
893 ao_ref_init (&r2
, store2
);
894 return refs_may_alias_p_1 (&r1
, &r2
, false);
897 /* If the call CALL may use the memory reference REF return true,
898 otherwise return false. */
901 ref_maybe_used_by_call_p_1 (gimple call
, ao_ref
*ref
)
905 int flags
= gimple_call_flags (call
);
907 /* Const functions without a static chain do not implicitly use memory. */
908 if (!gimple_call_chain (call
)
909 && (flags
& (ECF_CONST
|ECF_NOVOPS
)))
912 base
= ao_ref_base (ref
);
916 /* If the reference is based on a decl that is not aliased the call
917 cannot possibly use it. */
919 && !may_be_aliased (base
)
920 /* But local statics can be used through recursion. */
921 && !is_global_var (base
))
924 callee
= gimple_call_fndecl (call
);
926 /* Handle those builtin functions explicitly that do not act as
927 escape points. See tree-ssa-structalias.c:find_func_aliases
928 for the list of builtins we might need to handle here. */
929 if (callee
!= NULL_TREE
930 && DECL_BUILT_IN_CLASS (callee
) == BUILT_IN_NORMAL
)
931 switch (DECL_FUNCTION_CODE (callee
))
933 /* All the following functions clobber memory pointed to by
934 their first argument. */
935 case BUILT_IN_STRCPY
:
936 case BUILT_IN_STRNCPY
:
937 case BUILT_IN_MEMCPY
:
938 case BUILT_IN_MEMMOVE
:
939 case BUILT_IN_MEMPCPY
:
940 case BUILT_IN_STPCPY
:
941 case BUILT_IN_STPNCPY
:
942 case BUILT_IN_STRCAT
:
943 case BUILT_IN_STRNCAT
:
946 tree size
= NULL_TREE
;
947 if (gimple_call_num_args (call
) == 3)
948 size
= gimple_call_arg (call
, 2);
949 ao_ref_init_from_ptr_and_size (&dref
,
950 gimple_call_arg (call
, 1),
952 return refs_may_alias_p_1 (&dref
, ref
, false);
957 tree size
= gimple_call_arg (call
, 2);
958 ao_ref_init_from_ptr_and_size (&dref
,
959 gimple_call_arg (call
, 0),
961 return refs_may_alias_p_1 (&dref
, ref
, false);
963 /* The following builtins do not read from memory. */
965 case BUILT_IN_MALLOC
:
966 case BUILT_IN_CALLOC
:
967 case BUILT_IN_MEMSET
:
969 case BUILT_IN_FREXPF
:
970 case BUILT_IN_FREXPL
:
971 case BUILT_IN_GAMMA_R
:
972 case BUILT_IN_GAMMAF_R
:
973 case BUILT_IN_GAMMAL_R
:
974 case BUILT_IN_LGAMMA_R
:
975 case BUILT_IN_LGAMMAF_R
:
976 case BUILT_IN_LGAMMAL_R
:
980 case BUILT_IN_REMQUO
:
981 case BUILT_IN_REMQUOF
:
982 case BUILT_IN_REMQUOL
:
983 case BUILT_IN_SINCOS
:
984 case BUILT_IN_SINCOSF
:
985 case BUILT_IN_SINCOSL
:
989 /* Fallthru to general call handling. */;
992 /* Check if base is a global static variable that is not read
994 if (TREE_CODE (base
) == VAR_DECL
995 && TREE_STATIC (base
)
996 && !TREE_PUBLIC (base
))
1000 if (callee
!= NULL_TREE
1002 = ipa_reference_get_not_read_global (cgraph_node (callee
)))
1003 && bitmap_bit_p (not_read
, DECL_UID (base
)))
1007 /* If the base variable is call-used or call-clobbered then
1009 if (flags
& (ECF_PURE
|ECF_CONST
|ECF_LOOPING_CONST_OR_PURE
|ECF_NOVOPS
))
1013 if (is_call_used (base
))
1016 else if (INDIRECT_REF_P (base
)
1017 && TREE_CODE (TREE_OPERAND (base
, 0)) == SSA_NAME
)
1019 struct ptr_info_def
*pi
= SSA_NAME_PTR_INFO (TREE_OPERAND (base
, 0));
1023 if (pt_solution_includes_global (&pi
->pt
)
1024 || pt_solutions_intersect (&cfun
->gimple_df
->callused
, &pi
->pt
)
1025 || pt_solutions_intersect (&cfun
->gimple_df
->escaped
, &pi
->pt
))
1035 if (is_call_clobbered (base
))
1038 else if (INDIRECT_REF_P (base
)
1039 && TREE_CODE (TREE_OPERAND (base
, 0)) == SSA_NAME
)
1041 struct ptr_info_def
*pi
= SSA_NAME_PTR_INFO (TREE_OPERAND (base
, 0));
1045 if (pt_solution_includes_global (&pi
->pt
)
1046 || pt_solutions_intersect (&cfun
->gimple_df
->escaped
, &pi
->pt
))
1053 /* Inspect call arguments for passed-by-value aliases. */
1055 for (i
= 0; i
< gimple_call_num_args (call
); ++i
)
1057 tree op
= gimple_call_arg (call
, i
);
1059 if (TREE_CODE (op
) == WITH_SIZE_EXPR
)
1060 op
= TREE_OPERAND (op
, 0);
1062 if (TREE_CODE (op
) != SSA_NAME
1063 && !is_gimple_min_invariant (op
))
1066 ao_ref_init (&r
, op
);
1067 if (refs_may_alias_p_1 (&r
, ref
, true))
1076 ref_maybe_used_by_call_p (gimple call
, tree ref
)
1080 ao_ref_init (&r
, ref
);
1081 res
= ref_maybe_used_by_call_p_1 (call
, &r
);
1083 ++alias_stats
.ref_maybe_used_by_call_p_may_alias
;
1085 ++alias_stats
.ref_maybe_used_by_call_p_no_alias
;
1090 /* If the statement STMT may use the memory reference REF return
1091 true, otherwise return false. */
1094 ref_maybe_used_by_stmt_p (gimple stmt
, tree ref
)
1096 if (is_gimple_assign (stmt
))
1100 /* All memory assign statements are single. */
1101 if (!gimple_assign_single_p (stmt
))
1104 rhs
= gimple_assign_rhs1 (stmt
);
1105 if (is_gimple_reg (rhs
)
1106 || is_gimple_min_invariant (rhs
)
1107 || gimple_assign_rhs_code (stmt
) == CONSTRUCTOR
)
1110 return refs_may_alias_p (rhs
, ref
);
1112 else if (is_gimple_call (stmt
))
1113 return ref_maybe_used_by_call_p (stmt
, ref
);
1118 /* If the call in statement CALL may clobber the memory reference REF
1119 return true, otherwise return false. */
1122 call_may_clobber_ref_p_1 (gimple call
, ao_ref
*ref
)
1127 /* If the call is pure or const it cannot clobber anything. */
1128 if (gimple_call_flags (call
)
1129 & (ECF_PURE
|ECF_CONST
|ECF_LOOPING_CONST_OR_PURE
|ECF_NOVOPS
))
1132 base
= ao_ref_base (ref
);
1136 if (TREE_CODE (base
) == SSA_NAME
1137 || CONSTANT_CLASS_P (base
))
1140 /* If the reference is based on a decl that is not aliased the call
1141 cannot possibly clobber it. */
1143 && !may_be_aliased (base
)
1144 /* But local non-readonly statics can be modified through recursion
1145 or the call may implement a threading barrier which we must
1146 treat as may-def. */
1147 && (TREE_READONLY (base
)
1148 || !is_global_var (base
)))
1151 callee
= gimple_call_fndecl (call
);
1153 /* Handle those builtin functions explicitly that do not act as
1154 escape points. See tree-ssa-structalias.c:find_func_aliases
1155 for the list of builtins we might need to handle here. */
1156 if (callee
!= NULL_TREE
1157 && DECL_BUILT_IN_CLASS (callee
) == BUILT_IN_NORMAL
)
1158 switch (DECL_FUNCTION_CODE (callee
))
1160 /* All the following functions clobber memory pointed to by
1161 their first argument. */
1162 case BUILT_IN_STRCPY
:
1163 case BUILT_IN_STRNCPY
:
1164 case BUILT_IN_MEMCPY
:
1165 case BUILT_IN_MEMMOVE
:
1166 case BUILT_IN_MEMPCPY
:
1167 case BUILT_IN_STPCPY
:
1168 case BUILT_IN_STPNCPY
:
1169 case BUILT_IN_STRCAT
:
1170 case BUILT_IN_STRNCAT
:
1171 case BUILT_IN_MEMSET
:
1174 tree size
= NULL_TREE
;
1175 if (gimple_call_num_args (call
) == 3)
1176 size
= gimple_call_arg (call
, 2);
1177 ao_ref_init_from_ptr_and_size (&dref
,
1178 gimple_call_arg (call
, 0),
1180 return refs_may_alias_p_1 (&dref
, ref
, false);
1182 case BUILT_IN_BCOPY
:
1185 tree size
= gimple_call_arg (call
, 2);
1186 ao_ref_init_from_ptr_and_size (&dref
,
1187 gimple_call_arg (call
, 1),
1189 return refs_may_alias_p_1 (&dref
, ref
, false);
1191 /* Allocating memory does not have any side-effects apart from
1192 being the definition point for the pointer. */
1193 case BUILT_IN_MALLOC
:
1194 case BUILT_IN_CALLOC
:
1195 /* Unix98 specifies that errno is set on allocation failure.
1196 Until we properly can track the errno location assume it
1197 is not a plain decl but anonymous storage in a different
1198 translation unit. */
1199 if (flag_errno_math
)
1201 struct ptr_info_def
*pi
;
1204 if (INDIRECT_REF_P (base
)
1205 && TREE_CODE (TREE_OPERAND (base
, 0)) == SSA_NAME
1206 && (pi
= SSA_NAME_PTR_INFO (TREE_OPERAND (base
, 0))))
1207 return pi
->pt
.anything
|| pi
->pt
.nonlocal
;
1210 /* Freeing memory kills the pointed-to memory. More importantly
1211 the call has to serve as a barrier for moving loads and stores
1215 tree ptr
= gimple_call_arg (call
, 0);
1216 return ptr_deref_may_alias_ref_p_1 (ptr
, ref
);
1218 case BUILT_IN_GAMMA_R
:
1219 case BUILT_IN_GAMMAF_R
:
1220 case BUILT_IN_GAMMAL_R
:
1221 case BUILT_IN_LGAMMA_R
:
1222 case BUILT_IN_LGAMMAF_R
:
1223 case BUILT_IN_LGAMMAL_R
:
1225 tree out
= gimple_call_arg (call
, 1);
1226 if (ptr_deref_may_alias_ref_p_1 (out
, ref
))
1228 if (flag_errno_math
)
1232 case BUILT_IN_FREXP
:
1233 case BUILT_IN_FREXPF
:
1234 case BUILT_IN_FREXPL
:
1236 case BUILT_IN_MODFF
:
1237 case BUILT_IN_MODFL
:
1239 tree out
= gimple_call_arg (call
, 1);
1240 return ptr_deref_may_alias_ref_p_1 (out
, ref
);
1242 case BUILT_IN_REMQUO
:
1243 case BUILT_IN_REMQUOF
:
1244 case BUILT_IN_REMQUOL
:
1246 tree out
= gimple_call_arg (call
, 2);
1247 if (ptr_deref_may_alias_ref_p_1 (out
, ref
))
1249 if (flag_errno_math
)
1253 case BUILT_IN_SINCOS
:
1254 case BUILT_IN_SINCOSF
:
1255 case BUILT_IN_SINCOSL
:
1257 tree sin
= gimple_call_arg (call
, 1);
1258 tree cos
= gimple_call_arg (call
, 2);
1259 return (ptr_deref_may_alias_ref_p_1 (sin
, ref
)
1260 || ptr_deref_may_alias_ref_p_1 (cos
, ref
));
1263 /* Fallthru to general call handling. */;
1266 /* Check if base is a global static variable that is not written
1268 if (callee
!= NULL_TREE
1269 && TREE_CODE (base
) == VAR_DECL
1270 && TREE_STATIC (base
)
1271 && !TREE_PUBLIC (base
))
1276 = ipa_reference_get_not_written_global (cgraph_node (callee
)))
1277 && bitmap_bit_p (not_written
, DECL_UID (base
)))
1282 return is_call_clobbered (base
);
1283 else if (INDIRECT_REF_P (base
)
1284 && TREE_CODE (TREE_OPERAND (base
, 0)) == SSA_NAME
)
1286 struct ptr_info_def
*pi
= SSA_NAME_PTR_INFO (TREE_OPERAND (base
, 0));
1290 return (pt_solution_includes_global (&pi
->pt
)
1291 || pt_solutions_intersect (&cfun
->gimple_df
->escaped
, &pi
->pt
));
1297 static bool ATTRIBUTE_UNUSED
1298 call_may_clobber_ref_p (gimple call
, tree ref
)
1302 ao_ref_init (&r
, ref
);
1303 res
= call_may_clobber_ref_p_1 (call
, &r
);
1305 ++alias_stats
.call_may_clobber_ref_p_may_alias
;
1307 ++alias_stats
.call_may_clobber_ref_p_no_alias
;
1312 /* If the statement STMT may clobber the memory reference REF return true,
1313 otherwise return false. */
1316 stmt_may_clobber_ref_p_1 (gimple stmt
, ao_ref
*ref
)
1318 if (is_gimple_call (stmt
))
1320 tree lhs
= gimple_call_lhs (stmt
);
1322 && !is_gimple_reg (lhs
))
1325 ao_ref_init (&r
, lhs
);
1326 if (refs_may_alias_p_1 (ref
, &r
, true))
1330 return call_may_clobber_ref_p_1 (stmt
, ref
);
1332 else if (is_gimple_assign (stmt
))
1335 ao_ref_init (&r
, gimple_assign_lhs (stmt
));
1336 return refs_may_alias_p_1 (ref
, &r
, true);
1338 else if (gimple_code (stmt
) == GIMPLE_ASM
)
1345 stmt_may_clobber_ref_p (gimple stmt
, tree ref
)
1348 ao_ref_init (&r
, ref
);
1349 return stmt_may_clobber_ref_p_1 (stmt
, &r
);
1353 /* Walk the virtual use-def chain of VUSE until hitting the virtual operand
1354 TARGET or a statement clobbering the memory reference REF in which
1355 case false is returned. The walk starts with VUSE, one argument of PHI. */
1358 maybe_skip_until (gimple phi
, tree target
, ao_ref
*ref
,
1359 tree vuse
, bitmap
*visited
)
1362 *visited
= BITMAP_ALLOC (NULL
);
1364 bitmap_set_bit (*visited
, SSA_NAME_VERSION (PHI_RESULT (phi
)));
1366 /* Walk until we hit the target. */
1367 while (vuse
!= target
)
1369 gimple def_stmt
= SSA_NAME_DEF_STMT (vuse
);
1370 /* Recurse for PHI nodes. */
1371 if (gimple_code (def_stmt
) == GIMPLE_PHI
)
1373 /* An already visited PHI node ends the walk successfully. */
1374 if (bitmap_bit_p (*visited
, SSA_NAME_VERSION (PHI_RESULT (def_stmt
))))
1376 vuse
= get_continuation_for_phi (def_stmt
, ref
, visited
);
1381 /* A clobbering statement or the end of the IL ends it failing. */
1382 else if (gimple_nop_p (def_stmt
)
1383 || stmt_may_clobber_ref_p_1 (def_stmt
, ref
))
1385 vuse
= gimple_vuse (def_stmt
);
1390 /* Starting from a PHI node for the virtual operand of the memory reference
1391 REF find a continuation virtual operand that allows to continue walking
1392 statements dominating PHI skipping only statements that cannot possibly
1393 clobber REF. Returns NULL_TREE if no suitable virtual operand can
1397 get_continuation_for_phi (gimple phi
, ao_ref
*ref
, bitmap
*visited
)
1399 unsigned nargs
= gimple_phi_num_args (phi
);
1401 /* Through a single-argument PHI we can simply look through. */
1403 return PHI_ARG_DEF (phi
, 0);
1405 /* For two arguments try to skip non-aliasing code until we hit
1406 the phi argument definition that dominates the other one. */
1409 tree arg0
= PHI_ARG_DEF (phi
, 0);
1410 tree arg1
= PHI_ARG_DEF (phi
, 1);
1411 gimple def0
= SSA_NAME_DEF_STMT (arg0
);
1412 gimple def1
= SSA_NAME_DEF_STMT (arg1
);
1417 else if (gimple_nop_p (def0
)
1418 || (!gimple_nop_p (def1
)
1419 && dominated_by_p (CDI_DOMINATORS
,
1420 gimple_bb (def1
), gimple_bb (def0
))))
1422 if (maybe_skip_until (phi
, arg0
, ref
, arg1
, visited
))
1425 else if (gimple_nop_p (def1
)
1426 || dominated_by_p (CDI_DOMINATORS
,
1427 gimple_bb (def0
), gimple_bb (def1
)))
1429 if (maybe_skip_until (phi
, arg1
, ref
, arg0
, visited
))
1432 /* Special case of a diamond:
1434 goto (cond) ? L1 : L2
1435 L1: store1 = ... #MEM_2 = vuse(MEM_1)
1437 L2: store2 = ... #MEM_3 = vuse(MEM_1)
1438 L3: MEM_4 = PHI<MEM_2, MEM_3>
1439 We were called with the PHI at L3, MEM_2 and MEM_3 don't
1440 dominate each other, but still we can easily skip this PHI node
1441 if we recognize that the vuse MEM operand is the same for both,
1442 and that we can skip both statements (they don't clobber us).
1443 This is still linear. Don't use maybe_skip_until, that might
1444 potentially be slow. */
1445 else if ((common_vuse
= gimple_vuse (def0
))
1446 && common_vuse
== gimple_vuse (def1
))
1448 if (!stmt_may_clobber_ref_p_1 (def0
, ref
)
1449 && !stmt_may_clobber_ref_p_1 (def1
, ref
))
1457 /* Based on the memory reference REF and its virtual use VUSE call
1458 WALKER for each virtual use that is equivalent to VUSE, including VUSE
1459 itself. That is, for each virtual use for which its defining statement
1460 does not clobber REF.
1462 WALKER is called with REF, the current virtual use and DATA. If
1463 WALKER returns non-NULL the walk stops and its result is returned.
1464 At the end of a non-successful walk NULL is returned.
1466 TRANSLATE if non-NULL is called with a pointer to REF, the virtual
1467 use which definition is a statement that may clobber REF and DATA.
1468 If TRANSLATE returns (void *)-1 the walk stops and NULL is returned.
1469 If TRANSLATE returns non-NULL the walk stops and its result is returned.
1470 If TRANSLATE returns NULL the walk continues and TRANSLATE is supposed
1471 to adjust REF and *DATA to make that valid.
1473 TODO: Cache the vector of equivalent vuses per ref, vuse pair. */
1476 walk_non_aliased_vuses (ao_ref
*ref
, tree vuse
,
1477 void *(*walker
)(ao_ref
*, tree
, void *),
1478 void *(*translate
)(ao_ref
*, tree
, void *), void *data
)
1480 bitmap visited
= NULL
;
1483 timevar_push (TV_ALIAS_STMT_WALK
);
1489 /* ??? Do we want to account this to TV_ALIAS_STMT_WALK? */
1490 res
= (*walker
) (ref
, vuse
, data
);
1494 def_stmt
= SSA_NAME_DEF_STMT (vuse
);
1495 if (gimple_nop_p (def_stmt
))
1497 else if (gimple_code (def_stmt
) == GIMPLE_PHI
)
1498 vuse
= get_continuation_for_phi (def_stmt
, ref
, &visited
);
1501 if (stmt_may_clobber_ref_p_1 (def_stmt
, ref
))
1505 res
= (*translate
) (ref
, vuse
, data
);
1506 /* Failed lookup and translation. */
1507 if (res
== (void *)-1)
1512 /* Lookup succeeded. */
1513 else if (res
!= NULL
)
1515 /* Translation succeeded, continue walking. */
1517 vuse
= gimple_vuse (def_stmt
);
1523 BITMAP_FREE (visited
);
1525 timevar_pop (TV_ALIAS_STMT_WALK
);
1531 /* Based on the memory reference REF call WALKER for each vdef which
1532 defining statement may clobber REF, starting with VDEF. If REF
1533 is NULL_TREE, each defining statement is visited.
1535 WALKER is called with REF, the current vdef and DATA. If WALKER
1536 returns true the walk is stopped, otherwise it continues.
1538 At PHI nodes walk_aliased_vdefs forks into one walk for reach
1539 PHI argument (but only one walk continues on merge points), the
1540 return value is true if any of the walks was successful.
1542 The function returns the number of statements walked. */
1545 walk_aliased_vdefs_1 (ao_ref
*ref
, tree vdef
,
1546 bool (*walker
)(ao_ref
*, tree
, void *), void *data
,
1547 bitmap
*visited
, unsigned int cnt
)
1551 gimple def_stmt
= SSA_NAME_DEF_STMT (vdef
);
1554 && !bitmap_set_bit (*visited
, SSA_NAME_VERSION (vdef
)))
1557 if (gimple_nop_p (def_stmt
))
1559 else if (gimple_code (def_stmt
) == GIMPLE_PHI
)
1563 *visited
= BITMAP_ALLOC (NULL
);
1564 for (i
= 0; i
< gimple_phi_num_args (def_stmt
); ++i
)
1565 cnt
+= walk_aliased_vdefs_1 (ref
, gimple_phi_arg_def (def_stmt
, i
),
1566 walker
, data
, visited
, 0);
1570 /* ??? Do we want to account this to TV_ALIAS_STMT_WALK? */
1573 || stmt_may_clobber_ref_p_1 (def_stmt
, ref
))
1574 && (*walker
) (ref
, vdef
, data
))
1577 vdef
= gimple_vuse (def_stmt
);
1583 walk_aliased_vdefs (ao_ref
*ref
, tree vdef
,
1584 bool (*walker
)(ao_ref
*, tree
, void *), void *data
,
1587 bitmap local_visited
= NULL
;
1590 timevar_push (TV_ALIAS_STMT_WALK
);
1592 ret
= walk_aliased_vdefs_1 (ref
, vdef
, walker
, data
,
1593 visited
? visited
: &local_visited
, 0);
1595 BITMAP_FREE (local_visited
);
1597 timevar_pop (TV_ALIAS_STMT_WALK
);