GCC Middle and Back End API Reference
tree-ssa-alias.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "tm_p.h"
#include "target.h"
#include "basic-block.h"
#include "timevar.h"
#include "ggc.h"
#include "langhooks.h"
#include "flags.h"
#include "function.h"
#include "tree-pretty-print.h"
#include "dumpfile.h"
#include "gimple.h"
#include "gimple-ssa.h"
#include "tree-ssanames.h"
#include "tree-dfa.h"
#include "tree-inline.h"
#include "params.h"
#include "vec.h"
#include "pointer-set.h"
#include "alloc-pool.h"
#include "tree-ssa-alias.h"
#include "ipa-reference.h"
#include "sync-builtins.def"
Include dependency graph for tree-ssa-alias.c:

Macros

#define DEF_SYNC_BUILTIN(ENUM, NAME, TYPE, ATTRS)   case ENUM:
#define DEF_SYNC_BUILTIN(ENUM, NAME, TYPE, ATTRS)   case ENUM:

Functions

void dump_alias_stats ()
bool ptr_deref_may_alias_global_p ()
static bool ptr_deref_may_alias_decl_p ()
bool ptr_derefs_may_alias_p ()
static bool ptr_deref_may_alias_ref_p_1 ()
bool ref_may_alias_global_p ()
bool stmt_may_clobber_global_p ()
void dump_alias_info ()
DEBUG_FUNCTION void debug_alias_info ()
void dump_points_to_solution ()
DEBUG_FUNCTION void debug ()
void dump_points_to_info_for ()
DEBUG_FUNCTION void debug_points_to_info_for ()
void ao_ref_init ()
tree ao_ref_base ()
static alias_set_type ao_ref_base_alias_set ()
alias_set_type ao_ref_alias_set ()
void ao_ref_init_from_ptr_and_size ()
static int same_type_for_tbaa ()
static bool aliasing_component_refs_p (tree ref1, alias_set_type ref1_alias_set, alias_set_type base1_alias_set, HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1, tree ref2, alias_set_type ref2_alias_set, alias_set_type base2_alias_set, HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2, bool ref2_is_decl)
static bool nonoverlapping_component_refs_of_decl_p ()
static bool decl_refs_may_alias_p (tree ref1, tree base1, HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1, tree ref2, tree base2, HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2)
static bool indirect_ref_may_alias_decl_p (tree ref1, tree base1, HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1, alias_set_type ref1_alias_set, alias_set_type base1_alias_set, tree ref2, tree base2, HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2, alias_set_type ref2_alias_set, alias_set_type base2_alias_set, bool tbaa_p)
static bool indirect_refs_may_alias_p (tree ref1, tree base1, HOST_WIDE_INT offset1, HOST_WIDE_INT max_size1, alias_set_type ref1_alias_set, alias_set_type base1_alias_set, tree ref2, tree base2, HOST_WIDE_INT offset2, HOST_WIDE_INT max_size2, alias_set_type ref2_alias_set, alias_set_type base2_alias_set, bool tbaa_p)
bool refs_may_alias_p_1 ()
bool refs_may_alias_p ()
bool refs_anti_dependent_p ()
bool refs_output_dependent_p ()
static bool ref_maybe_used_by_call_p_1 ()
static bool ref_maybe_used_by_call_p ()
bool ref_maybe_used_by_stmt_p ()
static bool call_may_clobber_ref_p_1 ()
bool call_may_clobber_ref_p ()
bool stmt_may_clobber_ref_p_1 ()
bool stmt_may_clobber_ref_p ()
static bool stmt_kills_ref_p_1 ()
bool stmt_kills_ref_p ()
static bool maybe_skip_until (gimple phi, tree target, ao_ref *ref, tree vuse, unsigned int *cnt, bitmap *visited, bool abort_on_visited)
static tree get_continuation_for_phi_1 (gimple phi, tree arg0, tree arg1, ao_ref *ref, unsigned int *cnt, bitmap *visited, bool abort_on_visited)
tree get_continuation_for_phi (gimple phi, ao_ref *ref, unsigned int *cnt, bitmap *visited, bool abort_on_visited)
void * walk_non_aliased_vuses (ao_ref *ref, tree vuse, void *(*walker)(ao_ref *, tree, unsigned int, void *), void *(*translate)(ao_ref *, tree, void *), void *data)
static unsigned int walk_aliased_vdefs_1 (ao_ref *ref, tree vdef, bool(*walker)(ao_ref *, tree, void *), void *data, bitmap *visited, unsigned int cnt)
unsigned int walk_aliased_vdefs (ao_ref *ref, tree vdef, bool(*walker)(ao_ref *, tree, void *), void *data, bitmap *visited)

Variables

struct {
   unsigned HOST_WIDE_INT   refs_may_alias_p_may_alias
   unsigned HOST_WIDE_INT   refs_may_alias_p_no_alias
   unsigned HOST_WIDE_INT   ref_maybe_used_by_call_p_may_alias
   unsigned HOST_WIDE_INT   ref_maybe_used_by_call_p_no_alias
   unsigned HOST_WIDE_INT   call_may_clobber_ref_p_may_alias
   unsigned HOST_WIDE_INT   call_may_clobber_ref_p_no_alias
alias_stats

Macro Definition Documentation

#define DEF_SYNC_BUILTIN (   ENUM,
  NAME,
  TYPE,
  ATTRS 
)    case ENUM:
#define DEF_SYNC_BUILTIN (   ENUM,
  NAME,
  TYPE,
  ATTRS 
)    case ENUM:

Function Documentation

static bool aliasing_component_refs_p ( tree  ref1,
alias_set_type  ref1_alias_set,
alias_set_type  base1_alias_set,
HOST_WIDE_INT  offset1,
HOST_WIDE_INT  max_size1,
tree  ref2,
alias_set_type  ref2_alias_set,
alias_set_type  base2_alias_set,
HOST_WIDE_INT  offset2,
HOST_WIDE_INT  max_size2,
bool  ref2_is_decl 
)
static

Determine if the two component references REF1 and REF2 which are based on access types TYPE1 and TYPE2 and of which at least one is based on an indirect reference may alias. REF2 is the only one that can be a decl in which case REF2_IS_DECL is true. REF1_ALIAS_SET, BASE1_ALIAS_SET, REF2_ALIAS_SET and BASE2_ALIAS_SET are the respective alias sets.

 If one reference is a component references through pointers try to find a
 common base and apply offset based disambiguation.  This handles
 for example
   struct A { int i; int j; } *q;
   struct B { struct A a; int k; } *p;
 disambiguating q->i and p->a.j.   
 Choose bases and base types to search for.   
 Now search for the type1 in the access path of ref2.  This
 would be a common base for doing offset based disambiguation on.   
 If we couldn't compare types we have to bail out.   
 If we didn't find a common base, try the other way around.   
 If we couldn't compare types we have to bail out.   
 If we have two type access paths B1.path1 and B2.path2 they may
 only alias if either B1 is in B2.path2 or B2 is in B1.path1.
 But we can still have a path that goes B1.path1...B2.path2 with
 a part that we do not see.  So we can only disambiguate now
 if there is no B2 in the tail of path1 and no B1 on the
 tail of path2.   
 If this is ptr vs. decl then we know there is no ptr ... decl path.   
alias_set_type ao_ref_alias_set ( )

Returns the reference alias set of the memory reference *REF.

tree ao_ref_base ( )

Returns the base object of the memory reference *REF.

static alias_set_type ao_ref_base_alias_set ( )
static
void ao_ref_init ( )

Initializes the alias-oracle reference representation *R from REF.

Referenced by may_move_till().

void ao_ref_init_from_ptr_and_size ( )

Init an alias-oracle reference representation from a gimple pointer PTR and a gimple size SIZE in bytes. If SIZE is NULL_TREE the the size is assumed to be unknown. The access is assumed to be only to or after of the pointer target, not before it.

Referenced by fold_builtin_logarithm(), get_ssa_def_if_simple_copy(), load_from_unmodified_param(), refs_may_alias_p(), refs_output_dependent_p(), and type_like_member_ptr_p().

bool call_may_clobber_ref_p ( )

If the call in statement CALL may clobber the memory reference REF return true, otherwise return false.

static bool call_may_clobber_ref_p_1 ( )
static

If the call in statement CALL may clobber the memory reference REF return true, otherwise return false.

 If the call is pure or const it cannot clobber anything.   
 A call that is not without side-effects might involve volatile
 accesses and thus conflicts with all other volatile accesses.   
 If the reference is based on a decl that is not aliased the call
 cannot possibly clobber it.   
     But local non-readonly statics can be modified through recursion
     or the call may implement a threading barrier which we must
     treat as may-def.   
 Handle those builtin functions explicitly that do not act as
 escape points.  See tree-ssa-structalias.c:find_func_aliases
 for the list of builtins we might need to handle here.   
       All the following functions clobber memory pointed to by
       their first argument.   
           Don't pass in size for strncat, as the maximum size
           is strlen (dest) + n + 1 instead of n, resp.
           n + 1 at dest + strlen (dest), but strlen (dest) isn't
           known.   
           Don't pass in size for __strncat_chk, as the maximum size
           is strlen (dest) + n + 1 instead of n, resp.
           n + 1 at dest + strlen (dest), but strlen (dest) isn't
           known.   
       Allocating memory does not have any side-effects apart from
       being the definition point for the pointer.   
         Unix98 specifies that errno is set on allocation failure.   
       Freeing memory kills the pointed-to memory.  More importantly
       the call has to serve as a barrier for moving loads and stores
       across it.   
       __sync_* builtins and some OpenMP builtins act as threading
       barriers.   

This file contains the definitions and documentation for the synchronization builtins used in the GNU compiler. Copyright (C) 2005-2013 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/.

Before including this file, you should define a macro:

DEF_SYNC_BUILTIN (ENUM, NAME, TYPE, ATTRS)

See builtins.def for details.

Synchronization Primitives. The "_N" version is the one that the user is supposed to be using. It's overloaded, and is resolved to one of the "_1" through "_16" versions, plus some extra casts.

__sync* builtins for the C++ memory model.

         Fallthru to general call handling.   
 Check if base is a global static variable that is not written
 by the function.   
 Check if the base variable is call-clobbered.   

References gimple_call_arg(), ptr_deref_may_alias_ref_p_1(), and targetm.

DEBUG_FUNCTION void debug ( )

Unified dump function for pt_solution.

DEBUG_FUNCTION void debug_alias_info ( void  )

Dump alias information on stderr.

DEBUG_FUNCTION void debug_points_to_info_for ( )

Dump points-to information for VAR into stderr.

References ao_ref_s::base_alias_set, and ao_ref_s::ref.

static bool decl_refs_may_alias_p ( tree  ref1,
tree  base1,
HOST_WIDE_INT  offset1,
HOST_WIDE_INT  max_size1,
tree  ref2,
tree  base2,
HOST_WIDE_INT  offset2,
HOST_WIDE_INT  max_size2 
)
static

Return true if two memory references based on the variables BASE1 and BASE2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. REF1 and REF2 if non-NULL are the complete memory reference trees.

 If both references are based on different variables, they cannot alias.   
 If both references are based on the same variable, they cannot alias if
 the accesses do not overlap.   
 For components with variable position, the above test isn't sufficient,
 so we disambiguate component references manually.   
void dump_alias_info ( )

Dump alias information on FILE.

Referenced by debug_sa_points_to_info().

void dump_alias_stats ( )
void dump_points_to_info_for ( )

Dump points-to information for SSA_NAME PTR into FILE.

void dump_points_to_solution ( )

Dump the points-to set *PT into FILE.

tree get_continuation_for_phi ( gimple  phi,
ao_ref ref,
unsigned int *  cnt,
bitmap visited,
bool  abort_on_visited 
)

Starting from a PHI node for the virtual operand of the memory reference REF find a continuation virtual operand that allows to continue walking statements dominating PHI skipping only statements that cannot possibly clobber REF. Increments *CNT for each alias disambiguation done. Returns NULL_TREE if no suitable virtual operand can be found.

 Through a single-argument PHI we can simply look through.   
 For two or more arguments try to pairwise skip non-aliasing code
 until we hit the phi argument definition that dominates the other one.   
     Find a candidate for the virtual operand which definition
     dominates those of all others.   
     Then pairwise reduce against the found candidate.   

References BITMAP_ALLOC, bitmap_set_bit, gimple_nop_p(), gimple_phi_arg_def(), gimple_phi_num_args(), gimple_vuse(), NULL, SSA_NAME_DEF_STMT, SSA_NAME_VERSION, stmt_may_clobber_ref_p_1(), visited, and walk_aliased_vdefs_1().

Referenced by stmt_kills_ref_p_1().

static tree get_continuation_for_phi_1 ( gimple  phi,
tree  arg0,
tree  arg1,
ao_ref ref,
unsigned int *  cnt,
bitmap visited,
bool  abort_on_visited 
)
static

For two PHI arguments ARG0 and ARG1 try to skip non-aliasing code until we hit the phi argument definition that dominates the other one. Return that, or NULL_TREE if there is no such definition.

Special case of a diamond: MEM_1 = ... goto (cond) ? L1 : L2 L1: store1 = ... #MEM_2 = vuse(MEM_1) goto L3 L2: store2 = ... #MEM_3 = vuse(MEM_1) L3: MEM_4 = PHI<MEM_2, MEM_3> We were called with the PHI at L3, MEM_2 and MEM_3 don't dominate each other, but still we can easily skip this PHI node if we recognize that the vuse MEM operand is the same for both, and that we can skip both statements (they don't clobber us). This is still linear. Don't use maybe_skip_until, that might potentially be slow.

Referenced by maybe_skip_until().

static bool indirect_ref_may_alias_decl_p ( tree  ref1,
tree  base1,
HOST_WIDE_INT  offset1,
HOST_WIDE_INT  max_size1,
alias_set_type  ref1_alias_set,
alias_set_type  base1_alias_set,
tree  ref2,
tree  base2,
HOST_WIDE_INT  offset2,
HOST_WIDE_INT  max_size2,
alias_set_type  ref2_alias_set,
alias_set_type  base2_alias_set,
bool  tbaa_p 
)
static

Return true if an indirect reference based on *PTR1 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) may alias a variable based on BASE2 constrained to [OFFSET2, OFFSET2 + MAX_SIZE2). *PTR1 and BASE2 have the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1 in which case they are computed on-demand. REF1 and REF2 if non-NULL are the complete memory reference trees.

 The offset embedded in MEM_REFs can be negative.  Bias them
 so that the resulting offset adjustment is positive.   
 If only one reference is based on a variable, they cannot alias if
 the pointer access is beyond the extent of the variable access.
 (the pointer base cannot validly point to an offset less than zero
 of the variable).
 ???  IVOPTs creates bases that do not honor this restriction,
 so do not apply this optimization for TARGET_MEM_REFs.   
 They also cannot alias if the pointer may not point to the decl.   
 Disambiguations that rely on strict aliasing rules follow.   
 If the alias set for a pointer access is zero all bets are off.   
 When we are trying to disambiguate an access with a pointer dereference
 as base versus one with a decl as base we can use both the size
 of the decl and its dynamic type for extra disambiguation.
 ???  We do not know anything about the dynamic type of the decl
 other than that its alias-set contains base2_alias_set as a subset
 which does not help us here.   
 As we know nothing useful about the dynamic type of the decl just
 use the usual conflict check rather than a subset test.
 ???  We could introduce -fvery-strict-aliasing when the language
 does not allow decls to have a dynamic type that differs from their
 static type.  Then we can check 
 !alias_set_subset_of (base1_alias_set, base2_alias_set) instead.   
 If the size of the access relevant for TBAA through the pointer
 is bigger than the size of the decl we can't possibly access the
 decl via that pointer.   
     ???  This in turn may run afoul when a decl of type T which is
     a member of union type U is accessed through a pointer to
     type U and sizeof T is smaller than sizeof U.   
 If the decl is accessed via a MEM_REF, reconstruct the base
 we can use for TBAA and an appropriately adjusted offset.   
 If either reference is view-converted, give up now.   
 If both references are through the same type, they do not alias
 if the accesses do not overlap.  This does extra disambiguation
 for mixed/pointer accesses but requires strict aliasing.
 For MEM_REFs we require that the component-ref offset we computed
 is relative to the start of the type which we ensure by
 comparing rvalue and access type and disregarding the constant
 pointer offset.   
 Do access-path based disambiguation.   
static bool indirect_refs_may_alias_p ( tree  ref1,
tree  base1,
HOST_WIDE_INT  offset1,
HOST_WIDE_INT  max_size1,
alias_set_type  ref1_alias_set,
alias_set_type  base1_alias_set,
tree  ref2,
tree  base2,
HOST_WIDE_INT  offset2,
HOST_WIDE_INT  max_size2,
alias_set_type  ref2_alias_set,
alias_set_type  base2_alias_set,
bool  tbaa_p 
)
static

Return true if two indirect references based on *PTR1 and *PTR2 constrained to [OFFSET1, OFFSET1 + MAX_SIZE1) and [OFFSET2, OFFSET2 + MAX_SIZE2) may alias. *PTR1 and *PTR2 have the alias sets BASE1_ALIAS_SET and BASE2_ALIAS_SET which can be -1 in which case they are computed on-demand. REF1 and REF2 if non-NULL are the complete memory reference trees.

 If both bases are based on pointers they cannot alias if they may not
 point to the same memory object or if they point to the same object
 and the accesses do not overlap.   
     The offset embedded in MEM_REFs can be negative.  Bias them
     so that the resulting offset adjustment is positive.   
 Disambiguations that rely on strict aliasing rules follow.   
 If the alias set for a pointer access is zero all bets are off.   
 If both references are through the same type, they do not alias
 if the accesses do not overlap.  This does extra disambiguation
 for mixed/pointer accesses but requires strict aliasing.   
 Do type-based disambiguation.   
 Do access-path based disambiguation.   
static bool maybe_skip_until ( gimple  phi,
tree  target,
ao_ref ref,
tree  vuse,
unsigned int *  cnt,
bitmap visited,
bool  abort_on_visited 
)
static

Walk the virtual use-def chain of VUSE until hitting the virtual operand TARGET or a statement clobbering the memory reference REF in which case false is returned. The walk starts with VUSE, one argument of PHI.

 Walk until we hit the target.   
     Recurse for PHI nodes.   
         An already visited PHI node ends the walk successfully.   
         A clobbering statement or the end of the IL ends it failing.   
     If we reach a new basic-block see if we already skipped it
     in a previous walk that ended successfully.   

References get_continuation_for_phi_1(), NULL_TREE, and PHI_ARG_DEF.

static bool nonoverlapping_component_refs_of_decl_p ( )
static

Return true if we can determine that component references REF1 and REF2, that are within a common DECL, cannot overlap.

 Create the stack of handled components for REF1.   
 Create the stack of handled components for REF2.   
 We must have the same base DECL.   
 Pop the stacks in parallel and examine the COMPONENT_REFs of the same
 rank.  This is sufficient because we start from the same DECL and you
 cannot reference several fields at a time with COMPONENT_REFs (unlike
 with ARRAY_RANGE_REFs for arrays) so you always need the same number
 of them to access a sub-component, unless you're in a union, in which
 case the return value will precisely be false.   
     Beware of BIT_FIELD_REF.   
     ??? We cannot simply use the type of operand #0 of the refs here
     as the Fortran compiler smuggles type punning into COMPONENT_REFs
     for common blocks instead of using unions like everyone else.   
     We cannot disambiguate fields in a union or qualified union.   
     Different fields of the same record type cannot overlap.
     ??? Bitfields can overlap at RTL level so punt on them.   
static bool ptr_deref_may_alias_decl_p ( )
static

Return true if dereferencing PTR may alias DECL. The caller is responsible for applying TBAA to see if PTR may access DECL at all.

 Conversions are irrelevant for points-to information and
 data-dependence analysis can feed us those.   
 Anything we do not explicilty handle aliases.   
 Disregard pointer offsetting.   
 ADDR_EXPR pointers either just offset another pointer or directly
 specify the pointed-to set.   
 Non-aliased variables can not be pointed to.   
 If we do not have useful points-to information for this pointer
 we cannot disambiguate anything else.   

References TREE_CODE, and TREE_OPERAND.

bool ptr_deref_may_alias_global_p ( )

Return true, if dereferencing PTR may alias with a global variable.

 If we end up with a pointer constant here that may point
 to global memory.   
 If we do not have points-to information for this variable,
 we have to punt.   
 ???  This does not use TBAA to prune globals ptr may not access.   

Referenced by tm_log_emit_restores().

static bool ptr_deref_may_alias_ref_p_1 ( )
static

Return true if dereferencing PTR may alias *REF. The caller is responsible for applying TBAA to see if PTR may access *REF at all.

Referenced by call_may_clobber_ref_p_1().

bool ptr_derefs_may_alias_p ( )

Return true if dereferenced PTR1 and PTR2 may alias. The caller is responsible for applying TBAA to see if accesses through PTR1 and PTR2 may conflict at all.

 Conversions are irrelevant for points-to information and
 data-dependence analysis can feed us those.   
 Disregard pointer offsetting.   
 ADDR_EXPR pointers either just offset another pointer or directly
 specify the pointed-to set.   
 From here we require SSA name pointers.  Anything else aliases.   
 We may end up with two empty points-to solutions for two same pointers.
 In this case we still want to say both pointers alias, so shortcut
 that here.   
 If we do not have useful points-to information for either pointer
 we cannot disambiguate anything else.   
 ???  This does not use TBAA to prune decls from the intersection
 that not both pointers may access.   

Referenced by object_address_invariant_in_loop_p().

bool ref_may_alias_global_p ( )

Return true whether REF may refer to global memory.

References gimple_assign_lhs(), and TREE_CODE.

static bool ref_maybe_used_by_call_p ( )
static

References NULL_TREE.

static bool ref_maybe_used_by_call_p_1 ( )
static

If the call CALL may use the memory reference REF return true, otherwise return false.

 Const functions without a static chain do not implicitly use memory.   
 A call that is not without side-effects might involve volatile
 accesses and thus conflicts with all other volatile accesses.   
 If the reference is based on a decl that is not aliased the call
 cannot possibly use it.   
     But local statics can be used through recursion.   
 Handle those builtin functions explicitly that do not act as
 escape points.  See tree-ssa-structalias.c:find_func_aliases
 for the list of builtins we might need to handle here.   
       All the following functions read memory pointed to by
       their second argument.  strcat/strncat additionally
       reads memory pointed to by the first argument.   
         FALLTHRU  
         FALLTHRU  
       The following functions read memory pointed to by their
       first argument.   
       These read memory pointed to by the first argument.   
       These read memory pointed to by the first argument.   
       These read memory pointed to by the first argument with size
       in the third argument.   
       These read memory pointed to by the first and second arguments.   
       The following builtins do not read from memory.   
       __sync_* builtins and some OpenMP builtins act as threading
       barriers.   

This file contains the definitions and documentation for the synchronization builtins used in the GNU compiler. Copyright (C) 2005-2013 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/.

Before including this file, you should define a macro:

DEF_SYNC_BUILTIN (ENUM, NAME, TYPE, ATTRS)

See builtins.def for details.

Synchronization Primitives. The "_N" version is the one that the user is supposed to be using. It's overloaded, and is resolved to one of the "_1" through "_16" versions, plus some extra casts.

__sync* builtins for the C++ memory model.

         Fallthru to general call handling.   
 Check if base is a global static variable that is not read
 by the function.   
     FIXME: Callee can be an OMP builtin that does not have a call graph
     node yet.  We should enforce that there are nodes for all decls in the
     IL and remove this check instead.   
 Check if the base variable is call-used.   
 Inspect call arguments for passed-by-value aliases.   
bool ref_maybe_used_by_stmt_p ( )

If the statement STMT may use the memory reference REF return true, otherwise return false.

All memory assign statements are single.

     If ref escapes the function then the return acts as a use.   

Referenced by dse_optimize_stmt().

bool refs_anti_dependent_p ( )

Returns true if there is a anti-dependence for the STORE that executes after the LOAD.

bool refs_may_alias_p_1 ( )

Return true, if the two memory references REF1 and REF2 may alias.

 Decompose the references into their base objects and the access.   
 We can end up with registers or constants as bases for example from
 *D.1663_44 = VIEW_CONVERT_EXPR<struct DB_LSN>(__tmp$B0F64_59);
 which is seen as a struct copy.   
 We can end up referring to code via function and label decls.
 As we likely do not properly track code aliases conservatively
 bail out.   
 Two volatile accesses always conflict.   
 Defer to simple offset based disambiguation if we have
 references based on two decls.  Do this before defering to
 TBAA to handle must-alias cases in conformance with the
 GCC extension of allowing type-punning through unions.   
 Canonicalize the pointer-vs-decl case.   
 First defer to TBAA if possible.   
 Dispatch to the pointer-vs-decl or pointer-vs-pointer disambiguators.   
 We really do not want to end up here, but returning true is safe.   

Referenced by fold_builtin_logarithm(), refs_may_alias_p(), and refs_output_dependent_p().

bool refs_output_dependent_p ( )

Returns true if there is a output dependence for the stores STORE1 and STORE2.

References ao_ref_init_from_ptr_and_size(), gimple_call_arg(), gimple_call_num_args(), NULL_TREE, and refs_may_alias_p_1().

static int same_type_for_tbaa ( )
inlinestatic

Return 1 if TYPE1 and TYPE2 are to be considered equivalent for the purpose of TBAA. Return 0 if they are distinct and -1 if we cannot decide.

 If we would have to do structural comparison bail out.   
 Compare the canonical types.   
 ??? Array types are not properly unified in all cases as we have
 spurious changes in the index types for example.  Removing this
 causes all sorts of problems with the Fortran frontend.   
 ??? In Ada, an lvalue of an unconstrained type can be used to access an
 object of one of its constrained subtypes, e.g. when a function with an
 unconstrained parameter passed by reference is called on an object and
 inlined.  But, even in the case of a fixed size, type and subtypes are
 not equivalent enough as to share the same TYPE_CANONICAL, since this
 would mean that conversions between them are useless, whereas they are
 not (e.g. type and subtypes can have different modes).  So, in the end,
 they are only guaranteed to have the same alias set.   
 The types are known to be not equal.   

References handled_component_p(), HOST_WIDE_INT, TREE_OPERAND, and TREE_TYPE.

static bool stmt_kills_ref_p_1 ( )
static

If STMT kills the memory reference REF return true, otherwise return false.

 For a must-alias check we need to be able to constrain
 the access properly.   
     The assignment is not necessarily carried out if it can throw
     and we can catch it in the current function where we could inspect
     the previous value.
     ???  We only need to care about the RHS throwing.  For aggregate
     assignments or similar calls and non-call exceptions the LHS
     might throw as well.   
     We can get MEM[symbol: sZ, index: D.8862_1] here,
     so base == ref->base does not always hold.   
         If both base and ref->base are MEM_REFs, only compare the
         first operand, and if the second operand isn't equal constant,
         try to add the offsets into offset and ref_offset.   
     For a must-alias check we need to be able to constrain
     the access properly.   

References BITMAP_ALLOC, bitmap_bit_p, bitmap_set_bit, get_continuation_for_phi(), gimple_bb(), gimple_nop_p(), gimple_vuse(), NULL, PHI_RESULT, SSA_NAME_DEF_STMT, SSA_NAME_VERSION, and stmt_may_clobber_ref_p_1().

bool stmt_may_clobber_global_p ( )

Return true whether STMT may clobber global memory.

??? We can ask the oracle whether an artificial pointer dereference with a pointer with points-to information covering all global memory (what about non-address taken memory?) maybe clobbered by this call. As there is at the moment no convenient way of doing that without generating garbage do some manual checking instead. ??? We could make a NULL ao_ref argument to the various predicates special, meaning any global memory.

bool stmt_may_clobber_ref_p ( )
bool stmt_may_clobber_ref_p_1 ( )

If the statement STMT may clobber the memory reference REF return true, otherwise return false.

Referenced by get_continuation_for_phi(), and stmt_kills_ref_p_1().

unsigned int walk_aliased_vdefs ( ao_ref ref,
tree  vdef,
bool(*)(ao_ref *, tree, void *)  walker,
void *  data,
bitmap visited 
)
static unsigned int walk_aliased_vdefs_1 ( ao_ref ref,
tree  vdef,
bool(*)(ao_ref *, tree, void *)  walker,
void *  data,
bitmap visited,
unsigned int  cnt 
)
static

Based on the memory reference REF call WALKER for each vdef which defining statement may clobber REF, starting with VDEF. If REF is NULL_TREE, each defining statement is visited.

WALKER is called with REF, the current vdef and DATA. If WALKER returns true the walk is stopped, otherwise it continues.

At PHI nodes walk_aliased_vdefs forks into one walk for reach PHI argument (but only one walk continues on merge points), the return value is true if any of the walks was successful.

The function returns the number of statements walked.

??? Do we want to account this to TV_ALIAS_STMT_WALK?

Referenced by get_continuation_for_phi().

void* walk_non_aliased_vuses ( ao_ref ref,
tree  vuse,
void *(*)(ao_ref *, tree, unsigned int, void *)  walker,
void *(*)(ao_ref *, tree, void *)  translate,
void *  data 
)

Based on the memory reference REF and its virtual use VUSE call WALKER for each virtual use that is equivalent to VUSE, including VUSE itself. That is, for each virtual use for which its defining statement does not clobber REF.

WALKER is called with REF, the current virtual use and DATA. If WALKER returns non-NULL the walk stops and its result is returned. At the end of a non-successful walk NULL is returned.

TRANSLATE if non-NULL is called with a pointer to REF, the virtual use which definition is a statement that may clobber REF and DATA. If TRANSLATE returns (void *)-1 the walk stops and NULL is returned. If TRANSLATE returns non-NULL the walk stops and its result is returned. If TRANSLATE returns NULL the walk continues and TRANSLATE is supposed to adjust REF and *DATA to make that valid.

TODO: Cache the vector of equivalent vuses per ref, vuse pair.

     ???  Do we want to account this to TV_ALIAS_STMT_WALK?   
     Abort walk.   
     Lookup succeeded.   
             Failed lookup and translation.   
             Lookup succeeded.   
             Translation succeeded, continue walking.   

Variable Documentation

struct { ... } alias_stats

Alias analysis for trees. Copyright (C) 2004-2013 Free Software Foundation, Inc. Contributed by Diego Novillo dnovi.nosp@m.llo@.nosp@m.redha.nosp@m.t.co.nosp@m.m

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/. Broad overview of how alias analysis on gimple works:

Statements clobbering or using memory are linked through the virtual operand factored use-def chain. The virtual operand is unique per function, its symbol is accessible via gimple_vop (cfun). Virtual operands are used for efficiently walking memory statements in the gimple IL and are useful for things like value-numbering as a generation count for memory references.

SSA_NAME pointers may have associated points-to information accessible via the SSA_NAME_PTR_INFO macro. Flow-insensitive points-to information is (re-)computed by the TODO_rebuild_alias pass manager todo. Points-to information is also used for more precise tracking of call-clobbered and call-used variables and related disambiguations.

This file contains functions for disambiguating memory references, the so called alias-oracle and tools for walking of the gimple IL.

The main alias-oracle entry-points are

bool stmt_may_clobber_ref_p (gimple, tree)

This function queries if a statement may invalidate (parts of) the memory designated by the reference tree argument.

bool ref_maybe_used_by_stmt_p (gimple, tree)

This function queries if a statement may need (parts of) the memory designated by the reference tree argument.

There are variants of these functions that only handle the call part of a statement, call_may_clobber_ref_p and ref_maybe_used_by_call_p. Note that these do not disambiguate against a possible call lhs.

bool refs_may_alias_p (tree, tree)

This function tries to disambiguate two reference trees.

bool ptr_deref_may_alias_global_p (tree)

This function queries if dereferencing a pointer variable may alias global memory.

More low-level disambiguators are available and documented in this file. Low-level disambiguators dealing with points-to information are in tree-ssa-structalias.c. Query statistics for the different low-level disambiguators. A high-level query may trigger multiple of them.

unsigned HOST_WIDE_INT call_may_clobber_ref_p_may_alias
unsigned HOST_WIDE_INT call_may_clobber_ref_p_no_alias
unsigned HOST_WIDE_INT ref_maybe_used_by_call_p_may_alias
unsigned HOST_WIDE_INT ref_maybe_used_by_call_p_no_alias
unsigned HOST_WIDE_INT refs_may_alias_p_may_alias
unsigned HOST_WIDE_INT refs_may_alias_p_no_alias