1 /* Alias analysis for GNU C
2 Copyright (C) 1997-2013 Free Software Foundation, Inc.
3 Contributed by John Carr (jfc@mit.edu).
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
32 #include "hard-reg-set.h"
33 #include "basic-block.h"
35 #include "diagnostic-core.h"
37 #include "splay-tree.h"
39 #include "langhooks.h"
44 #include "tree-ssa-alias.h"
45 #include "pointer-set.h"
47 #include "gimple-ssa.h"
49 /* The aliasing API provided here solves related but different problems:
51 Say there exists (in c)
65 Consider the four questions:
67 Can a store to x1 interfere with px2->y1?
68 Can a store to x1 interfere with px2->z2?
69 Can a store to x1 change the value pointed to by with py?
70 Can a store to x1 change the value pointed to by with pz?
72 The answer to these questions can be yes, yes, yes, and maybe.
74 The first two questions can be answered with a simple examination
75 of the type system. If structure X contains a field of type Y then
76 a store through a pointer to an X can overwrite any field that is
77 contained (recursively) in an X (unless we know that px1 != px2).
79 The last two questions can be solved in the same way as the first
80 two questions but this is too conservative. The observation is
81 that in some cases we can know which (if any) fields are addressed
82 and if those addresses are used in bad ways. This analysis may be
83 language specific. In C, arbitrary operations may be applied to
84 pointers. However, there is some indication that this may be too
85 conservative for some C++ types.
87 The pass ipa-type-escape does this analysis for the types whose
88 instances do not escape across the compilation boundary.
90 Historically in GCC, these two problems were combined and a single
91 data structure that was used to represent the solution to these
92 problems. We now have two similar but different data structures,
93 The data structure to solve the last two questions is similar to
94 the first, but does not contain the fields whose address are never
95 taken. For types that do escape the compilation unit, the data
96 structures will have identical information.
99 /* The alias sets assigned to MEMs assist the back-end in determining
100 which MEMs can alias which other MEMs. In general, two MEMs in
101 different alias sets cannot alias each other, with one important
102 exception. Consider something like:
104 struct S { int i; double d; };
106 a store to an `S' can alias something of either type `int' or type
107 `double'. (However, a store to an `int' cannot alias a `double'
108 and vice versa.) We indicate this via a tree structure that looks
116 (The arrows are directed and point downwards.)
117 In this situation we say the alias set for `struct S' is the
118 `superset' and that those for `int' and `double' are `subsets'.
120 To see whether two alias sets can point to the same memory, we must
121 see if either alias set is a subset of the other. We need not trace
122 past immediate descendants, however, since we propagate all
123 grandchildren up one level.
125 Alias set zero is implicitly a superset of all other alias sets.
126 However, this is no actual entry for alias set zero. It is an
127 error to attempt to explicitly construct a subset of zero. */
129 struct GTY(()) alias_set_entry_d
{
130 /* The alias set number, as stored in MEM_ALIAS_SET. */
131 alias_set_type alias_set
;
133 /* Nonzero if would have a child of zero: this effectively makes this
134 alias set the same as alias set zero. */
137 /* The children of the alias set. These are not just the immediate
138 children, but, in fact, all descendants. So, if we have:
140 struct T { struct S s; float f; }
142 continuing our example above, the children here will be all of
143 `int', `double', `float', and `struct S'. */
144 splay_tree
GTY((param1_is (int), param2_is (int))) children
;
146 typedef struct alias_set_entry_d
*alias_set_entry
;
148 static int rtx_equal_for_memref_p (const_rtx
, const_rtx
);
149 static int memrefs_conflict_p (int, rtx
, int, rtx
, HOST_WIDE_INT
);
150 static void record_set (rtx
, const_rtx
, void *);
151 static int base_alias_check (rtx
, rtx
, rtx
, rtx
, enum machine_mode
,
153 static rtx
find_base_value (rtx
);
154 static int mems_in_disjoint_alias_sets_p (const_rtx
, const_rtx
);
155 static int insert_subset_children (splay_tree_node
, void*);
156 static alias_set_entry
get_alias_set_entry (alias_set_type
);
157 static bool nonoverlapping_component_refs_p (const_rtx
, const_rtx
);
158 static tree
decl_for_component_ref (tree
);
159 static int write_dependence_p (const_rtx
,
160 const_rtx
, enum machine_mode
, rtx
,
163 static void memory_modified_1 (rtx
, const_rtx
, void *);
165 /* Set up all info needed to perform alias analysis on memory references. */
167 /* Returns the size in bytes of the mode of X. */
168 #define SIZE_FOR_MODE(X) (GET_MODE_SIZE (GET_MODE (X)))
170 /* Cap the number of passes we make over the insns propagating alias
171 information through set chains.
172 ??? 10 is a completely arbitrary choice. This should be based on the
173 maximum loop depth in the CFG, but we do not have this information
174 available (even if current_loops _is_ available). */
175 #define MAX_ALIAS_LOOP_PASSES 10
177 /* reg_base_value[N] gives an address to which register N is related.
178 If all sets after the first add or subtract to the current value
179 or otherwise modify it so it does not point to a different top level
180 object, reg_base_value[N] is equal to the address part of the source
183 A base address can be an ADDRESS, SYMBOL_REF, or LABEL_REF. ADDRESS
184 expressions represent three types of base:
186 1. incoming arguments. There is just one ADDRESS to represent all
187 arguments, since we do not know at this level whether accesses
188 based on different arguments can alias. The ADDRESS has id 0.
190 2. stack_pointer_rtx, frame_pointer_rtx, hard_frame_pointer_rtx
191 (if distinct from frame_pointer_rtx) and arg_pointer_rtx.
192 Each of these rtxes has a separate ADDRESS associated with it,
193 each with a negative id.
195 GCC is (and is required to be) precise in which register it
196 chooses to access a particular region of stack. We can therefore
197 assume that accesses based on one of these rtxes do not alias
198 accesses based on another of these rtxes.
200 3. bases that are derived from malloc()ed memory (REG_NOALIAS).
201 Each such piece of memory has a separate ADDRESS associated
202 with it, each with an id greater than 0.
204 Accesses based on one ADDRESS do not alias accesses based on other
205 ADDRESSes. Accesses based on ADDRESSes in groups (2) and (3) do not
206 alias globals either; the ADDRESSes have Pmode to indicate this.
207 The ADDRESS in group (1) _may_ alias globals; it has VOIDmode to
210 static GTY(()) vec
<rtx
, va_gc
> *reg_base_value
;
211 static rtx
*new_reg_base_value
;
213 /* The single VOIDmode ADDRESS that represents all argument bases.
215 static GTY(()) rtx arg_base_value
;
217 /* Used to allocate unique ids to each REG_NOALIAS ADDRESS. */
218 static int unique_id
;
220 /* We preserve the copy of old array around to avoid amount of garbage
221 produced. About 8% of garbage produced were attributed to this
223 static GTY((deletable
)) vec
<rtx
, va_gc
> *old_reg_base_value
;
225 /* Values of XINT (address, 0) of Pmode ADDRESS rtxes for special
227 #define UNIQUE_BASE_VALUE_SP -1
228 #define UNIQUE_BASE_VALUE_ARGP -2
229 #define UNIQUE_BASE_VALUE_FP -3
230 #define UNIQUE_BASE_VALUE_HFP -4
232 #define static_reg_base_value \
233 (this_target_rtl->x_static_reg_base_value)
235 #define REG_BASE_VALUE(X) \
236 (REGNO (X) < vec_safe_length (reg_base_value) \
237 ? (*reg_base_value)[REGNO (X)] : 0)
239 /* Vector indexed by N giving the initial (unchanging) value known for
240 pseudo-register N. This vector is initialized in init_alias_analysis,
241 and does not change until end_alias_analysis is called. */
242 static GTY(()) vec
<rtx
, va_gc
> *reg_known_value
;
244 /* Vector recording for each reg_known_value whether it is due to a
245 REG_EQUIV note. Future passes (viz., reload) may replace the
246 pseudo with the equivalent expression and so we account for the
247 dependences that would be introduced if that happens.
249 The REG_EQUIV notes created in assign_parms may mention the arg
250 pointer, and there are explicit insns in the RTL that modify the
251 arg pointer. Thus we must ensure that such insns don't get
252 scheduled across each other because that would invalidate the
253 REG_EQUIV notes. One could argue that the REG_EQUIV notes are
254 wrong, but solving the problem in the scheduler will likely give
255 better code, so we do it here. */
256 static sbitmap reg_known_equiv_p
;
258 /* True when scanning insns from the start of the rtl to the
259 NOTE_INSN_FUNCTION_BEG note. */
260 static bool copying_arguments
;
263 /* The splay-tree used to store the various alias set entries. */
264 static GTY (()) vec
<alias_set_entry
, va_gc
> *alias_sets
;
266 /* Build a decomposed reference object for querying the alias-oracle
267 from the MEM rtx and store it in *REF.
268 Returns false if MEM is not suitable for the alias-oracle. */
271 ao_ref_from_mem (ao_ref
*ref
, const_rtx mem
)
273 tree expr
= MEM_EXPR (mem
);
279 ao_ref_init (ref
, expr
);
281 /* Get the base of the reference and see if we have to reject or
283 base
= ao_ref_base (ref
);
284 if (base
== NULL_TREE
)
287 /* The tree oracle doesn't like bases that are neither decls
288 nor indirect references of SSA names. */
290 || (TREE_CODE (base
) == MEM_REF
291 && TREE_CODE (TREE_OPERAND (base
, 0)) == SSA_NAME
)
292 || (TREE_CODE (base
) == TARGET_MEM_REF
293 && TREE_CODE (TMR_BASE (base
)) == SSA_NAME
)))
296 /* If this is a reference based on a partitioned decl replace the
297 base with a MEM_REF of the pointer representative we
298 created during stack slot partitioning. */
299 if (TREE_CODE (base
) == VAR_DECL
300 && ! is_global_var (base
)
301 && cfun
->gimple_df
->decls_to_pointers
!= NULL
)
304 namep
= pointer_map_contains (cfun
->gimple_df
->decls_to_pointers
, base
);
306 ref
->base
= build_simple_mem_ref (*(tree
*)namep
);
309 ref
->ref_alias_set
= MEM_ALIAS_SET (mem
);
311 /* If MEM_OFFSET or MEM_SIZE are unknown what we got from MEM_EXPR
312 is conservative, so trust it. */
313 if (!MEM_OFFSET_KNOWN_P (mem
)
314 || !MEM_SIZE_KNOWN_P (mem
))
317 /* If the base decl is a parameter we can have negative MEM_OFFSET in
318 case of promoted subregs on bigendian targets. Trust the MEM_EXPR
320 if (MEM_OFFSET (mem
) < 0
321 && (MEM_SIZE (mem
) + MEM_OFFSET (mem
)) * BITS_PER_UNIT
== ref
->size
)
324 /* Otherwise continue and refine size and offset we got from analyzing
325 MEM_EXPR by using MEM_SIZE and MEM_OFFSET. */
327 ref
->offset
+= MEM_OFFSET (mem
) * BITS_PER_UNIT
;
328 ref
->size
= MEM_SIZE (mem
) * BITS_PER_UNIT
;
330 /* The MEM may extend into adjacent fields, so adjust max_size if
332 if (ref
->max_size
!= -1
333 && ref
->size
> ref
->max_size
)
334 ref
->max_size
= ref
->size
;
336 /* If MEM_OFFSET and MEM_SIZE get us outside of the base object of
337 the MEM_EXPR punt. This happens for STRICT_ALIGNMENT targets a lot. */
338 if (MEM_EXPR (mem
) != get_spill_slot_decl (false)
340 || (DECL_P (ref
->base
)
341 && (!tree_fits_uhwi_p (DECL_SIZE (ref
->base
))
342 || (TREE_INT_CST_LOW (DECL_SIZE ((ref
->base
)))
343 < (unsigned HOST_WIDE_INT
)(ref
->offset
+ ref
->size
))))))
349 /* Query the alias-oracle on whether the two memory rtx X and MEM may
350 alias. If TBAA_P is set also apply TBAA. Returns true if the
351 two rtxen may alias, false otherwise. */
354 rtx_refs_may_alias_p (const_rtx x
, const_rtx mem
, bool tbaa_p
)
358 if (!ao_ref_from_mem (&ref1
, x
)
359 || !ao_ref_from_mem (&ref2
, mem
))
362 return refs_may_alias_p_1 (&ref1
, &ref2
,
364 && MEM_ALIAS_SET (x
) != 0
365 && MEM_ALIAS_SET (mem
) != 0);
368 /* Returns a pointer to the alias set entry for ALIAS_SET, if there is
369 such an entry, or NULL otherwise. */
371 static inline alias_set_entry
372 get_alias_set_entry (alias_set_type alias_set
)
374 return (*alias_sets
)[alias_set
];
377 /* Returns nonzero if the alias sets for MEM1 and MEM2 are such that
378 the two MEMs cannot alias each other. */
381 mems_in_disjoint_alias_sets_p (const_rtx mem1
, const_rtx mem2
)
383 /* Perform a basic sanity check. Namely, that there are no alias sets
384 if we're not using strict aliasing. This helps to catch bugs
385 whereby someone uses PUT_CODE, but doesn't clear MEM_ALIAS_SET, or
386 where a MEM is allocated in some way other than by the use of
387 gen_rtx_MEM, and the MEM_ALIAS_SET is not cleared. If we begin to
388 use alias sets to indicate that spilled registers cannot alias each
389 other, we might need to remove this check. */
390 gcc_assert (flag_strict_aliasing
391 || (!MEM_ALIAS_SET (mem1
) && !MEM_ALIAS_SET (mem2
)));
393 return ! alias_sets_conflict_p (MEM_ALIAS_SET (mem1
), MEM_ALIAS_SET (mem2
));
396 /* Insert the NODE into the splay tree given by DATA. Used by
397 record_alias_subset via splay_tree_foreach. */
400 insert_subset_children (splay_tree_node node
, void *data
)
402 splay_tree_insert ((splay_tree
) data
, node
->key
, node
->value
);
407 /* Return true if the first alias set is a subset of the second. */
410 alias_set_subset_of (alias_set_type set1
, alias_set_type set2
)
414 /* Everything is a subset of the "aliases everything" set. */
418 /* Otherwise, check if set1 is a subset of set2. */
419 ase
= get_alias_set_entry (set2
);
421 && (ase
->has_zero_child
422 || splay_tree_lookup (ase
->children
,
423 (splay_tree_key
) set1
)))
428 /* Return 1 if the two specified alias sets may conflict. */
431 alias_sets_conflict_p (alias_set_type set1
, alias_set_type set2
)
436 if (alias_sets_must_conflict_p (set1
, set2
))
439 /* See if the first alias set is a subset of the second. */
440 ase
= get_alias_set_entry (set1
);
442 && (ase
->has_zero_child
443 || splay_tree_lookup (ase
->children
,
444 (splay_tree_key
) set2
)))
447 /* Now do the same, but with the alias sets reversed. */
448 ase
= get_alias_set_entry (set2
);
450 && (ase
->has_zero_child
451 || splay_tree_lookup (ase
->children
,
452 (splay_tree_key
) set1
)))
455 /* The two alias sets are distinct and neither one is the
456 child of the other. Therefore, they cannot conflict. */
460 /* Return 1 if the two specified alias sets will always conflict. */
463 alias_sets_must_conflict_p (alias_set_type set1
, alias_set_type set2
)
465 if (set1
== 0 || set2
== 0 || set1
== set2
)
471 /* Return 1 if any MEM object of type T1 will always conflict (using the
472 dependency routines in this file) with any MEM object of type T2.
473 This is used when allocating temporary storage. If T1 and/or T2 are
474 NULL_TREE, it means we know nothing about the storage. */
477 objects_must_conflict_p (tree t1
, tree t2
)
479 alias_set_type set1
, set2
;
481 /* If neither has a type specified, we don't know if they'll conflict
482 because we may be using them to store objects of various types, for
483 example the argument and local variables areas of inlined functions. */
484 if (t1
== 0 && t2
== 0)
487 /* If they are the same type, they must conflict. */
489 /* Likewise if both are volatile. */
490 || (t1
!= 0 && TYPE_VOLATILE (t1
) && t2
!= 0 && TYPE_VOLATILE (t2
)))
493 set1
= t1
? get_alias_set (t1
) : 0;
494 set2
= t2
? get_alias_set (t2
) : 0;
496 /* We can't use alias_sets_conflict_p because we must make sure
497 that every subtype of t1 will conflict with every subtype of
498 t2 for which a pair of subobjects of these respective subtypes
499 overlaps on the stack. */
500 return alias_sets_must_conflict_p (set1
, set2
);
503 /* Return the outermost parent of component present in the chain of
504 component references handled by get_inner_reference in T with the
506 - the component is non-addressable, or
507 - the parent has alias set zero,
508 or NULL_TREE if no such parent exists. In the former cases, the alias
509 set of this parent is the alias set that must be used for T itself. */
512 component_uses_parent_alias_set_from (const_tree t
)
514 const_tree found
= NULL_TREE
;
516 while (handled_component_p (t
))
518 switch (TREE_CODE (t
))
521 if (DECL_NONADDRESSABLE_P (TREE_OPERAND (t
, 1)))
526 case ARRAY_RANGE_REF
:
527 if (TYPE_NONALIASED_COMPONENT (TREE_TYPE (TREE_OPERAND (t
, 0))))
536 case VIEW_CONVERT_EXPR
:
537 /* Bitfields and casts are never addressable. */
545 if (get_alias_set (TREE_TYPE (TREE_OPERAND (t
, 0))) == 0)
548 t
= TREE_OPERAND (t
, 0);
552 return TREE_OPERAND (found
, 0);
558 /* Return whether the pointer-type T effective for aliasing may
559 access everything and thus the reference has to be assigned
563 ref_all_alias_ptr_type_p (const_tree t
)
565 return (TREE_CODE (TREE_TYPE (t
)) == VOID_TYPE
566 || TYPE_REF_CAN_ALIAS_ALL (t
));
569 /* Return the alias set for the memory pointed to by T, which may be
570 either a type or an expression. Return -1 if there is nothing
571 special about dereferencing T. */
573 static alias_set_type
574 get_deref_alias_set_1 (tree t
)
576 /* All we care about is the type. */
580 /* If we have an INDIRECT_REF via a void pointer, we don't
581 know anything about what that might alias. Likewise if the
582 pointer is marked that way. */
583 if (ref_all_alias_ptr_type_p (t
))
589 /* Return the alias set for the memory pointed to by T, which may be
590 either a type or an expression. */
593 get_deref_alias_set (tree t
)
595 /* If we're not doing any alias analysis, just assume everything
596 aliases everything else. */
597 if (!flag_strict_aliasing
)
600 alias_set_type set
= get_deref_alias_set_1 (t
);
602 /* Fall back to the alias-set of the pointed-to type. */
607 set
= get_alias_set (TREE_TYPE (t
));
613 /* Return the pointer-type relevant for TBAA purposes from the
614 memory reference tree *T or NULL_TREE in which case *T is
615 adjusted to point to the outermost component reference that
616 can be used for assigning an alias set. */
619 reference_alias_ptr_type_1 (tree
*t
)
623 /* Get the base object of the reference. */
625 while (handled_component_p (inner
))
627 /* If there is a VIEW_CONVERT_EXPR in the chain we cannot use
628 the type of any component references that wrap it to
629 determine the alias-set. */
630 if (TREE_CODE (inner
) == VIEW_CONVERT_EXPR
)
631 *t
= TREE_OPERAND (inner
, 0);
632 inner
= TREE_OPERAND (inner
, 0);
635 /* Handle pointer dereferences here, they can override the
637 if (INDIRECT_REF_P (inner
)
638 && ref_all_alias_ptr_type_p (TREE_TYPE (TREE_OPERAND (inner
, 0))))
639 return TREE_TYPE (TREE_OPERAND (inner
, 0));
640 else if (TREE_CODE (inner
) == TARGET_MEM_REF
)
641 return TREE_TYPE (TMR_OFFSET (inner
));
642 else if (TREE_CODE (inner
) == MEM_REF
643 && ref_all_alias_ptr_type_p (TREE_TYPE (TREE_OPERAND (inner
, 1))))
644 return TREE_TYPE (TREE_OPERAND (inner
, 1));
646 /* If the innermost reference is a MEM_REF that has a
647 conversion embedded treat it like a VIEW_CONVERT_EXPR above,
648 using the memory access type for determining the alias-set. */
649 if (TREE_CODE (inner
) == MEM_REF
650 && (TYPE_MAIN_VARIANT (TREE_TYPE (inner
))
652 (TREE_TYPE (TREE_TYPE (TREE_OPERAND (inner
, 1))))))
653 return TREE_TYPE (TREE_OPERAND (inner
, 1));
655 /* Otherwise, pick up the outermost object that we could have
657 tree tem
= component_uses_parent_alias_set_from (*t
);
664 /* Return the pointer-type relevant for TBAA purposes from the
665 gimple memory reference tree T. This is the type to be used for
666 the offset operand of MEM_REF or TARGET_MEM_REF replacements of T
667 and guarantees that get_alias_set will return the same alias
668 set for T and the replacement. */
671 reference_alias_ptr_type (tree t
)
673 tree ptype
= reference_alias_ptr_type_1 (&t
);
674 /* If there is a given pointer type for aliasing purposes, return it. */
675 if (ptype
!= NULL_TREE
)
678 /* Otherwise build one from the outermost component reference we
680 if (TREE_CODE (t
) == MEM_REF
681 || TREE_CODE (t
) == TARGET_MEM_REF
)
682 return TREE_TYPE (TREE_OPERAND (t
, 1));
684 return build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (t
)));
687 /* Return whether the pointer-types T1 and T2 used to determine
688 two alias sets of two references will yield the same answer
689 from get_deref_alias_set. */
692 alias_ptr_types_compatible_p (tree t1
, tree t2
)
694 if (TYPE_MAIN_VARIANT (t1
) == TYPE_MAIN_VARIANT (t2
))
697 if (ref_all_alias_ptr_type_p (t1
)
698 || ref_all_alias_ptr_type_p (t2
))
701 return (TYPE_MAIN_VARIANT (TREE_TYPE (t1
))
702 == TYPE_MAIN_VARIANT (TREE_TYPE (t2
)));
705 /* Return the alias set for T, which may be either a type or an
706 expression. Call language-specific routine for help, if needed. */
709 get_alias_set (tree t
)
713 /* If we're not doing any alias analysis, just assume everything
714 aliases everything else. Also return 0 if this or its type is
716 if (! flag_strict_aliasing
|| t
== error_mark_node
718 && (TREE_TYPE (t
) == 0 || TREE_TYPE (t
) == error_mark_node
)))
721 /* We can be passed either an expression or a type. This and the
722 language-specific routine may make mutually-recursive calls to each other
723 to figure out what to do. At each juncture, we see if this is a tree
724 that the language may need to handle specially. First handle things that
728 /* Give the language a chance to do something with this tree
729 before we look at it. */
731 set
= lang_hooks
.get_alias_set (t
);
735 /* Get the alias pointer-type to use or the outermost object
736 that we could have a pointer to. */
737 tree ptype
= reference_alias_ptr_type_1 (&t
);
739 return get_deref_alias_set (ptype
);
741 /* If we've already determined the alias set for a decl, just return
742 it. This is necessary for C++ anonymous unions, whose component
743 variables don't look like union members (boo!). */
744 if (TREE_CODE (t
) == VAR_DECL
745 && DECL_RTL_SET_P (t
) && MEM_P (DECL_RTL (t
)))
746 return MEM_ALIAS_SET (DECL_RTL (t
));
748 /* Now all we care about is the type. */
752 /* Variant qualifiers don't affect the alias set, so get the main
754 t
= TYPE_MAIN_VARIANT (t
);
756 /* Always use the canonical type as well. If this is a type that
757 requires structural comparisons to identify compatible types
758 use alias set zero. */
759 if (TYPE_STRUCTURAL_EQUALITY_P (t
))
761 /* Allow the language to specify another alias set for this
763 set
= lang_hooks
.get_alias_set (t
);
769 t
= TYPE_CANONICAL (t
);
771 /* The canonical type should not require structural equality checks. */
772 gcc_checking_assert (!TYPE_STRUCTURAL_EQUALITY_P (t
));
774 /* If this is a type with a known alias set, return it. */
775 if (TYPE_ALIAS_SET_KNOWN_P (t
))
776 return TYPE_ALIAS_SET (t
);
778 /* We don't want to set TYPE_ALIAS_SET for incomplete types. */
779 if (!COMPLETE_TYPE_P (t
))
781 /* For arrays with unknown size the conservative answer is the
782 alias set of the element type. */
783 if (TREE_CODE (t
) == ARRAY_TYPE
)
784 return get_alias_set (TREE_TYPE (t
));
786 /* But return zero as a conservative answer for incomplete types. */
790 /* See if the language has special handling for this type. */
791 set
= lang_hooks
.get_alias_set (t
);
795 /* There are no objects of FUNCTION_TYPE, so there's no point in
796 using up an alias set for them. (There are, of course, pointers
797 and references to functions, but that's different.) */
798 else if (TREE_CODE (t
) == FUNCTION_TYPE
|| TREE_CODE (t
) == METHOD_TYPE
)
801 /* Unless the language specifies otherwise, let vector types alias
802 their components. This avoids some nasty type punning issues in
803 normal usage. And indeed lets vectors be treated more like an
805 else if (TREE_CODE (t
) == VECTOR_TYPE
)
806 set
= get_alias_set (TREE_TYPE (t
));
808 /* Unless the language specifies otherwise, treat array types the
809 same as their components. This avoids the asymmetry we get
810 through recording the components. Consider accessing a
811 character(kind=1) through a reference to a character(kind=1)[1:1].
812 Or consider if we want to assign integer(kind=4)[0:D.1387] and
813 integer(kind=4)[4] the same alias set or not.
814 Just be pragmatic here and make sure the array and its element
815 type get the same alias set assigned. */
816 else if (TREE_CODE (t
) == ARRAY_TYPE
&& !TYPE_NONALIASED_COMPONENT (t
))
817 set
= get_alias_set (TREE_TYPE (t
));
819 /* From the former common C and C++ langhook implementation:
821 Unfortunately, there is no canonical form of a pointer type.
822 In particular, if we have `typedef int I', then `int *', and
823 `I *' are different types. So, we have to pick a canonical
824 representative. We do this below.
826 Technically, this approach is actually more conservative that
827 it needs to be. In particular, `const int *' and `int *'
828 should be in different alias sets, according to the C and C++
829 standard, since their types are not the same, and so,
830 technically, an `int **' and `const int **' cannot point at
833 But, the standard is wrong. In particular, this code is
838 const int* const* cipp = ipp;
839 And, it doesn't make sense for that to be legal unless you
840 can dereference IPP and CIPP. So, we ignore cv-qualifiers on
841 the pointed-to types. This issue has been reported to the
844 In addition to the above canonicalization issue, with LTO
845 we should also canonicalize `T (*)[]' to `T *' avoiding
846 alias issues with pointer-to element types and pointer-to
849 Likewise we need to deal with the situation of incomplete
850 pointed-to types and make `*(struct X **)&a' and
851 `*(struct X {} **)&a' alias. Otherwise we will have to
852 guarantee that all pointer-to incomplete type variants
853 will be replaced by pointer-to complete type variants if
856 With LTO the convenient situation of using `void *' to
857 access and store any pointer type will also become
858 more apparent (and `void *' is just another pointer-to
859 incomplete type). Assigning alias-set zero to `void *'
860 and all pointer-to incomplete types is a not appealing
861 solution. Assigning an effective alias-set zero only
862 affecting pointers might be - by recording proper subset
863 relationships of all pointer alias-sets.
865 Pointer-to function types are another grey area which
866 needs caution. Globbing them all into one alias-set
867 or the above effective zero set would work.
869 For now just assign the same alias-set to all pointers.
870 That's simple and avoids all the above problems. */
871 else if (POINTER_TYPE_P (t
)
872 && t
!= ptr_type_node
)
873 set
= get_alias_set (ptr_type_node
);
875 /* Otherwise make a new alias set for this type. */
878 /* Each canonical type gets its own alias set, so canonical types
879 shouldn't form a tree. It doesn't really matter for types
880 we handle specially above, so only check it where it possibly
881 would result in a bogus alias set. */
882 gcc_checking_assert (TYPE_CANONICAL (t
) == t
);
884 set
= new_alias_set ();
887 TYPE_ALIAS_SET (t
) = set
;
889 /* If this is an aggregate type or a complex type, we must record any
890 component aliasing information. */
891 if (AGGREGATE_TYPE_P (t
) || TREE_CODE (t
) == COMPLEX_TYPE
)
892 record_component_aliases (t
);
897 /* Return a brand-new alias set. */
902 if (flag_strict_aliasing
)
905 vec_safe_push (alias_sets
, (alias_set_entry
) 0);
906 vec_safe_push (alias_sets
, (alias_set_entry
) 0);
907 return alias_sets
->length () - 1;
913 /* Indicate that things in SUBSET can alias things in SUPERSET, but that
914 not everything that aliases SUPERSET also aliases SUBSET. For example,
915 in C, a store to an `int' can alias a load of a structure containing an
916 `int', and vice versa. But it can't alias a load of a 'double' member
917 of the same structure. Here, the structure would be the SUPERSET and
918 `int' the SUBSET. This relationship is also described in the comment at
919 the beginning of this file.
921 This function should be called only once per SUPERSET/SUBSET pair.
923 It is illegal for SUPERSET to be zero; everything is implicitly a
924 subset of alias set zero. */
927 record_alias_subset (alias_set_type superset
, alias_set_type subset
)
929 alias_set_entry superset_entry
;
930 alias_set_entry subset_entry
;
932 /* It is possible in complex type situations for both sets to be the same,
933 in which case we can ignore this operation. */
934 if (superset
== subset
)
937 gcc_assert (superset
);
939 superset_entry
= get_alias_set_entry (superset
);
940 if (superset_entry
== 0)
942 /* Create an entry for the SUPERSET, so that we have a place to
943 attach the SUBSET. */
944 superset_entry
= ggc_alloc_cleared_alias_set_entry_d ();
945 superset_entry
->alias_set
= superset
;
946 superset_entry
->children
947 = splay_tree_new_ggc (splay_tree_compare_ints
,
948 ggc_alloc_splay_tree_scalar_scalar_splay_tree_s
,
949 ggc_alloc_splay_tree_scalar_scalar_splay_tree_node_s
);
950 superset_entry
->has_zero_child
= 0;
951 (*alias_sets
)[superset
] = superset_entry
;
955 superset_entry
->has_zero_child
= 1;
958 subset_entry
= get_alias_set_entry (subset
);
959 /* If there is an entry for the subset, enter all of its children
960 (if they are not already present) as children of the SUPERSET. */
963 if (subset_entry
->has_zero_child
)
964 superset_entry
->has_zero_child
= 1;
966 splay_tree_foreach (subset_entry
->children
, insert_subset_children
,
967 superset_entry
->children
);
970 /* Enter the SUBSET itself as a child of the SUPERSET. */
971 splay_tree_insert (superset_entry
->children
,
972 (splay_tree_key
) subset
, 0);
976 /* Record that component types of TYPE, if any, are part of that type for
977 aliasing purposes. For record types, we only record component types
978 for fields that are not marked non-addressable. For array types, we
979 only record the component type if it is not marked non-aliased. */
982 record_component_aliases (tree type
)
984 alias_set_type superset
= get_alias_set (type
);
990 switch (TREE_CODE (type
))
994 case QUAL_UNION_TYPE
:
995 /* Recursively record aliases for the base classes, if there are any. */
996 if (TYPE_BINFO (type
))
999 tree binfo
, base_binfo
;
1001 for (binfo
= TYPE_BINFO (type
), i
= 0;
1002 BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
1003 record_alias_subset (superset
,
1004 get_alias_set (BINFO_TYPE (base_binfo
)));
1006 for (field
= TYPE_FIELDS (type
); field
!= 0; field
= DECL_CHAIN (field
))
1007 if (TREE_CODE (field
) == FIELD_DECL
&& !DECL_NONADDRESSABLE_P (field
))
1008 record_alias_subset (superset
, get_alias_set (TREE_TYPE (field
)));
1012 record_alias_subset (superset
, get_alias_set (TREE_TYPE (type
)));
1015 /* VECTOR_TYPE and ARRAY_TYPE share the alias set with their
1023 /* Allocate an alias set for use in storing and reading from the varargs
1026 static GTY(()) alias_set_type varargs_set
= -1;
1029 get_varargs_alias_set (void)
1032 /* We now lower VA_ARG_EXPR, and there's currently no way to attach the
1033 varargs alias set to an INDIRECT_REF (FIXME!), so we can't
1034 consistently use the varargs alias set for loads from the varargs
1035 area. So don't use it anywhere. */
1038 if (varargs_set
== -1)
1039 varargs_set
= new_alias_set ();
1045 /* Likewise, but used for the fixed portions of the frame, e.g., register
1048 static GTY(()) alias_set_type frame_set
= -1;
1051 get_frame_alias_set (void)
1053 if (frame_set
== -1)
1054 frame_set
= new_alias_set ();
1059 /* Create a new, unique base with id ID. */
1062 unique_base_value (HOST_WIDE_INT id
)
1064 return gen_rtx_ADDRESS (Pmode
, id
);
1067 /* Return true if accesses based on any other base value cannot alias
1068 those based on X. */
1071 unique_base_value_p (rtx x
)
1073 return GET_CODE (x
) == ADDRESS
&& GET_MODE (x
) == Pmode
;
1076 /* Return true if X is known to be a base value. */
1079 known_base_value_p (rtx x
)
1081 switch (GET_CODE (x
))
1088 /* Arguments may or may not be bases; we don't know for sure. */
1089 return GET_MODE (x
) != VOIDmode
;
1096 /* Inside SRC, the source of a SET, find a base address. */
1099 find_base_value (rtx src
)
1103 #if defined (FIND_BASE_TERM)
1104 /* Try machine-dependent ways to find the base term. */
1105 src
= FIND_BASE_TERM (src
);
1108 switch (GET_CODE (src
))
1115 regno
= REGNO (src
);
1116 /* At the start of a function, argument registers have known base
1117 values which may be lost later. Returning an ADDRESS
1118 expression here allows optimization based on argument values
1119 even when the argument registers are used for other purposes. */
1120 if (regno
< FIRST_PSEUDO_REGISTER
&& copying_arguments
)
1121 return new_reg_base_value
[regno
];
1123 /* If a pseudo has a known base value, return it. Do not do this
1124 for non-fixed hard regs since it can result in a circular
1125 dependency chain for registers which have values at function entry.
1127 The test above is not sufficient because the scheduler may move
1128 a copy out of an arg reg past the NOTE_INSN_FUNCTION_BEGIN. */
1129 if ((regno
>= FIRST_PSEUDO_REGISTER
|| fixed_regs
[regno
])
1130 && regno
< vec_safe_length (reg_base_value
))
1132 /* If we're inside init_alias_analysis, use new_reg_base_value
1133 to reduce the number of relaxation iterations. */
1134 if (new_reg_base_value
&& new_reg_base_value
[regno
]
1135 && DF_REG_DEF_COUNT (regno
) == 1)
1136 return new_reg_base_value
[regno
];
1138 if ((*reg_base_value
)[regno
])
1139 return (*reg_base_value
)[regno
];
1145 /* Check for an argument passed in memory. Only record in the
1146 copying-arguments block; it is too hard to track changes
1148 if (copying_arguments
1149 && (XEXP (src
, 0) == arg_pointer_rtx
1150 || (GET_CODE (XEXP (src
, 0)) == PLUS
1151 && XEXP (XEXP (src
, 0), 0) == arg_pointer_rtx
)))
1152 return arg_base_value
;
1156 src
= XEXP (src
, 0);
1157 if (GET_CODE (src
) != PLUS
&& GET_CODE (src
) != MINUS
)
1160 /* ... fall through ... */
1165 rtx temp
, src_0
= XEXP (src
, 0), src_1
= XEXP (src
, 1);
1167 /* If either operand is a REG that is a known pointer, then it
1169 if (REG_P (src_0
) && REG_POINTER (src_0
))
1170 return find_base_value (src_0
);
1171 if (REG_P (src_1
) && REG_POINTER (src_1
))
1172 return find_base_value (src_1
);
1174 /* If either operand is a REG, then see if we already have
1175 a known value for it. */
1178 temp
= find_base_value (src_0
);
1185 temp
= find_base_value (src_1
);
1190 /* If either base is named object or a special address
1191 (like an argument or stack reference), then use it for the
1193 if (src_0
!= 0 && known_base_value_p (src_0
))
1196 if (src_1
!= 0 && known_base_value_p (src_1
))
1199 /* Guess which operand is the base address:
1200 If either operand is a symbol, then it is the base. If
1201 either operand is a CONST_INT, then the other is the base. */
1202 if (CONST_INT_P (src_1
) || CONSTANT_P (src_0
))
1203 return find_base_value (src_0
);
1204 else if (CONST_INT_P (src_0
) || CONSTANT_P (src_1
))
1205 return find_base_value (src_1
);
1211 /* The standard form is (lo_sum reg sym) so look only at the
1213 return find_base_value (XEXP (src
, 1));
1216 /* If the second operand is constant set the base
1217 address to the first operand. */
1218 if (CONST_INT_P (XEXP (src
, 1)) && INTVAL (XEXP (src
, 1)) != 0)
1219 return find_base_value (XEXP (src
, 0));
1223 /* As we do not know which address space the pointer is referring to, we can
1224 handle this only if the target does not support different pointer or
1225 address modes depending on the address space. */
1226 if (!target_default_pointer_address_modes_p ())
1228 if (GET_MODE_SIZE (GET_MODE (src
)) < GET_MODE_SIZE (Pmode
))
1238 return find_base_value (XEXP (src
, 0));
1241 case SIGN_EXTEND
: /* used for NT/Alpha pointers */
1242 /* As we do not know which address space the pointer is referring to, we can
1243 handle this only if the target does not support different pointer or
1244 address modes depending on the address space. */
1245 if (!target_default_pointer_address_modes_p ())
1249 rtx temp
= find_base_value (XEXP (src
, 0));
1251 if (temp
!= 0 && CONSTANT_P (temp
))
1252 temp
= convert_memory_address (Pmode
, temp
);
1264 /* Called from init_alias_analysis indirectly through note_stores,
1265 or directly if DEST is a register with a REG_NOALIAS note attached.
1266 SET is null in the latter case. */
1268 /* While scanning insns to find base values, reg_seen[N] is nonzero if
1269 register N has been set in this function. */
1270 static sbitmap reg_seen
;
1273 record_set (rtx dest
, const_rtx set
, void *data ATTRIBUTE_UNUSED
)
1282 regno
= REGNO (dest
);
1284 gcc_checking_assert (regno
< reg_base_value
->length ());
1286 /* If this spans multiple hard registers, then we must indicate that every
1287 register has an unusable value. */
1288 if (regno
< FIRST_PSEUDO_REGISTER
)
1289 n
= hard_regno_nregs
[regno
][GET_MODE (dest
)];
1296 bitmap_set_bit (reg_seen
, regno
+ n
);
1297 new_reg_base_value
[regno
+ n
] = 0;
1304 /* A CLOBBER wipes out any old value but does not prevent a previously
1305 unset register from acquiring a base address (i.e. reg_seen is not
1307 if (GET_CODE (set
) == CLOBBER
)
1309 new_reg_base_value
[regno
] = 0;
1312 src
= SET_SRC (set
);
1316 /* There's a REG_NOALIAS note against DEST. */
1317 if (bitmap_bit_p (reg_seen
, regno
))
1319 new_reg_base_value
[regno
] = 0;
1322 bitmap_set_bit (reg_seen
, regno
);
1323 new_reg_base_value
[regno
] = unique_base_value (unique_id
++);
1327 /* If this is not the first set of REGNO, see whether the new value
1328 is related to the old one. There are two cases of interest:
1330 (1) The register might be assigned an entirely new value
1331 that has the same base term as the original set.
1333 (2) The set might be a simple self-modification that
1334 cannot change REGNO's base value.
1336 If neither case holds, reject the original base value as invalid.
1337 Note that the following situation is not detected:
1339 extern int x, y; int *p = &x; p += (&y-&x);
1341 ANSI C does not allow computing the difference of addresses
1342 of distinct top level objects. */
1343 if (new_reg_base_value
[regno
] != 0
1344 && find_base_value (src
) != new_reg_base_value
[regno
])
1345 switch (GET_CODE (src
))
1349 if (XEXP (src
, 0) != dest
&& XEXP (src
, 1) != dest
)
1350 new_reg_base_value
[regno
] = 0;
1353 /* If the value we add in the PLUS is also a valid base value,
1354 this might be the actual base value, and the original value
1357 rtx other
= NULL_RTX
;
1359 if (XEXP (src
, 0) == dest
)
1360 other
= XEXP (src
, 1);
1361 else if (XEXP (src
, 1) == dest
)
1362 other
= XEXP (src
, 0);
1364 if (! other
|| find_base_value (other
))
1365 new_reg_base_value
[regno
] = 0;
1369 if (XEXP (src
, 0) != dest
|| !CONST_INT_P (XEXP (src
, 1)))
1370 new_reg_base_value
[regno
] = 0;
1373 new_reg_base_value
[regno
] = 0;
1376 /* If this is the first set of a register, record the value. */
1377 else if ((regno
>= FIRST_PSEUDO_REGISTER
|| ! fixed_regs
[regno
])
1378 && ! bitmap_bit_p (reg_seen
, regno
) && new_reg_base_value
[regno
] == 0)
1379 new_reg_base_value
[regno
] = find_base_value (src
);
1381 bitmap_set_bit (reg_seen
, regno
);
1384 /* Return REG_BASE_VALUE for REGNO. Selective scheduler uses this to avoid
1385 using hard registers with non-null REG_BASE_VALUE for renaming. */
1387 get_reg_base_value (unsigned int regno
)
1389 return (*reg_base_value
)[regno
];
1392 /* If a value is known for REGNO, return it. */
1395 get_reg_known_value (unsigned int regno
)
1397 if (regno
>= FIRST_PSEUDO_REGISTER
)
1399 regno
-= FIRST_PSEUDO_REGISTER
;
1400 if (regno
< vec_safe_length (reg_known_value
))
1401 return (*reg_known_value
)[regno
];
1409 set_reg_known_value (unsigned int regno
, rtx val
)
1411 if (regno
>= FIRST_PSEUDO_REGISTER
)
1413 regno
-= FIRST_PSEUDO_REGISTER
;
1414 if (regno
< vec_safe_length (reg_known_value
))
1415 (*reg_known_value
)[regno
] = val
;
1419 /* Similarly for reg_known_equiv_p. */
1422 get_reg_known_equiv_p (unsigned int regno
)
1424 if (regno
>= FIRST_PSEUDO_REGISTER
)
1426 regno
-= FIRST_PSEUDO_REGISTER
;
1427 if (regno
< vec_safe_length (reg_known_value
))
1428 return bitmap_bit_p (reg_known_equiv_p
, regno
);
1434 set_reg_known_equiv_p (unsigned int regno
, bool val
)
1436 if (regno
>= FIRST_PSEUDO_REGISTER
)
1438 regno
-= FIRST_PSEUDO_REGISTER
;
1439 if (regno
< vec_safe_length (reg_known_value
))
1442 bitmap_set_bit (reg_known_equiv_p
, regno
);
1444 bitmap_clear_bit (reg_known_equiv_p
, regno
);
1450 /* Returns a canonical version of X, from the point of view alias
1451 analysis. (For example, if X is a MEM whose address is a register,
1452 and the register has a known value (say a SYMBOL_REF), then a MEM
1453 whose address is the SYMBOL_REF is returned.) */
1458 /* Recursively look for equivalences. */
1459 if (REG_P (x
) && REGNO (x
) >= FIRST_PSEUDO_REGISTER
)
1461 rtx t
= get_reg_known_value (REGNO (x
));
1465 return canon_rtx (t
);
1468 if (GET_CODE (x
) == PLUS
)
1470 rtx x0
= canon_rtx (XEXP (x
, 0));
1471 rtx x1
= canon_rtx (XEXP (x
, 1));
1473 if (x0
!= XEXP (x
, 0) || x1
!= XEXP (x
, 1))
1475 if (CONST_INT_P (x0
))
1476 return plus_constant (GET_MODE (x
), x1
, INTVAL (x0
));
1477 else if (CONST_INT_P (x1
))
1478 return plus_constant (GET_MODE (x
), x0
, INTVAL (x1
));
1479 return gen_rtx_PLUS (GET_MODE (x
), x0
, x1
);
1483 /* This gives us much better alias analysis when called from
1484 the loop optimizer. Note we want to leave the original
1485 MEM alone, but need to return the canonicalized MEM with
1486 all the flags with their original values. */
1488 x
= replace_equiv_address_nv (x
, canon_rtx (XEXP (x
, 0)));
1493 /* Return 1 if X and Y are identical-looking rtx's.
1494 Expect that X and Y has been already canonicalized.
1496 We use the data in reg_known_value above to see if two registers with
1497 different numbers are, in fact, equivalent. */
1500 rtx_equal_for_memref_p (const_rtx x
, const_rtx y
)
1507 if (x
== 0 && y
== 0)
1509 if (x
== 0 || y
== 0)
1515 code
= GET_CODE (x
);
1516 /* Rtx's of different codes cannot be equal. */
1517 if (code
!= GET_CODE (y
))
1520 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
1521 (REG:SI x) and (REG:HI x) are NOT equivalent. */
1523 if (GET_MODE (x
) != GET_MODE (y
))
1526 /* Some RTL can be compared without a recursive examination. */
1530 return REGNO (x
) == REGNO (y
);
1533 return XEXP (x
, 0) == XEXP (y
, 0);
1536 return XSTR (x
, 0) == XSTR (y
, 0);
1539 /* This is magic, don't go through canonicalization et al. */
1540 return rtx_equal_p (ENTRY_VALUE_EXP (x
), ENTRY_VALUE_EXP (y
));
1544 /* There's no need to compare the contents of CONST_DOUBLEs or
1545 CONST_INTs because pointer equality is a good enough
1546 comparison for these nodes. */
1553 /* canon_rtx knows how to handle plus. No need to canonicalize. */
1555 return ((rtx_equal_for_memref_p (XEXP (x
, 0), XEXP (y
, 0))
1556 && rtx_equal_for_memref_p (XEXP (x
, 1), XEXP (y
, 1)))
1557 || (rtx_equal_for_memref_p (XEXP (x
, 0), XEXP (y
, 1))
1558 && rtx_equal_for_memref_p (XEXP (x
, 1), XEXP (y
, 0))));
1559 /* For commutative operations, the RTX match if the operand match in any
1560 order. Also handle the simple binary and unary cases without a loop. */
1561 if (COMMUTATIVE_P (x
))
1563 rtx xop0
= canon_rtx (XEXP (x
, 0));
1564 rtx yop0
= canon_rtx (XEXP (y
, 0));
1565 rtx yop1
= canon_rtx (XEXP (y
, 1));
1567 return ((rtx_equal_for_memref_p (xop0
, yop0
)
1568 && rtx_equal_for_memref_p (canon_rtx (XEXP (x
, 1)), yop1
))
1569 || (rtx_equal_for_memref_p (xop0
, yop1
)
1570 && rtx_equal_for_memref_p (canon_rtx (XEXP (x
, 1)), yop0
)));
1572 else if (NON_COMMUTATIVE_P (x
))
1574 return (rtx_equal_for_memref_p (canon_rtx (XEXP (x
, 0)),
1575 canon_rtx (XEXP (y
, 0)))
1576 && rtx_equal_for_memref_p (canon_rtx (XEXP (x
, 1)),
1577 canon_rtx (XEXP (y
, 1))));
1579 else if (UNARY_P (x
))
1580 return rtx_equal_for_memref_p (canon_rtx (XEXP (x
, 0)),
1581 canon_rtx (XEXP (y
, 0)));
1583 /* Compare the elements. If any pair of corresponding elements
1584 fail to match, return 0 for the whole things.
1586 Limit cases to types which actually appear in addresses. */
1588 fmt
= GET_RTX_FORMAT (code
);
1589 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1594 if (XINT (x
, i
) != XINT (y
, i
))
1599 /* Two vectors must have the same length. */
1600 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
1603 /* And the corresponding elements must match. */
1604 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1605 if (rtx_equal_for_memref_p (canon_rtx (XVECEXP (x
, i
, j
)),
1606 canon_rtx (XVECEXP (y
, i
, j
))) == 0)
1611 if (rtx_equal_for_memref_p (canon_rtx (XEXP (x
, i
)),
1612 canon_rtx (XEXP (y
, i
))) == 0)
1616 /* This can happen for asm operands. */
1618 if (strcmp (XSTR (x
, i
), XSTR (y
, i
)))
1622 /* This can happen for an asm which clobbers memory. */
1626 /* It is believed that rtx's at this level will never
1627 contain anything but integers and other rtx's,
1628 except for within LABEL_REFs and SYMBOL_REFs. */
1637 find_base_term (rtx x
)
1640 struct elt_loc_list
*l
, *f
;
1643 #if defined (FIND_BASE_TERM)
1644 /* Try machine-dependent ways to find the base term. */
1645 x
= FIND_BASE_TERM (x
);
1648 switch (GET_CODE (x
))
1651 return REG_BASE_VALUE (x
);
1654 /* As we do not know which address space the pointer is referring to, we can
1655 handle this only if the target does not support different pointer or
1656 address modes depending on the address space. */
1657 if (!target_default_pointer_address_modes_p ())
1659 if (GET_MODE_SIZE (GET_MODE (x
)) < GET_MODE_SIZE (Pmode
))
1669 return find_base_term (XEXP (x
, 0));
1672 case SIGN_EXTEND
: /* Used for Alpha/NT pointers */
1673 /* As we do not know which address space the pointer is referring to, we can
1674 handle this only if the target does not support different pointer or
1675 address modes depending on the address space. */
1676 if (!target_default_pointer_address_modes_p ())
1680 rtx temp
= find_base_term (XEXP (x
, 0));
1682 if (temp
!= 0 && CONSTANT_P (temp
))
1683 temp
= convert_memory_address (Pmode
, temp
);
1689 val
= CSELIB_VAL_PTR (x
);
1695 if (cselib_sp_based_value_p (val
))
1696 return static_reg_base_value
[STACK_POINTER_REGNUM
];
1699 /* Temporarily reset val->locs to avoid infinite recursion. */
1702 for (l
= f
; l
; l
= l
->next
)
1703 if (GET_CODE (l
->loc
) == VALUE
1704 && CSELIB_VAL_PTR (l
->loc
)->locs
1705 && !CSELIB_VAL_PTR (l
->loc
)->locs
->next
1706 && CSELIB_VAL_PTR (l
->loc
)->locs
->loc
== x
)
1708 else if ((ret
= find_base_term (l
->loc
)) != 0)
1715 /* The standard form is (lo_sum reg sym) so look only at the
1717 return find_base_term (XEXP (x
, 1));
1721 if (GET_CODE (x
) != PLUS
&& GET_CODE (x
) != MINUS
)
1727 rtx tmp1
= XEXP (x
, 0);
1728 rtx tmp2
= XEXP (x
, 1);
1730 /* This is a little bit tricky since we have to determine which of
1731 the two operands represents the real base address. Otherwise this
1732 routine may return the index register instead of the base register.
1734 That may cause us to believe no aliasing was possible, when in
1735 fact aliasing is possible.
1737 We use a few simple tests to guess the base register. Additional
1738 tests can certainly be added. For example, if one of the operands
1739 is a shift or multiply, then it must be the index register and the
1740 other operand is the base register. */
1742 if (tmp1
== pic_offset_table_rtx
&& CONSTANT_P (tmp2
))
1743 return find_base_term (tmp2
);
1745 /* If either operand is known to be a pointer, then prefer it
1746 to determine the base term. */
1747 if (REG_P (tmp1
) && REG_POINTER (tmp1
))
1749 else if (REG_P (tmp2
) && REG_POINTER (tmp2
))
1756 /* Go ahead and find the base term for both operands. If either base
1757 term is from a pointer or is a named object or a special address
1758 (like an argument or stack reference), then use it for the
1760 rtx base
= find_base_term (tmp1
);
1761 if (base
!= NULL_RTX
1762 && ((REG_P (tmp1
) && REG_POINTER (tmp1
))
1763 || known_base_value_p (base
)))
1765 base
= find_base_term (tmp2
);
1766 if (base
!= NULL_RTX
1767 && ((REG_P (tmp2
) && REG_POINTER (tmp2
))
1768 || known_base_value_p (base
)))
1771 /* We could not determine which of the two operands was the
1772 base register and which was the index. So we can determine
1773 nothing from the base alias check. */
1778 if (CONST_INT_P (XEXP (x
, 1)) && INTVAL (XEXP (x
, 1)) != 0)
1779 return find_base_term (XEXP (x
, 0));
1791 /* Return true if accesses to address X may alias accesses based
1792 on the stack pointer. */
1795 may_be_sp_based_p (rtx x
)
1797 rtx base
= find_base_term (x
);
1798 return !base
|| base
== static_reg_base_value
[STACK_POINTER_REGNUM
];
1801 /* Return 0 if the addresses X and Y are known to point to different
1802 objects, 1 if they might be pointers to the same object. */
1805 base_alias_check (rtx x
, rtx x_base
, rtx y
, rtx y_base
,
1806 enum machine_mode x_mode
, enum machine_mode y_mode
)
1808 /* If the address itself has no known base see if a known equivalent
1809 value has one. If either address still has no known base, nothing
1810 is known about aliasing. */
1815 if (! flag_expensive_optimizations
|| (x_c
= canon_rtx (x
)) == x
)
1818 x_base
= find_base_term (x_c
);
1826 if (! flag_expensive_optimizations
|| (y_c
= canon_rtx (y
)) == y
)
1829 y_base
= find_base_term (y_c
);
1834 /* If the base addresses are equal nothing is known about aliasing. */
1835 if (rtx_equal_p (x_base
, y_base
))
1838 /* The base addresses are different expressions. If they are not accessed
1839 via AND, there is no conflict. We can bring knowledge of object
1840 alignment into play here. For example, on alpha, "char a, b;" can
1841 alias one another, though "char a; long b;" cannot. AND addesses may
1842 implicitly alias surrounding objects; i.e. unaligned access in DImode
1843 via AND address can alias all surrounding object types except those
1844 with aligment 8 or higher. */
1845 if (GET_CODE (x
) == AND
&& GET_CODE (y
) == AND
)
1847 if (GET_CODE (x
) == AND
1848 && (!CONST_INT_P (XEXP (x
, 1))
1849 || (int) GET_MODE_UNIT_SIZE (y_mode
) < -INTVAL (XEXP (x
, 1))))
1851 if (GET_CODE (y
) == AND
1852 && (!CONST_INT_P (XEXP (y
, 1))
1853 || (int) GET_MODE_UNIT_SIZE (x_mode
) < -INTVAL (XEXP (y
, 1))))
1856 /* Differing symbols not accessed via AND never alias. */
1857 if (GET_CODE (x_base
) != ADDRESS
&& GET_CODE (y_base
) != ADDRESS
)
1860 if (unique_base_value_p (x_base
) || unique_base_value_p (y_base
))
1866 /* Callback for for_each_rtx, that returns 1 upon encountering a VALUE
1867 whose UID is greater than the int uid that D points to. */
1870 refs_newer_value_cb (rtx
*x
, void *d
)
1872 if (GET_CODE (*x
) == VALUE
&& CSELIB_VAL_PTR (*x
)->uid
> *(int *)d
)
1878 /* Return TRUE if EXPR refers to a VALUE whose uid is greater than
1882 refs_newer_value_p (rtx expr
, rtx v
)
1884 int minuid
= CSELIB_VAL_PTR (v
)->uid
;
1886 return for_each_rtx (&expr
, refs_newer_value_cb
, &minuid
);
1889 /* Convert the address X into something we can use. This is done by returning
1890 it unchanged unless it is a value; in the latter case we call cselib to get
1891 a more useful rtx. */
1897 struct elt_loc_list
*l
;
1899 if (GET_CODE (x
) != VALUE
)
1901 v
= CSELIB_VAL_PTR (x
);
1904 bool have_equivs
= cselib_have_permanent_equivalences ();
1906 v
= canonical_cselib_val (v
);
1907 for (l
= v
->locs
; l
; l
= l
->next
)
1908 if (CONSTANT_P (l
->loc
))
1910 for (l
= v
->locs
; l
; l
= l
->next
)
1911 if (!REG_P (l
->loc
) && !MEM_P (l
->loc
)
1912 /* Avoid infinite recursion when potentially dealing with
1913 var-tracking artificial equivalences, by skipping the
1914 equivalences themselves, and not choosing expressions
1915 that refer to newer VALUEs. */
1917 || (GET_CODE (l
->loc
) != VALUE
1918 && !refs_newer_value_p (l
->loc
, x
))))
1922 for (l
= v
->locs
; l
; l
= l
->next
)
1924 || (GET_CODE (l
->loc
) != VALUE
1925 && !refs_newer_value_p (l
->loc
, x
)))
1927 /* Return the canonical value. */
1931 return v
->locs
->loc
;
1936 /* Return the address of the (N_REFS + 1)th memory reference to ADDR
1937 where SIZE is the size in bytes of the memory reference. If ADDR
1938 is not modified by the memory reference then ADDR is returned. */
1941 addr_side_effect_eval (rtx addr
, int size
, int n_refs
)
1945 switch (GET_CODE (addr
))
1948 offset
= (n_refs
+ 1) * size
;
1951 offset
= -(n_refs
+ 1) * size
;
1954 offset
= n_refs
* size
;
1957 offset
= -n_refs
* size
;
1965 addr
= gen_rtx_PLUS (GET_MODE (addr
), XEXP (addr
, 0),
1966 gen_int_mode (offset
, GET_MODE (addr
)));
1968 addr
= XEXP (addr
, 0);
1969 addr
= canon_rtx (addr
);
1974 /* Return TRUE if an object X sized at XSIZE bytes and another object
1975 Y sized at YSIZE bytes, starting C bytes after X, may overlap. If
1976 any of the sizes is zero, assume an overlap, otherwise use the
1977 absolute value of the sizes as the actual sizes. */
1980 offset_overlap_p (HOST_WIDE_INT c
, int xsize
, int ysize
)
1982 return (xsize
== 0 || ysize
== 0
1985 : (abs (ysize
) > -c
)));
1988 /* Return one if X and Y (memory addresses) reference the
1989 same location in memory or if the references overlap.
1990 Return zero if they do not overlap, else return
1991 minus one in which case they still might reference the same location.
1993 C is an offset accumulator. When
1994 C is nonzero, we are testing aliases between X and Y + C.
1995 XSIZE is the size in bytes of the X reference,
1996 similarly YSIZE is the size in bytes for Y.
1997 Expect that canon_rtx has been already called for X and Y.
1999 If XSIZE or YSIZE is zero, we do not know the amount of memory being
2000 referenced (the reference was BLKmode), so make the most pessimistic
2003 If XSIZE or YSIZE is negative, we may access memory outside the object
2004 being referenced as a side effect. This can happen when using AND to
2005 align memory references, as is done on the Alpha.
2007 Nice to notice that varying addresses cannot conflict with fp if no
2008 local variables had their addresses taken, but that's too hard now.
2010 ??? Contrary to the tree alias oracle this does not return
2011 one for X + non-constant and Y + non-constant when X and Y are equal.
2012 If that is fixed the TBAA hack for union type-punning can be removed. */
2015 memrefs_conflict_p (int xsize
, rtx x
, int ysize
, rtx y
, HOST_WIDE_INT c
)
2017 if (GET_CODE (x
) == VALUE
)
2021 struct elt_loc_list
*l
= NULL
;
2022 if (CSELIB_VAL_PTR (x
))
2023 for (l
= canonical_cselib_val (CSELIB_VAL_PTR (x
))->locs
;
2025 if (REG_P (l
->loc
) && rtx_equal_for_memref_p (l
->loc
, y
))
2032 /* Don't call get_addr if y is the same VALUE. */
2036 if (GET_CODE (y
) == VALUE
)
2040 struct elt_loc_list
*l
= NULL
;
2041 if (CSELIB_VAL_PTR (y
))
2042 for (l
= canonical_cselib_val (CSELIB_VAL_PTR (y
))->locs
;
2044 if (REG_P (l
->loc
) && rtx_equal_for_memref_p (l
->loc
, x
))
2051 /* Don't call get_addr if x is the same VALUE. */
2055 if (GET_CODE (x
) == HIGH
)
2057 else if (GET_CODE (x
) == LO_SUM
)
2060 x
= addr_side_effect_eval (x
, abs (xsize
), 0);
2061 if (GET_CODE (y
) == HIGH
)
2063 else if (GET_CODE (y
) == LO_SUM
)
2066 y
= addr_side_effect_eval (y
, abs (ysize
), 0);
2068 if (rtx_equal_for_memref_p (x
, y
))
2070 return offset_overlap_p (c
, xsize
, ysize
);
2073 /* This code used to check for conflicts involving stack references and
2074 globals but the base address alias code now handles these cases. */
2076 if (GET_CODE (x
) == PLUS
)
2078 /* The fact that X is canonicalized means that this
2079 PLUS rtx is canonicalized. */
2080 rtx x0
= XEXP (x
, 0);
2081 rtx x1
= XEXP (x
, 1);
2083 if (GET_CODE (y
) == PLUS
)
2085 /* The fact that Y is canonicalized means that this
2086 PLUS rtx is canonicalized. */
2087 rtx y0
= XEXP (y
, 0);
2088 rtx y1
= XEXP (y
, 1);
2090 if (rtx_equal_for_memref_p (x1
, y1
))
2091 return memrefs_conflict_p (xsize
, x0
, ysize
, y0
, c
);
2092 if (rtx_equal_for_memref_p (x0
, y0
))
2093 return memrefs_conflict_p (xsize
, x1
, ysize
, y1
, c
);
2094 if (CONST_INT_P (x1
))
2096 if (CONST_INT_P (y1
))
2097 return memrefs_conflict_p (xsize
, x0
, ysize
, y0
,
2098 c
- INTVAL (x1
) + INTVAL (y1
));
2100 return memrefs_conflict_p (xsize
, x0
, ysize
, y
,
2103 else if (CONST_INT_P (y1
))
2104 return memrefs_conflict_p (xsize
, x
, ysize
, y0
, c
+ INTVAL (y1
));
2108 else if (CONST_INT_P (x1
))
2109 return memrefs_conflict_p (xsize
, x0
, ysize
, y
, c
- INTVAL (x1
));
2111 else if (GET_CODE (y
) == PLUS
)
2113 /* The fact that Y is canonicalized means that this
2114 PLUS rtx is canonicalized. */
2115 rtx y0
= XEXP (y
, 0);
2116 rtx y1
= XEXP (y
, 1);
2118 if (CONST_INT_P (y1
))
2119 return memrefs_conflict_p (xsize
, x
, ysize
, y0
, c
+ INTVAL (y1
));
2124 if (GET_CODE (x
) == GET_CODE (y
))
2125 switch (GET_CODE (x
))
2129 /* Handle cases where we expect the second operands to be the
2130 same, and check only whether the first operand would conflict
2133 rtx x1
= canon_rtx (XEXP (x
, 1));
2134 rtx y1
= canon_rtx (XEXP (y
, 1));
2135 if (! rtx_equal_for_memref_p (x1
, y1
))
2137 x0
= canon_rtx (XEXP (x
, 0));
2138 y0
= canon_rtx (XEXP (y
, 0));
2139 if (rtx_equal_for_memref_p (x0
, y0
))
2140 return offset_overlap_p (c
, xsize
, ysize
);
2142 /* Can't properly adjust our sizes. */
2143 if (!CONST_INT_P (x1
))
2145 xsize
/= INTVAL (x1
);
2146 ysize
/= INTVAL (x1
);
2148 return memrefs_conflict_p (xsize
, x0
, ysize
, y0
, c
);
2155 /* Deal with alignment ANDs by adjusting offset and size so as to
2156 cover the maximum range, without taking any previously known
2157 alignment into account. Make a size negative after such an
2158 adjustments, so that, if we end up with e.g. two SYMBOL_REFs, we
2159 assume a potential overlap, because they may end up in contiguous
2160 memory locations and the stricter-alignment access may span over
2162 if (GET_CODE (x
) == AND
&& CONST_INT_P (XEXP (x
, 1)))
2164 HOST_WIDE_INT sc
= INTVAL (XEXP (x
, 1));
2165 unsigned HOST_WIDE_INT uc
= sc
;
2166 if (sc
< 0 && -uc
== (uc
& -uc
))
2173 return memrefs_conflict_p (xsize
, canon_rtx (XEXP (x
, 0)),
2177 if (GET_CODE (y
) == AND
&& CONST_INT_P (XEXP (y
, 1)))
2179 HOST_WIDE_INT sc
= INTVAL (XEXP (y
, 1));
2180 unsigned HOST_WIDE_INT uc
= sc
;
2181 if (sc
< 0 && -uc
== (uc
& -uc
))
2188 return memrefs_conflict_p (xsize
, x
,
2189 ysize
, canon_rtx (XEXP (y
, 0)), c
);
2195 if (CONST_INT_P (x
) && CONST_INT_P (y
))
2197 c
+= (INTVAL (y
) - INTVAL (x
));
2198 return offset_overlap_p (c
, xsize
, ysize
);
2201 if (GET_CODE (x
) == CONST
)
2203 if (GET_CODE (y
) == CONST
)
2204 return memrefs_conflict_p (xsize
, canon_rtx (XEXP (x
, 0)),
2205 ysize
, canon_rtx (XEXP (y
, 0)), c
);
2207 return memrefs_conflict_p (xsize
, canon_rtx (XEXP (x
, 0)),
2210 if (GET_CODE (y
) == CONST
)
2211 return memrefs_conflict_p (xsize
, x
, ysize
,
2212 canon_rtx (XEXP (y
, 0)), c
);
2214 /* Assume a potential overlap for symbolic addresses that went
2215 through alignment adjustments (i.e., that have negative
2216 sizes), because we can't know how far they are from each
2219 return (xsize
< 0 || ysize
< 0 || offset_overlap_p (c
, xsize
, ysize
));
2227 /* Functions to compute memory dependencies.
2229 Since we process the insns in execution order, we can build tables
2230 to keep track of what registers are fixed (and not aliased), what registers
2231 are varying in known ways, and what registers are varying in unknown
2234 If both memory references are volatile, then there must always be a
2235 dependence between the two references, since their order can not be
2236 changed. A volatile and non-volatile reference can be interchanged
2239 We also must allow AND addresses, because they may generate accesses
2240 outside the object being referenced. This is used to generate aligned
2241 addresses from unaligned addresses, for instance, the alpha
2242 storeqi_unaligned pattern. */
2244 /* Read dependence: X is read after read in MEM takes place. There can
2245 only be a dependence here if both reads are volatile, or if either is
2246 an explicit barrier. */
2249 read_dependence (const_rtx mem
, const_rtx x
)
2251 if (MEM_VOLATILE_P (x
) && MEM_VOLATILE_P (mem
))
2253 if (MEM_ALIAS_SET (x
) == ALIAS_SET_MEMORY_BARRIER
2254 || MEM_ALIAS_SET (mem
) == ALIAS_SET_MEMORY_BARRIER
)
2259 /* Return true if we can determine that the fields referenced cannot
2260 overlap for any pair of objects. */
2263 nonoverlapping_component_refs_p (const_rtx rtlx
, const_rtx rtly
)
2265 const_tree x
= MEM_EXPR (rtlx
), y
= MEM_EXPR (rtly
);
2266 const_tree fieldx
, fieldy
, typex
, typey
, orig_y
;
2268 if (!flag_strict_aliasing
2270 || TREE_CODE (x
) != COMPONENT_REF
2271 || TREE_CODE (y
) != COMPONENT_REF
)
2276 /* The comparison has to be done at a common type, since we don't
2277 know how the inheritance hierarchy works. */
2281 fieldx
= TREE_OPERAND (x
, 1);
2282 typex
= TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (fieldx
));
2287 fieldy
= TREE_OPERAND (y
, 1);
2288 typey
= TYPE_MAIN_VARIANT (DECL_FIELD_CONTEXT (fieldy
));
2293 y
= TREE_OPERAND (y
, 0);
2295 while (y
&& TREE_CODE (y
) == COMPONENT_REF
);
2297 x
= TREE_OPERAND (x
, 0);
2299 while (x
&& TREE_CODE (x
) == COMPONENT_REF
);
2300 /* Never found a common type. */
2304 /* If we're left with accessing different fields of a structure, then no
2305 possible overlap, unless they are both bitfields. */
2306 if (TREE_CODE (typex
) == RECORD_TYPE
&& fieldx
!= fieldy
)
2307 return !(DECL_BIT_FIELD (fieldx
) && DECL_BIT_FIELD (fieldy
));
2309 /* The comparison on the current field failed. If we're accessing
2310 a very nested structure, look at the next outer level. */
2311 x
= TREE_OPERAND (x
, 0);
2312 y
= TREE_OPERAND (y
, 0);
2315 && TREE_CODE (x
) == COMPONENT_REF
2316 && TREE_CODE (y
) == COMPONENT_REF
);
2321 /* Look at the bottom of the COMPONENT_REF list for a DECL, and return it. */
2324 decl_for_component_ref (tree x
)
2328 x
= TREE_OPERAND (x
, 0);
2330 while (x
&& TREE_CODE (x
) == COMPONENT_REF
);
2332 return x
&& DECL_P (x
) ? x
: NULL_TREE
;
2335 /* Walk up the COMPONENT_REF list in X and adjust *OFFSET to compensate
2336 for the offset of the field reference. *KNOWN_P says whether the
2340 adjust_offset_for_component_ref (tree x
, bool *known_p
,
2341 HOST_WIDE_INT
*offset
)
2347 tree xoffset
= component_ref_field_offset (x
);
2348 tree field
= TREE_OPERAND (x
, 1);
2350 if (! tree_fits_uhwi_p (xoffset
))
2355 *offset
+= (tree_low_cst (xoffset
, 1)
2356 + (tree_low_cst (DECL_FIELD_BIT_OFFSET (field
), 1)
2359 x
= TREE_OPERAND (x
, 0);
2361 while (x
&& TREE_CODE (x
) == COMPONENT_REF
);
2364 /* Return nonzero if we can determine the exprs corresponding to memrefs
2365 X and Y and they do not overlap.
2366 If LOOP_VARIANT is set, skip offset-based disambiguation */
2369 nonoverlapping_memrefs_p (const_rtx x
, const_rtx y
, bool loop_invariant
)
2371 tree exprx
= MEM_EXPR (x
), expry
= MEM_EXPR (y
);
2374 bool moffsetx_known_p
, moffsety_known_p
;
2375 HOST_WIDE_INT moffsetx
= 0, moffsety
= 0;
2376 HOST_WIDE_INT offsetx
= 0, offsety
= 0, sizex
, sizey
, tem
;
2378 /* Unless both have exprs, we can't tell anything. */
2379 if (exprx
== 0 || expry
== 0)
2382 /* For spill-slot accesses make sure we have valid offsets. */
2383 if ((exprx
== get_spill_slot_decl (false)
2384 && ! MEM_OFFSET_KNOWN_P (x
))
2385 || (expry
== get_spill_slot_decl (false)
2386 && ! MEM_OFFSET_KNOWN_P (y
)))
2389 /* If the field reference test failed, look at the DECLs involved. */
2390 moffsetx_known_p
= MEM_OFFSET_KNOWN_P (x
);
2391 if (moffsetx_known_p
)
2392 moffsetx
= MEM_OFFSET (x
);
2393 if (TREE_CODE (exprx
) == COMPONENT_REF
)
2395 tree t
= decl_for_component_ref (exprx
);
2398 adjust_offset_for_component_ref (exprx
, &moffsetx_known_p
, &moffsetx
);
2402 moffsety_known_p
= MEM_OFFSET_KNOWN_P (y
);
2403 if (moffsety_known_p
)
2404 moffsety
= MEM_OFFSET (y
);
2405 if (TREE_CODE (expry
) == COMPONENT_REF
)
2407 tree t
= decl_for_component_ref (expry
);
2410 adjust_offset_for_component_ref (expry
, &moffsety_known_p
, &moffsety
);
2414 if (! DECL_P (exprx
) || ! DECL_P (expry
))
2417 /* With invalid code we can end up storing into the constant pool.
2418 Bail out to avoid ICEing when creating RTL for this.
2419 See gfortran.dg/lto/20091028-2_0.f90. */
2420 if (TREE_CODE (exprx
) == CONST_DECL
2421 || TREE_CODE (expry
) == CONST_DECL
)
2424 rtlx
= DECL_RTL (exprx
);
2425 rtly
= DECL_RTL (expry
);
2427 /* If either RTL is not a MEM, it must be a REG or CONCAT, meaning they
2428 can't overlap unless they are the same because we never reuse that part
2429 of the stack frame used for locals for spilled pseudos. */
2430 if ((!MEM_P (rtlx
) || !MEM_P (rtly
))
2431 && ! rtx_equal_p (rtlx
, rtly
))
2434 /* If we have MEMs referring to different address spaces (which can
2435 potentially overlap), we cannot easily tell from the addresses
2436 whether the references overlap. */
2437 if (MEM_P (rtlx
) && MEM_P (rtly
)
2438 && MEM_ADDR_SPACE (rtlx
) != MEM_ADDR_SPACE (rtly
))
2441 /* Get the base and offsets of both decls. If either is a register, we
2442 know both are and are the same, so use that as the base. The only
2443 we can avoid overlap is if we can deduce that they are nonoverlapping
2444 pieces of that decl, which is very rare. */
2445 basex
= MEM_P (rtlx
) ? XEXP (rtlx
, 0) : rtlx
;
2446 if (GET_CODE (basex
) == PLUS
&& CONST_INT_P (XEXP (basex
, 1)))
2447 offsetx
= INTVAL (XEXP (basex
, 1)), basex
= XEXP (basex
, 0);
2449 basey
= MEM_P (rtly
) ? XEXP (rtly
, 0) : rtly
;
2450 if (GET_CODE (basey
) == PLUS
&& CONST_INT_P (XEXP (basey
, 1)))
2451 offsety
= INTVAL (XEXP (basey
, 1)), basey
= XEXP (basey
, 0);
2453 /* If the bases are different, we know they do not overlap if both
2454 are constants or if one is a constant and the other a pointer into the
2455 stack frame. Otherwise a different base means we can't tell if they
2457 if (! rtx_equal_p (basex
, basey
))
2458 return ((CONSTANT_P (basex
) && CONSTANT_P (basey
))
2459 || (CONSTANT_P (basex
) && REG_P (basey
)
2460 && REGNO_PTR_FRAME_P (REGNO (basey
)))
2461 || (CONSTANT_P (basey
) && REG_P (basex
)
2462 && REGNO_PTR_FRAME_P (REGNO (basex
))));
2464 /* Offset based disambiguation not appropriate for loop invariant */
2468 sizex
= (!MEM_P (rtlx
) ? (int) GET_MODE_SIZE (GET_MODE (rtlx
))
2469 : MEM_SIZE_KNOWN_P (rtlx
) ? MEM_SIZE (rtlx
)
2471 sizey
= (!MEM_P (rtly
) ? (int) GET_MODE_SIZE (GET_MODE (rtly
))
2472 : MEM_SIZE_KNOWN_P (rtly
) ? MEM_SIZE (rtly
)
2475 /* If we have an offset for either memref, it can update the values computed
2477 if (moffsetx_known_p
)
2478 offsetx
+= moffsetx
, sizex
-= moffsetx
;
2479 if (moffsety_known_p
)
2480 offsety
+= moffsety
, sizey
-= moffsety
;
2482 /* If a memref has both a size and an offset, we can use the smaller size.
2483 We can't do this if the offset isn't known because we must view this
2484 memref as being anywhere inside the DECL's MEM. */
2485 if (MEM_SIZE_KNOWN_P (x
) && moffsetx_known_p
)
2486 sizex
= MEM_SIZE (x
);
2487 if (MEM_SIZE_KNOWN_P (y
) && moffsety_known_p
)
2488 sizey
= MEM_SIZE (y
);
2490 /* Put the values of the memref with the lower offset in X's values. */
2491 if (offsetx
> offsety
)
2493 tem
= offsetx
, offsetx
= offsety
, offsety
= tem
;
2494 tem
= sizex
, sizex
= sizey
, sizey
= tem
;
2497 /* If we don't know the size of the lower-offset value, we can't tell
2498 if they conflict. Otherwise, we do the test. */
2499 return sizex
>= 0 && offsety
>= offsetx
+ sizex
;
2502 /* Helper for true_dependence and canon_true_dependence.
2503 Checks for true dependence: X is read after store in MEM takes place.
2505 If MEM_CANONICALIZED is FALSE, then X_ADDR and MEM_ADDR should be
2506 NULL_RTX, and the canonical addresses of MEM and X are both computed
2507 here. If MEM_CANONICALIZED, then MEM must be already canonicalized.
2509 If X_ADDR is non-NULL, it is used in preference of XEXP (x, 0).
2511 Returns 1 if there is a true dependence, 0 otherwise. */
2514 true_dependence_1 (const_rtx mem
, enum machine_mode mem_mode
, rtx mem_addr
,
2515 const_rtx x
, rtx x_addr
, bool mem_canonicalized
)
2520 gcc_checking_assert (mem_canonicalized
? (mem_addr
!= NULL_RTX
)
2521 : (mem_addr
== NULL_RTX
&& x_addr
== NULL_RTX
));
2523 if (MEM_VOLATILE_P (x
) && MEM_VOLATILE_P (mem
))
2526 /* (mem:BLK (scratch)) is a special mechanism to conflict with everything.
2527 This is used in epilogue deallocation functions, and in cselib. */
2528 if (GET_MODE (x
) == BLKmode
&& GET_CODE (XEXP (x
, 0)) == SCRATCH
)
2530 if (GET_MODE (mem
) == BLKmode
&& GET_CODE (XEXP (mem
, 0)) == SCRATCH
)
2532 if (MEM_ALIAS_SET (x
) == ALIAS_SET_MEMORY_BARRIER
2533 || MEM_ALIAS_SET (mem
) == ALIAS_SET_MEMORY_BARRIER
)
2536 /* Read-only memory is by definition never modified, and therefore can't
2537 conflict with anything. We don't expect to find read-only set on MEM,
2538 but stupid user tricks can produce them, so don't die. */
2539 if (MEM_READONLY_P (x
))
2542 /* If we have MEMs referring to different address spaces (which can
2543 potentially overlap), we cannot easily tell from the addresses
2544 whether the references overlap. */
2545 if (MEM_ADDR_SPACE (mem
) != MEM_ADDR_SPACE (x
))
2550 mem_addr
= XEXP (mem
, 0);
2551 if (mem_mode
== VOIDmode
)
2552 mem_mode
= GET_MODE (mem
);
2557 x_addr
= XEXP (x
, 0);
2558 if (!((GET_CODE (x_addr
) == VALUE
2559 && GET_CODE (mem_addr
) != VALUE
2560 && reg_mentioned_p (x_addr
, mem_addr
))
2561 || (GET_CODE (x_addr
) != VALUE
2562 && GET_CODE (mem_addr
) == VALUE
2563 && reg_mentioned_p (mem_addr
, x_addr
))))
2565 x_addr
= get_addr (x_addr
);
2566 if (! mem_canonicalized
)
2567 mem_addr
= get_addr (mem_addr
);
2571 base
= find_base_term (x_addr
);
2572 if (base
&& (GET_CODE (base
) == LABEL_REF
2573 || (GET_CODE (base
) == SYMBOL_REF
2574 && CONSTANT_POOL_ADDRESS_P (base
))))
2577 rtx mem_base
= find_base_term (mem_addr
);
2578 if (! base_alias_check (x_addr
, base
, mem_addr
, mem_base
,
2579 GET_MODE (x
), mem_mode
))
2582 x_addr
= canon_rtx (x_addr
);
2583 if (!mem_canonicalized
)
2584 mem_addr
= canon_rtx (mem_addr
);
2586 if ((ret
= memrefs_conflict_p (GET_MODE_SIZE (mem_mode
), mem_addr
,
2587 SIZE_FOR_MODE (x
), x_addr
, 0)) != -1)
2590 if (mems_in_disjoint_alias_sets_p (x
, mem
))
2593 if (nonoverlapping_memrefs_p (mem
, x
, false))
2596 if (nonoverlapping_component_refs_p (mem
, x
))
2599 return rtx_refs_may_alias_p (x
, mem
, true);
2602 /* True dependence: X is read after store in MEM takes place. */
2605 true_dependence (const_rtx mem
, enum machine_mode mem_mode
, const_rtx x
)
2607 return true_dependence_1 (mem
, mem_mode
, NULL_RTX
,
2608 x
, NULL_RTX
, /*mem_canonicalized=*/false);
2611 /* Canonical true dependence: X is read after store in MEM takes place.
2612 Variant of true_dependence which assumes MEM has already been
2613 canonicalized (hence we no longer do that here).
2614 The mem_addr argument has been added, since true_dependence_1 computed
2615 this value prior to canonicalizing. */
2618 canon_true_dependence (const_rtx mem
, enum machine_mode mem_mode
, rtx mem_addr
,
2619 const_rtx x
, rtx x_addr
)
2621 return true_dependence_1 (mem
, mem_mode
, mem_addr
,
2622 x
, x_addr
, /*mem_canonicalized=*/true);
2625 /* Returns nonzero if a write to X might alias a previous read from
2626 (or, if WRITEP is true, a write to) MEM.
2627 If X_CANONCALIZED is true, then X_ADDR is the canonicalized address of X,
2628 and X_MODE the mode for that access.
2629 If MEM_CANONICALIZED is true, MEM is canonicalized. */
2632 write_dependence_p (const_rtx mem
,
2633 const_rtx x
, enum machine_mode x_mode
, rtx x_addr
,
2634 bool mem_canonicalized
, bool x_canonicalized
, bool writep
)
2640 gcc_checking_assert (x_canonicalized
2641 ? (x_addr
!= NULL_RTX
&& x_mode
!= VOIDmode
)
2642 : (x_addr
== NULL_RTX
&& x_mode
== VOIDmode
));
2644 if (MEM_VOLATILE_P (x
) && MEM_VOLATILE_P (mem
))
2647 /* (mem:BLK (scratch)) is a special mechanism to conflict with everything.
2648 This is used in epilogue deallocation functions. */
2649 if (GET_MODE (x
) == BLKmode
&& GET_CODE (XEXP (x
, 0)) == SCRATCH
)
2651 if (GET_MODE (mem
) == BLKmode
&& GET_CODE (XEXP (mem
, 0)) == SCRATCH
)
2653 if (MEM_ALIAS_SET (x
) == ALIAS_SET_MEMORY_BARRIER
2654 || MEM_ALIAS_SET (mem
) == ALIAS_SET_MEMORY_BARRIER
)
2657 /* A read from read-only memory can't conflict with read-write memory. */
2658 if (!writep
&& MEM_READONLY_P (mem
))
2661 /* If we have MEMs referring to different address spaces (which can
2662 potentially overlap), we cannot easily tell from the addresses
2663 whether the references overlap. */
2664 if (MEM_ADDR_SPACE (mem
) != MEM_ADDR_SPACE (x
))
2667 mem_addr
= XEXP (mem
, 0);
2670 x_addr
= XEXP (x
, 0);
2671 if (!((GET_CODE (x_addr
) == VALUE
2672 && GET_CODE (mem_addr
) != VALUE
2673 && reg_mentioned_p (x_addr
, mem_addr
))
2674 || (GET_CODE (x_addr
) != VALUE
2675 && GET_CODE (mem_addr
) == VALUE
2676 && reg_mentioned_p (mem_addr
, x_addr
))))
2678 x_addr
= get_addr (x_addr
);
2679 if (!mem_canonicalized
)
2680 mem_addr
= get_addr (mem_addr
);
2684 base
= find_base_term (mem_addr
);
2687 && (GET_CODE (base
) == LABEL_REF
2688 || (GET_CODE (base
) == SYMBOL_REF
2689 && CONSTANT_POOL_ADDRESS_P (base
))))
2692 rtx x_base
= find_base_term (x_addr
);
2693 if (! base_alias_check (x_addr
, x_base
, mem_addr
, base
, GET_MODE (x
),
2697 if (!x_canonicalized
)
2699 x_addr
= canon_rtx (x_addr
);
2700 x_mode
= GET_MODE (x
);
2702 if (!mem_canonicalized
)
2703 mem_addr
= canon_rtx (mem_addr
);
2705 if ((ret
= memrefs_conflict_p (SIZE_FOR_MODE (mem
), mem_addr
,
2706 GET_MODE_SIZE (x_mode
), x_addr
, 0)) != -1)
2709 if (nonoverlapping_memrefs_p (x
, mem
, false))
2712 return rtx_refs_may_alias_p (x
, mem
, false);
2715 /* Anti dependence: X is written after read in MEM takes place. */
2718 anti_dependence (const_rtx mem
, const_rtx x
)
2720 return write_dependence_p (mem
, x
, VOIDmode
, NULL_RTX
,
2721 /*mem_canonicalized=*/false,
2722 /*x_canonicalized*/false, /*writep=*/false);
2725 /* Likewise, but we already have a canonicalized MEM, and X_ADDR for X.
2726 Also, consider X in X_MODE (which might be from an enclosing
2727 STRICT_LOW_PART / ZERO_EXTRACT).
2728 If MEM_CANONICALIZED is true, MEM is canonicalized. */
2731 canon_anti_dependence (const_rtx mem
, bool mem_canonicalized
,
2732 const_rtx x
, enum machine_mode x_mode
, rtx x_addr
)
2734 return write_dependence_p (mem
, x
, x_mode
, x_addr
,
2735 mem_canonicalized
, /*x_canonicalized=*/true,
2739 /* Output dependence: X is written after store in MEM takes place. */
2742 output_dependence (const_rtx mem
, const_rtx x
)
2744 return write_dependence_p (mem
, x
, VOIDmode
, NULL_RTX
,
2745 /*mem_canonicalized=*/false,
2746 /*x_canonicalized*/false, /*writep=*/true);
2751 /* Check whether X may be aliased with MEM. Don't do offset-based
2752 memory disambiguation & TBAA. */
2754 may_alias_p (const_rtx mem
, const_rtx x
)
2756 rtx x_addr
, mem_addr
;
2758 if (MEM_VOLATILE_P (x
) && MEM_VOLATILE_P (mem
))
2761 /* (mem:BLK (scratch)) is a special mechanism to conflict with everything.
2762 This is used in epilogue deallocation functions. */
2763 if (GET_MODE (x
) == BLKmode
&& GET_CODE (XEXP (x
, 0)) == SCRATCH
)
2765 if (GET_MODE (mem
) == BLKmode
&& GET_CODE (XEXP (mem
, 0)) == SCRATCH
)
2767 if (MEM_ALIAS_SET (x
) == ALIAS_SET_MEMORY_BARRIER
2768 || MEM_ALIAS_SET (mem
) == ALIAS_SET_MEMORY_BARRIER
)
2771 /* Read-only memory is by definition never modified, and therefore can't
2772 conflict with anything. We don't expect to find read-only set on MEM,
2773 but stupid user tricks can produce them, so don't die. */
2774 if (MEM_READONLY_P (x
))
2777 /* If we have MEMs referring to different address spaces (which can
2778 potentially overlap), we cannot easily tell from the addresses
2779 whether the references overlap. */
2780 if (MEM_ADDR_SPACE (mem
) != MEM_ADDR_SPACE (x
))
2783 x_addr
= XEXP (x
, 0);
2784 mem_addr
= XEXP (mem
, 0);
2785 if (!((GET_CODE (x_addr
) == VALUE
2786 && GET_CODE (mem_addr
) != VALUE
2787 && reg_mentioned_p (x_addr
, mem_addr
))
2788 || (GET_CODE (x_addr
) != VALUE
2789 && GET_CODE (mem_addr
) == VALUE
2790 && reg_mentioned_p (mem_addr
, x_addr
))))
2792 x_addr
= get_addr (x_addr
);
2793 mem_addr
= get_addr (mem_addr
);
2796 rtx x_base
= find_base_term (x_addr
);
2797 rtx mem_base
= find_base_term (mem_addr
);
2798 if (! base_alias_check (x_addr
, x_base
, mem_addr
, mem_base
,
2799 GET_MODE (x
), GET_MODE (mem_addr
)))
2802 x_addr
= canon_rtx (x_addr
);
2803 mem_addr
= canon_rtx (mem_addr
);
2805 if (nonoverlapping_memrefs_p (mem
, x
, true))
2808 /* TBAA not valid for loop_invarint */
2809 return rtx_refs_may_alias_p (x
, mem
, false);
2813 init_alias_target (void)
2817 if (!arg_base_value
)
2818 arg_base_value
= gen_rtx_ADDRESS (VOIDmode
, 0);
2820 memset (static_reg_base_value
, 0, sizeof static_reg_base_value
);
2822 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2823 /* Check whether this register can hold an incoming pointer
2824 argument. FUNCTION_ARG_REGNO_P tests outgoing register
2825 numbers, so translate if necessary due to register windows. */
2826 if (FUNCTION_ARG_REGNO_P (OUTGOING_REGNO (i
))
2827 && HARD_REGNO_MODE_OK (i
, Pmode
))
2828 static_reg_base_value
[i
] = arg_base_value
;
2830 static_reg_base_value
[STACK_POINTER_REGNUM
]
2831 = unique_base_value (UNIQUE_BASE_VALUE_SP
);
2832 static_reg_base_value
[ARG_POINTER_REGNUM
]
2833 = unique_base_value (UNIQUE_BASE_VALUE_ARGP
);
2834 static_reg_base_value
[FRAME_POINTER_REGNUM
]
2835 = unique_base_value (UNIQUE_BASE_VALUE_FP
);
2836 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
2837 static_reg_base_value
[HARD_FRAME_POINTER_REGNUM
]
2838 = unique_base_value (UNIQUE_BASE_VALUE_HFP
);
2842 /* Set MEMORY_MODIFIED when X modifies DATA (that is assumed
2843 to be memory reference. */
2844 static bool memory_modified
;
2846 memory_modified_1 (rtx x
, const_rtx pat ATTRIBUTE_UNUSED
, void *data
)
2850 if (anti_dependence (x
, (const_rtx
)data
) || output_dependence (x
, (const_rtx
)data
))
2851 memory_modified
= true;
2856 /* Return true when INSN possibly modify memory contents of MEM
2857 (i.e. address can be modified). */
2859 memory_modified_in_insn_p (const_rtx mem
, const_rtx insn
)
2863 memory_modified
= false;
2864 note_stores (PATTERN (insn
), memory_modified_1
, CONST_CAST_RTX(mem
));
2865 return memory_modified
;
2868 /* Return TRUE if the destination of a set is rtx identical to
2871 set_dest_equal_p (const_rtx set
, const_rtx item
)
2873 rtx dest
= SET_DEST (set
);
2874 return rtx_equal_p (dest
, item
);
2877 /* Like memory_modified_in_insn_p, but return TRUE if INSN will
2878 *DEFINITELY* modify the memory contents of MEM. */
2880 memory_must_be_modified_in_insn_p (const_rtx mem
, const_rtx insn
)
2884 insn
= PATTERN (insn
);
2885 if (GET_CODE (insn
) == SET
)
2886 return set_dest_equal_p (insn
, mem
);
2887 else if (GET_CODE (insn
) == PARALLEL
)
2890 for (i
= 0; i
< XVECLEN (insn
, 0); i
++)
2892 rtx sub
= XVECEXP (insn
, 0, i
);
2893 if (GET_CODE (sub
) == SET
2894 && set_dest_equal_p (sub
, mem
))
2901 /* Initialize the aliasing machinery. Initialize the REG_KNOWN_VALUE
2905 init_alias_analysis (void)
2907 unsigned int maxreg
= max_reg_num ();
2915 timevar_push (TV_ALIAS_ANALYSIS
);
2917 vec_safe_grow_cleared (reg_known_value
, maxreg
- FIRST_PSEUDO_REGISTER
);
2918 reg_known_equiv_p
= sbitmap_alloc (maxreg
- FIRST_PSEUDO_REGISTER
);
2919 bitmap_clear (reg_known_equiv_p
);
2921 /* If we have memory allocated from the previous run, use it. */
2922 if (old_reg_base_value
)
2923 reg_base_value
= old_reg_base_value
;
2926 reg_base_value
->truncate (0);
2928 vec_safe_grow_cleared (reg_base_value
, maxreg
);
2930 new_reg_base_value
= XNEWVEC (rtx
, maxreg
);
2931 reg_seen
= sbitmap_alloc (maxreg
);
2933 /* The basic idea is that each pass through this loop will use the
2934 "constant" information from the previous pass to propagate alias
2935 information through another level of assignments.
2937 The propagation is done on the CFG in reverse post-order, to propagate
2938 things forward as far as possible in each iteration.
2940 This could get expensive if the assignment chains are long. Maybe
2941 we should throttle the number of iterations, possibly based on
2942 the optimization level or flag_expensive_optimizations.
2944 We could propagate more information in the first pass by making use
2945 of DF_REG_DEF_COUNT to determine immediately that the alias information
2946 for a pseudo is "constant".
2948 A program with an uninitialized variable can cause an infinite loop
2949 here. Instead of doing a full dataflow analysis to detect such problems
2950 we just cap the number of iterations for the loop.
2952 The state of the arrays for the set chain in question does not matter
2953 since the program has undefined behavior. */
2955 rpo
= XNEWVEC (int, n_basic_blocks
);
2956 rpo_cnt
= pre_and_rev_post_order_compute (NULL
, rpo
, false);
2961 /* Assume nothing will change this iteration of the loop. */
2964 /* We want to assign the same IDs each iteration of this loop, so
2965 start counting from one each iteration of the loop. */
2968 /* We're at the start of the function each iteration through the
2969 loop, so we're copying arguments. */
2970 copying_arguments
= true;
2972 /* Wipe the potential alias information clean for this pass. */
2973 memset (new_reg_base_value
, 0, maxreg
* sizeof (rtx
));
2975 /* Wipe the reg_seen array clean. */
2976 bitmap_clear (reg_seen
);
2978 /* Initialize the alias information for this pass. */
2979 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2980 if (static_reg_base_value
[i
])
2982 new_reg_base_value
[i
] = static_reg_base_value
[i
];
2983 bitmap_set_bit (reg_seen
, i
);
2986 /* Walk the insns adding values to the new_reg_base_value array. */
2987 for (i
= 0; i
< rpo_cnt
; i
++)
2989 basic_block bb
= BASIC_BLOCK (rpo
[i
]);
2990 FOR_BB_INSNS (bb
, insn
)
2992 if (NONDEBUG_INSN_P (insn
))
2996 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
2997 /* The prologue/epilogue insns are not threaded onto the
2998 insn chain until after reload has completed. Thus,
2999 there is no sense wasting time checking if INSN is in
3000 the prologue/epilogue until after reload has completed. */
3001 if (reload_completed
3002 && prologue_epilogue_contains (insn
))
3006 /* If this insn has a noalias note, process it, Otherwise,
3007 scan for sets. A simple set will have no side effects
3008 which could change the base value of any other register. */
3010 if (GET_CODE (PATTERN (insn
)) == SET
3011 && REG_NOTES (insn
) != 0
3012 && find_reg_note (insn
, REG_NOALIAS
, NULL_RTX
))
3013 record_set (SET_DEST (PATTERN (insn
)), NULL_RTX
, NULL
);
3015 note_stores (PATTERN (insn
), record_set
, NULL
);
3017 set
= single_set (insn
);
3020 && REG_P (SET_DEST (set
))
3021 && REGNO (SET_DEST (set
)) >= FIRST_PSEUDO_REGISTER
)
3023 unsigned int regno
= REGNO (SET_DEST (set
));
3024 rtx src
= SET_SRC (set
);
3027 note
= find_reg_equal_equiv_note (insn
);
3028 if (note
&& REG_NOTE_KIND (note
) == REG_EQUAL
3029 && DF_REG_DEF_COUNT (regno
) != 1)
3032 if (note
!= NULL_RTX
3033 && GET_CODE (XEXP (note
, 0)) != EXPR_LIST
3034 && ! rtx_varies_p (XEXP (note
, 0), 1)
3035 && ! reg_overlap_mentioned_p (SET_DEST (set
),
3038 set_reg_known_value (regno
, XEXP (note
, 0));
3039 set_reg_known_equiv_p (regno
,
3040 REG_NOTE_KIND (note
) == REG_EQUIV
);
3042 else if (DF_REG_DEF_COUNT (regno
) == 1
3043 && GET_CODE (src
) == PLUS
3044 && REG_P (XEXP (src
, 0))
3045 && (t
= get_reg_known_value (REGNO (XEXP (src
, 0))))
3046 && CONST_INT_P (XEXP (src
, 1)))
3048 t
= plus_constant (GET_MODE (src
), t
,
3049 INTVAL (XEXP (src
, 1)));
3050 set_reg_known_value (regno
, t
);
3051 set_reg_known_equiv_p (regno
, false);
3053 else if (DF_REG_DEF_COUNT (regno
) == 1
3054 && ! rtx_varies_p (src
, 1))
3056 set_reg_known_value (regno
, src
);
3057 set_reg_known_equiv_p (regno
, false);
3061 else if (NOTE_P (insn
)
3062 && NOTE_KIND (insn
) == NOTE_INSN_FUNCTION_BEG
)
3063 copying_arguments
= false;
3067 /* Now propagate values from new_reg_base_value to reg_base_value. */
3068 gcc_assert (maxreg
== (unsigned int) max_reg_num ());
3070 for (ui
= 0; ui
< maxreg
; ui
++)
3072 if (new_reg_base_value
[ui
]
3073 && new_reg_base_value
[ui
] != (*reg_base_value
)[ui
]
3074 && ! rtx_equal_p (new_reg_base_value
[ui
], (*reg_base_value
)[ui
]))
3076 (*reg_base_value
)[ui
] = new_reg_base_value
[ui
];
3081 while (changed
&& ++pass
< MAX_ALIAS_LOOP_PASSES
);
3084 /* Fill in the remaining entries. */
3085 FOR_EACH_VEC_ELT (*reg_known_value
, i
, val
)
3087 int regno
= i
+ FIRST_PSEUDO_REGISTER
;
3089 set_reg_known_value (regno
, regno_reg_rtx
[regno
]);
3093 free (new_reg_base_value
);
3094 new_reg_base_value
= 0;
3095 sbitmap_free (reg_seen
);
3097 timevar_pop (TV_ALIAS_ANALYSIS
);
3100 /* Equate REG_BASE_VALUE (reg1) to REG_BASE_VALUE (reg2).
3101 Special API for var-tracking pass purposes. */
3104 vt_equate_reg_base_value (const_rtx reg1
, const_rtx reg2
)
3106 (*reg_base_value
)[REGNO (reg1
)] = REG_BASE_VALUE (reg2
);
3110 end_alias_analysis (void)
3112 old_reg_base_value
= reg_base_value
;
3113 vec_free (reg_known_value
);
3114 sbitmap_free (reg_known_equiv_p
);
3117 #include "gt-alias.h"