Print cgraph_uid in function header
[official-gcc.git] / gcc-4_6-mobile-vtable-security / gcc / tree-ssa-alias.c
blobe3bb3a8ba0c35771e6b141b6a9c113f8a5c0432c
1 /* Alias analysis for trees.
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Diego Novillo <dnovillo@redhat.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
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/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "tm_p.h"
28 #include "target.h"
29 #include "basic-block.h"
30 #include "timevar.h"
31 #include "ggc.h"
32 #include "langhooks.h"
33 #include "flags.h"
34 #include "function.h"
35 #include "tree-pretty-print.h"
36 #include "tree-dump.h"
37 #include "gimple.h"
38 #include "tree-flow.h"
39 #include "tree-inline.h"
40 #include "tree-pass.h"
41 #include "convert.h"
42 #include "params.h"
43 #include "ipa-type-escape.h"
44 #include "vec.h"
45 #include "bitmap.h"
46 #include "vecprim.h"
47 #include "pointer-set.h"
48 #include "alloc-pool.h"
49 #include "tree-ssa-alias.h"
50 #include "dbgcnt.h"
51 #include "l-ipo.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
95 alias global memory.
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. */
105 static struct {
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;
112 } alias_stats;
114 void
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. */
141 bool
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
147 to global memory. */
148 if (TREE_CODE (ptr) != SSA_NAME)
149 return true;
151 pi = SSA_NAME_PTR_INFO (ptr);
153 /* If we do not have points-to information for this variable,
154 we have to punt. */
155 if (!pi)
156 return true;
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. */
166 static bool
167 ptr_deref_may_alias_decl_p (tree ptr, tree decl)
169 struct ptr_info_def *pi;
171 /* Conversions are irrelevant for points-to information and
172 data-dependence analysis can feed us those. */
173 STRIP_NOPS (ptr);
175 /* Anything we do not explicilty handle aliases. */
176 if ((TREE_CODE (ptr) != SSA_NAME
177 && TREE_CODE (ptr) != ADDR_EXPR
178 && TREE_CODE (ptr) != POINTER_PLUS_EXPR)
179 || !POINTER_TYPE_P (TREE_TYPE (ptr))
180 || (TREE_CODE (decl) != VAR_DECL
181 && TREE_CODE (decl) != PARM_DECL
182 && TREE_CODE (decl) != RESULT_DECL))
183 return true;
185 /* Disregard pointer offsetting. */
186 if (TREE_CODE (ptr) == POINTER_PLUS_EXPR)
190 ptr = TREE_OPERAND (ptr, 0);
192 while (TREE_CODE (ptr) == POINTER_PLUS_EXPR);
193 return ptr_deref_may_alias_decl_p (ptr, decl);
196 /* ADDR_EXPR pointers either just offset another pointer or directly
197 specify the pointed-to set. */
198 if (TREE_CODE (ptr) == ADDR_EXPR)
200 tree base = get_base_address (TREE_OPERAND (ptr, 0));
201 if (base
202 && (INDIRECT_REF_P (base)
203 || TREE_CODE (base) == MEM_REF))
204 ptr = TREE_OPERAND (base, 0);
205 else if (base
206 && SSA_VAR_P (base))
207 return base == decl;
208 else if (base
209 && CONSTANT_CLASS_P (base))
210 return false;
211 else
212 return true;
215 /* Non-aliased variables can not be pointed to. */
216 if (!may_be_aliased (decl))
217 return false;
219 /* If we do not have useful points-to information for this pointer
220 we cannot disambiguate anything else. */
221 pi = SSA_NAME_PTR_INFO (ptr);
222 if (!pi)
223 return true;
225 /* If the decl can be used as a restrict tag and we have a restrict
226 pointer and that pointers points-to set doesn't contain this decl
227 then they can't alias. */
228 if (DECL_RESTRICTED_P (decl)
229 && TYPE_RESTRICT (TREE_TYPE (ptr))
230 && pi->pt.vars_contains_restrict)
231 return bitmap_bit_p (pi->pt.vars, DECL_PT_UID (decl));
233 return pt_solution_includes (&pi->pt, decl);
236 /* Return true if dereferenced PTR1 and PTR2 may alias.
237 The caller is responsible for applying TBAA to see if accesses
238 through PTR1 and PTR2 may conflict at all. */
240 bool
241 ptr_derefs_may_alias_p (tree ptr1, tree ptr2)
243 struct ptr_info_def *pi1, *pi2;
245 /* Conversions are irrelevant for points-to information and
246 data-dependence analysis can feed us those. */
247 STRIP_NOPS (ptr1);
248 STRIP_NOPS (ptr2);
250 /* Anything we do not explicilty handle aliases. */
251 if ((TREE_CODE (ptr1) != SSA_NAME
252 && TREE_CODE (ptr1) != ADDR_EXPR
253 && TREE_CODE (ptr1) != POINTER_PLUS_EXPR)
254 || (TREE_CODE (ptr2) != SSA_NAME
255 && TREE_CODE (ptr2) != ADDR_EXPR
256 && TREE_CODE (ptr2) != POINTER_PLUS_EXPR)
257 || !POINTER_TYPE_P (TREE_TYPE (ptr1))
258 || !POINTER_TYPE_P (TREE_TYPE (ptr2)))
259 return true;
261 /* Disregard pointer offsetting. */
262 if (TREE_CODE (ptr1) == POINTER_PLUS_EXPR)
266 ptr1 = TREE_OPERAND (ptr1, 0);
268 while (TREE_CODE (ptr1) == POINTER_PLUS_EXPR);
269 return ptr_derefs_may_alias_p (ptr1, ptr2);
271 if (TREE_CODE (ptr2) == POINTER_PLUS_EXPR)
275 ptr2 = TREE_OPERAND (ptr2, 0);
277 while (TREE_CODE (ptr2) == POINTER_PLUS_EXPR);
278 return ptr_derefs_may_alias_p (ptr1, ptr2);
281 /* ADDR_EXPR pointers either just offset another pointer or directly
282 specify the pointed-to set. */
283 if (TREE_CODE (ptr1) == ADDR_EXPR)
285 tree base = get_base_address (TREE_OPERAND (ptr1, 0));
286 if (base
287 && (INDIRECT_REF_P (base)
288 || TREE_CODE (base) == MEM_REF))
289 ptr1 = TREE_OPERAND (base, 0);
290 else if (base
291 && SSA_VAR_P (base))
292 return ptr_deref_may_alias_decl_p (ptr2, base);
293 else
294 return true;
296 if (TREE_CODE (ptr2) == ADDR_EXPR)
298 tree base = get_base_address (TREE_OPERAND (ptr2, 0));
299 if (base
300 && (INDIRECT_REF_P (base)
301 || TREE_CODE (base) == MEM_REF))
302 ptr2 = TREE_OPERAND (base, 0);
303 else if (base
304 && SSA_VAR_P (base))
305 return ptr_deref_may_alias_decl_p (ptr1, base);
306 else
307 return true;
310 /* We may end up with two empty points-to solutions for two same pointers.
311 In this case we still want to say both pointers alias, so shortcut
312 that here. */
313 if (ptr1 == ptr2)
314 return true;
316 /* If we do not have useful points-to information for either pointer
317 we cannot disambiguate anything else. */
318 pi1 = SSA_NAME_PTR_INFO (ptr1);
319 pi2 = SSA_NAME_PTR_INFO (ptr2);
320 if (!pi1 || !pi2)
321 return true;
323 /* If both pointers are restrict-qualified try to disambiguate
324 with restrict information. */
325 if (TYPE_RESTRICT (TREE_TYPE (ptr1))
326 && TYPE_RESTRICT (TREE_TYPE (ptr2))
327 && !pt_solutions_same_restrict_base (&pi1->pt, &pi2->pt))
328 return false;
330 /* ??? This does not use TBAA to prune decls from the intersection
331 that not both pointers may access. */
332 return pt_solutions_intersect (&pi1->pt, &pi2->pt);
335 /* Return true if dereferencing PTR may alias *REF.
336 The caller is responsible for applying TBAA to see if PTR
337 may access *REF at all. */
339 static bool
340 ptr_deref_may_alias_ref_p_1 (tree ptr, ao_ref *ref)
342 tree base = ao_ref_base (ref);
344 if (INDIRECT_REF_P (base)
345 || TREE_CODE (base) == MEM_REF)
346 return ptr_derefs_may_alias_p (ptr, TREE_OPERAND (base, 0));
347 else if (SSA_VAR_P (base))
348 return ptr_deref_may_alias_decl_p (ptr, base);
350 return true;
354 /* Dump alias information on FILE. */
356 void
357 dump_alias_info (FILE *file)
359 size_t i;
360 const char *funcname
361 = lang_hooks.decl_printable_name (current_function_decl, 2);
362 referenced_var_iterator rvi;
363 tree var;
365 fprintf (file, "\n\nAlias information for %s\n\n", funcname);
367 fprintf (file, "Aliased symbols\n\n");
369 FOR_EACH_REFERENCED_VAR (cfun, var, rvi)
371 if (may_be_aliased (var))
372 dump_variable (file, var);
375 fprintf (file, "\nCall clobber information\n");
377 fprintf (file, "\nESCAPED");
378 dump_points_to_solution (file, &cfun->gimple_df->escaped);
380 fprintf (file, "\n\nFlow-insensitive points-to information\n\n");
382 for (i = 1; i < num_ssa_names; i++)
384 tree ptr = ssa_name (i);
385 struct ptr_info_def *pi;
387 if (ptr == NULL_TREE
388 || SSA_NAME_IN_FREE_LIST (ptr))
389 continue;
391 pi = SSA_NAME_PTR_INFO (ptr);
392 if (pi)
393 dump_points_to_info_for (file, ptr);
396 fprintf (file, "\n");
400 /* Dump alias information on stderr. */
402 DEBUG_FUNCTION void
403 debug_alias_info (void)
405 dump_alias_info (stderr);
409 /* Dump the points-to set *PT into FILE. */
411 void
412 dump_points_to_solution (FILE *file, struct pt_solution *pt)
414 if (pt->anything)
415 fprintf (file, ", points-to anything");
417 if (pt->nonlocal)
418 fprintf (file, ", points-to non-local");
420 if (pt->escaped)
421 fprintf (file, ", points-to escaped");
423 if (pt->ipa_escaped)
424 fprintf (file, ", points-to unit escaped");
426 if (pt->null)
427 fprintf (file, ", points-to NULL");
429 if (pt->vars)
431 fprintf (file, ", points-to vars: ");
432 dump_decl_set (file, pt->vars);
433 if (pt->vars_contains_global)
434 fprintf (file, " (includes global vars)");
435 if (pt->vars_contains_restrict)
436 fprintf (file, " (includes restrict tags)");
440 /* Dump points-to information for SSA_NAME PTR into FILE. */
442 void
443 dump_points_to_info_for (FILE *file, tree ptr)
445 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr);
447 print_generic_expr (file, ptr, dump_flags);
449 if (pi)
450 dump_points_to_solution (file, &pi->pt);
451 else
452 fprintf (file, ", points-to anything");
454 fprintf (file, "\n");
458 /* Dump points-to information for VAR into stderr. */
460 DEBUG_FUNCTION void
461 debug_points_to_info_for (tree var)
463 dump_points_to_info_for (stderr, var);
467 /* Initializes the alias-oracle reference representation *R from REF. */
469 void
470 ao_ref_init (ao_ref *r, tree ref)
472 r->ref = ref;
473 r->base = NULL_TREE;
474 r->offset = 0;
475 r->size = -1;
476 r->max_size = -1;
477 r->ref_alias_set = -1;
478 r->base_alias_set = -1;
481 /* Returns the base object of the memory reference *REF. */
483 tree
484 ao_ref_base (ao_ref *ref)
486 if (ref->base)
487 return ref->base;
488 ref->base = get_ref_base_and_extent (ref->ref, &ref->offset, &ref->size,
489 &ref->max_size);
490 return ref->base;
493 /* Returns the base object alias set of the memory reference *REF. */
495 static alias_set_type
496 ao_ref_base_alias_set (ao_ref *ref)
498 tree base_ref;
499 if (ref->base_alias_set != -1)
500 return ref->base_alias_set;
501 if (!ref->ref)
502 return 0;
503 base_ref = ref->ref;
504 while (handled_component_p (base_ref))
505 base_ref = TREE_OPERAND (base_ref, 0);
506 ref->base_alias_set = get_alias_set (base_ref);
507 return ref->base_alias_set;
510 /* Returns the reference alias set of the memory reference *REF. */
512 alias_set_type
513 ao_ref_alias_set (ao_ref *ref)
515 if (ref->ref_alias_set != -1)
516 return ref->ref_alias_set;
517 ref->ref_alias_set = get_alias_set (ref->ref);
518 return ref->ref_alias_set;
521 /* Init an alias-oracle reference representation from a gimple pointer
522 PTR and a gimple size SIZE in bytes. If SIZE is NULL_TREE the the
523 size is assumed to be unknown. The access is assumed to be only
524 to or after of the pointer target, not before it. */
526 void
527 ao_ref_init_from_ptr_and_size (ao_ref *ref, tree ptr, tree size)
529 HOST_WIDE_INT t1, t2;
530 ref->ref = NULL_TREE;
531 if (TREE_CODE (ptr) == ADDR_EXPR)
532 ref->base = get_ref_base_and_extent (TREE_OPERAND (ptr, 0),
533 &ref->offset, &t1, &t2);
534 else
536 ref->base = build2 (MEM_REF, char_type_node,
537 ptr, null_pointer_node);
538 ref->offset = 0;
540 if (size
541 && host_integerp (size, 0)
542 && TREE_INT_CST_LOW (size) * 8 / 8 == TREE_INT_CST_LOW (size))
543 ref->max_size = ref->size = TREE_INT_CST_LOW (size) * 8;
544 else
545 ref->max_size = ref->size = -1;
546 ref->ref_alias_set = 0;
547 ref->base_alias_set = 0;
550 /* Return 1 if TYPE1 and TYPE2 are to be considered equivalent for the
551 purpose of TBAA. Return 0 if they are distinct and -1 if we cannot
552 decide. */
554 static inline int
555 same_type_for_tbaa (tree type1, tree type2)
557 type1 = TYPE_MAIN_VARIANT (type1);
558 type2 = TYPE_MAIN_VARIANT (type2);
560 /* If we would have to do structural comparison bail out. */
561 if (TYPE_STRUCTURAL_EQUALITY_P (type1)
562 || TYPE_STRUCTURAL_EQUALITY_P (type2))
563 return -1;
565 /* Compare the canonical types. */
566 if (TYPE_CANONICAL (type1) == TYPE_CANONICAL (type2))
567 return 1;
569 /* ??? Array types are not properly unified in all cases as we have
570 spurious changes in the index types for example. Removing this
571 causes all sorts of problems with the Fortran frontend. */
572 if (TREE_CODE (type1) == ARRAY_TYPE
573 && TREE_CODE (type2) == ARRAY_TYPE)
574 return -1;
576 /* ??? In Ada, an lvalue of an unconstrained type can be used to access an
577 object of one of its constrained subtypes, e.g. when a function with an
578 unconstrained parameter passed by reference is called on an object and
579 inlined. But, even in the case of a fixed size, type and subtypes are
580 not equivalent enough as to share the same TYPE_CANONICAL, since this
581 would mean that conversions between them are useless, whereas they are
582 not (e.g. type and subtypes can have different modes). So, in the end,
583 they are only guaranteed to have the same alias set. */
584 if (get_alias_set (type1) == get_alias_set (type2))
585 return -1;
587 if (L_IPO_COMP_MODE)
588 return equivalent_struct_types_for_tbaa (type1, type2);
590 /* The types are known to be not equal. */
591 return 0;
594 /* Determine if the two component references REF1 and REF2 which are
595 based on access types TYPE1 and TYPE2 and of which at least one is based
596 on an indirect reference may alias. REF2 is the only one that can
597 be a decl in which case REF2_IS_DECL is true.
598 REF1_ALIAS_SET, BASE1_ALIAS_SET, REF2_ALIAS_SET and BASE2_ALIAS_SET
599 are the respective alias sets. */
601 static bool
602 aliasing_component_refs_p (tree ref1,
603 alias_set_type ref1_alias_set,
604 alias_set_type base1_alias_set,
605 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
606 tree ref2,
607 alias_set_type ref2_alias_set,
608 alias_set_type base2_alias_set,
609 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
610 bool ref2_is_decl)
612 /* If one reference is a component references through pointers try to find a
613 common base and apply offset based disambiguation. This handles
614 for example
615 struct A { int i; int j; } *q;
616 struct B { struct A a; int k; } *p;
617 disambiguating q->i and p->a.j. */
618 tree base1, base2;
619 tree type1, type2;
620 tree *refp;
621 int same_p;
623 /* Choose bases and base types to search for. */
624 base1 = ref1;
625 while (handled_component_p (base1))
626 base1 = TREE_OPERAND (base1, 0);
627 type1 = TREE_TYPE (base1);
628 base2 = ref2;
629 while (handled_component_p (base2))
630 base2 = TREE_OPERAND (base2, 0);
631 type2 = TREE_TYPE (base2);
633 /* Now search for the type1 in the access path of ref2. This
634 would be a common base for doing offset based disambiguation on. */
635 refp = &ref2;
636 while (handled_component_p (*refp)
637 && same_type_for_tbaa (TREE_TYPE (*refp), type1) == 0)
638 refp = &TREE_OPERAND (*refp, 0);
639 same_p = same_type_for_tbaa (TREE_TYPE (*refp), type1);
640 /* If we couldn't compare types we have to bail out. */
641 if (same_p == -1)
642 return true;
643 else if (same_p == 1)
645 HOST_WIDE_INT offadj, sztmp, msztmp;
646 get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp);
647 offset2 -= offadj;
648 get_ref_base_and_extent (base1, &offadj, &sztmp, &msztmp);
649 offset1 -= offadj;
650 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
652 /* If we didn't find a common base, try the other way around. */
653 refp = &ref1;
654 while (handled_component_p (*refp)
655 && same_type_for_tbaa (TREE_TYPE (*refp), type2) == 0)
656 refp = &TREE_OPERAND (*refp, 0);
657 same_p = same_type_for_tbaa (TREE_TYPE (*refp), type2);
658 /* If we couldn't compare types we have to bail out. */
659 if (same_p == -1)
660 return true;
661 else if (same_p == 1)
663 HOST_WIDE_INT offadj, sztmp, msztmp;
664 get_ref_base_and_extent (*refp, &offadj, &sztmp, &msztmp);
665 offset1 -= offadj;
666 get_ref_base_and_extent (base2, &offadj, &sztmp, &msztmp);
667 offset2 -= offadj;
668 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
671 /* If we have two type access paths B1.path1 and B2.path2 they may
672 only alias if either B1 is in B2.path2 or B2 is in B1.path1.
673 But we can still have a path that goes B1.path1...B2.path2 with
674 a part that we do not see. So we can only disambiguate now
675 if there is no B2 in the tail of path1 and no B1 on the
676 tail of path2. */
677 if (base1_alias_set == ref2_alias_set
678 || alias_set_subset_of (base1_alias_set, ref2_alias_set))
679 return true;
680 /* If this is ptr vs. decl then we know there is no ptr ... decl path. */
681 if (!ref2_is_decl)
682 return (base2_alias_set == ref1_alias_set
683 || alias_set_subset_of (base2_alias_set, ref1_alias_set));
684 return false;
687 /* Return true if two memory references based on the variables BASE1
688 and BASE2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and
689 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. */
691 static bool
692 decl_refs_may_alias_p (tree base1,
693 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
694 tree base2,
695 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2)
697 gcc_assert (SSA_VAR_P (base1) && SSA_VAR_P (base2));
699 /* If both references are based on different variables, they cannot alias. */
700 if (base1 != base2)
701 return false;
703 /* If both references are based on the same variable, they cannot alias if
704 the accesses do not overlap. */
705 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
708 /* Return true if an indirect reference based on *PTR1 constrained
709 to [OFFSET1, OFFSET1 + MAX_SIZE1) may alias a variable based on BASE2
710 constrained to [OFFSET2, OFFSET2 + MAX_SIZE2). *PTR1 and BASE2 have
711 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
712 in which case they are computed on-demand. REF1 and REF2
713 if non-NULL are the complete memory reference trees. */
715 static bool
716 indirect_ref_may_alias_decl_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
717 HOST_WIDE_INT offset1,
718 HOST_WIDE_INT max_size1 ATTRIBUTE_UNUSED,
719 alias_set_type ref1_alias_set,
720 alias_set_type base1_alias_set,
721 tree ref2 ATTRIBUTE_UNUSED, tree base2,
722 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
723 alias_set_type ref2_alias_set,
724 alias_set_type base2_alias_set, bool tbaa_p)
726 tree ptr1;
727 tree ptrtype1, dbase2;
728 HOST_WIDE_INT offset1p = offset1, offset2p = offset2;
729 HOST_WIDE_INT doffset1, doffset2;
731 ptr1 = TREE_OPERAND (base1, 0);
733 /* The offset embedded in MEM_REFs can be negative. Bias them
734 so that the resulting offset adjustment is positive. */
735 if (TREE_CODE (base1) == MEM_REF
736 || TREE_CODE (base1) == TARGET_MEM_REF)
738 double_int moff = mem_ref_offset (base1);
739 moff = double_int_lshift (moff,
740 BITS_PER_UNIT == 8
741 ? 3 : exact_log2 (BITS_PER_UNIT),
742 HOST_BITS_PER_DOUBLE_INT, true);
743 if (double_int_negative_p (moff))
744 offset2p += double_int_neg (moff).low;
745 else
746 offset1p += moff.low;
749 /* If only one reference is based on a variable, they cannot alias if
750 the pointer access is beyond the extent of the variable access.
751 (the pointer base cannot validly point to an offset less than zero
752 of the variable).
753 ??? IVOPTs creates bases that do not honor this restriction,
754 so do not apply this optimization for TARGET_MEM_REFs. */
755 if (TREE_CODE (base1) != TARGET_MEM_REF
756 && !ranges_overlap_p (MAX (0, offset1p), -1, offset2p, max_size2))
757 return false;
758 /* They also cannot alias if the pointer may not point to the decl. */
759 if (!ptr_deref_may_alias_decl_p (ptr1, base2))
760 return false;
762 /* Disambiguations that rely on strict aliasing rules follow. */
763 if (!flag_strict_aliasing || !tbaa_p)
764 return true;
766 if (TREE_CODE (base1) == MEM_REF)
767 ptrtype1 = TREE_TYPE (TREE_OPERAND (base1, 1));
768 else if (TREE_CODE (base1) == TARGET_MEM_REF)
769 ptrtype1 = TREE_TYPE (TMR_OFFSET (base1));
770 else
771 ptrtype1 = TREE_TYPE (ptr1);
773 /* If the alias set for a pointer access is zero all bets are off. */
774 if (base1_alias_set == -1)
775 base1_alias_set = get_deref_alias_set (ptrtype1);
776 if (base1_alias_set == 0)
777 return true;
778 if (base2_alias_set == -1)
779 base2_alias_set = get_alias_set (base2);
781 /* When we are trying to disambiguate an access with a pointer dereference
782 as base versus one with a decl as base we can use both the size
783 of the decl and its dynamic type for extra disambiguation.
784 ??? We do not know anything about the dynamic type of the decl
785 other than that its alias-set contains base2_alias_set as a subset
786 which does not help us here. */
787 /* As we know nothing useful about the dynamic type of the decl just
788 use the usual conflict check rather than a subset test.
789 ??? We could introduce -fvery-strict-aliasing when the language
790 does not allow decls to have a dynamic type that differs from their
791 static type. Then we can check
792 !alias_set_subset_of (base1_alias_set, base2_alias_set) instead. */
793 if (base1_alias_set != base2_alias_set
794 && !alias_sets_conflict_p (base1_alias_set, base2_alias_set))
795 return false;
796 /* If the size of the access relevant for TBAA through the pointer
797 is bigger than the size of the decl we can't possibly access the
798 decl via that pointer. */
799 if (DECL_SIZE (base2) && COMPLETE_TYPE_P (TREE_TYPE (ptrtype1))
800 && TREE_CODE (DECL_SIZE (base2)) == INTEGER_CST
801 && TREE_CODE (TYPE_SIZE (TREE_TYPE (ptrtype1))) == INTEGER_CST
802 /* ??? This in turn may run afoul when a decl of type T which is
803 a member of union type U is accessed through a pointer to
804 type U and sizeof T is smaller than sizeof U. */
805 && TREE_CODE (TREE_TYPE (ptrtype1)) != UNION_TYPE
806 && TREE_CODE (TREE_TYPE (ptrtype1)) != QUAL_UNION_TYPE
807 && tree_int_cst_lt (DECL_SIZE (base2), TYPE_SIZE (TREE_TYPE (ptrtype1))))
808 return false;
810 if (!ref2)
811 return true;
813 /* If the decl is accressed via a MEM_REF, reconstruct the base
814 we can use for TBAA and an appropriately adjusted offset. */
815 dbase2 = ref2;
816 while (handled_component_p (dbase2))
817 dbase2 = TREE_OPERAND (dbase2, 0);
818 doffset1 = offset1;
819 doffset2 = offset2;
820 if (TREE_CODE (dbase2) == MEM_REF
821 || TREE_CODE (dbase2) == TARGET_MEM_REF)
823 double_int moff = mem_ref_offset (dbase2);
824 moff = double_int_lshift (moff,
825 BITS_PER_UNIT == 8
826 ? 3 : exact_log2 (BITS_PER_UNIT),
827 HOST_BITS_PER_DOUBLE_INT, true);
828 if (double_int_negative_p (moff))
829 doffset1 -= double_int_neg (moff).low;
830 else
831 doffset2 -= moff.low;
834 /* If either reference is view-converted, give up now. */
835 if (same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) != 1
836 || same_type_for_tbaa (TREE_TYPE (dbase2),
837 TREE_TYPE (reference_alias_ptr_type (dbase2))) != 1)
838 return true;
840 /* If both references are through the same type, they do not alias
841 if the accesses do not overlap. This does extra disambiguation
842 for mixed/pointer accesses but requires strict aliasing.
843 For MEM_REFs we require that the component-ref offset we computed
844 is relative to the start of the type which we ensure by
845 comparing rvalue and access type and disregarding the constant
846 pointer offset. */
847 if ((TREE_CODE (base1) != TARGET_MEM_REF
848 || (!TMR_INDEX (base1) && !TMR_INDEX2 (base1)))
849 && same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (dbase2)) == 1)
850 return ranges_overlap_p (doffset1, max_size1, doffset2, max_size2);
852 /* Do access-path based disambiguation. */
853 if (ref1 && ref2
854 && handled_component_p (ref1)
855 && handled_component_p (ref2)
856 && TREE_CODE (base1) != TARGET_MEM_REF
857 && (TREE_CODE (base1) != MEM_REF
858 || same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) == 1))
859 return aliasing_component_refs_p (ref1,
860 ref1_alias_set, base1_alias_set,
861 offset1, max_size1,
862 ref2,
863 ref2_alias_set, base2_alias_set,
864 offset2, max_size2, true);
866 return true;
869 /* Return true if two indirect references based on *PTR1
870 and *PTR2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and
871 [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. *PTR1 and *PTR2 have
872 the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1
873 in which case they are computed on-demand. REF1 and REF2
874 if non-NULL are the complete memory reference trees. */
876 static bool
877 indirect_refs_may_alias_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
878 HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1,
879 alias_set_type ref1_alias_set,
880 alias_set_type base1_alias_set,
881 tree ref2 ATTRIBUTE_UNUSED, tree base2,
882 HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2,
883 alias_set_type ref2_alias_set,
884 alias_set_type base2_alias_set, bool tbaa_p)
886 tree ptr1;
887 tree ptr2;
888 tree ptrtype1, ptrtype2;
890 ptr1 = TREE_OPERAND (base1, 0);
891 ptr2 = TREE_OPERAND (base2, 0);
893 /* If both bases are based on pointers they cannot alias if they may not
894 point to the same memory object or if they point to the same object
895 and the accesses do not overlap. */
896 if ((!cfun || gimple_in_ssa_p (cfun))
897 && operand_equal_p (ptr1, ptr2, 0)
898 && (((TREE_CODE (base1) != TARGET_MEM_REF
899 || (!TMR_INDEX (base1) && !TMR_INDEX2 (base1)))
900 && (TREE_CODE (base2) != TARGET_MEM_REF
901 || (!TMR_INDEX (base2) && !TMR_INDEX2 (base2))))
902 || (TREE_CODE (base1) == TARGET_MEM_REF
903 && TREE_CODE (base2) == TARGET_MEM_REF
904 && (TMR_STEP (base1) == TMR_STEP (base2)
905 || (TMR_STEP (base1) && TMR_STEP (base2)
906 && operand_equal_p (TMR_STEP (base1),
907 TMR_STEP (base2), 0)))
908 && (TMR_INDEX (base1) == TMR_INDEX (base2)
909 || (TMR_INDEX (base1) && TMR_INDEX (base2)
910 && operand_equal_p (TMR_INDEX (base1),
911 TMR_INDEX (base2), 0)))
912 && (TMR_INDEX2 (base1) == TMR_INDEX2 (base2)
913 || (TMR_INDEX2 (base1) && TMR_INDEX2 (base2)
914 && operand_equal_p (TMR_INDEX2 (base1),
915 TMR_INDEX2 (base2), 0))))))
917 /* The offset embedded in MEM_REFs can be negative. Bias them
918 so that the resulting offset adjustment is positive. */
919 if (TREE_CODE (base1) == MEM_REF
920 || TREE_CODE (base1) == TARGET_MEM_REF)
922 double_int moff = mem_ref_offset (base1);
923 moff = double_int_lshift (moff,
924 BITS_PER_UNIT == 8
925 ? 3 : exact_log2 (BITS_PER_UNIT),
926 HOST_BITS_PER_DOUBLE_INT, true);
927 if (double_int_negative_p (moff))
928 offset2 += double_int_neg (moff).low;
929 else
930 offset1 += moff.low;
932 if (TREE_CODE (base2) == MEM_REF
933 || TREE_CODE (base2) == TARGET_MEM_REF)
935 double_int moff = mem_ref_offset (base2);
936 moff = double_int_lshift (moff,
937 BITS_PER_UNIT == 8
938 ? 3 : exact_log2 (BITS_PER_UNIT),
939 HOST_BITS_PER_DOUBLE_INT, true);
940 if (double_int_negative_p (moff))
941 offset1 += double_int_neg (moff).low;
942 else
943 offset2 += moff.low;
945 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
947 if (!ptr_derefs_may_alias_p (ptr1, ptr2))
948 return false;
950 /* Disambiguations that rely on strict aliasing rules follow. */
951 if (!flag_strict_aliasing || !tbaa_p)
952 return true;
954 if (TREE_CODE (base1) == MEM_REF)
955 ptrtype1 = TREE_TYPE (TREE_OPERAND (base1, 1));
956 else if (TREE_CODE (base1) == TARGET_MEM_REF)
957 ptrtype1 = TREE_TYPE (TMR_OFFSET (base1));
958 else
959 ptrtype1 = TREE_TYPE (ptr1);
960 if (TREE_CODE (base2) == MEM_REF)
961 ptrtype2 = TREE_TYPE (TREE_OPERAND (base2, 1));
962 else if (TREE_CODE (base2) == TARGET_MEM_REF)
963 ptrtype2 = TREE_TYPE (TMR_OFFSET (base2));
964 else
965 ptrtype2 = TREE_TYPE (ptr2);
967 /* If the alias set for a pointer access is zero all bets are off. */
968 if (base1_alias_set == -1)
969 base1_alias_set = get_deref_alias_set (ptrtype1);
970 if (base1_alias_set == 0)
971 return true;
972 if (base2_alias_set == -1)
973 base2_alias_set = get_deref_alias_set (ptrtype2);
974 if (base2_alias_set == 0)
975 return true;
977 /* If both references are through the same type, they do not alias
978 if the accesses do not overlap. This does extra disambiguation
979 for mixed/pointer accesses but requires strict aliasing. */
980 if ((TREE_CODE (base1) != TARGET_MEM_REF
981 || (!TMR_INDEX (base1) && !TMR_INDEX2 (base1)))
982 && (TREE_CODE (base2) != TARGET_MEM_REF
983 || (!TMR_INDEX (base2) && !TMR_INDEX2 (base2)))
984 && same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) == 1
985 && same_type_for_tbaa (TREE_TYPE (base2), TREE_TYPE (ptrtype2)) == 1
986 && same_type_for_tbaa (TREE_TYPE (ptrtype1),
987 TREE_TYPE (ptrtype2)) == 1)
988 return ranges_overlap_p (offset1, max_size1, offset2, max_size2);
990 /* Do type-based disambiguation. */
991 if (base1_alias_set != base2_alias_set
992 && !alias_sets_conflict_p (base1_alias_set, base2_alias_set))
993 return false;
995 /* Do access-path based disambiguation. */
996 if (ref1 && ref2
997 && handled_component_p (ref1)
998 && handled_component_p (ref2)
999 && TREE_CODE (base1) != TARGET_MEM_REF
1000 && TREE_CODE (base2) != TARGET_MEM_REF
1001 && (TREE_CODE (base1) != MEM_REF
1002 || same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) == 1)
1003 && (TREE_CODE (base2) != MEM_REF
1004 || same_type_for_tbaa (TREE_TYPE (base2), TREE_TYPE (ptrtype2)) == 1))
1005 return aliasing_component_refs_p (ref1,
1006 ref1_alias_set, base1_alias_set,
1007 offset1, max_size1,
1008 ref2,
1009 ref2_alias_set, base2_alias_set,
1010 offset2, max_size2, false);
1012 return true;
1015 /* Return true, if the two memory references REF1 and REF2 may alias. */
1017 bool
1018 refs_may_alias_p_1 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
1020 tree base1, base2;
1021 HOST_WIDE_INT offset1 = 0, offset2 = 0;
1022 HOST_WIDE_INT max_size1 = -1, max_size2 = -1;
1023 bool var1_p, var2_p, ind1_p, ind2_p;
1025 gcc_checking_assert ((!ref1->ref
1026 || TREE_CODE (ref1->ref) == SSA_NAME
1027 || DECL_P (ref1->ref)
1028 || TREE_CODE (ref1->ref) == STRING_CST
1029 || handled_component_p (ref1->ref)
1030 || INDIRECT_REF_P (ref1->ref)
1031 || TREE_CODE (ref1->ref) == MEM_REF
1032 || TREE_CODE (ref1->ref) == TARGET_MEM_REF)
1033 && (!ref2->ref
1034 || TREE_CODE (ref2->ref) == SSA_NAME
1035 || DECL_P (ref2->ref)
1036 || TREE_CODE (ref2->ref) == STRING_CST
1037 || handled_component_p (ref2->ref)
1038 || INDIRECT_REF_P (ref2->ref)
1039 || TREE_CODE (ref2->ref) == MEM_REF
1040 || TREE_CODE (ref2->ref) == TARGET_MEM_REF));
1042 if (!dbg_cnt (alias))
1043 return true;
1045 /* Decompose the references into their base objects and the access. */
1046 base1 = ao_ref_base (ref1);
1047 offset1 = ref1->offset;
1048 max_size1 = ref1->max_size;
1049 base2 = ao_ref_base (ref2);
1050 offset2 = ref2->offset;
1051 max_size2 = ref2->max_size;
1053 /* We can end up with registers or constants as bases for example from
1054 *D.1663_44 = VIEW_CONVERT_EXPR<struct DB_LSN>(__tmp$B0F64_59);
1055 which is seen as a struct copy. */
1056 if (TREE_CODE (base1) == SSA_NAME
1057 || TREE_CODE (base1) == CONST_DECL
1058 || TREE_CODE (base1) == CONSTRUCTOR
1059 || TREE_CODE (base1) == ADDR_EXPR
1060 || CONSTANT_CLASS_P (base1)
1061 || TREE_CODE (base2) == SSA_NAME
1062 || TREE_CODE (base2) == CONST_DECL
1063 || TREE_CODE (base2) == CONSTRUCTOR
1064 || TREE_CODE (base2) == ADDR_EXPR
1065 || CONSTANT_CLASS_P (base2))
1066 return false;
1068 /* We can end up refering to code via function and label decls.
1069 As we likely do not properly track code aliases conservatively
1070 bail out. */
1071 if (TREE_CODE (base1) == FUNCTION_DECL
1072 || TREE_CODE (base1) == LABEL_DECL
1073 || TREE_CODE (base2) == FUNCTION_DECL
1074 || TREE_CODE (base2) == LABEL_DECL)
1075 return true;
1077 /* Defer to simple offset based disambiguation if we have
1078 references based on two decls. Do this before defering to
1079 TBAA to handle must-alias cases in conformance with the
1080 GCC extension of allowing type-punning through unions. */
1081 var1_p = SSA_VAR_P (base1);
1082 var2_p = SSA_VAR_P (base2);
1083 if (var1_p && var2_p)
1084 return decl_refs_may_alias_p (base1, offset1, max_size1,
1085 base2, offset2, max_size2);
1087 ind1_p = (INDIRECT_REF_P (base1)
1088 || (TREE_CODE (base1) == MEM_REF)
1089 || (TREE_CODE (base1) == TARGET_MEM_REF));
1090 ind2_p = (INDIRECT_REF_P (base2)
1091 || (TREE_CODE (base2) == MEM_REF)
1092 || (TREE_CODE (base2) == TARGET_MEM_REF));
1094 /* Canonicalize the pointer-vs-decl case. */
1095 if (ind1_p && var2_p)
1097 HOST_WIDE_INT tmp1;
1098 tree tmp2;
1099 ao_ref *tmp3;
1100 tmp1 = offset1; offset1 = offset2; offset2 = tmp1;
1101 tmp1 = max_size1; max_size1 = max_size2; max_size2 = tmp1;
1102 tmp2 = base1; base1 = base2; base2 = tmp2;
1103 tmp3 = ref1; ref1 = ref2; ref2 = tmp3;
1104 var1_p = true;
1105 ind1_p = false;
1106 var2_p = false;
1107 ind2_p = true;
1110 /* First defer to TBAA if possible. */
1111 if (tbaa_p
1112 && flag_strict_aliasing
1113 && !alias_sets_conflict_p (ao_ref_alias_set (ref1),
1114 ao_ref_alias_set (ref2)))
1115 return false;
1117 /* Dispatch to the pointer-vs-decl or pointer-vs-pointer disambiguators. */
1118 if (var1_p && ind2_p)
1119 return indirect_ref_may_alias_decl_p (ref2->ref, base2,
1120 offset2, max_size2,
1121 ao_ref_alias_set (ref2), -1,
1122 ref1->ref, base1,
1123 offset1, max_size1,
1124 ao_ref_alias_set (ref1),
1125 ao_ref_base_alias_set (ref1),
1126 tbaa_p);
1127 else if (ind1_p && ind2_p)
1128 return indirect_refs_may_alias_p (ref1->ref, base1,
1129 offset1, max_size1,
1130 ao_ref_alias_set (ref1), -1,
1131 ref2->ref, base2,
1132 offset2, max_size2,
1133 ao_ref_alias_set (ref2), -1,
1134 tbaa_p);
1136 /* We really do not want to end up here, but returning true is safe. */
1137 #ifdef ENABLE_CHECKING
1138 gcc_unreachable ();
1139 #else
1140 return true;
1141 #endif
1144 bool
1145 refs_may_alias_p (tree ref1, tree ref2)
1147 ao_ref r1, r2;
1148 bool res;
1149 ao_ref_init (&r1, ref1);
1150 ao_ref_init (&r2, ref2);
1151 res = refs_may_alias_p_1 (&r1, &r2, true);
1152 if (res)
1153 ++alias_stats.refs_may_alias_p_may_alias;
1154 else
1155 ++alias_stats.refs_may_alias_p_no_alias;
1156 return res;
1159 /* Returns true if there is a anti-dependence for the STORE that
1160 executes after the LOAD. */
1162 bool
1163 refs_anti_dependent_p (tree load, tree store)
1165 ao_ref r1, r2;
1166 ao_ref_init (&r1, load);
1167 ao_ref_init (&r2, store);
1168 return refs_may_alias_p_1 (&r1, &r2, false);
1171 /* Returns true if there is a output dependence for the stores
1172 STORE1 and STORE2. */
1174 bool
1175 refs_output_dependent_p (tree store1, tree store2)
1177 ao_ref r1, r2;
1178 ao_ref_init (&r1, store1);
1179 ao_ref_init (&r2, store2);
1180 return refs_may_alias_p_1 (&r1, &r2, false);
1183 /* If the call CALL may use the memory reference REF return true,
1184 otherwise return false. */
1186 static bool
1187 ref_maybe_used_by_call_p_1 (gimple call, ao_ref *ref)
1189 tree base, callee;
1190 unsigned i;
1191 int flags = gimple_call_flags (call);
1193 /* Const functions without a static chain do not implicitly use memory. */
1194 if (!gimple_call_chain (call)
1195 && (flags & (ECF_CONST|ECF_NOVOPS)))
1196 goto process_args;
1198 base = ao_ref_base (ref);
1199 if (!base)
1200 return true;
1202 /* If the reference is based on a decl that is not aliased the call
1203 cannot possibly use it. */
1204 if (DECL_P (base)
1205 && !may_be_aliased (base)
1206 /* But local statics can be used through recursion. */
1207 && !is_global_var (base))
1208 goto process_args;
1210 callee = gimple_call_fndecl (call);
1212 /* Handle those builtin functions explicitly that do not act as
1213 escape points. See tree-ssa-structalias.c:find_func_aliases
1214 for the list of builtins we might need to handle here. */
1215 if (callee != NULL_TREE
1216 && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
1217 switch (DECL_FUNCTION_CODE (callee))
1219 /* All the following functions read memory pointed to by
1220 their second argument. strcat/strncat additionally
1221 reads memory pointed to by the first argument. */
1222 case BUILT_IN_STRCAT:
1223 case BUILT_IN_STRNCAT:
1225 ao_ref dref;
1226 ao_ref_init_from_ptr_and_size (&dref,
1227 gimple_call_arg (call, 0),
1228 NULL_TREE);
1229 if (refs_may_alias_p_1 (&dref, ref, false))
1230 return true;
1232 /* FALLTHRU */
1233 case BUILT_IN_STRCPY:
1234 case BUILT_IN_STRNCPY:
1235 case BUILT_IN_MEMCPY:
1236 case BUILT_IN_MEMMOVE:
1237 case BUILT_IN_MEMPCPY:
1238 case BUILT_IN_STPCPY:
1239 case BUILT_IN_STPNCPY:
1241 ao_ref dref;
1242 tree size = NULL_TREE;
1243 if (gimple_call_num_args (call) == 3)
1244 size = gimple_call_arg (call, 2);
1245 ao_ref_init_from_ptr_and_size (&dref,
1246 gimple_call_arg (call, 1),
1247 size);
1248 return refs_may_alias_p_1 (&dref, ref, false);
1250 case BUILT_IN_BCOPY:
1252 ao_ref dref;
1253 tree size = gimple_call_arg (call, 2);
1254 ao_ref_init_from_ptr_and_size (&dref,
1255 gimple_call_arg (call, 0),
1256 size);
1257 return refs_may_alias_p_1 (&dref, ref, false);
1259 /* The following builtins do not read from memory. */
1260 case BUILT_IN_FREE:
1261 case BUILT_IN_MALLOC:
1262 case BUILT_IN_CALLOC:
1263 case BUILT_IN_MEMSET:
1264 case BUILT_IN_FREXP:
1265 case BUILT_IN_FREXPF:
1266 case BUILT_IN_FREXPL:
1267 case BUILT_IN_GAMMA_R:
1268 case BUILT_IN_GAMMAF_R:
1269 case BUILT_IN_GAMMAL_R:
1270 case BUILT_IN_LGAMMA_R:
1271 case BUILT_IN_LGAMMAF_R:
1272 case BUILT_IN_LGAMMAL_R:
1273 case BUILT_IN_MODF:
1274 case BUILT_IN_MODFF:
1275 case BUILT_IN_MODFL:
1276 case BUILT_IN_REMQUO:
1277 case BUILT_IN_REMQUOF:
1278 case BUILT_IN_REMQUOL:
1279 case BUILT_IN_SINCOS:
1280 case BUILT_IN_SINCOSF:
1281 case BUILT_IN_SINCOSL:
1282 return false;
1283 /* __sync_* builtins and some OpenMP builtins act as threading
1284 barriers. */
1285 #undef DEF_SYNC_BUILTIN
1286 #define DEF_SYNC_BUILTIN(ENUM, NAME, TYPE, ATTRS) case ENUM:
1287 #include "sync-builtins.def"
1288 #undef DEF_SYNC_BUILTIN
1289 case BUILT_IN_GOMP_ATOMIC_START:
1290 case BUILT_IN_GOMP_ATOMIC_END:
1291 case BUILT_IN_GOMP_BARRIER:
1292 case BUILT_IN_GOMP_TASKWAIT:
1293 case BUILT_IN_GOMP_CRITICAL_START:
1294 case BUILT_IN_GOMP_CRITICAL_END:
1295 case BUILT_IN_GOMP_CRITICAL_NAME_START:
1296 case BUILT_IN_GOMP_CRITICAL_NAME_END:
1297 case BUILT_IN_GOMP_LOOP_END:
1298 case BUILT_IN_GOMP_ORDERED_START:
1299 case BUILT_IN_GOMP_ORDERED_END:
1300 case BUILT_IN_GOMP_PARALLEL_END:
1301 case BUILT_IN_GOMP_SECTIONS_END:
1302 case BUILT_IN_GOMP_SINGLE_COPY_START:
1303 case BUILT_IN_GOMP_SINGLE_COPY_END:
1304 return true;
1306 default:
1307 /* Fallthru to general call handling. */;
1310 /* Check if base is a global static variable that is not read
1311 by the function. */
1312 if (TREE_CODE (base) == VAR_DECL
1313 && TREE_STATIC (base))
1315 bitmap not_read;
1317 if (callee != NULL_TREE
1318 && (not_read
1319 = ipa_reference_get_not_read_global (cgraph_node (callee)))
1320 && bitmap_bit_p (not_read, DECL_UID (base)))
1321 goto process_args;
1324 /* Check if the base variable is call-used. */
1325 if (DECL_P (base))
1327 if (pt_solution_includes (gimple_call_use_set (call), base))
1328 return true;
1330 else if ((INDIRECT_REF_P (base)
1331 || TREE_CODE (base) == MEM_REF)
1332 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
1334 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0));
1335 if (!pi)
1336 return true;
1338 if (pt_solutions_intersect (gimple_call_use_set (call), &pi->pt))
1339 return true;
1341 else
1342 return true;
1344 /* Inspect call arguments for passed-by-value aliases. */
1345 process_args:
1346 for (i = 0; i < gimple_call_num_args (call); ++i)
1348 tree op = gimple_call_arg (call, i);
1349 int flags = gimple_call_arg_flags (call, i);
1351 if (flags & EAF_UNUSED)
1352 continue;
1354 if (TREE_CODE (op) == WITH_SIZE_EXPR)
1355 op = TREE_OPERAND (op, 0);
1357 if (TREE_CODE (op) != SSA_NAME
1358 && !is_gimple_min_invariant (op))
1360 ao_ref r;
1361 ao_ref_init (&r, op);
1362 if (refs_may_alias_p_1 (&r, ref, true))
1363 return true;
1367 return false;
1370 static bool
1371 ref_maybe_used_by_call_p (gimple call, tree ref)
1373 ao_ref r;
1374 bool res;
1375 ao_ref_init (&r, ref);
1376 res = ref_maybe_used_by_call_p_1 (call, &r);
1377 if (res)
1378 ++alias_stats.ref_maybe_used_by_call_p_may_alias;
1379 else
1380 ++alias_stats.ref_maybe_used_by_call_p_no_alias;
1381 return res;
1385 /* If the statement STMT may use the memory reference REF return
1386 true, otherwise return false. */
1388 bool
1389 ref_maybe_used_by_stmt_p (gimple stmt, tree ref)
1391 if (is_gimple_assign (stmt))
1393 tree rhs;
1395 /* All memory assign statements are single. */
1396 if (!gimple_assign_single_p (stmt))
1397 return false;
1399 rhs = gimple_assign_rhs1 (stmt);
1400 if (is_gimple_reg (rhs)
1401 || is_gimple_min_invariant (rhs)
1402 || gimple_assign_rhs_code (stmt) == CONSTRUCTOR)
1403 return false;
1405 return refs_may_alias_p (rhs, ref);
1407 else if (is_gimple_call (stmt))
1408 return ref_maybe_used_by_call_p (stmt, ref);
1410 return true;
1413 /* If the call in statement CALL may clobber the memory reference REF
1414 return true, otherwise return false. */
1416 static bool
1417 call_may_clobber_ref_p_1 (gimple call, ao_ref *ref)
1419 tree base;
1420 tree callee;
1422 /* If the call is pure or const it cannot clobber anything. */
1423 if (gimple_call_flags (call)
1424 & (ECF_PURE|ECF_CONST|ECF_LOOPING_CONST_OR_PURE|ECF_NOVOPS))
1425 return false;
1427 base = ao_ref_base (ref);
1428 if (!base)
1429 return true;
1431 if (TREE_CODE (base) == SSA_NAME
1432 || CONSTANT_CLASS_P (base))
1433 return false;
1435 /* If the reference is based on a decl that is not aliased the call
1436 cannot possibly clobber it. */
1437 if (DECL_P (base)
1438 && !may_be_aliased (base)
1439 /* But local non-readonly statics can be modified through recursion
1440 or the call may implement a threading barrier which we must
1441 treat as may-def. */
1442 && (TREE_READONLY (base)
1443 || !is_global_var (base)))
1444 return false;
1446 callee = gimple_call_fndecl (call);
1448 /* Handle those builtin functions explicitly that do not act as
1449 escape points. See tree-ssa-structalias.c:find_func_aliases
1450 for the list of builtins we might need to handle here. */
1451 if (callee != NULL_TREE
1452 && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
1453 switch (DECL_FUNCTION_CODE (callee))
1455 /* All the following functions clobber memory pointed to by
1456 their first argument. */
1457 case BUILT_IN_STRCPY:
1458 case BUILT_IN_STRNCPY:
1459 case BUILT_IN_MEMCPY:
1460 case BUILT_IN_MEMMOVE:
1461 case BUILT_IN_MEMPCPY:
1462 case BUILT_IN_STPCPY:
1463 case BUILT_IN_STPNCPY:
1464 case BUILT_IN_STRCAT:
1465 case BUILT_IN_STRNCAT:
1466 case BUILT_IN_MEMSET:
1468 ao_ref dref;
1469 tree size = NULL_TREE;
1470 /* Don't pass in size for strncat, as the maximum size
1471 is strlen (dest) + n + 1 instead of n, resp.
1472 n + 1 at dest + strlen (dest), but strlen (dest) isn't
1473 known. */
1474 if (gimple_call_num_args (call) == 3
1475 && DECL_FUNCTION_CODE (callee) != BUILT_IN_STRNCAT)
1476 size = gimple_call_arg (call, 2);
1477 ao_ref_init_from_ptr_and_size (&dref,
1478 gimple_call_arg (call, 0),
1479 size);
1480 return refs_may_alias_p_1 (&dref, ref, false);
1482 case BUILT_IN_BCOPY:
1484 ao_ref dref;
1485 tree size = gimple_call_arg (call, 2);
1486 ao_ref_init_from_ptr_and_size (&dref,
1487 gimple_call_arg (call, 1),
1488 size);
1489 return refs_may_alias_p_1 (&dref, ref, false);
1491 /* Allocating memory does not have any side-effects apart from
1492 being the definition point for the pointer. */
1493 case BUILT_IN_MALLOC:
1494 case BUILT_IN_CALLOC:
1495 /* Unix98 specifies that errno is set on allocation failure. */
1496 if (flag_errno_math
1497 && targetm.ref_may_alias_errno (ref))
1498 return true;
1499 return false;
1500 /* Freeing memory kills the pointed-to memory. More importantly
1501 the call has to serve as a barrier for moving loads and stores
1502 across it. */
1503 case BUILT_IN_FREE:
1505 tree ptr = gimple_call_arg (call, 0);
1506 return ptr_deref_may_alias_ref_p_1 (ptr, ref);
1508 case BUILT_IN_GAMMA_R:
1509 case BUILT_IN_GAMMAF_R:
1510 case BUILT_IN_GAMMAL_R:
1511 case BUILT_IN_LGAMMA_R:
1512 case BUILT_IN_LGAMMAF_R:
1513 case BUILT_IN_LGAMMAL_R:
1515 tree out = gimple_call_arg (call, 1);
1516 if (ptr_deref_may_alias_ref_p_1 (out, ref))
1517 return true;
1518 if (flag_errno_math)
1519 break;
1520 return false;
1522 case BUILT_IN_FREXP:
1523 case BUILT_IN_FREXPF:
1524 case BUILT_IN_FREXPL:
1525 case BUILT_IN_MODF:
1526 case BUILT_IN_MODFF:
1527 case BUILT_IN_MODFL:
1529 tree out = gimple_call_arg (call, 1);
1530 return ptr_deref_may_alias_ref_p_1 (out, ref);
1532 case BUILT_IN_REMQUO:
1533 case BUILT_IN_REMQUOF:
1534 case BUILT_IN_REMQUOL:
1536 tree out = gimple_call_arg (call, 2);
1537 if (ptr_deref_may_alias_ref_p_1 (out, ref))
1538 return true;
1539 if (flag_errno_math)
1540 break;
1541 return false;
1543 case BUILT_IN_SINCOS:
1544 case BUILT_IN_SINCOSF:
1545 case BUILT_IN_SINCOSL:
1547 tree sin = gimple_call_arg (call, 1);
1548 tree cos = gimple_call_arg (call, 2);
1549 return (ptr_deref_may_alias_ref_p_1 (sin, ref)
1550 || ptr_deref_may_alias_ref_p_1 (cos, ref));
1552 /* __sync_* builtins and some OpenMP builtins act as threading
1553 barriers. */
1554 #undef DEF_SYNC_BUILTIN
1555 #define DEF_SYNC_BUILTIN(ENUM, NAME, TYPE, ATTRS) case ENUM:
1556 #include "sync-builtins.def"
1557 #undef DEF_SYNC_BUILTIN
1558 case BUILT_IN_GOMP_ATOMIC_START:
1559 case BUILT_IN_GOMP_ATOMIC_END:
1560 case BUILT_IN_GOMP_BARRIER:
1561 case BUILT_IN_GOMP_TASKWAIT:
1562 case BUILT_IN_GOMP_CRITICAL_START:
1563 case BUILT_IN_GOMP_CRITICAL_END:
1564 case BUILT_IN_GOMP_CRITICAL_NAME_START:
1565 case BUILT_IN_GOMP_CRITICAL_NAME_END:
1566 case BUILT_IN_GOMP_LOOP_END:
1567 case BUILT_IN_GOMP_ORDERED_START:
1568 case BUILT_IN_GOMP_ORDERED_END:
1569 case BUILT_IN_GOMP_PARALLEL_END:
1570 case BUILT_IN_GOMP_SECTIONS_END:
1571 case BUILT_IN_GOMP_SINGLE_COPY_START:
1572 case BUILT_IN_GOMP_SINGLE_COPY_END:
1573 return true;
1574 default:
1575 /* Fallthru to general call handling. */;
1578 /* Check if base is a global static variable that is not written
1579 by the function. */
1580 if (callee != NULL_TREE
1581 && TREE_CODE (base) == VAR_DECL
1582 && TREE_STATIC (base))
1584 bitmap not_written;
1586 if ((not_written
1587 = ipa_reference_get_not_written_global (cgraph_node (callee)))
1588 && bitmap_bit_p (not_written, DECL_UID (base)))
1589 return false;
1592 /* Check if the base variable is call-clobbered. */
1593 if (DECL_P (base))
1594 return pt_solution_includes (gimple_call_clobber_set (call), base);
1595 else if ((INDIRECT_REF_P (base)
1596 || TREE_CODE (base) == MEM_REF)
1597 && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
1599 struct ptr_info_def *pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0));
1600 if (!pi)
1601 return true;
1603 return pt_solutions_intersect (gimple_call_clobber_set (call), &pi->pt);
1606 return true;
1609 /* If the call in statement CALL may clobber the memory reference REF
1610 return true, otherwise return false. */
1612 bool
1613 call_may_clobber_ref_p (gimple call, tree ref)
1615 bool res;
1616 ao_ref r;
1617 ao_ref_init (&r, ref);
1618 res = call_may_clobber_ref_p_1 (call, &r);
1619 if (res)
1620 ++alias_stats.call_may_clobber_ref_p_may_alias;
1621 else
1622 ++alias_stats.call_may_clobber_ref_p_no_alias;
1623 return res;
1627 /* If the statement STMT may clobber the memory reference REF return true,
1628 otherwise return false. */
1630 bool
1631 stmt_may_clobber_ref_p_1 (gimple stmt, ao_ref *ref)
1633 if (is_gimple_call (stmt))
1635 tree lhs = gimple_call_lhs (stmt);
1636 if (lhs
1637 && TREE_CODE (lhs) != SSA_NAME)
1639 ao_ref r;
1640 ao_ref_init (&r, lhs);
1641 if (refs_may_alias_p_1 (ref, &r, true))
1642 return true;
1645 return call_may_clobber_ref_p_1 (stmt, ref);
1647 else if (gimple_assign_single_p (stmt))
1649 tree lhs = gimple_assign_lhs (stmt);
1650 if (TREE_CODE (lhs) != SSA_NAME)
1652 ao_ref r;
1653 ao_ref_init (&r, lhs);
1654 return refs_may_alias_p_1 (ref, &r, true);
1657 else if (gimple_code (stmt) == GIMPLE_ASM)
1658 return true;
1660 return false;
1663 bool
1664 stmt_may_clobber_ref_p (gimple stmt, tree ref)
1666 ao_ref r;
1667 ao_ref_init (&r, ref);
1668 return stmt_may_clobber_ref_p_1 (stmt, &r);
1671 /* If STMT kills the memory reference REF return true, otherwise
1672 return false. */
1674 static bool
1675 stmt_kills_ref_p_1 (gimple stmt, ao_ref *ref)
1677 if (gimple_has_lhs (stmt)
1678 && TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME
1679 /* The assignment is not necessarily carried out if it can throw
1680 and we can catch it in the current function where we could inspect
1681 the previous value.
1682 ??? We only need to care about the RHS throwing. For aggregate
1683 assignments or similar calls and non-call exceptions the LHS
1684 might throw as well. */
1685 && !stmt_can_throw_internal (stmt))
1687 tree base, lhs = gimple_get_lhs (stmt);
1688 HOST_WIDE_INT size, offset, max_size;
1689 ao_ref_base (ref);
1690 base = get_ref_base_and_extent (lhs, &offset, &size, &max_size);
1691 /* We can get MEM[symbol: sZ, index: D.8862_1] here,
1692 so base == ref->base does not always hold. */
1693 if (base == ref->base)
1695 /* For a must-alias check we need to be able to constrain
1696 the accesses properly. */
1697 if (size != -1 && size == max_size
1698 && ref->max_size != -1)
1700 if (offset <= ref->offset
1701 && offset + size >= ref->offset + ref->max_size)
1702 return true;
1706 return false;
1709 bool
1710 stmt_kills_ref_p (gimple stmt, tree ref)
1712 ao_ref r;
1713 ao_ref_init (&r, ref);
1714 return stmt_kills_ref_p_1 (stmt, &r);
1718 /* Walk the virtual use-def chain of VUSE until hitting the virtual operand
1719 TARGET or a statement clobbering the memory reference REF in which
1720 case false is returned. The walk starts with VUSE, one argument of PHI. */
1722 static bool
1723 maybe_skip_until (gimple phi, tree target, ao_ref *ref,
1724 tree vuse, bitmap *visited)
1726 if (!*visited)
1727 *visited = BITMAP_ALLOC (NULL);
1729 bitmap_set_bit (*visited, SSA_NAME_VERSION (PHI_RESULT (phi)));
1731 /* Walk until we hit the target. */
1732 while (vuse != target)
1734 gimple def_stmt = SSA_NAME_DEF_STMT (vuse);
1735 /* Recurse for PHI nodes. */
1736 if (gimple_code (def_stmt) == GIMPLE_PHI)
1738 /* An already visited PHI node ends the walk successfully. */
1739 if (bitmap_bit_p (*visited, SSA_NAME_VERSION (PHI_RESULT (def_stmt))))
1740 return true;
1741 vuse = get_continuation_for_phi (def_stmt, ref, visited);
1742 if (!vuse)
1743 return false;
1744 continue;
1746 /* A clobbering statement or the end of the IL ends it failing. */
1747 else if (gimple_nop_p (def_stmt)
1748 || stmt_may_clobber_ref_p_1 (def_stmt, ref))
1749 return false;
1750 vuse = gimple_vuse (def_stmt);
1752 return true;
1755 /* Starting from a PHI node for the virtual operand of the memory reference
1756 REF find a continuation virtual operand that allows to continue walking
1757 statements dominating PHI skipping only statements that cannot possibly
1758 clobber REF. Returns NULL_TREE if no suitable virtual operand can
1759 be found. */
1761 tree
1762 get_continuation_for_phi (gimple phi, ao_ref *ref, bitmap *visited)
1764 unsigned nargs = gimple_phi_num_args (phi);
1766 /* Through a single-argument PHI we can simply look through. */
1767 if (nargs == 1)
1768 return PHI_ARG_DEF (phi, 0);
1770 /* For two arguments try to skip non-aliasing code until we hit
1771 the phi argument definition that dominates the other one. */
1772 if (nargs == 2)
1774 tree arg0 = PHI_ARG_DEF (phi, 0);
1775 tree arg1 = PHI_ARG_DEF (phi, 1);
1776 gimple def0 = SSA_NAME_DEF_STMT (arg0);
1777 gimple def1 = SSA_NAME_DEF_STMT (arg1);
1778 tree common_vuse;
1780 if (arg0 == arg1)
1781 return arg0;
1782 else if (gimple_nop_p (def0)
1783 || (!gimple_nop_p (def1)
1784 && dominated_by_p (CDI_DOMINATORS,
1785 gimple_bb (def1), gimple_bb (def0))))
1787 if (maybe_skip_until (phi, arg0, ref, arg1, visited))
1788 return arg0;
1790 else if (gimple_nop_p (def1)
1791 || dominated_by_p (CDI_DOMINATORS,
1792 gimple_bb (def0), gimple_bb (def1)))
1794 if (maybe_skip_until (phi, arg1, ref, arg0, visited))
1795 return arg1;
1797 /* Special case of a diamond:
1798 MEM_1 = ...
1799 goto (cond) ? L1 : L2
1800 L1: store1 = ... #MEM_2 = vuse(MEM_1)
1801 goto L3
1802 L2: store2 = ... #MEM_3 = vuse(MEM_1)
1803 L3: MEM_4 = PHI<MEM_2, MEM_3>
1804 We were called with the PHI at L3, MEM_2 and MEM_3 don't
1805 dominate each other, but still we can easily skip this PHI node
1806 if we recognize that the vuse MEM operand is the same for both,
1807 and that we can skip both statements (they don't clobber us).
1808 This is still linear. Don't use maybe_skip_until, that might
1809 potentially be slow. */
1810 else if ((common_vuse = gimple_vuse (def0))
1811 && common_vuse == gimple_vuse (def1))
1813 if (!stmt_may_clobber_ref_p_1 (def0, ref)
1814 && !stmt_may_clobber_ref_p_1 (def1, ref))
1815 return common_vuse;
1819 return NULL_TREE;
1822 /* Based on the memory reference REF and its virtual use VUSE call
1823 WALKER for each virtual use that is equivalent to VUSE, including VUSE
1824 itself. That is, for each virtual use for which its defining statement
1825 does not clobber REF.
1827 WALKER is called with REF, the current virtual use and DATA. If
1828 WALKER returns non-NULL the walk stops and its result is returned.
1829 At the end of a non-successful walk NULL is returned.
1831 TRANSLATE if non-NULL is called with a pointer to REF, the virtual
1832 use which definition is a statement that may clobber REF and DATA.
1833 If TRANSLATE returns (void *)-1 the walk stops and NULL is returned.
1834 If TRANSLATE returns non-NULL the walk stops and its result is returned.
1835 If TRANSLATE returns NULL the walk continues and TRANSLATE is supposed
1836 to adjust REF and *DATA to make that valid.
1838 TODO: Cache the vector of equivalent vuses per ref, vuse pair. */
1840 void *
1841 walk_non_aliased_vuses (ao_ref *ref, tree vuse,
1842 void *(*walker)(ao_ref *, tree, void *),
1843 void *(*translate)(ao_ref *, tree, void *), void *data)
1845 bitmap visited = NULL;
1846 void *res;
1848 timevar_push (TV_ALIAS_STMT_WALK);
1852 gimple def_stmt;
1854 /* ??? Do we want to account this to TV_ALIAS_STMT_WALK? */
1855 res = (*walker) (ref, vuse, data);
1856 if (res)
1857 break;
1859 def_stmt = SSA_NAME_DEF_STMT (vuse);
1860 if (gimple_nop_p (def_stmt))
1861 break;
1862 else if (gimple_code (def_stmt) == GIMPLE_PHI)
1863 vuse = get_continuation_for_phi (def_stmt, ref, &visited);
1864 else
1866 if (stmt_may_clobber_ref_p_1 (def_stmt, ref))
1868 if (!translate)
1869 break;
1870 res = (*translate) (ref, vuse, data);
1871 /* Failed lookup and translation. */
1872 if (res == (void *)-1)
1874 res = NULL;
1875 break;
1877 /* Lookup succeeded. */
1878 else if (res != NULL)
1879 break;
1880 /* Translation succeeded, continue walking. */
1882 vuse = gimple_vuse (def_stmt);
1885 while (vuse);
1887 if (visited)
1888 BITMAP_FREE (visited);
1890 timevar_pop (TV_ALIAS_STMT_WALK);
1892 return res;
1896 /* Based on the memory reference REF call WALKER for each vdef which
1897 defining statement may clobber REF, starting with VDEF. If REF
1898 is NULL_TREE, each defining statement is visited.
1900 WALKER is called with REF, the current vdef and DATA. If WALKER
1901 returns true the walk is stopped, otherwise it continues.
1903 At PHI nodes walk_aliased_vdefs forks into one walk for reach
1904 PHI argument (but only one walk continues on merge points), the
1905 return value is true if any of the walks was successful.
1907 The function returns the number of statements walked. */
1909 static unsigned int
1910 walk_aliased_vdefs_1 (ao_ref *ref, tree vdef,
1911 bool (*walker)(ao_ref *, tree, void *), void *data,
1912 bitmap *visited, unsigned int cnt)
1916 gimple def_stmt = SSA_NAME_DEF_STMT (vdef);
1918 if (*visited
1919 && !bitmap_set_bit (*visited, SSA_NAME_VERSION (vdef)))
1920 return cnt;
1922 if (gimple_nop_p (def_stmt))
1923 return cnt;
1924 else if (gimple_code (def_stmt) == GIMPLE_PHI)
1926 unsigned i;
1927 if (!*visited)
1928 *visited = BITMAP_ALLOC (NULL);
1929 for (i = 0; i < gimple_phi_num_args (def_stmt); ++i)
1930 cnt += walk_aliased_vdefs_1 (ref, gimple_phi_arg_def (def_stmt, i),
1931 walker, data, visited, 0);
1932 return cnt;
1935 /* ??? Do we want to account this to TV_ALIAS_STMT_WALK? */
1936 cnt++;
1937 if ((!ref
1938 || stmt_may_clobber_ref_p_1 (def_stmt, ref))
1939 && (*walker) (ref, vdef, data))
1940 return cnt;
1942 vdef = gimple_vuse (def_stmt);
1944 while (1);
1947 unsigned int
1948 walk_aliased_vdefs (ao_ref *ref, tree vdef,
1949 bool (*walker)(ao_ref *, tree, void *), void *data,
1950 bitmap *visited)
1952 bitmap local_visited = NULL;
1953 unsigned int ret;
1955 timevar_push (TV_ALIAS_STMT_WALK);
1957 ret = walk_aliased_vdefs_1 (ref, vdef, walker, data,
1958 visited ? visited : &local_visited, 0);
1959 if (local_visited)
1960 BITMAP_FREE (local_visited);
1962 timevar_pop (TV_ALIAS_STMT_WALK);
1964 return ret;