1 /* Alias analysis for trees.
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
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 "basic-block.h"
32 #include "langhooks.h"
35 #include "tree-pretty-print.h"
36 #include "tree-dump.h"
38 #include "tree-flow.h"
39 #include "tree-inline.h"
40 #include "tree-pass.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 /* Conversions are irrelevant for points-to information and
169 data-dependence analysis can feed us those. */
172 /* Anything we do not explicilty handle aliases. */
173 if ((TREE_CODE (ptr
) != SSA_NAME
174 && TREE_CODE (ptr
) != ADDR_EXPR
175 && TREE_CODE (ptr
) != POINTER_PLUS_EXPR
)
176 || !POINTER_TYPE_P (TREE_TYPE (ptr
))
177 || (TREE_CODE (decl
) != VAR_DECL
178 && TREE_CODE (decl
) != PARM_DECL
179 && TREE_CODE (decl
) != RESULT_DECL
))
182 /* Disregard pointer offsetting. */
183 if (TREE_CODE (ptr
) == POINTER_PLUS_EXPR
)
187 ptr
= TREE_OPERAND (ptr
, 0);
189 while (TREE_CODE (ptr
) == POINTER_PLUS_EXPR
);
190 return ptr_deref_may_alias_decl_p (ptr
, decl
);
193 /* ADDR_EXPR pointers either just offset another pointer or directly
194 specify the pointed-to set. */
195 if (TREE_CODE (ptr
) == ADDR_EXPR
)
197 tree base
= get_base_address (TREE_OPERAND (ptr
, 0));
199 && (TREE_CODE (base
) == MEM_REF
200 || TREE_CODE (base
) == TARGET_MEM_REF
))
201 ptr
= TREE_OPERAND (base
, 0);
206 && CONSTANT_CLASS_P (base
))
212 /* Non-aliased variables can not be pointed to. */
213 if (!may_be_aliased (decl
))
216 /* If we do not have useful points-to information for this pointer
217 we cannot disambiguate anything else. */
218 pi
= SSA_NAME_PTR_INFO (ptr
);
222 return pt_solution_includes (&pi
->pt
, decl
);
225 /* Return true if dereferenced PTR1 and PTR2 may alias.
226 The caller is responsible for applying TBAA to see if accesses
227 through PTR1 and PTR2 may conflict at all. */
230 ptr_derefs_may_alias_p (tree ptr1
, tree ptr2
)
232 struct ptr_info_def
*pi1
, *pi2
;
234 /* Conversions are irrelevant for points-to information and
235 data-dependence analysis can feed us those. */
239 /* Anything we do not explicilty handle aliases. */
240 if ((TREE_CODE (ptr1
) != SSA_NAME
241 && TREE_CODE (ptr1
) != ADDR_EXPR
242 && TREE_CODE (ptr1
) != POINTER_PLUS_EXPR
)
243 || (TREE_CODE (ptr2
) != SSA_NAME
244 && TREE_CODE (ptr2
) != ADDR_EXPR
245 && TREE_CODE (ptr2
) != POINTER_PLUS_EXPR
)
246 || !POINTER_TYPE_P (TREE_TYPE (ptr1
))
247 || !POINTER_TYPE_P (TREE_TYPE (ptr2
)))
250 /* Disregard pointer offsetting. */
251 if (TREE_CODE (ptr1
) == POINTER_PLUS_EXPR
)
255 ptr1
= TREE_OPERAND (ptr1
, 0);
257 while (TREE_CODE (ptr1
) == POINTER_PLUS_EXPR
);
258 return ptr_derefs_may_alias_p (ptr1
, ptr2
);
260 if (TREE_CODE (ptr2
) == POINTER_PLUS_EXPR
)
264 ptr2
= TREE_OPERAND (ptr2
, 0);
266 while (TREE_CODE (ptr2
) == POINTER_PLUS_EXPR
);
267 return ptr_derefs_may_alias_p (ptr1
, ptr2
);
270 /* ADDR_EXPR pointers either just offset another pointer or directly
271 specify the pointed-to set. */
272 if (TREE_CODE (ptr1
) == ADDR_EXPR
)
274 tree base
= get_base_address (TREE_OPERAND (ptr1
, 0));
276 && (TREE_CODE (base
) == MEM_REF
277 || TREE_CODE (base
) == TARGET_MEM_REF
))
278 ptr1
= TREE_OPERAND (base
, 0);
281 return ptr_deref_may_alias_decl_p (ptr2
, base
);
285 if (TREE_CODE (ptr2
) == ADDR_EXPR
)
287 tree base
= get_base_address (TREE_OPERAND (ptr2
, 0));
289 && (TREE_CODE (base
) == MEM_REF
290 || TREE_CODE (base
) == TARGET_MEM_REF
))
291 ptr2
= TREE_OPERAND (base
, 0);
294 return ptr_deref_may_alias_decl_p (ptr1
, base
);
299 /* We may end up with two empty points-to solutions for two same pointers.
300 In this case we still want to say both pointers alias, so shortcut
305 /* If we do not have useful points-to information for either pointer
306 we cannot disambiguate anything else. */
307 pi1
= SSA_NAME_PTR_INFO (ptr1
);
308 pi2
= SSA_NAME_PTR_INFO (ptr2
);
312 /* ??? This does not use TBAA to prune decls from the intersection
313 that not both pointers may access. */
314 return pt_solutions_intersect (&pi1
->pt
, &pi2
->pt
);
317 /* Return true if dereferencing PTR may alias *REF.
318 The caller is responsible for applying TBAA to see if PTR
319 may access *REF at all. */
322 ptr_deref_may_alias_ref_p_1 (tree ptr
, ao_ref
*ref
)
324 tree base
= ao_ref_base (ref
);
326 if (TREE_CODE (base
) == MEM_REF
327 || TREE_CODE (base
) == TARGET_MEM_REF
)
328 return ptr_derefs_may_alias_p (ptr
, TREE_OPERAND (base
, 0));
329 else if (DECL_P (base
))
330 return ptr_deref_may_alias_decl_p (ptr
, base
);
336 /* Dump alias information on FILE. */
339 dump_alias_info (FILE *file
)
343 = lang_hooks
.decl_printable_name (current_function_decl
, 2);
344 referenced_var_iterator rvi
;
347 fprintf (file
, "\n\nAlias information for %s\n\n", funcname
);
349 fprintf (file
, "Aliased symbols\n\n");
351 FOR_EACH_REFERENCED_VAR (cfun
, var
, rvi
)
353 if (may_be_aliased (var
))
354 dump_variable (file
, var
);
357 fprintf (file
, "\nCall clobber information\n");
359 fprintf (file
, "\nESCAPED");
360 dump_points_to_solution (file
, &cfun
->gimple_df
->escaped
);
362 fprintf (file
, "\n\nFlow-insensitive points-to information\n\n");
364 for (i
= 1; i
< num_ssa_names
; i
++)
366 tree ptr
= ssa_name (i
);
367 struct ptr_info_def
*pi
;
370 || SSA_NAME_IN_FREE_LIST (ptr
))
373 pi
= SSA_NAME_PTR_INFO (ptr
);
375 dump_points_to_info_for (file
, ptr
);
378 fprintf (file
, "\n");
382 /* Dump alias information on stderr. */
385 debug_alias_info (void)
387 dump_alias_info (stderr
);
391 /* Dump the points-to set *PT into FILE. */
394 dump_points_to_solution (FILE *file
, struct pt_solution
*pt
)
397 fprintf (file
, ", points-to anything");
400 fprintf (file
, ", points-to non-local");
403 fprintf (file
, ", points-to escaped");
406 fprintf (file
, ", points-to unit escaped");
409 fprintf (file
, ", points-to NULL");
413 fprintf (file
, ", points-to vars: ");
414 dump_decl_set (file
, pt
->vars
);
415 if (pt
->vars_contains_global
)
416 fprintf (file
, " (includes global vars)");
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
476 ao_ref_base_alias_set (ao_ref
*ref
)
479 if (ref
->base_alias_set
!= -1)
480 return ref
->base_alias_set
;
484 while (handled_component_p (base_ref
))
485 base_ref
= TREE_OPERAND (base_ref
, 0);
486 ref
->base_alias_set
= get_alias_set (base_ref
);
487 return ref
->base_alias_set
;
490 /* Returns the reference alias set of the memory reference *REF. */
493 ao_ref_alias_set (ao_ref
*ref
)
495 if (ref
->ref_alias_set
!= -1)
496 return ref
->ref_alias_set
;
497 ref
->ref_alias_set
= get_alias_set (ref
->ref
);
498 return ref
->ref_alias_set
;
501 /* Init an alias-oracle reference representation from a gimple pointer
502 PTR and a gimple size SIZE in bytes. If SIZE is NULL_TREE the the
503 size is assumed to be unknown. The access is assumed to be only
504 to or after of the pointer target, not before it. */
507 ao_ref_init_from_ptr_and_size (ao_ref
*ref
, tree ptr
, tree size
)
509 HOST_WIDE_INT t1
, t2
;
510 ref
->ref
= NULL_TREE
;
511 if (TREE_CODE (ptr
) == ADDR_EXPR
)
512 ref
->base
= get_ref_base_and_extent (TREE_OPERAND (ptr
, 0),
513 &ref
->offset
, &t1
, &t2
);
516 ref
->base
= build2 (MEM_REF
, char_type_node
,
517 ptr
, null_pointer_node
);
521 && host_integerp (size
, 0)
522 && TREE_INT_CST_LOW (size
) * 8 / 8 == TREE_INT_CST_LOW (size
))
523 ref
->max_size
= ref
->size
= TREE_INT_CST_LOW (size
) * 8;
525 ref
->max_size
= ref
->size
= -1;
526 ref
->ref_alias_set
= 0;
527 ref
->base_alias_set
= 0;
530 /* Return 1 if TYPE1 and TYPE2 are to be considered equivalent for the
531 purpose of TBAA. Return 0 if they are distinct and -1 if we cannot
535 same_type_for_tbaa (tree type1
, tree type2
)
537 type1
= TYPE_MAIN_VARIANT (type1
);
538 type2
= TYPE_MAIN_VARIANT (type2
);
540 /* If we would have to do structural comparison bail out. */
541 if (TYPE_STRUCTURAL_EQUALITY_P (type1
)
542 || TYPE_STRUCTURAL_EQUALITY_P (type2
))
545 /* Compare the canonical types. */
546 if (TYPE_CANONICAL (type1
) == TYPE_CANONICAL (type2
))
549 /* ??? Array types are not properly unified in all cases as we have
550 spurious changes in the index types for example. Removing this
551 causes all sorts of problems with the Fortran frontend. */
552 if (TREE_CODE (type1
) == ARRAY_TYPE
553 && TREE_CODE (type2
) == ARRAY_TYPE
)
556 /* ??? In Ada, an lvalue of an unconstrained type can be used to access an
557 object of one of its constrained subtypes, e.g. when a function with an
558 unconstrained parameter passed by reference is called on an object and
559 inlined. But, even in the case of a fixed size, type and subtypes are
560 not equivalent enough as to share the same TYPE_CANONICAL, since this
561 would mean that conversions between them are useless, whereas they are
562 not (e.g. type and subtypes can have different modes). So, in the end,
563 they are only guaranteed to have the same alias set. */
564 if (get_alias_set (type1
) == get_alias_set (type2
))
567 /* The types are known to be not equal. */
571 /* Determine if the two component references REF1 and REF2 which are
572 based on access types TYPE1 and TYPE2 and of which at least one is based
573 on an indirect reference may alias. REF2 is the only one that can
574 be a decl in which case REF2_IS_DECL is true.
575 REF1_ALIAS_SET, BASE1_ALIAS_SET, REF2_ALIAS_SET and BASE2_ALIAS_SET
576 are the respective alias sets. */
579 aliasing_component_refs_p (tree ref1
,
580 alias_set_type ref1_alias_set
,
581 alias_set_type base1_alias_set
,
582 HOST_WIDE_INT offset1
, HOST_WIDE_INT max_size1
,
584 alias_set_type ref2_alias_set
,
585 alias_set_type base2_alias_set
,
586 HOST_WIDE_INT offset2
, HOST_WIDE_INT max_size2
,
589 /* If one reference is a component references through pointers try to find a
590 common base and apply offset based disambiguation. This handles
592 struct A { int i; int j; } *q;
593 struct B { struct A a; int k; } *p;
594 disambiguating q->i and p->a.j. */
600 /* Choose bases and base types to search for. */
602 while (handled_component_p (base1
))
603 base1
= TREE_OPERAND (base1
, 0);
604 type1
= TREE_TYPE (base1
);
606 while (handled_component_p (base2
))
607 base2
= TREE_OPERAND (base2
, 0);
608 type2
= TREE_TYPE (base2
);
610 /* Now search for the type1 in the access path of ref2. This
611 would be a common base for doing offset based disambiguation on. */
613 while (handled_component_p (*refp
)
614 && same_type_for_tbaa (TREE_TYPE (*refp
), type1
) == 0)
615 refp
= &TREE_OPERAND (*refp
, 0);
616 same_p
= same_type_for_tbaa (TREE_TYPE (*refp
), type1
);
617 /* If we couldn't compare types we have to bail out. */
620 else if (same_p
== 1)
622 HOST_WIDE_INT offadj
, sztmp
, msztmp
;
623 get_ref_base_and_extent (*refp
, &offadj
, &sztmp
, &msztmp
);
625 get_ref_base_and_extent (base1
, &offadj
, &sztmp
, &msztmp
);
627 return ranges_overlap_p (offset1
, max_size1
, offset2
, max_size2
);
629 /* If we didn't find a common base, try the other way around. */
631 while (handled_component_p (*refp
)
632 && same_type_for_tbaa (TREE_TYPE (*refp
), type2
) == 0)
633 refp
= &TREE_OPERAND (*refp
, 0);
634 same_p
= same_type_for_tbaa (TREE_TYPE (*refp
), type2
);
635 /* If we couldn't compare types we have to bail out. */
638 else if (same_p
== 1)
640 HOST_WIDE_INT offadj
, sztmp
, msztmp
;
641 get_ref_base_and_extent (*refp
, &offadj
, &sztmp
, &msztmp
);
643 get_ref_base_and_extent (base2
, &offadj
, &sztmp
, &msztmp
);
645 return ranges_overlap_p (offset1
, max_size1
, offset2
, max_size2
);
648 /* If we have two type access paths B1.path1 and B2.path2 they may
649 only alias if either B1 is in B2.path2 or B2 is in B1.path1.
650 But we can still have a path that goes B1.path1...B2.path2 with
651 a part that we do not see. So we can only disambiguate now
652 if there is no B2 in the tail of path1 and no B1 on the
654 if (base1_alias_set
== ref2_alias_set
655 || alias_set_subset_of (base1_alias_set
, ref2_alias_set
))
657 /* If this is ptr vs. decl then we know there is no ptr ... decl path. */
659 return (base2_alias_set
== ref1_alias_set
660 || alias_set_subset_of (base2_alias_set
, ref1_alias_set
));
664 /* Return true if two memory references based on the variables BASE1
665 and BASE2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and
666 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. */
669 decl_refs_may_alias_p (tree base1
,
670 HOST_WIDE_INT offset1
, HOST_WIDE_INT max_size1
,
672 HOST_WIDE_INT offset2
, HOST_WIDE_INT max_size2
)
674 gcc_checking_assert (DECL_P (base1
) && DECL_P (base2
));
676 /* If both references are based on different variables, they cannot alias. */
680 /* If both references are based on the same variable, they cannot alias if
681 the accesses do not overlap. */
682 return ranges_overlap_p (offset1
, max_size1
, offset2
, max_size2
);
685 /* Return true if an indirect reference based on *PTR1 constrained
686 to [OFFSET1, OFFSET1 + MAX_SIZE1) may alias a variable based on BASE2
687 constrained to [OFFSET2, OFFSET2 + MAX_SIZE2). *PTR1 and BASE2 have
688 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
689 in which case they are computed on-demand. REF1 and REF2
690 if non-NULL are the complete memory reference trees. */
693 indirect_ref_may_alias_decl_p (tree ref1 ATTRIBUTE_UNUSED
, tree base1
,
694 HOST_WIDE_INT offset1
,
695 HOST_WIDE_INT max_size1 ATTRIBUTE_UNUSED
,
696 alias_set_type ref1_alias_set
,
697 alias_set_type base1_alias_set
,
698 tree ref2 ATTRIBUTE_UNUSED
, tree base2
,
699 HOST_WIDE_INT offset2
, HOST_WIDE_INT max_size2
,
700 alias_set_type ref2_alias_set
,
701 alias_set_type base2_alias_set
, bool tbaa_p
)
704 tree ptrtype1
, dbase2
;
705 HOST_WIDE_INT offset1p
= offset1
, offset2p
= offset2
;
706 HOST_WIDE_INT doffset1
, doffset2
;
709 gcc_checking_assert ((TREE_CODE (base1
) == MEM_REF
710 || TREE_CODE (base1
) == TARGET_MEM_REF
)
713 ptr1
= TREE_OPERAND (base1
, 0);
715 /* The offset embedded in MEM_REFs can be negative. Bias them
716 so that the resulting offset adjustment is positive. */
717 moff
= mem_ref_offset (base1
);
718 moff
= double_int_lshift (moff
,
720 ? 3 : exact_log2 (BITS_PER_UNIT
),
721 HOST_BITS_PER_DOUBLE_INT
, true);
722 if (double_int_negative_p (moff
))
723 offset2p
+= double_int_neg (moff
).low
;
725 offset1p
+= moff
.low
;
727 /* If only one reference is based on a variable, they cannot alias if
728 the pointer access is beyond the extent of the variable access.
729 (the pointer base cannot validly point to an offset less than zero
731 ??? IVOPTs creates bases that do not honor this restriction,
732 so do not apply this optimization for TARGET_MEM_REFs. */
733 if (TREE_CODE (base1
) != TARGET_MEM_REF
734 && !ranges_overlap_p (MAX (0, offset1p
), -1, offset2p
, max_size2
))
736 /* They also cannot alias if the pointer may not point to the decl. */
737 if (!ptr_deref_may_alias_decl_p (ptr1
, base2
))
740 /* Disambiguations that rely on strict aliasing rules follow. */
741 if (!flag_strict_aliasing
|| !tbaa_p
)
744 ptrtype1
= TREE_TYPE (TREE_OPERAND (base1
, 1));
746 /* If the alias set for a pointer access is zero all bets are off. */
747 if (base1_alias_set
== -1)
748 base1_alias_set
= get_deref_alias_set (ptrtype1
);
749 if (base1_alias_set
== 0)
751 if (base2_alias_set
== -1)
752 base2_alias_set
= get_alias_set (base2
);
754 /* When we are trying to disambiguate an access with a pointer dereference
755 as base versus one with a decl as base we can use both the size
756 of the decl and its dynamic type for extra disambiguation.
757 ??? We do not know anything about the dynamic type of the decl
758 other than that its alias-set contains base2_alias_set as a subset
759 which does not help us here. */
760 /* As we know nothing useful about the dynamic type of the decl just
761 use the usual conflict check rather than a subset test.
762 ??? We could introduce -fvery-strict-aliasing when the language
763 does not allow decls to have a dynamic type that differs from their
764 static type. Then we can check
765 !alias_set_subset_of (base1_alias_set, base2_alias_set) instead. */
766 if (base1_alias_set
!= base2_alias_set
767 && !alias_sets_conflict_p (base1_alias_set
, base2_alias_set
))
769 /* If the size of the access relevant for TBAA through the pointer
770 is bigger than the size of the decl we can't possibly access the
771 decl via that pointer. */
772 if (DECL_SIZE (base2
) && COMPLETE_TYPE_P (TREE_TYPE (ptrtype1
))
773 && TREE_CODE (DECL_SIZE (base2
)) == INTEGER_CST
774 && TREE_CODE (TYPE_SIZE (TREE_TYPE (ptrtype1
))) == INTEGER_CST
775 /* ??? This in turn may run afoul when a decl of type T which is
776 a member of union type U is accessed through a pointer to
777 type U and sizeof T is smaller than sizeof U. */
778 && TREE_CODE (TREE_TYPE (ptrtype1
)) != UNION_TYPE
779 && TREE_CODE (TREE_TYPE (ptrtype1
)) != QUAL_UNION_TYPE
780 && tree_int_cst_lt (DECL_SIZE (base2
), TYPE_SIZE (TREE_TYPE (ptrtype1
))))
786 /* If the decl is accessed via a MEM_REF, reconstruct the base
787 we can use for TBAA and an appropriately adjusted offset. */
789 while (handled_component_p (dbase2
))
790 dbase2
= TREE_OPERAND (dbase2
, 0);
793 if (TREE_CODE (dbase2
) == MEM_REF
794 || TREE_CODE (dbase2
) == TARGET_MEM_REF
)
796 double_int moff
= mem_ref_offset (dbase2
);
797 moff
= double_int_lshift (moff
,
799 ? 3 : exact_log2 (BITS_PER_UNIT
),
800 HOST_BITS_PER_DOUBLE_INT
, true);
801 if (double_int_negative_p (moff
))
802 doffset1
-= double_int_neg (moff
).low
;
804 doffset2
-= moff
.low
;
807 /* If either reference is view-converted, give up now. */
808 if (same_type_for_tbaa (TREE_TYPE (base1
), TREE_TYPE (ptrtype1
)) != 1
809 || same_type_for_tbaa (TREE_TYPE (dbase2
),
810 TREE_TYPE (reference_alias_ptr_type (dbase2
))) != 1)
813 /* If both references are through the same type, they do not alias
814 if the accesses do not overlap. This does extra disambiguation
815 for mixed/pointer accesses but requires strict aliasing.
816 For MEM_REFs we require that the component-ref offset we computed
817 is relative to the start of the type which we ensure by
818 comparing rvalue and access type and disregarding the constant
820 if ((TREE_CODE (base1
) != TARGET_MEM_REF
821 || (!TMR_INDEX (base1
) && !TMR_INDEX2 (base1
)))
822 && same_type_for_tbaa (TREE_TYPE (base1
), TREE_TYPE (dbase2
)) == 1)
823 return ranges_overlap_p (doffset1
, max_size1
, doffset2
, max_size2
);
825 /* Do access-path based disambiguation. */
827 && (handled_component_p (ref1
) || handled_component_p (ref2
)))
828 return aliasing_component_refs_p (ref1
,
829 ref1_alias_set
, base1_alias_set
,
832 ref2_alias_set
, base2_alias_set
,
833 offset2
, max_size2
, true);
838 /* Return true if two indirect references based on *PTR1
839 and *PTR2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and
840 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. *PTR1 and *PTR2 have
841 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
842 in which case they are computed on-demand. REF1 and REF2
843 if non-NULL are the complete memory reference trees. */
846 indirect_refs_may_alias_p (tree ref1 ATTRIBUTE_UNUSED
, tree base1
,
847 HOST_WIDE_INT offset1
, HOST_WIDE_INT max_size1
,
848 alias_set_type ref1_alias_set
,
849 alias_set_type base1_alias_set
,
850 tree ref2 ATTRIBUTE_UNUSED
, tree base2
,
851 HOST_WIDE_INT offset2
, HOST_WIDE_INT max_size2
,
852 alias_set_type ref2_alias_set
,
853 alias_set_type base2_alias_set
, bool tbaa_p
)
857 tree ptrtype1
, ptrtype2
;
859 gcc_checking_assert ((TREE_CODE (base1
) == MEM_REF
860 || TREE_CODE (base1
) == TARGET_MEM_REF
)
861 && (TREE_CODE (base2
) == MEM_REF
862 || TREE_CODE (base2
) == TARGET_MEM_REF
));
864 ptr1
= TREE_OPERAND (base1
, 0);
865 ptr2
= TREE_OPERAND (base2
, 0);
867 /* If both bases are based on pointers they cannot alias if they may not
868 point to the same memory object or if they point to the same object
869 and the accesses do not overlap. */
870 if ((!cfun
|| gimple_in_ssa_p (cfun
))
871 && operand_equal_p (ptr1
, ptr2
, 0)
872 && (((TREE_CODE (base1
) != TARGET_MEM_REF
873 || (!TMR_INDEX (base1
) && !TMR_INDEX2 (base1
)))
874 && (TREE_CODE (base2
) != TARGET_MEM_REF
875 || (!TMR_INDEX (base2
) && !TMR_INDEX2 (base2
))))
876 || (TREE_CODE (base1
) == TARGET_MEM_REF
877 && TREE_CODE (base2
) == TARGET_MEM_REF
878 && (TMR_STEP (base1
) == TMR_STEP (base2
)
879 || (TMR_STEP (base1
) && TMR_STEP (base2
)
880 && operand_equal_p (TMR_STEP (base1
),
881 TMR_STEP (base2
), 0)))
882 && (TMR_INDEX (base1
) == TMR_INDEX (base2
)
883 || (TMR_INDEX (base1
) && TMR_INDEX (base2
)
884 && operand_equal_p (TMR_INDEX (base1
),
885 TMR_INDEX (base2
), 0)))
886 && (TMR_INDEX2 (base1
) == TMR_INDEX2 (base2
)
887 || (TMR_INDEX2 (base1
) && TMR_INDEX2 (base2
)
888 && operand_equal_p (TMR_INDEX2 (base1
),
889 TMR_INDEX2 (base2
), 0))))))
892 /* The offset embedded in MEM_REFs can be negative. Bias them
893 so that the resulting offset adjustment is positive. */
894 moff
= mem_ref_offset (base1
);
895 moff
= double_int_lshift (moff
,
897 ? 3 : exact_log2 (BITS_PER_UNIT
),
898 HOST_BITS_PER_DOUBLE_INT
, true);
899 if (double_int_negative_p (moff
))
900 offset2
+= double_int_neg (moff
).low
;
903 moff
= mem_ref_offset (base2
);
904 moff
= double_int_lshift (moff
,
906 ? 3 : exact_log2 (BITS_PER_UNIT
),
907 HOST_BITS_PER_DOUBLE_INT
, true);
908 if (double_int_negative_p (moff
))
909 offset1
+= double_int_neg (moff
).low
;
912 return ranges_overlap_p (offset1
, max_size1
, offset2
, max_size2
);
914 if (!ptr_derefs_may_alias_p (ptr1
, ptr2
))
917 /* Disambiguations that rely on strict aliasing rules follow. */
918 if (!flag_strict_aliasing
|| !tbaa_p
)
921 ptrtype1
= TREE_TYPE (TREE_OPERAND (base1
, 1));
922 ptrtype2
= TREE_TYPE (TREE_OPERAND (base2
, 1));
924 /* If the alias set for a pointer access is zero all bets are off. */
925 if (base1_alias_set
== -1)
926 base1_alias_set
= get_deref_alias_set (ptrtype1
);
927 if (base1_alias_set
== 0)
929 if (base2_alias_set
== -1)
930 base2_alias_set
= get_deref_alias_set (ptrtype2
);
931 if (base2_alias_set
== 0)
934 /* If both references are through the same type, they do not alias
935 if the accesses do not overlap. This does extra disambiguation
936 for mixed/pointer accesses but requires strict aliasing. */
937 if ((TREE_CODE (base1
) != TARGET_MEM_REF
938 || (!TMR_INDEX (base1
) && !TMR_INDEX2 (base1
)))
939 && (TREE_CODE (base2
) != TARGET_MEM_REF
940 || (!TMR_INDEX (base2
) && !TMR_INDEX2 (base2
)))
941 && same_type_for_tbaa (TREE_TYPE (base1
), TREE_TYPE (ptrtype1
)) == 1
942 && same_type_for_tbaa (TREE_TYPE (base2
), TREE_TYPE (ptrtype2
)) == 1
943 && same_type_for_tbaa (TREE_TYPE (ptrtype1
),
944 TREE_TYPE (ptrtype2
)) == 1)
945 return ranges_overlap_p (offset1
, max_size1
, offset2
, max_size2
);
947 /* Do type-based disambiguation. */
948 if (base1_alias_set
!= base2_alias_set
949 && !alias_sets_conflict_p (base1_alias_set
, base2_alias_set
))
952 /* Do access-path based disambiguation. */
954 && (handled_component_p (ref1
) || handled_component_p (ref2
))
955 && same_type_for_tbaa (TREE_TYPE (base1
), TREE_TYPE (ptrtype1
)) == 1
956 && same_type_for_tbaa (TREE_TYPE (base2
), TREE_TYPE (ptrtype2
)) == 1)
957 return aliasing_component_refs_p (ref1
,
958 ref1_alias_set
, base1_alias_set
,
961 ref2_alias_set
, base2_alias_set
,
962 offset2
, max_size2
, false);
967 /* Return true, if the two memory references REF1 and REF2 may alias. */
970 refs_may_alias_p_1 (ao_ref
*ref1
, ao_ref
*ref2
, bool tbaa_p
)
973 HOST_WIDE_INT offset1
= 0, offset2
= 0;
974 HOST_WIDE_INT max_size1
= -1, max_size2
= -1;
975 bool var1_p
, var2_p
, ind1_p
, ind2_p
;
977 gcc_checking_assert ((!ref1
->ref
978 || TREE_CODE (ref1
->ref
) == SSA_NAME
979 || DECL_P (ref1
->ref
)
980 || TREE_CODE (ref1
->ref
) == STRING_CST
981 || handled_component_p (ref1
->ref
)
982 || TREE_CODE (ref1
->ref
) == MEM_REF
983 || TREE_CODE (ref1
->ref
) == TARGET_MEM_REF
)
985 || TREE_CODE (ref2
->ref
) == SSA_NAME
986 || DECL_P (ref2
->ref
)
987 || TREE_CODE (ref2
->ref
) == STRING_CST
988 || handled_component_p (ref2
->ref
)
989 || TREE_CODE (ref2
->ref
) == MEM_REF
990 || TREE_CODE (ref2
->ref
) == TARGET_MEM_REF
));
992 /* Decompose the references into their base objects and the access. */
993 base1
= ao_ref_base (ref1
);
994 offset1
= ref1
->offset
;
995 max_size1
= ref1
->max_size
;
996 base2
= ao_ref_base (ref2
);
997 offset2
= ref2
->offset
;
998 max_size2
= ref2
->max_size
;
1000 /* We can end up with registers or constants as bases for example from
1001 *D.1663_44 = VIEW_CONVERT_EXPR<struct DB_LSN>(__tmp$B0F64_59);
1002 which is seen as a struct copy. */
1003 if (TREE_CODE (base1
) == SSA_NAME
1004 || TREE_CODE (base1
) == CONST_DECL
1005 || TREE_CODE (base1
) == CONSTRUCTOR
1006 || TREE_CODE (base1
) == ADDR_EXPR
1007 || CONSTANT_CLASS_P (base1
)
1008 || TREE_CODE (base2
) == SSA_NAME
1009 || TREE_CODE (base2
) == CONST_DECL
1010 || TREE_CODE (base2
) == CONSTRUCTOR
1011 || TREE_CODE (base2
) == ADDR_EXPR
1012 || CONSTANT_CLASS_P (base2
))
1015 /* We can end up refering to code via function and label decls.
1016 As we likely do not properly track code aliases conservatively
1018 if (TREE_CODE (base1
) == FUNCTION_DECL
1019 || TREE_CODE (base1
) == LABEL_DECL
1020 || TREE_CODE (base2
) == FUNCTION_DECL
1021 || TREE_CODE (base2
) == LABEL_DECL
)
1024 /* Defer to simple offset based disambiguation if we have
1025 references based on two decls. Do this before defering to
1026 TBAA to handle must-alias cases in conformance with the
1027 GCC extension of allowing type-punning through unions. */
1028 var1_p
= DECL_P (base1
);
1029 var2_p
= DECL_P (base2
);
1030 if (var1_p
&& var2_p
)
1031 return decl_refs_may_alias_p (base1
, offset1
, max_size1
,
1032 base2
, offset2
, max_size2
);
1034 ind1_p
= (TREE_CODE (base1
) == MEM_REF
1035 || TREE_CODE (base1
) == TARGET_MEM_REF
);
1036 ind2_p
= (TREE_CODE (base2
) == MEM_REF
1037 || TREE_CODE (base2
) == TARGET_MEM_REF
);
1039 /* Canonicalize the pointer-vs-decl case. */
1040 if (ind1_p
&& var2_p
)
1045 tmp1
= offset1
; offset1
= offset2
; offset2
= tmp1
;
1046 tmp1
= max_size1
; max_size1
= max_size2
; max_size2
= tmp1
;
1047 tmp2
= base1
; base1
= base2
; base2
= tmp2
;
1048 tmp3
= ref1
; ref1
= ref2
; ref2
= tmp3
;
1055 /* First defer to TBAA if possible. */
1057 && flag_strict_aliasing
1058 && !alias_sets_conflict_p (ao_ref_alias_set (ref1
),
1059 ao_ref_alias_set (ref2
)))
1062 /* Dispatch to the pointer-vs-decl or pointer-vs-pointer disambiguators. */
1063 if (var1_p
&& ind2_p
)
1064 return indirect_ref_may_alias_decl_p (ref2
->ref
, base2
,
1066 ao_ref_alias_set (ref2
), -1,
1069 ao_ref_alias_set (ref1
),
1070 ao_ref_base_alias_set (ref1
),
1072 else if (ind1_p
&& ind2_p
)
1073 return indirect_refs_may_alias_p (ref1
->ref
, base1
,
1075 ao_ref_alias_set (ref1
), -1,
1078 ao_ref_alias_set (ref2
), -1,
1081 /* We really do not want to end up here, but returning true is safe. */
1082 #ifdef ENABLE_CHECKING
1090 refs_may_alias_p (tree ref1
, tree ref2
)
1094 ao_ref_init (&r1
, ref1
);
1095 ao_ref_init (&r2
, ref2
);
1096 res
= refs_may_alias_p_1 (&r1
, &r2
, true);
1098 ++alias_stats
.refs_may_alias_p_may_alias
;
1100 ++alias_stats
.refs_may_alias_p_no_alias
;
1104 /* Returns true if there is a anti-dependence for the STORE that
1105 executes after the LOAD. */
1108 refs_anti_dependent_p (tree load
, tree store
)
1111 ao_ref_init (&r1
, load
);
1112 ao_ref_init (&r2
, store
);
1113 return refs_may_alias_p_1 (&r1
, &r2
, false);
1116 /* Returns true if there is a output dependence for the stores
1117 STORE1 and STORE2. */
1120 refs_output_dependent_p (tree store1
, tree store2
)
1123 ao_ref_init (&r1
, store1
);
1124 ao_ref_init (&r2
, store2
);
1125 return refs_may_alias_p_1 (&r1
, &r2
, false);
1128 /* If the call CALL may use the memory reference REF return true,
1129 otherwise return false. */
1132 ref_maybe_used_by_call_p_1 (gimple call
, ao_ref
*ref
)
1136 int flags
= gimple_call_flags (call
);
1138 /* Const functions without a static chain do not implicitly use memory. */
1139 if (!gimple_call_chain (call
)
1140 && (flags
& (ECF_CONST
|ECF_NOVOPS
)))
1143 base
= ao_ref_base (ref
);
1147 /* If the reference is based on a decl that is not aliased the call
1148 cannot possibly use it. */
1150 && !may_be_aliased (base
)
1151 /* But local statics can be used through recursion. */
1152 && !is_global_var (base
))
1155 callee
= gimple_call_fndecl (call
);
1157 /* Handle those builtin functions explicitly that do not act as
1158 escape points. See tree-ssa-structalias.c:find_func_aliases
1159 for the list of builtins we might need to handle here. */
1160 if (callee
!= NULL_TREE
1161 && DECL_BUILT_IN_CLASS (callee
) == BUILT_IN_NORMAL
)
1162 switch (DECL_FUNCTION_CODE (callee
))
1164 /* All the following functions read memory pointed to by
1165 their second argument. strcat/strncat additionally
1166 reads memory pointed to by the first argument. */
1167 case BUILT_IN_STRCAT
:
1168 case BUILT_IN_STRNCAT
:
1171 ao_ref_init_from_ptr_and_size (&dref
,
1172 gimple_call_arg (call
, 0),
1174 if (refs_may_alias_p_1 (&dref
, ref
, false))
1178 case BUILT_IN_STRCPY
:
1179 case BUILT_IN_STRNCPY
:
1180 case BUILT_IN_MEMCPY
:
1181 case BUILT_IN_MEMMOVE
:
1182 case BUILT_IN_MEMPCPY
:
1183 case BUILT_IN_STPCPY
:
1184 case BUILT_IN_STPNCPY
:
1185 case BUILT_IN_TM_MEMCPY
:
1186 case BUILT_IN_TM_MEMMOVE
:
1189 tree size
= NULL_TREE
;
1190 if (gimple_call_num_args (call
) == 3)
1191 size
= gimple_call_arg (call
, 2);
1192 ao_ref_init_from_ptr_and_size (&dref
,
1193 gimple_call_arg (call
, 1),
1195 return refs_may_alias_p_1 (&dref
, ref
, false);
1197 case BUILT_IN_STRCAT_CHK
:
1198 case BUILT_IN_STRNCAT_CHK
:
1201 ao_ref_init_from_ptr_and_size (&dref
,
1202 gimple_call_arg (call
, 0),
1204 if (refs_may_alias_p_1 (&dref
, ref
, false))
1208 case BUILT_IN_STRCPY_CHK
:
1209 case BUILT_IN_STRNCPY_CHK
:
1210 case BUILT_IN_MEMCPY_CHK
:
1211 case BUILT_IN_MEMMOVE_CHK
:
1212 case BUILT_IN_MEMPCPY_CHK
:
1213 case BUILT_IN_STPCPY_CHK
:
1216 tree size
= NULL_TREE
;
1217 if (gimple_call_num_args (call
) == 4)
1218 size
= gimple_call_arg (call
, 2);
1219 ao_ref_init_from_ptr_and_size (&dref
,
1220 gimple_call_arg (call
, 1),
1222 return refs_may_alias_p_1 (&dref
, ref
, false);
1224 case BUILT_IN_BCOPY
:
1227 tree size
= gimple_call_arg (call
, 2);
1228 ao_ref_init_from_ptr_and_size (&dref
,
1229 gimple_call_arg (call
, 0),
1231 return refs_may_alias_p_1 (&dref
, ref
, false);
1234 /* The following functions read memory pointed to by their
1236 CASE_BUILT_IN_TM_LOAD (1):
1237 CASE_BUILT_IN_TM_LOAD (2):
1238 CASE_BUILT_IN_TM_LOAD (4):
1239 CASE_BUILT_IN_TM_LOAD (8):
1240 CASE_BUILT_IN_TM_LOAD (FLOAT
):
1241 CASE_BUILT_IN_TM_LOAD (DOUBLE
):
1242 CASE_BUILT_IN_TM_LOAD (LDOUBLE
):
1243 CASE_BUILT_IN_TM_LOAD (M64
):
1244 CASE_BUILT_IN_TM_LOAD (M128
):
1245 CASE_BUILT_IN_TM_LOAD (M256
):
1246 case BUILT_IN_TM_LOG
:
1247 case BUILT_IN_TM_LOG_1
:
1248 case BUILT_IN_TM_LOG_2
:
1249 case BUILT_IN_TM_LOG_4
:
1250 case BUILT_IN_TM_LOG_8
:
1251 case BUILT_IN_TM_LOG_FLOAT
:
1252 case BUILT_IN_TM_LOG_DOUBLE
:
1253 case BUILT_IN_TM_LOG_LDOUBLE
:
1254 case BUILT_IN_TM_LOG_M64
:
1255 case BUILT_IN_TM_LOG_M128
:
1256 case BUILT_IN_TM_LOG_M256
:
1257 return ptr_deref_may_alias_ref_p_1 (gimple_call_arg (call
, 0), ref
);
1259 /* These read memory pointed to by the first argument. */
1260 case BUILT_IN_STRDUP
:
1261 case BUILT_IN_STRNDUP
:
1264 tree size
= NULL_TREE
;
1265 if (gimple_call_num_args (call
) == 2)
1266 size
= gimple_call_arg (call
, 1);
1267 ao_ref_init_from_ptr_and_size (&dref
,
1268 gimple_call_arg (call
, 0),
1270 return refs_may_alias_p_1 (&dref
, ref
, false);
1272 /* The following builtins do not read from memory. */
1274 case BUILT_IN_MALLOC
:
1275 case BUILT_IN_CALLOC
:
1276 case BUILT_IN_ALLOCA
:
1277 case BUILT_IN_ALLOCA_WITH_ALIGN
:
1278 case BUILT_IN_STACK_SAVE
:
1279 case BUILT_IN_STACK_RESTORE
:
1280 case BUILT_IN_MEMSET
:
1281 case BUILT_IN_TM_MEMSET
:
1282 case BUILT_IN_MEMSET_CHK
:
1283 case BUILT_IN_FREXP
:
1284 case BUILT_IN_FREXPF
:
1285 case BUILT_IN_FREXPL
:
1286 case BUILT_IN_GAMMA_R
:
1287 case BUILT_IN_GAMMAF_R
:
1288 case BUILT_IN_GAMMAL_R
:
1289 case BUILT_IN_LGAMMA_R
:
1290 case BUILT_IN_LGAMMAF_R
:
1291 case BUILT_IN_LGAMMAL_R
:
1293 case BUILT_IN_MODFF
:
1294 case BUILT_IN_MODFL
:
1295 case BUILT_IN_REMQUO
:
1296 case BUILT_IN_REMQUOF
:
1297 case BUILT_IN_REMQUOL
:
1298 case BUILT_IN_SINCOS
:
1299 case BUILT_IN_SINCOSF
:
1300 case BUILT_IN_SINCOSL
:
1301 case BUILT_IN_ASSUME_ALIGNED
:
1302 case BUILT_IN_VA_END
:
1304 /* __sync_* builtins and some OpenMP builtins act as threading
1306 #undef DEF_SYNC_BUILTIN
1307 #define DEF_SYNC_BUILTIN(ENUM, NAME, TYPE, ATTRS) case ENUM:
1308 #include "sync-builtins.def"
1309 #undef DEF_SYNC_BUILTIN
1310 case BUILT_IN_GOMP_ATOMIC_START
:
1311 case BUILT_IN_GOMP_ATOMIC_END
:
1312 case BUILT_IN_GOMP_BARRIER
:
1313 case BUILT_IN_GOMP_TASKWAIT
:
1314 case BUILT_IN_GOMP_CRITICAL_START
:
1315 case BUILT_IN_GOMP_CRITICAL_END
:
1316 case BUILT_IN_GOMP_CRITICAL_NAME_START
:
1317 case BUILT_IN_GOMP_CRITICAL_NAME_END
:
1318 case BUILT_IN_GOMP_LOOP_END
:
1319 case BUILT_IN_GOMP_ORDERED_START
:
1320 case BUILT_IN_GOMP_ORDERED_END
:
1321 case BUILT_IN_GOMP_PARALLEL_END
:
1322 case BUILT_IN_GOMP_SECTIONS_END
:
1323 case BUILT_IN_GOMP_SINGLE_COPY_START
:
1324 case BUILT_IN_GOMP_SINGLE_COPY_END
:
1328 /* Fallthru to general call handling. */;
1331 /* Check if base is a global static variable that is not read
1333 if (callee
!= NULL_TREE
1334 && TREE_CODE (base
) == VAR_DECL
1335 && TREE_STATIC (base
))
1337 struct cgraph_node
*node
= cgraph_get_node (callee
);
1340 /* FIXME: Callee can be an OMP builtin that does not have a call graph
1341 node yet. We should enforce that there are nodes for all decls in the
1342 IL and remove this check instead. */
1344 && (not_read
= ipa_reference_get_not_read_global (node
))
1345 && bitmap_bit_p (not_read
, DECL_UID (base
)))
1349 /* Check if the base variable is call-used. */
1352 if (pt_solution_includes (gimple_call_use_set (call
), base
))
1355 else if ((TREE_CODE (base
) == MEM_REF
1356 || TREE_CODE (base
) == TARGET_MEM_REF
)
1357 && TREE_CODE (TREE_OPERAND (base
, 0)) == SSA_NAME
)
1359 struct ptr_info_def
*pi
= SSA_NAME_PTR_INFO (TREE_OPERAND (base
, 0));
1363 if (pt_solutions_intersect (gimple_call_use_set (call
), &pi
->pt
))
1369 /* Inspect call arguments for passed-by-value aliases. */
1371 for (i
= 0; i
< gimple_call_num_args (call
); ++i
)
1373 tree op
= gimple_call_arg (call
, i
);
1374 int flags
= gimple_call_arg_flags (call
, i
);
1376 if (flags
& EAF_UNUSED
)
1379 if (TREE_CODE (op
) == WITH_SIZE_EXPR
)
1380 op
= TREE_OPERAND (op
, 0);
1382 if (TREE_CODE (op
) != SSA_NAME
1383 && !is_gimple_min_invariant (op
))
1386 ao_ref_init (&r
, op
);
1387 if (refs_may_alias_p_1 (&r
, ref
, true))
1396 ref_maybe_used_by_call_p (gimple call
, tree ref
)
1400 ao_ref_init (&r
, ref
);
1401 res
= ref_maybe_used_by_call_p_1 (call
, &r
);
1403 ++alias_stats
.ref_maybe_used_by_call_p_may_alias
;
1405 ++alias_stats
.ref_maybe_used_by_call_p_no_alias
;
1410 /* If the statement STMT may use the memory reference REF return
1411 true, otherwise return false. */
1414 ref_maybe_used_by_stmt_p (gimple stmt
, tree ref
)
1416 if (is_gimple_assign (stmt
))
1420 /* All memory assign statements are single. */
1421 if (!gimple_assign_single_p (stmt
))
1424 rhs
= gimple_assign_rhs1 (stmt
);
1425 if (is_gimple_reg (rhs
)
1426 || is_gimple_min_invariant (rhs
)
1427 || gimple_assign_rhs_code (stmt
) == CONSTRUCTOR
)
1430 return refs_may_alias_p (rhs
, ref
);
1432 else if (is_gimple_call (stmt
))
1433 return ref_maybe_used_by_call_p (stmt
, ref
);
1434 else if (gimple_code (stmt
) == GIMPLE_RETURN
)
1436 tree retval
= gimple_return_retval (stmt
);
1439 && TREE_CODE (retval
) != SSA_NAME
1440 && !is_gimple_min_invariant (retval
)
1441 && refs_may_alias_p (retval
, ref
))
1443 /* If ref escapes the function then the return acts as a use. */
1444 base
= get_base_address (ref
);
1447 else if (DECL_P (base
))
1448 return is_global_var (base
);
1449 else if (TREE_CODE (base
) == MEM_REF
1450 || TREE_CODE (base
) == TARGET_MEM_REF
)
1451 return ptr_deref_may_alias_global_p (TREE_OPERAND (base
, 0));
1458 /* If the call in statement CALL may clobber the memory reference REF
1459 return true, otherwise return false. */
1462 call_may_clobber_ref_p_1 (gimple call
, ao_ref
*ref
)
1467 /* If the call is pure or const it cannot clobber anything. */
1468 if (gimple_call_flags (call
)
1469 & (ECF_PURE
|ECF_CONST
|ECF_LOOPING_CONST_OR_PURE
|ECF_NOVOPS
))
1472 base
= ao_ref_base (ref
);
1476 if (TREE_CODE (base
) == SSA_NAME
1477 || CONSTANT_CLASS_P (base
))
1480 /* If the reference is based on a decl that is not aliased the call
1481 cannot possibly clobber it. */
1483 && !may_be_aliased (base
)
1484 /* But local non-readonly statics can be modified through recursion
1485 or the call may implement a threading barrier which we must
1486 treat as may-def. */
1487 && (TREE_READONLY (base
)
1488 || !is_global_var (base
)))
1491 callee
= gimple_call_fndecl (call
);
1493 /* Handle those builtin functions explicitly that do not act as
1494 escape points. See tree-ssa-structalias.c:find_func_aliases
1495 for the list of builtins we might need to handle here. */
1496 if (callee
!= NULL_TREE
1497 && DECL_BUILT_IN_CLASS (callee
) == BUILT_IN_NORMAL
)
1498 switch (DECL_FUNCTION_CODE (callee
))
1500 /* All the following functions clobber memory pointed to by
1501 their first argument. */
1502 case BUILT_IN_STRCPY
:
1503 case BUILT_IN_STRNCPY
:
1504 case BUILT_IN_MEMCPY
:
1505 case BUILT_IN_MEMMOVE
:
1506 case BUILT_IN_MEMPCPY
:
1507 case BUILT_IN_STPCPY
:
1508 case BUILT_IN_STPNCPY
:
1509 case BUILT_IN_STRCAT
:
1510 case BUILT_IN_STRNCAT
:
1511 case BUILT_IN_MEMSET
:
1512 case BUILT_IN_TM_MEMSET
:
1513 CASE_BUILT_IN_TM_STORE (1):
1514 CASE_BUILT_IN_TM_STORE (2):
1515 CASE_BUILT_IN_TM_STORE (4):
1516 CASE_BUILT_IN_TM_STORE (8):
1517 CASE_BUILT_IN_TM_STORE (FLOAT
):
1518 CASE_BUILT_IN_TM_STORE (DOUBLE
):
1519 CASE_BUILT_IN_TM_STORE (LDOUBLE
):
1520 CASE_BUILT_IN_TM_STORE (M64
):
1521 CASE_BUILT_IN_TM_STORE (M128
):
1522 CASE_BUILT_IN_TM_STORE (M256
):
1523 case BUILT_IN_TM_MEMCPY
:
1524 case BUILT_IN_TM_MEMMOVE
:
1527 tree size
= NULL_TREE
;
1528 /* Don't pass in size for strncat, as the maximum size
1529 is strlen (dest) + n + 1 instead of n, resp.
1530 n + 1 at dest + strlen (dest), but strlen (dest) isn't
1532 if (gimple_call_num_args (call
) == 3
1533 && DECL_FUNCTION_CODE (callee
) != BUILT_IN_STRNCAT
)
1534 size
= gimple_call_arg (call
, 2);
1535 ao_ref_init_from_ptr_and_size (&dref
,
1536 gimple_call_arg (call
, 0),
1538 return refs_may_alias_p_1 (&dref
, ref
, false);
1540 case BUILT_IN_STRCPY_CHK
:
1541 case BUILT_IN_STRNCPY_CHK
:
1542 case BUILT_IN_MEMCPY_CHK
:
1543 case BUILT_IN_MEMMOVE_CHK
:
1544 case BUILT_IN_MEMPCPY_CHK
:
1545 case BUILT_IN_STPCPY_CHK
:
1546 case BUILT_IN_STRCAT_CHK
:
1547 case BUILT_IN_STRNCAT_CHK
:
1548 case BUILT_IN_MEMSET_CHK
:
1551 tree size
= NULL_TREE
;
1552 /* Don't pass in size for __strncat_chk, as the maximum size
1553 is strlen (dest) + n + 1 instead of n, resp.
1554 n + 1 at dest + strlen (dest), but strlen (dest) isn't
1556 if (gimple_call_num_args (call
) == 4
1557 && DECL_FUNCTION_CODE (callee
) != BUILT_IN_STRNCAT_CHK
)
1558 size
= gimple_call_arg (call
, 2);
1559 ao_ref_init_from_ptr_and_size (&dref
,
1560 gimple_call_arg (call
, 0),
1562 return refs_may_alias_p_1 (&dref
, ref
, false);
1564 case BUILT_IN_BCOPY
:
1567 tree size
= gimple_call_arg (call
, 2);
1568 ao_ref_init_from_ptr_and_size (&dref
,
1569 gimple_call_arg (call
, 1),
1571 return refs_may_alias_p_1 (&dref
, ref
, false);
1573 /* Allocating memory does not have any side-effects apart from
1574 being the definition point for the pointer. */
1575 case BUILT_IN_MALLOC
:
1576 case BUILT_IN_CALLOC
:
1577 case BUILT_IN_STRDUP
:
1578 case BUILT_IN_STRNDUP
:
1579 /* Unix98 specifies that errno is set on allocation failure. */
1581 && targetm
.ref_may_alias_errno (ref
))
1584 case BUILT_IN_STACK_SAVE
:
1585 case BUILT_IN_ALLOCA
:
1586 case BUILT_IN_ALLOCA_WITH_ALIGN
:
1587 case BUILT_IN_ASSUME_ALIGNED
:
1589 /* Freeing memory kills the pointed-to memory. More importantly
1590 the call has to serve as a barrier for moving loads and stores
1593 case BUILT_IN_VA_END
:
1595 tree ptr
= gimple_call_arg (call
, 0);
1596 return ptr_deref_may_alias_ref_p_1 (ptr
, ref
);
1598 case BUILT_IN_GAMMA_R
:
1599 case BUILT_IN_GAMMAF_R
:
1600 case BUILT_IN_GAMMAL_R
:
1601 case BUILT_IN_LGAMMA_R
:
1602 case BUILT_IN_LGAMMAF_R
:
1603 case BUILT_IN_LGAMMAL_R
:
1605 tree out
= gimple_call_arg (call
, 1);
1606 if (ptr_deref_may_alias_ref_p_1 (out
, ref
))
1608 if (flag_errno_math
)
1612 case BUILT_IN_FREXP
:
1613 case BUILT_IN_FREXPF
:
1614 case BUILT_IN_FREXPL
:
1616 case BUILT_IN_MODFF
:
1617 case BUILT_IN_MODFL
:
1619 tree out
= gimple_call_arg (call
, 1);
1620 return ptr_deref_may_alias_ref_p_1 (out
, ref
);
1622 case BUILT_IN_REMQUO
:
1623 case BUILT_IN_REMQUOF
:
1624 case BUILT_IN_REMQUOL
:
1626 tree out
= gimple_call_arg (call
, 2);
1627 if (ptr_deref_may_alias_ref_p_1 (out
, ref
))
1629 if (flag_errno_math
)
1633 case BUILT_IN_SINCOS
:
1634 case BUILT_IN_SINCOSF
:
1635 case BUILT_IN_SINCOSL
:
1637 tree sin
= gimple_call_arg (call
, 1);
1638 tree cos
= gimple_call_arg (call
, 2);
1639 return (ptr_deref_may_alias_ref_p_1 (sin
, ref
)
1640 || ptr_deref_may_alias_ref_p_1 (cos
, ref
));
1642 /* __sync_* builtins and some OpenMP builtins act as threading
1644 #undef DEF_SYNC_BUILTIN
1645 #define DEF_SYNC_BUILTIN(ENUM, NAME, TYPE, ATTRS) case ENUM:
1646 #include "sync-builtins.def"
1647 #undef DEF_SYNC_BUILTIN
1648 case BUILT_IN_GOMP_ATOMIC_START
:
1649 case BUILT_IN_GOMP_ATOMIC_END
:
1650 case BUILT_IN_GOMP_BARRIER
:
1651 case BUILT_IN_GOMP_TASKWAIT
:
1652 case BUILT_IN_GOMP_CRITICAL_START
:
1653 case BUILT_IN_GOMP_CRITICAL_END
:
1654 case BUILT_IN_GOMP_CRITICAL_NAME_START
:
1655 case BUILT_IN_GOMP_CRITICAL_NAME_END
:
1656 case BUILT_IN_GOMP_LOOP_END
:
1657 case BUILT_IN_GOMP_ORDERED_START
:
1658 case BUILT_IN_GOMP_ORDERED_END
:
1659 case BUILT_IN_GOMP_PARALLEL_END
:
1660 case BUILT_IN_GOMP_SECTIONS_END
:
1661 case BUILT_IN_GOMP_SINGLE_COPY_START
:
1662 case BUILT_IN_GOMP_SINGLE_COPY_END
:
1665 /* Fallthru to general call handling. */;
1668 /* Check if base is a global static variable that is not written
1670 if (callee
!= NULL_TREE
1671 && TREE_CODE (base
) == VAR_DECL
1672 && TREE_STATIC (base
))
1674 struct cgraph_node
*node
= cgraph_get_node (callee
);
1678 && (not_written
= ipa_reference_get_not_written_global (node
))
1679 && bitmap_bit_p (not_written
, DECL_UID (base
)))
1683 /* Check if the base variable is call-clobbered. */
1685 return pt_solution_includes (gimple_call_clobber_set (call
), base
);
1686 else if ((TREE_CODE (base
) == MEM_REF
1687 || TREE_CODE (base
) == TARGET_MEM_REF
)
1688 && TREE_CODE (TREE_OPERAND (base
, 0)) == SSA_NAME
)
1690 struct ptr_info_def
*pi
= SSA_NAME_PTR_INFO (TREE_OPERAND (base
, 0));
1694 return pt_solutions_intersect (gimple_call_clobber_set (call
), &pi
->pt
);
1700 /* If the call in statement CALL may clobber the memory reference REF
1701 return true, otherwise return false. */
1704 call_may_clobber_ref_p (gimple call
, tree ref
)
1708 ao_ref_init (&r
, ref
);
1709 res
= call_may_clobber_ref_p_1 (call
, &r
);
1711 ++alias_stats
.call_may_clobber_ref_p_may_alias
;
1713 ++alias_stats
.call_may_clobber_ref_p_no_alias
;
1718 /* If the statement STMT may clobber the memory reference REF return true,
1719 otherwise return false. */
1722 stmt_may_clobber_ref_p_1 (gimple stmt
, ao_ref
*ref
)
1724 if (is_gimple_call (stmt
))
1726 tree lhs
= gimple_call_lhs (stmt
);
1728 && TREE_CODE (lhs
) != SSA_NAME
)
1731 ao_ref_init (&r
, lhs
);
1732 if (refs_may_alias_p_1 (ref
, &r
, true))
1736 return call_may_clobber_ref_p_1 (stmt
, ref
);
1738 else if (gimple_assign_single_p (stmt
))
1740 tree lhs
= gimple_assign_lhs (stmt
);
1741 if (TREE_CODE (lhs
) != SSA_NAME
)
1744 ao_ref_init (&r
, lhs
);
1745 return refs_may_alias_p_1 (ref
, &r
, true);
1748 else if (gimple_code (stmt
) == GIMPLE_ASM
)
1755 stmt_may_clobber_ref_p (gimple stmt
, tree ref
)
1758 ao_ref_init (&r
, ref
);
1759 return stmt_may_clobber_ref_p_1 (stmt
, &r
);
1762 /* If STMT kills the memory reference REF return true, otherwise
1766 stmt_kills_ref_p_1 (gimple stmt
, ao_ref
*ref
)
1768 /* For a must-alias check we need to be able to constrain
1769 the access properly. */
1771 if (ref
->max_size
== -1)
1774 if (gimple_has_lhs (stmt
)
1775 && TREE_CODE (gimple_get_lhs (stmt
)) != SSA_NAME
1776 /* The assignment is not necessarily carried out if it can throw
1777 and we can catch it in the current function where we could inspect
1779 ??? We only need to care about the RHS throwing. For aggregate
1780 assignments or similar calls and non-call exceptions the LHS
1781 might throw as well. */
1782 && !stmt_can_throw_internal (stmt
))
1784 tree base
, lhs
= gimple_get_lhs (stmt
);
1785 HOST_WIDE_INT size
, offset
, max_size
;
1786 base
= get_ref_base_and_extent (lhs
, &offset
, &size
, &max_size
);
1787 /* We can get MEM[symbol: sZ, index: D.8862_1] here,
1788 so base == ref->base does not always hold. */
1789 if (base
== ref
->base
)
1791 /* For a must-alias check we need to be able to constrain
1792 the access properly. */
1793 if (size
!= -1 && size
== max_size
)
1795 if (offset
<= ref
->offset
1796 && offset
+ size
>= ref
->offset
+ ref
->max_size
)
1802 if (is_gimple_call (stmt
))
1804 tree callee
= gimple_call_fndecl (stmt
);
1805 if (callee
!= NULL_TREE
1806 && DECL_BUILT_IN_CLASS (callee
) == BUILT_IN_NORMAL
)
1807 switch (DECL_FUNCTION_CODE (callee
))
1809 case BUILT_IN_MEMCPY
:
1810 case BUILT_IN_MEMPCPY
:
1811 case BUILT_IN_MEMMOVE
:
1812 case BUILT_IN_MEMSET
:
1813 case BUILT_IN_MEMCPY_CHK
:
1814 case BUILT_IN_MEMPCPY_CHK
:
1815 case BUILT_IN_MEMMOVE_CHK
:
1816 case BUILT_IN_MEMSET_CHK
:
1818 tree dest
= gimple_call_arg (stmt
, 0);
1819 tree len
= gimple_call_arg (stmt
, 2);
1820 tree base
= NULL_TREE
;
1821 HOST_WIDE_INT offset
= 0;
1822 if (!host_integerp (len
, 0))
1824 if (TREE_CODE (dest
) == ADDR_EXPR
)
1825 base
= get_addr_base_and_unit_offset (TREE_OPERAND (dest
, 0),
1827 else if (TREE_CODE (dest
) == SSA_NAME
)
1830 && base
== ao_ref_base (ref
))
1832 HOST_WIDE_INT size
= TREE_INT_CST_LOW (len
);
1833 if (offset
<= ref
->offset
/ BITS_PER_UNIT
1835 >= ((ref
->offset
+ ref
->max_size
+ BITS_PER_UNIT
- 1)
1842 case BUILT_IN_VA_END
:
1844 tree ptr
= gimple_call_arg (stmt
, 0);
1845 if (TREE_CODE (ptr
) == ADDR_EXPR
)
1847 tree base
= ao_ref_base (ref
);
1848 if (TREE_OPERAND (ptr
, 0) == base
)
1861 stmt_kills_ref_p (gimple stmt
, tree ref
)
1864 ao_ref_init (&r
, ref
);
1865 return stmt_kills_ref_p_1 (stmt
, &r
);
1869 /* Walk the virtual use-def chain of VUSE until hitting the virtual operand
1870 TARGET or a statement clobbering the memory reference REF in which
1871 case false is returned. The walk starts with VUSE, one argument of PHI. */
1874 maybe_skip_until (gimple phi
, tree target
, ao_ref
*ref
,
1875 tree vuse
, bitmap
*visited
)
1877 basic_block bb
= gimple_bb (phi
);
1880 *visited
= BITMAP_ALLOC (NULL
);
1882 bitmap_set_bit (*visited
, SSA_NAME_VERSION (PHI_RESULT (phi
)));
1884 /* Walk until we hit the target. */
1885 while (vuse
!= target
)
1887 gimple def_stmt
= SSA_NAME_DEF_STMT (vuse
);
1888 /* Recurse for PHI nodes. */
1889 if (gimple_code (def_stmt
) == GIMPLE_PHI
)
1891 /* An already visited PHI node ends the walk successfully. */
1892 if (bitmap_bit_p (*visited
, SSA_NAME_VERSION (PHI_RESULT (def_stmt
))))
1894 vuse
= get_continuation_for_phi (def_stmt
, ref
, visited
);
1899 /* A clobbering statement or the end of the IL ends it failing. */
1900 else if (gimple_nop_p (def_stmt
)
1901 || stmt_may_clobber_ref_p_1 (def_stmt
, ref
))
1903 /* If we reach a new basic-block see if we already skipped it
1904 in a previous walk that ended successfully. */
1905 if (gimple_bb (def_stmt
) != bb
)
1907 if (!bitmap_set_bit (*visited
, SSA_NAME_VERSION (vuse
)))
1909 bb
= gimple_bb (def_stmt
);
1911 vuse
= gimple_vuse (def_stmt
);
1916 /* For two PHI arguments ARG0 and ARG1 try to skip non-aliasing code
1917 until we hit the phi argument definition that dominates the other one.
1918 Return that, or NULL_TREE if there is no such definition. */
1921 get_continuation_for_phi_1 (gimple phi
, tree arg0
, tree arg1
,
1922 ao_ref
*ref
, bitmap
*visited
)
1924 gimple def0
= SSA_NAME_DEF_STMT (arg0
);
1925 gimple def1
= SSA_NAME_DEF_STMT (arg1
);
1930 else if (gimple_nop_p (def0
)
1931 || (!gimple_nop_p (def1
)
1932 && dominated_by_p (CDI_DOMINATORS
,
1933 gimple_bb (def1
), gimple_bb (def0
))))
1935 if (maybe_skip_until (phi
, arg0
, ref
, arg1
, visited
))
1938 else if (gimple_nop_p (def1
)
1939 || dominated_by_p (CDI_DOMINATORS
,
1940 gimple_bb (def0
), gimple_bb (def1
)))
1942 if (maybe_skip_until (phi
, arg1
, ref
, arg0
, visited
))
1945 /* Special case of a diamond:
1947 goto (cond) ? L1 : L2
1948 L1: store1 = ... #MEM_2 = vuse(MEM_1)
1950 L2: store2 = ... #MEM_3 = vuse(MEM_1)
1951 L3: MEM_4 = PHI<MEM_2, MEM_3>
1952 We were called with the PHI at L3, MEM_2 and MEM_3 don't
1953 dominate each other, but still we can easily skip this PHI node
1954 if we recognize that the vuse MEM operand is the same for both,
1955 and that we can skip both statements (they don't clobber us).
1956 This is still linear. Don't use maybe_skip_until, that might
1957 potentially be slow. */
1958 else if ((common_vuse
= gimple_vuse (def0
))
1959 && common_vuse
== gimple_vuse (def1
))
1961 if (!stmt_may_clobber_ref_p_1 (def0
, ref
)
1962 && !stmt_may_clobber_ref_p_1 (def1
, ref
))
1970 /* Starting from a PHI node for the virtual operand of the memory reference
1971 REF find a continuation virtual operand that allows to continue walking
1972 statements dominating PHI skipping only statements that cannot possibly
1973 clobber REF. Returns NULL_TREE if no suitable virtual operand can
1977 get_continuation_for_phi (gimple phi
, ao_ref
*ref
, bitmap
*visited
)
1979 unsigned nargs
= gimple_phi_num_args (phi
);
1981 /* Through a single-argument PHI we can simply look through. */
1983 return PHI_ARG_DEF (phi
, 0);
1985 /* For two or more arguments try to pairwise skip non-aliasing code
1986 until we hit the phi argument definition that dominates the other one. */
1987 else if (nargs
>= 2)
1992 /* Find a candidate for the virtual operand which definition
1993 dominates those of all others. */
1994 arg0
= PHI_ARG_DEF (phi
, 0);
1995 if (!SSA_NAME_IS_DEFAULT_DEF (arg0
))
1996 for (i
= 1; i
< nargs
; ++i
)
1998 arg1
= PHI_ARG_DEF (phi
, i
);
1999 if (SSA_NAME_IS_DEFAULT_DEF (arg1
))
2004 if (dominated_by_p (CDI_DOMINATORS
,
2005 gimple_bb (SSA_NAME_DEF_STMT (arg0
)),
2006 gimple_bb (SSA_NAME_DEF_STMT (arg1
))))
2010 /* Then pairwise reduce against the found candidate. */
2011 for (i
= 0; i
< nargs
; ++i
)
2013 arg1
= PHI_ARG_DEF (phi
, i
);
2014 arg0
= get_continuation_for_phi_1 (phi
, arg0
, arg1
, ref
, visited
);
2025 /* Based on the memory reference REF and its virtual use VUSE call
2026 WALKER for each virtual use that is equivalent to VUSE, including VUSE
2027 itself. That is, for each virtual use for which its defining statement
2028 does not clobber REF.
2030 WALKER is called with REF, the current virtual use and DATA. If
2031 WALKER returns non-NULL the walk stops and its result is returned.
2032 At the end of a non-successful walk NULL is returned.
2034 TRANSLATE if non-NULL is called with a pointer to REF, the virtual
2035 use which definition is a statement that may clobber REF and DATA.
2036 If TRANSLATE returns (void *)-1 the walk stops and NULL is returned.
2037 If TRANSLATE returns non-NULL the walk stops and its result is returned.
2038 If TRANSLATE returns NULL the walk continues and TRANSLATE is supposed
2039 to adjust REF and *DATA to make that valid.
2041 TODO: Cache the vector of equivalent vuses per ref, vuse pair. */
2044 walk_non_aliased_vuses (ao_ref
*ref
, tree vuse
,
2045 void *(*walker
)(ao_ref
*, tree
, void *),
2046 void *(*translate
)(ao_ref
*, tree
, void *), void *data
)
2048 bitmap visited
= NULL
;
2051 timevar_push (TV_ALIAS_STMT_WALK
);
2057 /* ??? Do we want to account this to TV_ALIAS_STMT_WALK? */
2058 res
= (*walker
) (ref
, vuse
, data
);
2062 def_stmt
= SSA_NAME_DEF_STMT (vuse
);
2063 if (gimple_nop_p (def_stmt
))
2065 else if (gimple_code (def_stmt
) == GIMPLE_PHI
)
2066 vuse
= get_continuation_for_phi (def_stmt
, ref
, &visited
);
2069 if (stmt_may_clobber_ref_p_1 (def_stmt
, ref
))
2073 res
= (*translate
) (ref
, vuse
, data
);
2074 /* Failed lookup and translation. */
2075 if (res
== (void *)-1)
2080 /* Lookup succeeded. */
2081 else if (res
!= NULL
)
2083 /* Translation succeeded, continue walking. */
2085 vuse
= gimple_vuse (def_stmt
);
2091 BITMAP_FREE (visited
);
2093 timevar_pop (TV_ALIAS_STMT_WALK
);
2099 /* Based on the memory reference REF call WALKER for each vdef which
2100 defining statement may clobber REF, starting with VDEF. If REF
2101 is NULL_TREE, each defining statement is visited.
2103 WALKER is called with REF, the current vdef and DATA. If WALKER
2104 returns true the walk is stopped, otherwise it continues.
2106 At PHI nodes walk_aliased_vdefs forks into one walk for reach
2107 PHI argument (but only one walk continues on merge points), the
2108 return value is true if any of the walks was successful.
2110 The function returns the number of statements walked. */
2113 walk_aliased_vdefs_1 (ao_ref
*ref
, tree vdef
,
2114 bool (*walker
)(ao_ref
*, tree
, void *), void *data
,
2115 bitmap
*visited
, unsigned int cnt
)
2119 gimple def_stmt
= SSA_NAME_DEF_STMT (vdef
);
2122 && !bitmap_set_bit (*visited
, SSA_NAME_VERSION (vdef
)))
2125 if (gimple_nop_p (def_stmt
))
2127 else if (gimple_code (def_stmt
) == GIMPLE_PHI
)
2131 *visited
= BITMAP_ALLOC (NULL
);
2132 for (i
= 0; i
< gimple_phi_num_args (def_stmt
); ++i
)
2133 cnt
+= walk_aliased_vdefs_1 (ref
, gimple_phi_arg_def (def_stmt
, i
),
2134 walker
, data
, visited
, 0);
2138 /* ??? Do we want to account this to TV_ALIAS_STMT_WALK? */
2141 || stmt_may_clobber_ref_p_1 (def_stmt
, ref
))
2142 && (*walker
) (ref
, vdef
, data
))
2145 vdef
= gimple_vuse (def_stmt
);
2151 walk_aliased_vdefs (ao_ref
*ref
, tree vdef
,
2152 bool (*walker
)(ao_ref
*, tree
, void *), void *data
,
2155 bitmap local_visited
= NULL
;
2158 timevar_push (TV_ALIAS_STMT_WALK
);
2160 ret
= walk_aliased_vdefs_1 (ref
, vdef
, walker
, data
,
2161 visited
? visited
: &local_visited
, 0);
2163 BITMAP_FREE (local_visited
);
2165 timevar_pop (TV_ALIAS_STMT_WALK
);