GCC Middle and Back End API Reference
alias.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "rtl.h"
#include "tree.h"
Include dependency graph for alias.c:

Data Structures

struct  alias_set_entry_d

Typedefs

typedef struct alias_set_entry_dalias_set_entry

Functions

static int rtx_equal_for_memref_p (const_rtx, const_rtx)
static int memrefs_conflict_p (int, rtx, int, rtx, HOST_WIDE_INT)
static void record_set (rtx, const_rtx, void *)
static int base_alias_check (rtx, rtx, rtx, rtx, enum machine_mode, enum machine_mode)
static rtx find_base_value (rtx)
static int mems_in_disjoint_alias_sets_p (const_rtx, const_rtx)
static int insert_subset_children (splay_tree_node, void *)
static alias_set_entry get_alias_set_entry (alias_set_type)
static bool nonoverlapping_component_refs_p (const_rtx, const_rtx)
static tree decl_for_component_ref (tree)
static int write_dependence_p (const_rtx, const_rtx, enum machine_mode, rtx, bool, bool, bool)
static void memory_modified_1 (rtx, const_rtx, void *)
static bool ao_ref_from_mem ()
static bool rtx_refs_may_alias_p ()
static alias_set_entry get_alias_set_entry ()
static int mems_in_disjoint_alias_sets_p ()
static int insert_subset_children ()
bool alias_set_subset_of ()
int alias_sets_conflict_p ()
int alias_sets_must_conflict_p ()
int objects_must_conflict_p ()
tree component_uses_parent_alias_set_from ()
static bool ref_all_alias_ptr_type_p ()
static alias_set_type get_deref_alias_set_1 ()
alias_set_type get_deref_alias_set ()
static tree reference_alias_ptr_type_1 ()
tree reference_alias_ptr_type ()
bool alias_ptr_types_compatible_p ()
alias_set_type get_alias_set ()
alias_set_type new_alias_set ()
void record_alias_subset ()
void record_component_aliases ()
alias_set_type get_varargs_alias_set ()
alias_set_type get_frame_alias_set ()
static rtx unique_base_value ()
static bool unique_base_value_p ()
static bool known_base_value_p ()
static rtx find_base_value ()
static void record_set ()
rtx get_reg_base_value ()
rtx get_reg_known_value ()
static void set_reg_known_value ()
bool get_reg_known_equiv_p ()
static void set_reg_known_equiv_p ()
rtx canon_rtx ()
static int rtx_equal_for_memref_p ()
static rtx find_base_term ()
bool may_be_sp_based_p ()
static int refs_newer_value_cb ()
static bool refs_newer_value_p ()
rtx get_addr ()
static rtx addr_side_effect_eval ()
static bool offset_overlap_p ()
static int memrefs_conflict_p ()
int read_dependence ()
static bool nonoverlapping_component_refs_p ()
static tree decl_for_component_ref ()
static void adjust_offset_for_component_ref (tree x, bool *known_p, HOST_WIDE_INT *offset)
int nonoverlapping_memrefs_p ()
static int true_dependence_1 (const_rtx mem, enum machine_mode mem_mode, rtx mem_addr, const_rtx x, rtx x_addr, bool mem_canonicalized)
int true_dependence ()
int canon_true_dependence (const_rtx mem, enum machine_mode mem_mode, rtx mem_addr, const_rtx x, rtx x_addr)
int anti_dependence ()
int canon_anti_dependence (const_rtx mem, bool mem_canonicalized, const_rtx x, enum machine_mode x_mode, rtx x_addr)
int output_dependence ()
int may_alias_p ()
void init_alias_target ()
static void memory_modified_1 ()
bool memory_modified_in_insn_p ()
static bool set_dest_equal_p ()
bool memory_must_be_modified_in_insn_p ()
void init_alias_analysis ()
void vt_equate_reg_base_value ()
void end_alias_analysis ()

Variables

static vec< rtx, va_gc > * reg_base_value
static rtxnew_reg_base_value
static rtx arg_base_value
static int unique_id
static vec< rtx, va_gc > * old_reg_base_value
static vec< rtx, va_gc > * reg_known_value
static sbitmap reg_known_equiv_p
static bool copying_arguments
static vec< alias_set_entry,
va_gc > * 
alias_sets
static alias_set_type varargs_set = -1
static alias_set_type frame_set = -1
static sbitmap reg_seen
static bool memory_modified

Typedef Documentation


Function Documentation

static rtx addr_side_effect_eval ( )
static

Return the address of the (N_REFS + 1)th memory reference to ADDR where SIZE is the size in bytes of the memory reference. If ADDR is not modified by the memory reference then ADDR is returned.

static void adjust_offset_for_component_ref ( tree  x,
bool known_p,
HOST_WIDE_INT offset 
)
static

Walk up the COMPONENT_REF list in X and adjust *OFFSET to compensate for the offset of the field reference. *KNOWN_P says whether the offset is known.

References GET_MODE, and XEXP.

bool alias_ptr_types_compatible_p ( )

Return whether the pointer-types T1 and T2 used to determine two alias sets of two references will yield the same answer from get_deref_alias_set.

References lang_hooks::get_alias_set.

bool alias_set_subset_of ( )

Return true if the first alias set is a subset of the second.

Everything is a subset of the "aliases everything" set.

 Otherwise, check if set1 is a subset of set2.   
int alias_sets_conflict_p ( )

Return 1 if the two specified alias sets may conflict.

 The easy case.   
 See if the first alias set is a subset of the second.   
 Now do the same, but with the alias sets reversed.   
 The two alias sets are distinct and neither one is the
 child of the other.  Therefore, they cannot conflict.   

Referenced by array_ref_element_size(), and rtx_refs_may_alias_p().

int alias_sets_must_conflict_p ( )

Return 1 if the two specified alias sets will always conflict.

References handled_component_p(), NULL_TREE, and TREE_CODE.

Referenced by insert_subset_children().

int anti_dependence ( )

Anti dependence: X is written after read in MEM takes place.

Referenced by expand_reg_info(), and write_dependence_p().

static bool ao_ref_from_mem ( )
static

Build a decomposed reference object for querying the alias-oracle from the MEM rtx and store it in *REF. Returns false if MEM is not suitable for the alias-oracle.

 Get the base of the reference and see if we have to reject or
 adjust it.   
 The tree oracle doesn't like bases that are neither decls
 nor indirect references of SSA names.   
 If this is a reference based on a partitioned decl replace the
 base with a MEM_REF of the pointer representative we
 created during stack slot partitioning.   
 If MEM_OFFSET or MEM_SIZE are unknown what we got from MEM_EXPR
 is conservative, so trust it.   
 If the base decl is a parameter we can have negative MEM_OFFSET in
 case of promoted subregs on bigendian targets.  Trust the MEM_EXPR
 here.   
 Otherwise continue and refine size and offset we got from analyzing
 MEM_EXPR by using MEM_SIZE and MEM_OFFSET.   
 The MEM may extend into adjacent fields, so adjust max_size if
 necessary.   
 If MEM_OFFSET and MEM_SIZE get us outside of the base object of
 the MEM_EXPR punt.  This happens for STRICT_ALIGNMENT targets a lot.   

References build_simple_mem_ref, cfun, and pointer_map_contains().

static int base_alias_check ( rtx  x,
rtx  x_base,
rtx  y,
rtx  y_base,
enum machine_mode  x_mode,
enum machine_mode  y_mode 
)
static

Return 0 if the addresses X and Y are known to point to different objects, 1 if they might be pointers to the same object.

 If the address itself has no known base see if a known equivalent
 value has one.  If either address still has no known base, nothing
 is known about aliasing.   
 If the base addresses are equal nothing is known about aliasing.   
 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.   
 Differing symbols not accessed via AND never alias.   
int canon_anti_dependence ( const_rtx  mem,
bool  mem_canonicalized,
const_rtx  x,
enum machine_mode  x_mode,
rtx  x_addr 
)

Likewise, but we already have a canonicalized MEM, and X_ADDR for X. Also, consider X in X_MODE (which might be from an enclosing STRICT_LOW_PART / ZERO_EXTRACT). If MEM_CANONICALIZED is true, MEM is canonicalized.

Referenced by cselib_invalidate_regno().

rtx canon_rtx ( )

Returns a canonical version of X, from the point of view alias analysis. (For example, if X is a MEM whose address is a register, and the register has a known value (say a SYMBOL_REF), then a MEM whose address is the SYMBOL_REF is returned.)

Recursively look for equivalences.

 This gives us much better alias analysis when called from
 the loop optimizer.   Note we want to leave the original
 MEM alone, but need to return the canonicalized MEM with
 all the flags with their original values.   

References gcc_unreachable, rtx_equal_for_memref_p(), XEXP, XINT, XSTR, XVECEXP, and XVECLEN.

Referenced by flush_hash_table(), and get_reg_known_equiv_p().

int canon_true_dependence ( const_rtx  mem,
enum machine_mode  mem_mode,
rtx  mem_addr,
const_rtx  x,
rtx  x_addr 
)

Canonical true dependence: X is read after store in MEM takes place. Variant of true_dependence which assumes MEM has already been canonicalized (hence we no longer do that here). The mem_addr argument has been added, since true_dependence_1 computed this value prior to canonicalizing.

tree component_uses_parent_alias_set_from ( )

Return the outermost parent of component present in the chain of component references handled by get_inner_reference in T with the following property:

  • the component is non-addressable, or
  • the parent has alias set zero, or NULL_TREE if no such parent exists. In the former cases, the alias set of this parent is the alias set that must be used for T itself.

Bitfields and casts are never addressable.

References TREE_CODE, TREE_TYPE, and TYPE_REF_CAN_ALIAS_ALL.

static tree decl_for_component_ref ( tree  )
static
static tree decl_for_component_ref ( )
static

Look at the bottom of the COMPONENT_REF list for a DECL, and return it.

References ALIAS_SET_MEMORY_BARRIER, gcc_checking_assert, GET_CODE, GET_MODE, MEM_ALIAS_SET, MEM_VOLATILE_P, NULL_RTX, and XEXP.

void end_alias_analysis ( void  )

Referenced by pre_insert_copies().

static rtx find_base_term ( )
static
 Try machine-dependent ways to find the base term.   
     As we do not know which address space the pointer is referring to, we can
     handle this only if the target does not support different pointer or
     address modes depending on the address space.   
     Fall through.   
     As we do not know which address space the pointer is referring to, we can
     handle this only if the target does not support different pointer or
     address modes depending on the address space.   
     Temporarily reset val->locs to avoid infinite recursion.   
     The standard form is (lo_sum reg sym) so look only at the
     second operand.   
     Fall through.   
       This is a little bit tricky since we have to determine which of
       the two operands represents the real base address.  Otherwise this
       routine may return the index register instead of the base register.

       That may cause us to believe no aliasing was possible, when in
       fact aliasing is possible.

       We use a few simple tests to guess the base register.  Additional
       tests can certainly be added.  For example, if one of the operands
       is a shift or multiply, then it must be the index register and the
       other operand is the base register.   
       If either operand is known to be a pointer, then prefer it
       to determine the base term.   
       Go ahead and find the base term for both operands.  If either base
       term is from a pointer or is a named object or a special address
       (like an argument or stack reference), then use it for the
       base term.   
       We could not determine which of the two operands was the
       base register and which was the index.  So we can determine
       nothing from the base alias check.   

Referenced by rtx_equal_for_memref_p().

static rtx find_base_value ( rtx  )
static
static rtx find_base_value ( )
static

Inside SRC, the source of a SET, find a base address.

 Try machine-dependent ways to find the base term.   
     At the start of a function, argument registers have known base
     values which may be lost later.  Returning an ADDRESS
     expression here allows optimization based on argument values
     even when the argument registers are used for other purposes.   
     If a pseudo has a known base value, return it.  Do not do this
     for non-fixed hard regs since it can result in a circular
     dependency chain for registers which have values at function entry.

     The test above is not sufficient because the scheduler may move
     a copy out of an arg reg past the NOTE_INSN_FUNCTION_BEGIN.   
         If we're inside init_alias_analysis, use new_reg_base_value
         to reduce the number of relaxation iterations.   
     Check for an argument passed in memory.  Only record in the
     copying-arguments block; it is too hard to track changes
     otherwise.   
     ... fall through ...   
       If either operand is a REG that is a known pointer, then it
       is the base.   
       If either operand is a REG, then see if we already have
       a known value for it.   
       If either base is named object or a special address
       (like an argument or stack reference), then use it for the
       base term.   
       Guess which operand is the base address:
       If either operand is a symbol, then it is the base.  If
       either operand is a CONST_INT, then the other is the base.   
     The standard form is (lo_sum reg sym) so look only at the
     second operand.   
     If the second operand is constant set the base
     address to the first operand.   
     As we do not know which address space the pointer is referring to, we can
     handle this only if the target does not support different pointer or
     address modes depending on the address space.   
     Fall through.   
     As we do not know which address space the pointer is referring to, we can
     handle this only if the target does not support different pointer or
     address modes depending on the address space.   
rtx get_addr ( )

Convert the address X into something we can use. This is done by returning it unchanged unless it is a value; in the latter case we call cselib to get a more useful rtx.

Avoid infinite recursion when potentially dealing with var-tracking artificial equivalences, by skipping the equivalences themselves, and not choosing expressions that refer to newer VALUEs.

         Return the canonical value.   

Referenced by nonoverlapping_memrefs_p(), and refs_newer_value_cb().

alias_set_type get_alias_set ( )

Return the alias set for T, which may be either a type or an expression. Call language-specific routine for help, if needed.

 If we're not doing any alias analysis, just assume everything
 aliases everything else.  Also return 0 if this or its type is
 an error.   
 We can be passed either an expression or a type.  This and the
 language-specific routine may make mutually-recursive calls to each other
 to figure out what to do.  At each juncture, we see if this is a tree
 that the language may need to handle specially.  First handle things that
 aren't types.   
     Give the language a chance to do something with this tree
     before we look at it.   
     Get the alias pointer-type to use or the outermost object
     that we could have a pointer to.   
     If we've already determined the alias set for a decl, just return
     it.  This is necessary for C++ anonymous unions, whose component
     variables don't look like union members (boo!).   
     Now all we care about is the type.   
 Variant qualifiers don't affect the alias set, so get the main
 variant.   
 Always use the canonical type as well.  If this is a type that
 requires structural comparisons to identify compatible types
 use alias set zero.   
     Allow the language to specify another alias set for this
     type.   
 The canonical type should not require structural equality checks.   
 If this is a type with a known alias set, return it.   
 We don't want to set TYPE_ALIAS_SET for incomplete types.   
     For arrays with unknown size the conservative answer is the
     alias set of the element type.   
     But return zero as a conservative answer for incomplete types.   
 See if the language has special handling for this type.   
 There are no objects of FUNCTION_TYPE, so there's no point in
 using up an alias set for them.  (There are, of course, pointers
 and references to functions, but that's different.)   
 Unless the language specifies otherwise, let vector types alias
 their components.  This avoids some nasty type punning issues in
 normal usage.  And indeed lets vectors be treated more like an
 array slice.   
 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.   
 From the former common C and C++ langhook implementation:

 Unfortunately, there is no canonical form of a pointer type.
 In particular, if we have `typedef int I', then `int *', and
 `I *' are different types.  So, we have to pick a canonical
 representative.  We do this below.

 Technically, this approach is actually more conservative that
 it needs to be.  In particular, `const int *' and `int *'
 should be in different alias sets, according to the C and C++
 standard, since their types are not the same, and so,
 technically, an `int **' and `const int **' cannot point at
 the same thing.

 But, the standard is wrong.  In particular, this code is
 legal C++:

 int *ip;
 int **ipp = &ip;
 const int* const* cipp = ipp;
 And, it doesn't make sense for that to be legal unless you
 can dereference IPP and CIPP.  So, we ignore cv-qualifiers on
 the pointed-to types.  This issue has been reported to the
 C++ committee.

 In addition to the above canonicalization issue, with LTO
 we should also canonicalize `T (*)[]' to `T *' avoiding
 alias issues with pointer-to element types and pointer-to
 array types.

 Likewise we need to deal with the situation of incomplete
 pointed-to types and make `*(struct X **)&a' and
 `*(struct X {} **)&a' alias.  Otherwise we will have to
 guarantee that all pointer-to incomplete type variants
 will be replaced by pointer-to complete type variants if
 they are available.

 With LTO the convenient situation of using `void *' to
 access and store any pointer type will also become
 more apparent (and `void *' is just another pointer-to
 incomplete type).  Assigning alias-set zero to `void *'
 and all pointer-to incomplete types is a not appealing
 solution.  Assigning an effective alias-set zero only
 affecting pointers might be - by recording proper subset
 relationships of all pointer alias-sets.

 Pointer-to function types are another grey area which
 needs caution.  Globbing them all into one alias-set
 or the above effective zero set would work.

 For now just assign the same alias-set to all pointers.
 That's simple and avoids all the above problems.   
 Otherwise make a new alias set for this type.   
     Each canonical type gets its own alias set, so canonical types
     shouldn't form a tree.  It doesn't really matter for types
     we handle specially above, so only check it where it possibly
     would result in a bogus alias set.   
 If this is an aggregate type or a complex type, we must record any
 component aliasing information.   

Referenced by all_zeros_p(), array_ref_element_size(), and new_alias_set().

static alias_set_entry get_alias_set_entry ( alias_set_type  )
static
static alias_set_entry get_alias_set_entry ( )
inlinestatic

Returns a pointer to the alias set entry for ALIAS_SET, if there is such an entry, or NULL otherwise.

alias_set_type get_deref_alias_set ( )

Return the alias set for the memory pointed to by T, which may be either a type or an expression.

If we're not doing any alias analysis, just assume everything aliases everything else.

 Fall back to the alias-set of the pointed-to type.   
static alias_set_type get_deref_alias_set_1 ( )
static

Return the alias set for the memory pointed to by T, which may be either a type or an expression. Return -1 if there is nothing special about dereferencing T.

All we care about is the type.

 If we have an INDIRECT_REF via a void pointer, we don't
 know anything about what that might alias.  Likewise if the
 pointer is marked that way.   

References TREE_CODE, and TREE_OPERAND.

alias_set_type get_frame_alias_set ( void  )
rtx get_reg_base_value ( )

Return REG_BASE_VALUE for REGNO. Selective scheduler uses this to avoid using hard registers with non-null REG_BASE_VALUE for renaming.

bool get_reg_known_equiv_p ( )

Similarly for reg_known_equiv_p.

References canon_rtx(), and XEXP.

rtx get_reg_known_value ( )

If a value is known for REGNO, return it.

References REGNO, XEXP, and XSTR.

alias_set_type get_varargs_alias_set ( void  )

We now lower VA_ARG_EXPR, and there's currently no way to attach the varargs alias set to an INDIRECT_REF (FIXME!), so we can't consistently use the varargs alias set for loads from the varargs area. So don't use it anywhere.

References DF_REG_DEF_COUNT.

void init_alias_analysis ( void  )

Initialize the aliasing machinery. Initialize the REG_KNOWN_VALUE array.

 If we have memory allocated from the previous run, use it.   
 The basic idea is that each pass through this loop will use the
 "constant" information from the previous pass to propagate alias
 information through another level of assignments.

 The propagation is done on the CFG in reverse post-order, to propagate
 things forward as far as possible in each iteration.

 This could get expensive if the assignment chains are long.  Maybe
 we should throttle the number of iterations, possibly based on
 the optimization level or flag_expensive_optimizations.

 We could propagate more information in the first pass by making use
 of DF_REG_DEF_COUNT to determine immediately that the alias information
 for a pseudo is "constant".

 A program with an uninitialized variable can cause an infinite loop
 here.  Instead of doing a full dataflow analysis to detect such problems
 we just cap the number of iterations for the loop.

 The state of the arrays for the set chain in question does not matter
 since the program has undefined behavior.   
     Assume nothing will change this iteration of the loop.   
     We want to assign the same IDs each iteration of this loop, so
     start counting from one each iteration of the loop.   
     We're at the start of the function each iteration through the
     loop, so we're copying arguments.   
     Wipe the potential alias information clean for this pass.   
     Wipe the reg_seen array clean.   
     Initialize the alias information for this pass.   
     Walk the insns adding values to the new_reg_base_value array.   
                 The prologue/epilogue insns are not threaded onto the
                 insn chain until after reload has completed.  Thus,
                 there is no sense wasting time checking if INSN is in
                 the prologue/epilogue until after reload has completed.   
                 If this insn has a noalias note, process it,  Otherwise,
                 scan for sets.  A simple set will have no side effects
                 which could change the base value of any other register.   
     Now propagate values from new_reg_base_value to reg_base_value.   
 Fill in the remaining entries.   
 Clean up.   

Referenced by memref_referenced_p(), and pre_insert_copies().

void init_alias_target ( void  )

Check whether this register can hold an incoming pointer argument. FUNCTION_ARG_REGNO_P tests outgoing register numbers, so translate if necessary due to register windows.

static int insert_subset_children ( splay_tree_node  ,
void *   
)
static
static int insert_subset_children ( )
static

Insert the NODE into the splay tree given by DATA. Used by record_alias_subset via splay_tree_foreach.

References alias_sets_must_conflict_p(), get_alias_set_entry(), and alias_set_entry_d::has_zero_child.

static bool known_base_value_p ( )
static

Return true if X is known to be a base value.

Arguments may or may not be bases; we don't know for sure.

References find_base_value().

Referenced by rtx_equal_for_memref_p().

int may_alias_p ( )

Check whether X may be aliased with MEM. Don't do offset-based memory disambiguation & TBAA.

 (mem:BLK (scratch)) is a special mechanism to conflict with everything.
 This is used in epilogue deallocation functions.   
 Read-only memory is by definition never modified, and therefore can't
 conflict with anything.  We don't expect to find read-only set on MEM,
 but stupid user tricks can produce them, so don't die.   
 If we have MEMs referring to different address spaces (which can
 potentially overlap), we cannot easily tell from the addresses
 whether the references overlap.   
 TBAA not valid for loop_invarint  
bool may_be_sp_based_p ( )

Return true if accesses to address X may alias accesses based on the stack pointer.

Referenced by record_store(), and store_killed_in_pat().

static void memory_modified_1 ( rtx  ,
const_rtx  ,
void *   
)
static
static void memory_modified_1 ( )
static

References ui.

bool memory_modified_in_insn_p ( )

Return true when INSN possibly modify memory contents of MEM (i.e. address can be modified).

bool memory_must_be_modified_in_insn_p ( )

Like memory_modified_in_insn_p, but return TRUE if INSN will DEFINITELY modify the memory contents of MEM.

References reg_base_value, sbitmap_free(), and vec_free().

static int memrefs_conflict_p ( int  ,
rtx  ,
int  ,
rtx  ,
HOST_WIDE_INT   
)
static
static int memrefs_conflict_p ( )
static

Return one if X and Y (memory addresses) reference the same location in memory or if the references overlap. Return zero if they do not overlap, else return minus one in which case they still might reference the same location.

C is an offset accumulator. When C is nonzero, we are testing aliases between X and Y + C. XSIZE is the size in bytes of the X reference, similarly YSIZE is the size in bytes for Y. Expect that canon_rtx has been already called for X and Y.

If XSIZE or YSIZE is zero, we do not know the amount of memory being referenced (the reference was BLKmode), so make the most pessimistic assumptions.

If XSIZE or YSIZE is negative, we may access memory outside the object being referenced as a side effect. This can happen when using AND to align memory references, as is done on the Alpha.

Nice to notice that varying addresses cannot conflict with fp if no local variables had their addresses taken, but that's too hard now.

??? Contrary to the tree alias oracle this does not return one for X + non-constant and Y + non-constant when X and Y are equal. If that is fixed the TBAA hack for union type-punning can be removed.

     Don't call get_addr if y is the same VALUE.   
     Don't call get_addr if x is the same VALUE.   
 This code used to check for conflicts involving stack references and
 globals but the base address alias code now handles these cases.   
     The fact that X is canonicalized means that this
     PLUS rtx is canonicalized.   
         The fact that Y is canonicalized means that this
         PLUS rtx is canonicalized.   
     The fact that Y is canonicalized means that this
     PLUS rtx is canonicalized.   
         Handle cases where we expect the second operands to be the
         same, and check only whether the first operand would conflict
         or not.   
         Can't properly adjust our sizes.   
 Deal with alignment ANDs by adjusting offset and size so as to
 cover the maximum range, without taking any previously known
 alignment into account.  Make a size negative after such an
 adjustments, so that, if we end up with e.g. two SYMBOL_REFs, we
 assume a potential overlap, because they may end up in contiguous
 memory locations and the stricter-alignment access may span over
 part of both.   
     Assume a potential overlap for symbolic addresses that went
     through alignment adjustments (i.e., that have negative
     sizes), because we can't know how far they are from each
     other.   
static int mems_in_disjoint_alias_sets_p ( const_rtx  ,
const_rtx   
)
static
static int mems_in_disjoint_alias_sets_p ( )
inlinestatic

Returns nonzero if the alias sets for MEM1 and MEM2 are such that the two MEMs cannot alias each other.

Perform a basic sanity check. Namely, that there are no alias sets if we're not using strict aliasing. This helps to catch bugs whereby someone uses PUT_CODE, but doesn't clear MEM_ALIAS_SET, or where a MEM is allocated in some way other than by the use of gen_rtx_MEM, and the MEM_ALIAS_SET is not cleared. If we begin to use alias sets to indicate that spilled registers cannot alias each other, we might need to remove this check.

References alias_set_entry_d::children, get_alias_set_entry(), and alias_set_entry_d::has_zero_child.

static bool nonoverlapping_component_refs_p ( const_rtx  ,
const_rtx   
)
static
static bool nonoverlapping_component_refs_p ( )
static

Return true if we can determine that the fields referenced cannot overlap for any pair of objects.

     The comparison has to be done at a common type, since we don't
     know how the inheritance hierarchy works.   
     Never found a common type.   
     If we're left with accessing different fields of a structure, then no
     possible overlap, unless they are both bitfields.   
     The comparison on the current field failed.  If we're accessing
     a very nested structure, look at the next outer level.   
int nonoverlapping_memrefs_p ( )

Return nonzero if we can determine the exprs corresponding to memrefs X and Y and they do not overlap. If LOOP_VARIANT is set, skip offset-based disambiguation

 Unless both have exprs, we can't tell anything.   
 For spill-slot accesses make sure we have valid offsets.   
 If the field reference test failed, look at the DECLs involved.   
 With invalid code we can end up storing into the constant pool.
 Bail out to avoid ICEing when creating RTL for this.
 See gfortran.dg/lto/20091028-2_0.f90.   
 If either RTL is not a MEM, it must be a REG or CONCAT, meaning they
 can't overlap unless they are the same because we never reuse that part
 of the stack frame used for locals for spilled pseudos.   
 If we have MEMs referring to different address spaces (which can
 potentially overlap), we cannot easily tell from the addresses
 whether the references overlap.   
 Get the base and offsets of both decls.  If either is a register, we
 know both are and are the same, so use that as the base.  The only
 we can avoid overlap is if we can deduce that they are nonoverlapping
 pieces of that decl, which is very rare.   
 If the bases are different, we know they do not overlap if both
 are constants or if one is a constant and the other a pointer into the
 stack frame.  Otherwise a different base means we can't tell if they
 overlap or not.   
 Offset based disambiguation not appropriate for loop invariant  
 If we have an offset for either memref, it can update the values computed
 above.   
 If a memref has both a size and an offset, we can use the smaller size.
 We can't do this if the offset isn't known because we must view this
 memref as being anywhere inside the DECL's MEM.   
 Put the values of the memref with the lower offset in X's values.   
 If we don't know the size of the lower-offset value, we can't tell
 if they conflict.  Otherwise, we do the test.   

References get_addr().

int objects_must_conflict_p ( )

Return 1 if any MEM object of type T1 will always conflict (using the dependency routines in this file) with any MEM object of type T2. This is used when allocating temporary storage. If T1 and/or T2 are NULL_TREE, it means we know nothing about the storage.

 If neither has a type specified, we don't know if they'll conflict
 because we may be using them to store objects of various types, for
 example the argument and local variables areas of inlined functions.   
 If they are the same type, they must conflict.   
     Likewise if both are volatile.   
 We can't use alias_sets_conflict_p because we must make sure
 that every subtype of t1 will conflict with every subtype of
 t2 for which a pair of subobjects of these respective subtypes
 overlaps on the stack.   

References DECL_NONADDRESSABLE_P, gcc_unreachable, TREE_OPERAND, TREE_TYPE, and TYPE_NONALIASED_COMPONENT.

static bool offset_overlap_p ( )
inlinestatic

Return TRUE if an object X sized at XSIZE bytes and another object Y sized at YSIZE bytes, starting C bytes after X, may overlap. If any of the sizes is zero, assume an overlap, otherwise use the absolute value of the sizes as the actual sizes.

int output_dependence ( )

Output dependence: X is written after store in MEM takes place.

Referenced by find_loads(), and write_dependence_p().

int read_dependence ( )

Functions to compute memory dependencies.

Since we process the insns in execution order, we can build tables to keep track of what registers are fixed (and not aliased), what registers are varying in known ways, and what registers are varying in unknown ways.

If both memory references are volatile, then there must always be a dependence between the two references, since their order can not be changed. A volatile and non-volatile reference can be interchanged though.

We also must allow AND addresses, because they may generate accesses outside the object being referenced. This is used to generate aligned addresses from unaligned addresses, for instance, the alpha storeqi_unaligned pattern. Read dependence: X is read after read in MEM takes place. There can only be a dependence here if both reads are volatile, or if either is an explicit barrier.

void record_alias_subset ( )

Indicate that things in SUBSET can alias things in SUPERSET, but that not everything that aliases SUPERSET also aliases SUBSET. For example, in C, a store to an `int' can alias a load of a structure containing an `int', and vice versa. But it can't alias a load of a 'double' member of the same structure. Here, the structure would be the SUPERSET and `int' the SUBSET. This relationship is also described in the comment at the beginning of this file.

This function should be called only once per SUPERSET/SUBSET pair.

It is illegal for SUPERSET to be zero; everything is implicitly a subset of alias set zero.

 It is possible in complex type situations for both sets to be the same,
 in which case we can ignore this operation.   
     Create an entry for the SUPERSET, so that we have a place to
     attach the SUBSET.   
     If there is an entry for the subset, enter all of its children
     (if they are not already present) as children of the SUPERSET.   
     Enter the SUBSET itself as a child of the SUPERSET.   

Referenced by new_alias_set().

void record_component_aliases ( )

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 not marked non-addressable. For array types, we only record the component type if it is not marked non-aliased.

Recursively record aliases for the base classes, if there are any.

   VECTOR_TYPE and ARRAY_TYPE share the alias set with their
   element type.   

References GET_CODE, and GET_MODE.

static void record_set ( rtx  ,
const_rtx  ,
void *   
)
static
static void record_set ( )
static
 If this spans multiple hard registers, then we must indicate that every
 register has an unusable value.   
     A CLOBBER wipes out any old value but does not prevent a previously
     unset register from acquiring a base address (i.e. reg_seen is not
     set).   
     There's a REG_NOALIAS note against DEST.   
 If this is not the first set of REGNO, see whether the new value
 is related to the old one.  There are two cases of interest:

    (1) The register might be assigned an entirely new value
        that has the same base term as the original set.

    (2) The set might be a simple self-modification that
        cannot change REGNO's base value.

 If neither case holds, reject the original base value as invalid.
 Note that the following situation is not detected:

     extern int x, y;  int *p = &x; p += (&y-&x);

 ANSI C does not allow computing the difference of addresses
 of distinct top level objects.   
       If the value we add in the PLUS is also a valid base value,
       this might be the actual base value, and the original value
       an index.   
 If this is the first set of a register, record the value.   

References NULL, and vec_safe_length().

static bool ref_all_alias_ptr_type_p ( )
static

Return whether the pointer-type T effective for aliasing may access everything and thus the reference has to be assigned alias-set zero.

tree reference_alias_ptr_type ( )

Return the pointer-type relevant for TBAA purposes from the gimple memory reference tree T. This is the type to be used for the offset operand of MEM_REF or TARGET_MEM_REF replacements of T and guarantees that get_alias_set will return the same alias set for T and the replacement.

If there is a given pointer type for aliasing purposes, return it.

 Otherwise build one from the outermost component reference we
 may use.   

Referenced by vect_permute_store_chain().

static tree reference_alias_ptr_type_1 ( )
static

Return the pointer-type relevant for TBAA purposes from the memory reference tree *T or NULL_TREE in which case *T is adjusted to point to the outermost component reference that can be used for assigning an alias set.

 Get the base object of the reference.   
     If there is a VIEW_CONVERT_EXPR in the chain we cannot use
     the type of any component references that wrap it to
     determine the alias-set.   
 Handle pointer dereferences here, they can override the
 alias-set.   
 If the innermost reference is a MEM_REF that has a
 conversion embedded treat it like a VIEW_CONVERT_EXPR above,
 using the memory access type for determining the alias-set.   
 Otherwise, pick up the outermost object that we could have
 a pointer to.   
static int refs_newer_value_cb ( )
static

Callback for for_each_rtx, that returns 1 upon encountering a VALUE whose UID is greater than the int uid that D points to.

References canonical_cselib_val(), CSELIB_VAL_PTR, get_addr(), elt_loc_list::loc, elt_loc_list::next, NULL, REG_P, and rtx_equal_for_memref_p().

static bool refs_newer_value_p ( )
static

Return TRUE if EXPR refers to a VALUE whose uid is greater than that of V.

static int rtx_equal_for_memref_p ( const_rtx  ,
const_rtx   
)
static

Referenced by canon_rtx(), and refs_newer_value_cb().

static int rtx_equal_for_memref_p ( )
static

Return 1 if X and Y are identical-looking rtx's. Expect that X and Y has been already canonicalized.

We use the data in reg_known_value above to see if two registers with different numbers are, in fact, equivalent.

 Rtx's of different codes cannot be equal.   
 (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
 (REG:SI x) and (REG:HI x) are NOT equivalent.   
 Some RTL can be compared without a recursive examination.   
     This is magic, don't go through canonicalization et al.   
     There's no need to compare the contents of CONST_DOUBLEs or
     CONST_INTs because pointer equality is a good enough
     comparison for these nodes.   
 canon_rtx knows how to handle plus.  No need to canonicalize.   
 For commutative operations, the RTX match if the operand match in any
 order.  Also handle the simple binary and unary cases without a loop.   
 Compare the elements.  If any pair of corresponding elements
 fail to match, return 0 for the whole things.

 Limit cases to types which actually appear in addresses.   
         Two vectors must have the same length.   
         And the corresponding elements must match.   
         This can happen for asm operands.   
       This can happen for an asm which clobbers memory.   
         It is believed that rtx's at this level will never
         contain anything but integers and other rtx's,
         except for within LABEL_REFs and SYMBOL_REFs.   

References CONST_INT_P, CONSTANT_P, convert_memory_address, cselib_sp_based_value_p(), CSELIB_VAL_PTR, find_base_term(), GET_CODE, GET_MODE, GET_MODE_SIZE, INTVAL, known_base_value_p(), elt_loc_list::loc, cselib_val_struct::locs, elt_loc_list::next, NULL, NULL_RTX, pic_offset_table_rtx, REG_P, REG_POINTER, target_default_pointer_address_modes_p(), and XEXP.

static bool rtx_refs_may_alias_p ( )
static

Query the alias-oracle on whether the two memory rtx X and MEM may alias. If TBAA_P is set also apply TBAA. Returns true if the two rtxen may alias, false otherwise.

References alias_sets_conflict_p(), gcc_assert, and MEM_ALIAS_SET.

static bool set_dest_equal_p ( )
inlinestatic

Return TRUE if the destination of a set is rtx identical to ITEM.

References REGNO.

static void set_reg_known_equiv_p ( )
static
static void set_reg_known_value ( )
static

Set it.

int true_dependence ( )

True dependence: X is read after store in MEM takes place.

Referenced by equiv_init_varies_p().

static int true_dependence_1 ( const_rtx  mem,
enum machine_mode  mem_mode,
rtx  mem_addr,
const_rtx  x,
rtx  x_addr,
bool  mem_canonicalized 
)
static

Helper for true_dependence and canon_true_dependence. Checks for true dependence: X is read after store in MEM takes place.

If MEM_CANONICALIZED is FALSE, then X_ADDR and MEM_ADDR should be NULL_RTX, and the canonical addresses of MEM and X are both computed here. If MEM_CANONICALIZED, then MEM must be already canonicalized.

If X_ADDR is non-NULL, it is used in preference of XEXP (x, 0).

Returns 1 if there is a true dependence, 0 otherwise.

 (mem:BLK (scratch)) is a special mechanism to conflict with everything.
 This is used in epilogue deallocation functions, and in cselib.   
 Read-only memory is by definition never modified, and therefore can't
 conflict with anything.  We don't expect to find read-only set on MEM,
 but stupid user tricks can produce them, so don't die.   
 If we have MEMs referring to different address spaces (which can
 potentially overlap), we cannot easily tell from the addresses
 whether the references overlap.   
static rtx unique_base_value ( )
static

Create a new, unique base with id ID.

References find_base_value(), REG_P, REG_POINTER, and XEXP.

static bool unique_base_value_p ( )
static

Return true if accesses based on any other base value cannot alias those based on X.

References find_base_value().

void vt_equate_reg_base_value ( )

Equate REG_BASE_VALUE (reg1) to REG_BASE_VALUE (reg2). Special API for var-tracking pass purposes.

static int write_dependence_p ( const_rtx  mem,
const_rtx  x,
enum machine_mode  x_mode,
rtx  x_addr,
bool  mem_canonicalized,
bool  x_canonicalized,
bool  writep 
)
static

Returns nonzero if a write to X might alias a previous read from (or, if WRITEP is true, a write to) MEM. If X_CANONCALIZED is true, then X_ADDR is the canonicalized address of X, and X_MODE the mode for that access. If MEM_CANONICALIZED is true, MEM is canonicalized.

 (mem:BLK (scratch)) is a special mechanism to conflict with everything.
 This is used in epilogue deallocation functions.   
 A read from read-only memory can't conflict with read-write memory.   
 If we have MEMs referring to different address spaces (which can
 potentially overlap), we cannot easily tell from the addresses
 whether the references overlap.   

References anti_dependence(), MEM_P, memory_modified, and output_dependence().


Variable Documentation

vec<alias_set_entry, va_gc>* alias_sets
static

The splay-tree used to store the various alias set entries.

rtx arg_base_value
static

The single VOIDmode ADDRESS that represents all argument bases. It has id 0.

bool copying_arguments
static

True when scanning insns from the start of the rtl to the NOTE_INSN_FUNCTION_BEG note.

alias_set_type frame_set = -1
static

Likewise, but used for the fixed portions of the frame, e.g., register save areas.

bool memory_modified
static

Set MEMORY_MODIFIED when X modifies DATA (that is assumed to be memory reference.

Referenced by write_dependence_p().

rtx* new_reg_base_value
static
vec<rtx, va_gc>* old_reg_base_value
static

We preserve the copy of old array around to avoid amount of garbage produced. About 8% of garbage produced were attributed to this array.

vec<rtx, va_gc>* reg_base_value
static

reg_base_value[N] gives an address to which register N is related. If all sets after the first add or subtract to the current value or otherwise modify it so it does not point to a different top level object, reg_base_value[N] is equal to the address part of the source of the first set.

A base address can be an ADDRESS, SYMBOL_REF, or LABEL_REF. ADDRESS expressions represent three types of base:

  1. incoming arguments. There is just one ADDRESS to represent all arguments, since we do not know at this level whether accesses based on different arguments can alias. The ADDRESS has id 0.
  1. stack_pointer_rtx, frame_pointer_rtx, hard_frame_pointer_rtx (if distinct from frame_pointer_rtx) and arg_pointer_rtx. Each of these rtxes has a separate ADDRESS associated with it, each with a negative id.

    GCC is (and is required to be) precise in which register it chooses to access a particular region of stack. We can therefore assume that accesses based on one of these rtxes do not alias accesses based on another of these rtxes.

  1. bases that are derived from malloc()ed memory (REG_NOALIAS). Each such piece of memory has a separate ADDRESS associated with it, each with an id greater than 0.

Accesses based on one ADDRESS do not alias accesses based on other ADDRESSes. Accesses based on ADDRESSes in groups (2) and (3) do not alias globals either; the ADDRESSes have Pmode to indicate this. The ADDRESS in group (1) may alias globals; it has VOIDmode to indicate this.

Referenced by memory_must_be_modified_in_insn_p().

sbitmap reg_known_equiv_p
static

Vector recording for each reg_known_value whether it is due to a REG_EQUIV note. Future passes (viz., reload) may replace the pseudo with the equivalent expression and so we account for the dependences that would be introduced if that happens.

The REG_EQUIV notes created in assign_parms may mention the arg pointer, and there are explicit insns in the RTL that modify the arg pointer. Thus we must ensure that such insns don't get scheduled across each other because that would invalidate the REG_EQUIV notes. One could argue that the REG_EQUIV notes are wrong, but solving the problem in the scheduler will likely give better code, so we do it here.

vec<rtx, va_gc>* reg_known_value
static

Vector indexed by N giving the initial (unchanging) value known for pseudo-register N. This vector is initialized in init_alias_analysis, and does not change until end_alias_analysis is called.

sbitmap reg_seen
static

Called from init_alias_analysis indirectly through note_stores, or directly if DEST is a register with a REG_NOALIAS note attached. SET is null in the latter case. While scanning insns to find base values, reg_seen[N] is nonzero if register N has been set in this function.

int unique_id
static

Used to allocate unique ids to each REG_NOALIAS ADDRESS.

alias_set_type varargs_set = -1
static

Allocate an alias set for use in storing and reading from the varargs spill area.