/* Alias analysis for GNU C
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
- 2007 Free Software Foundation, Inc.
+ 2007, 2008, 2009 Free Software Foundation, Inc.
Contributed by John Carr (jfc@mit.edu).
This file is part of GCC.
/* The alias set number, as stored in MEM_ALIAS_SET. */
alias_set_type alias_set;
+ /* Nonzero if would have a child of zero: this effectively makes this
+ alias set the same as alias set zero. */
+ int has_zero_child;
+
/* The children of the alias set. These are not just the immediate
children, but, in fact, all descendants. So, if we have:
continuing our example above, the children here will be all of
`int', `double', `float', and `struct S'. */
splay_tree GTY((param1_is (int), param2_is (int))) children;
-
- /* Nonzero if would have a child of zero: this effectively makes this
- alias set the same as alias set zero. */
- int has_zero_child;
};
typedef struct alias_set_entry *alias_set_entry;
static bool nonoverlapping_component_refs_p (const_tree, const_tree);
static tree decl_for_component_ref (tree);
static rtx adjust_offset_for_component_ref (tree, rtx);
-static int nonoverlapping_memrefs_p (const_rtx, const_rtx);
static int write_dependence_p (const_rtx, const_rtx, int);
-static void memory_modified_1 (const_rtx, const_rtx, const void *);
-static void record_alias_subset (alias_set_type, alias_set_type);
+static void memory_modified_1 (rtx, const_rtx, void *);
/* Set up all info needed to perform alias analysis on memory references. */
/* Otherwise, check if set1 is a subset of set2. */
ase = get_alias_set_entry (set2);
if (ase != 0
- && (splay_tree_lookup (ase->children,
- (splay_tree_key) set1)))
+ && ((ase->has_zero_child && set1 == 0)
+ || splay_tree_lookup (ase->children,
+ (splay_tree_key) set1)))
return true;
return false;
}
return 0;
}
+static int
+walk_mems_2 (rtx *x, rtx mem)
+{
+ if (MEM_P (*x))
+ {
+ if (alias_sets_conflict_p (MEM_ALIAS_SET(*x), MEM_ALIAS_SET(mem)))
+ return 1;
+
+ return -1;
+ }
+ return 0;
+}
+
+static int
+walk_mems_1 (rtx *x, rtx *pat)
+{
+ if (MEM_P (*x))
+ {
+ /* Visit all MEMs in *PAT and check indepedence. */
+ if (for_each_rtx (pat, (rtx_function) walk_mems_2, *x))
+ /* Indicate that dependence was determined and stop traversal. */
+ return 1;
+
+ return -1;
+ }
+ return 0;
+}
+
+/* Return 1 if two specified instructions have mem expr with conflict alias sets*/
+bool
+insn_alias_sets_conflict_p (rtx insn1, rtx insn2)
+{
+ /* For each pair of MEMs in INSN1 and INSN2 check their independence. */
+ return for_each_rtx (&PATTERN (insn1), (rtx_function) walk_mems_1,
+ &PATTERN (insn2));
+}
+
/* Return 1 if the two specified alias sets will always conflict. */
int
/* Check for accesses through restrict-qualified pointers. */
if (INDIRECT_REF_P (inner))
{
- tree decl = find_base_decl (TREE_OPERAND (inner, 0));
+ tree decl;
+
+ if (TREE_CODE (TREE_OPERAND (inner, 0)) == SSA_NAME)
+ decl = SSA_NAME_VAR (TREE_OPERAND (inner, 0));
+ else
+ decl = find_base_decl (TREE_OPERAND (inner, 0));
if (decl && DECL_POINTER_ALIAS_SET_KNOWN_P (decl))
{
return 0;
}
- /* For non-addressable fields we return the alias set of the
- outermost object that could have its address taken. If this
- is an SFT use the precomputed value. */
- if (TREE_CODE (t) == STRUCT_FIELD_TAG
- && SFT_NONADDRESSABLE_P (t))
- return SFT_ALIAS_SET (t);
-
/* Otherwise, pick up the outermost object that we could have a pointer
to, processing conversions as above. */
while (component_uses_parent_alias_set (t))
}
/* Variant qualifiers don't affect the alias set, so get the main
- variant. If this is a type with a known alias set, return it. */
+ variant. Always use the canonical type as well.
+ If this is a type with a known alias set, return it. */
t = TYPE_MAIN_VARIANT (t);
+ if (TYPE_CANONICAL (t))
+ t = TYPE_CANONICAL (t);
if (TYPE_ALIAS_SET_KNOWN_P (t))
return TYPE_ALIAS_SET (t);
+ /* We don't want to set TYPE_ALIAS_SET for incomplete types. */
+ if (!COMPLETE_TYPE_P (t))
+ {
+ /* For arrays with unknown size the conservative answer is the
+ alias set of the element type. */
+ if (TREE_CODE (t) == ARRAY_TYPE)
+ return get_alias_set (TREE_TYPE (t));
+
+ /* But return zero as a conservative answer for incomplete types. */
+ return 0;
+ }
+
/* See if the language has special handling for this type. */
set = lang_hooks.get_alias_set (t);
if (set != -1)
else if (TREE_CODE (t) == VECTOR_TYPE)
set = get_alias_set (TREE_TYPE (t));
+ /* Unless the language specifies otherwise, treat array types the
+ same as their components. This avoids the asymmetry we get
+ through recording the components. Consider accessing a
+ character(kind=1) through a reference to a character(kind=1)[1:1].
+ Or consider if we want to assign integer(kind=4)[0:D.1387] and
+ integer(kind=4)[4] the same alias set or not.
+ Just be pragmatic here and make sure the array and its element
+ type get the same alias set assigned. */
+ else if (TREE_CODE (t) == ARRAY_TYPE
+ && !TYPE_NONALIASED_COMPONENT (t))
+ set = get_alias_set (TREE_TYPE (t));
+
else
/* Otherwise make a new alias set for this type. */
set = new_alias_set ();
It is illegal for SUPERSET to be zero; everything is implicitly a
subset of alias set zero. */
-static void
+void
record_alias_subset (alias_set_type superset, alias_set_type subset)
{
alias_set_entry superset_entry;
{
/* Create an entry for the SUPERSET, so that we have a place to
attach the SUBSET. */
- superset_entry = ggc_alloc (sizeof (struct alias_set_entry));
+ superset_entry = GGC_NEW (struct alias_set_entry);
superset_entry->alias_set = superset;
superset_entry->children
= splay_tree_new_ggc (splay_tree_compare_ints);
/* Record that component types of TYPE, if any, are part of that type for
aliasing purposes. For record types, we only record component types
- for fields that are marked addressable. For array types, we always
- record the component types, so the front end should not call this
- function if the individual component aren't addressable. */
+ for fields that are not marked non-addressable. For array types, we
+ only record the component type if it is not marked non-aliased. */
void
record_component_aliases (tree type)
switch (TREE_CODE (type))
{
- case ARRAY_TYPE:
- if (! TYPE_NONALIASED_COMPONENT (type))
- record_alias_subset (superset, get_alias_set (TREE_TYPE (type)));
- break;
-
case RECORD_TYPE:
case UNION_TYPE:
case QUAL_UNION_TYPE:
get_alias_set (BINFO_TYPE (base_binfo)));
}
for (field = TYPE_FIELDS (type); field != 0; field = TREE_CHAIN (field))
- if (TREE_CODE (field) == FIELD_DECL && ! DECL_NONADDRESSABLE_P (field))
+ if (TREE_CODE (field) == FIELD_DECL && !DECL_NONADDRESSABLE_P (field))
record_alias_subset (superset, get_alias_set (TREE_TYPE (field)));
break;
record_alias_subset (superset, get_alias_set (TREE_TYPE (type)));
break;
+ /* VECTOR_TYPE and ARRAY_TYPE share the alias set with their
+ element type. */
+
default:
break;
}
{
unsigned int regno;
+#if defined (FIND_BASE_TERM)
+ /* Try machine-dependent ways to find the base term. */
+ src = FIND_BASE_TERM (src);
+#endif
+
switch (GET_CODE (src))
{
case SYMBOL_REF:
return 0;
/* Fall through. */
case LO_SUM:
+ /* The standard form is (lo_sum reg sym) so look only at the
+ second operand. */
+ return find_base_term (XEXP (x, 1));
case PLUS:
case MINUS:
{
if (rtx_equal_p (x_base, y_base))
return 1;
- /* The base addresses of the read and write are different expressions.
- If they are both symbols and they are not accessed via AND, there is
- no conflict. We can bring knowledge of object alignment into play
- here. For example, on alpha, "char a, b;" can alias one another,
- though "char a; long b;" cannot. */
+ /* The base addresses are different expressions. If they are not accessed
+ via AND, there is no conflict. We can bring knowledge of object
+ alignment into play here. For example, on alpha, "char a, b;" can
+ alias one another, though "char a; long b;" cannot. AND addesses may
+ implicitly alias surrounding objects; i.e. unaligned access in DImode
+ via AND address can alias all surrounding object types except those
+ with aligment 8 or higher. */
+ if (GET_CODE (x) == AND && GET_CODE (y) == AND)
+ return 1;
+ if (GET_CODE (x) == AND
+ && (GET_CODE (XEXP (x, 1)) != CONST_INT
+ || (int) GET_MODE_UNIT_SIZE (y_mode) < -INTVAL (XEXP (x, 1))))
+ return 1;
+ if (GET_CODE (y) == AND
+ && (GET_CODE (XEXP (y, 1)) != CONST_INT
+ || (int) GET_MODE_UNIT_SIZE (x_mode) < -INTVAL (XEXP (y, 1))))
+ return 1;
+
+ /* Differing symbols not accessed via AND never alias. */
if (GET_CODE (x_base) != ADDRESS && GET_CODE (y_base) != ADDRESS)
- {
- if (GET_CODE (x) == AND && GET_CODE (y) == AND)
- return 1;
- if (GET_CODE (x) == AND
- && (GET_CODE (XEXP (x, 1)) != CONST_INT
- || (int) GET_MODE_UNIT_SIZE (y_mode) < -INTVAL (XEXP (x, 1))))
- return 1;
- if (GET_CODE (y) == AND
- && (GET_CODE (XEXP (y, 1)) != CONST_INT
- || (int) GET_MODE_UNIT_SIZE (x_mode) < -INTVAL (XEXP (y, 1))))
- return 1;
- /* Differing symbols never alias. */
- return 0;
- }
+ return 0;
/* If one address is a stack reference there can be no alias:
stack references using different base registers do not alias,
/* Return nonzero if we can determine the exprs corresponding to memrefs
X and Y and they do not overlap. */
-static int
+int
nonoverlapping_memrefs_p (const_rtx x, const_rtx y)
{
tree exprx = MEM_EXPR (x), expry = MEM_EXPR (y);
\f
void
-init_alias_once (void)
+init_alias_target (void)
{
int i;
+ memset (static_reg_base_value, 0, sizeof static_reg_base_value);
+
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
/* Check whether this register can hold an incoming pointer
argument. FUNCTION_ARG_REGNO_P tests outgoing register
to be memory reference. */
static bool memory_modified;
static void
-memory_modified_1 (const_rtx x, const_rtx pat ATTRIBUTE_UNUSED, const void *data)
+memory_modified_1 (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
{
if (MEM_P (x))
{
if (!INSN_P (insn))
return false;
memory_modified = false;
- const_note_stores (PATTERN (insn), memory_modified_1, mem);
+ note_stores (PATTERN (insn), memory_modified_1, CONST_CAST_RTX(mem));
return memory_modified;
}
timevar_push (TV_ALIAS_ANALYSIS);
reg_known_value_size = maxreg - FIRST_PSEUDO_REGISTER;
- reg_known_value = ggc_calloc (reg_known_value_size, sizeof (rtx));
- reg_known_equiv_p = xcalloc (reg_known_value_size, sizeof (bool));
+ reg_known_value = GGC_CNEWVEC (rtx, reg_known_value_size);
+ reg_known_equiv_p = XCNEWVEC (bool, reg_known_value_size);
/* If we have memory allocated from the previous run, use it. */
if (old_reg_base_value)