/* True if this is a heap variable. */
unsigned int is_heap_var:1;
+ /* True if we may not use TBAA to prune references to this
+ variable. This is used for C++ placement new. */
+ unsigned int no_tbaa_pruning : 1;
+
/* Points-to set for this variable. */
bitmap solution;
/* Old points-to set for this variable. */
bitmap oldsolution;
- /* Finished points-to set for this variable (IE what is returned
- from find_what_p_points_to. */
- bitmap finished_solution;
-
/* Variable ids represented by this node. */
bitmap variables;
heapvar_lookup (tree from)
{
struct tree_map *h, in;
- in.from = from;
+ in.base.from = from;
- h = htab_find_with_hash (heapvar_for_stmt, &in, htab_hash_pointer (from));
+ h = (struct tree_map *) htab_find_with_hash (heapvar_for_stmt, &in,
+ htab_hash_pointer (from));
if (h)
return h->to;
return NULL_TREE;
struct tree_map *h;
void **loc;
- h = ggc_alloc (sizeof (struct tree_map));
+ h = GGC_NEW (struct tree_map);
h->hash = htab_hash_pointer (from);
- h->from = from;
+ h->base.from = from;
h->to = to;
loc = htab_find_slot_with_hash (heapvar_for_stmt, h, h->hash, INSERT);
*(struct tree_map **) loc = h;
static varinfo_t
new_var_info (tree t, unsigned int id, const char *name)
{
- varinfo_t ret = pool_alloc (variable_info_pool);
+ varinfo_t ret = (varinfo_t) pool_alloc (variable_info_pool);
+ tree var;
ret->id = id;
ret->name = name;
ret->is_special_var = false;
ret->is_unknown_size_var = false;
ret->has_union = false;
+ var = t;
+ if (TREE_CODE (var) == SSA_NAME)
+ var = SSA_NAME_VAR (var);
+ ret->no_tbaa_pruning = (DECL_P (var)
+ && POINTER_TYPE_P (TREE_TYPE (var))
+ && DECL_NO_TBAA_P (var));
ret->solution = BITMAP_ALLOC (&pta_obstack);
ret->oldsolution = BITMAP_ALLOC (&oldpta_obstack);
- ret->finished_solution = NULL;
ret->next = NULL;
ret->collapsed_to = NULL;
return ret;
new_constraint (const struct constraint_expr lhs,
const struct constraint_expr rhs)
{
- constraint_t ret = pool_alloc (constraint_pool);
+ constraint_t ret = (constraint_t) pool_alloc (constraint_pool);
ret->lhs = lhs;
ret->rhs = rhs;
return ret;
merge_graph_nodes (graph, to, from);
merge_node_constraints (graph, to, from);
+ if (get_varinfo (from)->no_tbaa_pruning)
+ get_varinfo (to)->no_tbaa_pruning = true;
+
if (update_changed && TEST_BIT (changed, from))
{
RESET_BIT (changed, from);
}
/* Map from trees to variable infos. */
-static htab_t vi_for_tree;
-
-typedef struct tree_vi
-{
- tree t;
- varinfo_t vi;
-} *tree_vi_t;
-
-/* Hash a tree id structure. */
+static struct pointer_map_t *vi_for_tree;
-static hashval_t
-tree_vi_hash (const void *p)
-{
- const tree_vi_t ta = (tree_vi_t) p;
- return htab_hash_pointer (ta->t);
-}
-/* Return true if the tree in P1 and the tree in P2 are the same. */
-
-static int
-tree_vi_eq (const void *p1, const void *p2)
-{
- const tree_vi_t ta1 = (tree_vi_t) p1;
- const tree_vi_t ta2 = (tree_vi_t) p2;
- return ta1->t == ta2->t;
-}
-
-/* Insert ID as the variable id for tree T in the hashtable. */
+/* Insert ID as the variable id for tree T in the vi_for_tree map. */
static void
insert_vi_for_tree (tree t, varinfo_t vi)
{
- void **slot;
- struct tree_vi finder;
- tree_vi_t new_pair;
-
- finder.t = t;
- slot = htab_find_slot (vi_for_tree, &finder, INSERT);
+ void **slot = pointer_map_insert (vi_for_tree, t);
+ gcc_assert (vi);
gcc_assert (*slot == NULL);
- new_pair = XNEW (struct tree_vi);
- new_pair->t = t;
- new_pair->vi = vi;
- *slot = (void *)new_pair;
+ *slot = vi;
}
/* Find the variable info for tree T in VI_FOR_TREE. If T does not
- exist in the hash table, return false, otherwise, return true and
- set *VI to the varinfo we found. */
+ exist in the map, return NULL, otherwise, return the varinfo we found. */
-static bool
-lookup_vi_for_tree (tree t, varinfo_t *vi)
+static varinfo_t
+lookup_vi_for_tree (tree t)
{
- tree_vi_t pair;
- struct tree_vi finder;
+ void **slot = pointer_map_contains (vi_for_tree, t);
+ if (slot == NULL)
+ return NULL;
- finder.t = t;
- pair = htab_find (vi_for_tree, &finder);
- if (pair == NULL)
- return false;
- *vi = pair->vi;
- return true;
+ return (varinfo_t) *slot;
}
/* Return a printable name for DECL */
return res;
}
-/* Find the variable id for tree T in the hashtable.
- If T doesn't exist in the hash table, create an entry for it. */
+/* Find the variable id for tree T in the map.
+ If T doesn't exist in the map, create an entry for it and return it. */
static varinfo_t
get_vi_for_tree (tree t)
{
- tree_vi_t pair;
- struct tree_vi finder;
-
- finder.t = t;
- pair = htab_find (vi_for_tree, &finder);
- if (pair == NULL)
+ void **slot = pointer_map_contains (vi_for_tree, t);
+ if (slot == NULL)
return get_varinfo (create_variable_info_for (t, alias_get_name (t)));
- return pair->vi;
+ return (varinfo_t) *slot;
}
/* Get a constraint expression from an SSA_VAR_P node. */
{
tree type = TREE_TYPE (t);
- if (POINTER_TYPE_P (type) || AGGREGATE_TYPE_P (type)
+ if (POINTER_TYPE_P (type)
+ || AGGREGATE_TYPE_P (type)
|| TREE_CODE (type) == COMPLEX_TYPE)
return true;
+
return false;
}
switch (TREE_CODE_CLASS (TREE_CODE (t)))
{
case tcc_expression:
+ case tcc_vl_exp:
{
switch (TREE_CODE (t))
{
tree pttype = TREE_TYPE (TREE_TYPE (t));
get_constraint_for (exp, results);
+
/* Make sure we capture constraints to all elements
of an array. */
if ((handled_component_p (exp)
}
/* Handle the structure copy case where we have a structure copy
- between a aggregate on the RHS and a dereference of a pointer on
+ between an aggregate on the RHS and a dereference of a pointer on
the LHS that is of SIZE (in bits)
For each field of the rhs variable (rhsfield)
}
}
+
/* Update related alias information kept in AI. This is used when
building name tags, alias sets and deciding grouping heuristics.
STMT is the statement to process. This function also updates
bitmap addr_taken;
use_operand_p use_p;
ssa_op_iter iter;
+ bool stmt_dereferences_ptr_p;
enum escape_type stmt_escape_type = is_escape_site (stmt);
+ struct mem_ref_stats_d *mem_ref_stats = gimple_mem_ref_stats (cfun);
+
+ stmt_dereferences_ptr_p = false;
if (stmt_escape_type == ESCAPE_TO_CALL
|| stmt_escape_type == ESCAPE_TO_PURE_CONST)
{
- ai->num_calls_found++;
+ mem_ref_stats->num_call_sites++;
if (stmt_escape_type == ESCAPE_TO_PURE_CONST)
- ai->num_pure_const_calls_found++;
+ mem_ref_stats->num_pure_const_call_sites++;
}
+ else if (stmt_escape_type == ESCAPE_TO_ASM)
+ mem_ref_stats->num_asm_sites++;
/* Mark all the variables whose address are taken by the statement. */
addr_taken = addresses_taken (stmt);
}
}
- /* Process each operand use. If an operand may be aliased, keep
- track of how many times it's being used. For pointers, determine
- whether they are dereferenced by the statement, or whether their
- value escapes, etc. */
+ /* Process each operand use. For pointers, determine whether they
+ are dereferenced by the statement, or whether their value
+ escapes, etc. */
FOR_EACH_PHI_OR_STMT_USE (use_p, stmt, iter, SSA_OP_USE)
{
tree op, var;
var_ann_t v_ann;
struct ptr_info_def *pi;
- bool is_store, is_potential_deref;
- unsigned num_uses, num_derefs;
+ unsigned num_uses, num_loads, num_stores;
op = USE_FROM_PTR (use_p);
so that they can be treated like regular statements?
Currently, they are treated as second-class
statements. */
- add_to_addressable_set (TREE_OPERAND (op, 0),
- &addressable_vars);
+ add_to_addressable_set (TREE_OPERAND (op, 0), &addressable_vars);
continue;
}
- /* Ignore constants. */
+ /* Ignore constants (they may occur in PHI node arguments). */
if (TREE_CODE (op) != SSA_NAME)
continue;
/* Determine whether OP is a dereferenced pointer, and if STMT
is an escape point, whether OP escapes. */
- count_uses_and_derefs (op, stmt, &num_uses, &num_derefs, &is_store);
+ count_uses_and_derefs (op, stmt, &num_uses, &num_loads, &num_stores);
/* Handle a corner case involving address expressions of the
form '&PTR->FLD'. The problem with these expressions is that
are not GIMPLE invariants), they can only appear on the RHS
of an assignment and their base address is always an
INDIRECT_REF expression. */
- is_potential_deref = false;
if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT
&& TREE_CODE (GIMPLE_STMT_OPERAND (stmt, 1)) == ADDR_EXPR
&& !is_gimple_val (GIMPLE_STMT_OPERAND (stmt, 1)))
tree base = get_base_address (TREE_OPERAND (rhs, 0));
if (TREE_CODE (base) == INDIRECT_REF
&& TREE_OPERAND (base, 0) == op)
- is_potential_deref = true;
+ num_loads++;
}
- if (num_derefs > 0 || is_potential_deref)
+ if (num_loads + num_stores > 0)
{
/* Mark OP as dereferenced. In a subsequent pass,
dereferenced pointers that point to a set of
/* If this is a store operation, mark OP as being
dereferenced to store, otherwise mark it as being
dereferenced to load. */
- if (is_store)
+ if (num_stores > 0)
pointer_set_insert (ai->dereferenced_ptrs_store, var);
else
pointer_set_insert (ai->dereferenced_ptrs_load, var);
+
+ /* Update the frequency estimate for all the dereferences of
+ pointer OP. */
+ update_mem_sym_stats_from_stmt (op, stmt, num_loads, num_stores);
+
+ /* Indicate that STMT contains pointer dereferences. */
+ stmt_dereferences_ptr_p = true;
}
- if (stmt_escape_type != NO_ESCAPE && num_derefs < num_uses)
+ if (stmt_escape_type != NO_ESCAPE && num_loads + num_stores < num_uses)
{
/* If STMT is an escape point and STMT contains at
least one direct use of OP, then the value of OP
return;
/* Mark stored variables in STMT as being written to and update the
- reference counter for potentially aliased symbols in STMT. */
- if (stmt_references_memory_p (stmt) && STORED_SYMS (stmt))
+ memory reference stats for all memory symbols referenced by STMT. */
+ if (stmt_references_memory_p (stmt))
{
unsigned i;
bitmap_iterator bi;
- EXECUTE_IF_SET_IN_BITMAP (STORED_SYMS (stmt), 0, i, bi)
- pointer_set_insert (ai->written_vars, referenced_var (i));
+
+ mem_ref_stats->num_mem_stmts++;
+
+ /* Notice that we only update memory reference stats for symbols
+ loaded and stored by the statement if the statement does not
+ contain pointer dereferences and it is not a call/asm site.
+ This is to avoid double accounting problems when creating
+ memory partitions. After computing points-to information,
+ pointer dereference statistics are used to update the
+ reference stats of the pointed-to variables, so here we
+ should only update direct references to symbols.
+
+ Indirect references are not updated here for two reasons: (1)
+ The first time we compute alias information, the sets
+ LOADED/STORED are empty for pointer dereferences, (2) After
+ partitioning, LOADED/STORED may have references to
+ partitions, not the original pointed-to variables. So, if we
+ always counted LOADED/STORED here and during partitioning, we
+ would count many symbols more than once.
+
+ This does cause some imprecision when a statement has a
+ combination of direct symbol references and pointer
+ dereferences (e.g., MEMORY_VAR = *PTR) or if a call site has
+ memory symbols in its argument list, but these cases do not
+ occur so frequently as to constitute a serious problem. */
+ if (STORED_SYMS (stmt))
+ EXECUTE_IF_SET_IN_BITMAP (STORED_SYMS (stmt), 0, i, bi)
+ {
+ tree sym = referenced_var (i);
+ pointer_set_insert (ai->written_vars, sym);
+ if (!stmt_dereferences_ptr_p
+ && stmt_escape_type != ESCAPE_TO_CALL
+ && stmt_escape_type != ESCAPE_TO_PURE_CONST
+ && stmt_escape_type != ESCAPE_TO_ASM)
+ update_mem_sym_stats_from_stmt (sym, stmt, 0, 1);
+ }
+
+ if (!stmt_dereferences_ptr_p
+ && LOADED_SYMS (stmt)
+ && stmt_escape_type != ESCAPE_TO_CALL
+ && stmt_escape_type != ESCAPE_TO_PURE_CONST
+ && stmt_escape_type != ESCAPE_TO_ASM)
+ EXECUTE_IF_SET_IN_BITMAP (LOADED_SYMS (stmt), 0, i, bi)
+ update_mem_sym_stats_from_stmt (referenced_var (i), stmt, 1, 0);
}
}
unsigned int i = 0;
unsigned int j = 0;
VEC (ce_s, heap) *temp = NULL;
- unsigned int rhsoffset = 0;
+ unsigned HOST_WIDE_INT rhsoffset = 0;
- if (TREE_CODE (expr) != PLUS_EXPR
- && TREE_CODE (expr) != MINUS_EXPR)
+ if (TREE_CODE (expr) != POINTER_PLUS_EXPR)
return false;
op0 = TREE_OPERAND (expr, 0);
op1 = TREE_OPERAND (expr, 1);
+ gcc_assert (POINTER_TYPE_P (TREE_TYPE (op0)));
get_constraint_for (op0, &temp);
- if (POINTER_TYPE_P (TREE_TYPE (op0))
- && TREE_CODE (op1) == INTEGER_CST
- && TREE_CODE (expr) == PLUS_EXPR)
+
+ /* We can only handle positive offsets that do not overflow
+ if we multiply it by BITS_PER_UNIT. */
+ if (host_integerp (op1, 1))
{
rhsoffset = TREE_INT_CST_LOW (op1) * BITS_PER_UNIT;
- }
- else
- return false;
+ if (rhsoffset / BITS_PER_UNIT != TREE_INT_CST_LOW (op1))
+ return false;
+ }
for (i = 0; VEC_iterate (ce_s, lhsc, i, c); i++)
for (j = 0; VEC_iterate (ce_s, temp, j, c2); j++)
}
}
/* In IPA mode, we need to generate constraints to pass call
- arguments through their calls. There are two case, either a
- modify_expr when we are returning a value, or just a plain
- call_expr when we are not. */
+ arguments through their calls. There are two cases, either a
+ GIMPLE_MODIFY_STMT when we are returning a value, or just a plain
+ CALL_EXPR when we are not. */
else if (in_ipa_mode
&& ((TREE_CODE (t) == GIMPLE_MODIFY_STMT
&& TREE_CODE (GIMPLE_STMT_OPERAND (t, 1)) == CALL_EXPR
{
tree lhsop;
tree rhsop;
- tree arglist;
+ tree arg;
+ call_expr_arg_iterator iter;
varinfo_t fi;
int i = 1;
tree decl;
}
else
{
- decl = TREE_OPERAND (rhsop, 0);
+ decl = CALL_EXPR_FN (rhsop);
fi = get_vi_for_tree (decl);
}
/* Assign all the passed arguments to the appropriate incoming
parameters of the function. */
- arglist = TREE_OPERAND (rhsop, 1);
- for (;arglist; arglist = TREE_CHAIN (arglist))
- {
- tree arg = TREE_VALUE (arglist);
+ FOR_EACH_CALL_EXPR_ARG (arg, iter, rhsop)
+ {
struct constraint_expr lhs ;
struct constraint_expr *rhsp;
}
i++;
}
+
/* If we are returning a value, assign it to the result. */
if (lhsop)
{
case tcc_constant:
case tcc_exceptional:
case tcc_expression:
+ case tcc_vl_exp:
case tcc_unary:
{
unsigned int j;
to process expressions other than simple operands
(e.g. INDIRECT_REF, ADDR_EXPR, CALL_EXPR). */
default:
- for (i = 0; i < TREE_CODE_LENGTH (TREE_CODE (rhsop)); i++)
+ for (i = 0; i < TREE_OPERAND_LENGTH (rhsop); i++)
{
tree op = TREE_OPERAND (rhsop, i);
unsigned int j;
}
}
}
+ else if (TREE_CODE (t) == CHANGE_DYNAMIC_TYPE_EXPR)
+ {
+ unsigned int j;
+
+ get_constraint_for (CHANGE_DYNAMIC_TYPE_LOCATION (t), &lhsc);
+ for (j = 0; VEC_iterate (ce_s, lhsc, j, c); ++j)
+ get_varinfo (c->var)->no_tbaa_pruning = true;
+ }
/* After promoting variables and computing aliasing we will
need to re-scan most statements. FIXME: Try to minimize the
than just the immediately containing structure. Returns the number
of fields pushed.
HAS_UNION is set to true if we find a union type as a field of
- TYPE. */
+ TYPE. ADDRESSABLE_TYPE is the type of the outermost object that could have
+ its address taken. */
int
push_fields_onto_fieldstack (tree type, VEC(fieldoff_s,heap) **fieldstack,
- HOST_WIDE_INT offset, bool *has_union)
+ HOST_WIDE_INT offset, bool *has_union,
+ tree addressable_type)
{
tree field;
int count = 0;
real_part->size = TYPE_SIZE (TREE_TYPE (type));
real_part->offset = offset;
real_part->decl = NULL_TREE;
+ real_part->alias_set = -1;
img_part = VEC_safe_push (fieldoff_s, heap, *fieldstack, NULL);
img_part->type = TREE_TYPE (type);
img_part->size = TYPE_SIZE (TREE_TYPE (type));
img_part->offset = offset + TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (type)));
img_part->decl = NULL_TREE;
+ img_part->alias_set = -1;
return 2;
}
push = true;
else if (!(pushed = push_fields_onto_fieldstack
(TREE_TYPE (type), fieldstack,
- offset + i * TREE_INT_CST_LOW (elsz), has_union)))
+ offset + i * TREE_INT_CST_LOW (elsz), has_union,
+ TREE_TYPE (type))))
/* Empty structures may have actual size, like in C++. So
see if we didn't push any subfields and the size is
nonzero, push the field onto the stack */
pair->size = elsz;
pair->decl = NULL_TREE;
pair->offset = offset + i * TREE_INT_CST_LOW (elsz);
+ pair->alias_set = -1;
count++;
}
else
push = true;
else if (!(pushed = push_fields_onto_fieldstack
(TREE_TYPE (field), fieldstack,
- offset + bitpos_of_field (field), has_union))
+ offset + bitpos_of_field (field), has_union,
+ (DECL_NONADDRESSABLE_P (field)
+ ? addressable_type
+ : TREE_TYPE (field))))
&& DECL_SIZE (field)
&& !integer_zerop (DECL_SIZE (field)))
/* Empty structures may have actual size, like in C++. So
pair->size = DECL_SIZE (field);
pair->decl = field;
pair->offset = offset + bitpos_of_field (field);
+ if (DECL_NONADDRESSABLE_P (field))
+ pair->alias_set = get_alias_set (addressable_type);
+ else
+ pair->alias_set = -1;
count++;
}
else
|| TREE_CODE (decltype) == QUAL_UNION_TYPE;
if (var_can_have_subvars (decl) && use_field_sensitive && !hasunion)
{
- push_fields_onto_fieldstack (decltype, &fieldstack, 0, &hasunion);
+ push_fields_onto_fieldstack (decltype, &fieldstack, 0, &hasunion,
+ decltype);
if (hasunion)
{
VEC_free (fieldoff_s, heap, fieldstack);
{
fprintf (file, "%s ", get_varinfo (i)->name);
}
- fprintf (file, "}\n");
+ fprintf (file, "}");
+ if (vi->no_tbaa_pruning)
+ fprintf (file, " no-tbaa-pruning");
+ fprintf (file, "\n");
}
}
tree t;
struct constraint_expr lhs, rhs;
- /* For each incoming pointer argument arg, ARG = ANYTHING or a
- dummy variable if flag_argument_noalias > 2. */
+ /* For each incoming pointer argument arg, create the constraint ARG
+ = ANYTHING or a dummy variable if flag_argument_noalias is set. */
for (t = DECL_ARGUMENTS (current_function_decl); t; t = TREE_CHAIN (t))
{
varinfo_t p;
if (!could_have_pointers (t))
continue;
- /* With flag_argument_noalias greater than two means that the incoming
- argument cannot alias anything except for itself so create a HEAP
- variable. */
- if (POINTER_TYPE_P (TREE_TYPE (t))
- && flag_argument_noalias > 2)
+ /* If flag_argument_noalias is set, then function pointer
+ arguments are guaranteed not to point to each other. In that
+ case, create an artificial variable PARM_NOALIAS and the
+ constraint ARG = &PARM_NOALIAS. */
+ if (POINTER_TYPE_P (TREE_TYPE (t)) && flag_argument_noalias > 0)
{
varinfo_t vi;
tree heapvar = heapvar_lookup (t);
if (heapvar == NULL_TREE)
{
+ var_ann_t ann;
heapvar = create_tmp_var_raw (TREE_TYPE (TREE_TYPE (t)),
"PARM_NOALIAS");
- get_var_ann (heapvar)->is_heapvar = 1;
DECL_EXTERNAL (heapvar) = 1;
if (gimple_referenced_vars (cfun))
add_referenced_var (heapvar);
+
heapvar_insert (t, heapvar);
+
+ ann = get_var_ann (heapvar);
+ if (flag_argument_noalias == 1)
+ ann->noalias_state = NO_ALIAS;
+ else if (flag_argument_noalias == 2)
+ ann->noalias_state = NO_ALIAS_GLOBAL;
+ else if (flag_argument_noalias == 3)
+ ann->noalias_state = NO_ALIAS_ANYTHING;
+ else
+ gcc_unreachable ();
}
+
vi = get_vi_for_tree (heapvar);
vi->is_artificial_var = 1;
vi->is_heap_var = 1;
}
}
+/* Structure used to put solution bitmaps in a hashtable so they can
+ be shared among variables with the same points-to set. */
+
+typedef struct shared_bitmap_info
+{
+ bitmap pt_vars;
+ hashval_t hashcode;
+} *shared_bitmap_info_t;
+
+static htab_t shared_bitmap_table;
+
+/* Hash function for a shared_bitmap_info_t */
+
+static hashval_t
+shared_bitmap_hash (const void *p)
+{
+ const shared_bitmap_info_t bi = (shared_bitmap_info_t) p;
+ return bi->hashcode;
+}
+
+/* Equality function for two shared_bitmap_info_t's. */
+
+static int
+shared_bitmap_eq (const void *p1, const void *p2)
+{
+ const shared_bitmap_info_t sbi1 = (shared_bitmap_info_t) p1;
+ const shared_bitmap_info_t sbi2 = (shared_bitmap_info_t) p2;
+ return bitmap_equal_p (sbi1->pt_vars, sbi2->pt_vars);
+}
+
+/* Lookup a bitmap in the shared bitmap hashtable, and return an already
+ existing instance if there is one, NULL otherwise. */
+
+static bitmap
+shared_bitmap_lookup (bitmap pt_vars)
+{
+ void **slot;
+ struct shared_bitmap_info sbi;
+
+ sbi.pt_vars = pt_vars;
+ sbi.hashcode = bitmap_hash (pt_vars);
+
+ slot = htab_find_slot_with_hash (shared_bitmap_table, &sbi,
+ sbi.hashcode, NO_INSERT);
+ if (!slot)
+ return NULL;
+ else
+ return ((shared_bitmap_info_t) *slot)->pt_vars;
+}
+
+
+/* Add a bitmap to the shared bitmap hashtable. */
+
+static void
+shared_bitmap_add (bitmap pt_vars)
+{
+ void **slot;
+ shared_bitmap_info_t sbi = XNEW (struct shared_bitmap_info);
+
+ sbi->pt_vars = pt_vars;
+ sbi->hashcode = bitmap_hash (pt_vars);
+
+ slot = htab_find_slot_with_hash (shared_bitmap_table, sbi,
+ sbi->hashcode, INSERT);
+ gcc_assert (!*slot);
+ *slot = (void *) sbi;
+}
+
+
/* Set bits in INTO corresponding to the variable uids in solution set
FROM, which came from variable PTR.
For variables that are actually dereferenced, we also use type
- based alias analysis to prune the points-to sets. */
+ based alias analysis to prune the points-to sets.
+ IS_DEREFED is true if PTR was directly dereferenced, which we use to
+ help determine whether we are we are allowed to prune using TBAA.
+ If NO_TBAA_PRUNING is true, we do not perform any TBAA pruning of
+ the from set. */
static void
-set_uids_in_ptset (tree ptr, bitmap into, bitmap from)
+set_uids_in_ptset (tree ptr, bitmap into, bitmap from, bool is_derefed,
+ bool no_tbaa_pruning)
{
unsigned int i;
bitmap_iterator bi;
bitmap_set_bit (into, DECL_UID (sv->var));
}
else if (TREE_CODE (vi->decl) == VAR_DECL
- || TREE_CODE (vi->decl) == PARM_DECL)
+ || TREE_CODE (vi->decl) == PARM_DECL
+ || TREE_CODE (vi->decl) == RESULT_DECL)
{
if (var_can_have_subvars (vi->decl)
&& get_subvars_for_var (vi->decl))
if (sft)
{
var_alias_set = get_alias_set (sft);
- if (!vi->directly_dereferenced
+ if (no_tbaa_pruning
+ || (!is_derefed && !vi->directly_dereferenced)
|| alias_sets_conflict_p (ptr_alias_set, var_alias_set))
bitmap_set_bit (into, DECL_UID (sft));
}
else
{
var_alias_set = get_alias_set (vi->decl);
- if (!vi->directly_dereferenced
+ if (no_tbaa_pruning
+ || (!is_derefed && !vi->directly_dereferenced)
|| alias_sets_conflict_p (ptr_alias_set, var_alias_set))
bitmap_set_bit (into, DECL_UID (vi->decl));
}
}
}
-/* Merge the necessary SMT's into the solution set for VI, which is
+/* Merge the necessary SMT's into the bitmap INTO, which is
P's varinfo. This involves merging all SMT's that are a subset of
the SMT necessary for P. */
static void
-merge_smts_into (tree p, varinfo_t vi)
+merge_smts_into (tree p, bitmap solution)
{
unsigned int i;
bitmap_iterator bi;
/* Need to set the SMT subsets first before this
will work properly. */
- bitmap_set_bit (vi->finished_solution, DECL_UID (smt));
+ bitmap_set_bit (solution, DECL_UID (smt));
EXECUTE_IF_SET_IN_BITMAP (used_smts, 0, i, bi)
{
tree newsmt = referenced_var (i);
if (alias_set_subset_of (get_alias_set (newsmttype),
smtset))
- bitmap_set_bit (vi->finished_solution, i);
+ bitmap_set_bit (solution, i);
}
aliases = MTAG_ALIASES (smt);
if (aliases)
- bitmap_ior_into (vi->finished_solution, aliases);
+ bitmap_ior_into (solution, aliases);
}
}
&& SSA_NAME_IS_DEFAULT_DEF (p))
lookup_p = SSA_NAME_VAR (p);
- if (lookup_vi_for_tree (lookup_p, &vi))
+ vi = lookup_vi_for_tree (lookup_p);
+ if (vi)
{
-
if (vi->is_artificial_var)
return false;
unsigned int i;
bitmap_iterator bi;
bool was_pt_anything = false;
-
+ bitmap finished_solution;
+ bitmap result;
+
if (!pi->is_dereferenced)
return false;
}
}
- /* Share the final set of variables between the SSA_NAME
- pointer infos for collapsed nodes that are collapsed to
- non-special variables. This is because special vars have
- no real types associated with them, so while we know the
- pointers are equivalent to them, we need to generate the
- solution separately since it will include SMT's from the
- original non-collapsed variable. */
- if (!vi->is_special_var && vi->finished_solution)
- {
- pi->pt_vars = vi->finished_solution;
- }
- else
+ /* Share the final set of variables when possible. */
+
+ finished_solution = BITMAP_GGC_ALLOC ();
+ stats.points_to_sets_created++;
+
+ /* Instead of using pt_anything, we merge in the SMT aliases
+ for the underlying SMT. In addition, if they could have
+ pointed to anything, they could point to global memory.
+ But we cannot do that for ref-all pointers because these
+ aliases have not been computed yet. */
+ if (was_pt_anything)
{
- vi->finished_solution = BITMAP_GGC_ALLOC ();
- stats.points_to_sets_created++;
-
- /* Instead of using pt_anything, we instead merge in the SMT
- aliases for the underlying SMT. */
- if (was_pt_anything)
+ if (PTR_IS_REF_ALL (p))
{
- merge_smts_into (p, vi);
- pi->pt_global_mem = 1;
+ pi->pt_anything = 1;
+ return false;
}
- set_uids_in_ptset (vi->decl, vi->finished_solution, vi->solution);
- pi->pt_vars = vi->finished_solution;
+ merge_smts_into (p, finished_solution);
+ pi->pt_global_mem = 1;
+ }
+
+ set_uids_in_ptset (vi->decl, finished_solution, vi->solution,
+ vi->directly_dereferenced,
+ vi->no_tbaa_pruning);
+ result = shared_bitmap_lookup (finished_solution);
+
+ if (!result)
+ {
+ shared_bitmap_add (finished_solution);
+ pi->pt_vars = finished_solution;
+ }
+ else
+ {
+ pi->pt_vars = result;
+ bitmap_clear (finished_solution);
}
if (bitmap_empty_p (pi->pt_vars))
sizeof (struct variable_info), 30);
constraints = VEC_alloc (constraint_t, heap, 8);
varmap = VEC_alloc (varinfo_t, heap, 8);
- vi_for_tree = htab_create (10, tree_vi_hash, tree_vi_eq, free);
+ vi_for_tree = pointer_map_create ();
memset (&stats, 0, sizeof (stats));
-
+ shared_bitmap_table = htab_create (511, shared_bitmap_hash,
+ shared_bitmap_eq, free);
init_base_vars ();
}
/* Now reallocate the size of the successor list as, and blow away
the predecessor bitmaps. */
graph->size = VEC_length (varinfo_t, varmap);
- graph->succs = xrealloc (graph->succs, graph->size * sizeof (bitmap));
+ graph->succs = XRESIZEVEC (bitmap, graph->succs, graph->size);
free (graph->implicit_preds);
graph->implicit_preds = NULL;
bitmap_obstack_release (&predbitmap_obstack);
}
+/* Compute the set of variables we can't TBAA prune. */
+
+static void
+compute_tbaa_pruning (void)
+{
+ unsigned int size = VEC_length (varinfo_t, varmap);
+ unsigned int i;
+ bool any;
+
+ changed_count = 0;
+ changed = sbitmap_alloc (size);
+ sbitmap_zero (changed);
+
+ /* Mark all initial no_tbaa_pruning nodes as changed. */
+ any = false;
+ for (i = 0; i < size; ++i)
+ {
+ varinfo_t ivi = get_varinfo (i);
+
+ if (find (i) == i && ivi->no_tbaa_pruning)
+ {
+ any = true;
+ if ((graph->succs[i] && !bitmap_empty_p (graph->succs[i]))
+ || VEC_length (constraint_t, graph->complex[i]) > 0)
+ {
+ SET_BIT (changed, i);
+ ++changed_count;
+ }
+ }
+ }
+
+ while (changed_count > 0)
+ {
+ struct topo_info *ti = init_topo_info ();
+ ++stats.iterations;
+
+ bitmap_obstack_initialize (&iteration_obstack);
+
+ compute_topo_order (graph, ti);
+
+ while (VEC_length (unsigned, ti->topo_order) != 0)
+ {
+ bitmap_iterator bi;
+
+ i = VEC_pop (unsigned, ti->topo_order);
+
+ /* If this variable is not a representative, skip it. */
+ if (find (i) != i)
+ continue;
+
+ /* If the node has changed, we need to process the complex
+ constraints and outgoing edges again. */
+ if (TEST_BIT (changed, i))
+ {
+ unsigned int j;
+ constraint_t c;
+ VEC(constraint_t,heap) *complex = graph->complex[i];
+
+ RESET_BIT (changed, i);
+ --changed_count;
+
+ /* Process the complex copy constraints. */
+ for (j = 0; VEC_iterate (constraint_t, complex, j, c); ++j)
+ {
+ if (c->lhs.type == SCALAR && c->rhs.type == SCALAR)
+ {
+ varinfo_t lhsvi = get_varinfo (find (c->lhs.var));
+
+ if (!lhsvi->no_tbaa_pruning)
+ {
+ lhsvi->no_tbaa_pruning = true;
+ if (!TEST_BIT (changed, lhsvi->id))
+ {
+ SET_BIT (changed, lhsvi->id);
+ ++changed_count;
+ }
+ }
+ }
+ }
+
+ /* Propagate to all successors. */
+ EXECUTE_IF_IN_NONNULL_BITMAP (graph->succs[i], 0, j, bi)
+ {
+ unsigned int to = find (j);
+ varinfo_t tovi = get_varinfo (to);
+
+ /* Don't propagate to ourselves. */
+ if (to == i)
+ continue;
+
+ if (!tovi->no_tbaa_pruning)
+ {
+ tovi->no_tbaa_pruning = true;
+ if (!TEST_BIT (changed, to))
+ {
+ SET_BIT (changed, to);
+ ++changed_count;
+ }
+ }
+ }
+ }
+ }
+
+ free_topo_info (ti);
+ bitmap_obstack_release (&iteration_obstack);
+ }
+
+ sbitmap_free (changed);
+
+ if (any)
+ {
+ for (i = 0; i < size; ++i)
+ {
+ varinfo_t ivi = get_varinfo (i);
+ varinfo_t ivip = get_varinfo (find (i));
+
+ if (ivip->no_tbaa_pruning)
+ {
+ tree var = ivi->decl;
+
+ if (TREE_CODE (var) == SSA_NAME)
+ var = SSA_NAME_VAR (var);
+
+ if (POINTER_TYPE_P (TREE_TYPE (var)))
+ {
+ DECL_NO_TBAA_P (var) = 1;
+
+ /* Tell the RTL layer that this pointer can alias
+ anything. */
+ DECL_POINTER_ALIAS_SET (var) = 0;
+ }
+ }
+ }
+ }
+}
+
/* Create points-to sets for the current function. See the comments
at the start of the file for an algorithmic overview. */
block_stmt_iterator bsi;
tree phi;
- for (phi = phi_nodes (bb); phi; phi = TREE_CHAIN (phi))
+ for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
{
if (is_gimple_reg (PHI_RESULT (phi)))
{
find_func_aliases (phi);
+
/* Update various related attributes like escaped
addresses, pointer dereferences for loads and stores.
This is used when creating name tags and alias
}
}
- for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
+ for (bsi = bsi_start (bb); !bsi_end_p (bsi); )
{
tree stmt = bsi_stmt (bsi);
This is used when creating name tags and alias
sets. */
update_alias_info (stmt, ai);
+
+ /* The information in CHANGE_DYNAMIC_TYPE_EXPR nodes has now
+ been captured, and we can remove them. */
+ if (TREE_CODE (stmt) == CHANGE_DYNAMIC_TYPE_EXPR)
+ bsi_remove (&bsi, true);
+ else
+ bsi_next (&bsi);
}
}
solve_graph (graph);
+ compute_tbaa_pruning ();
+
if (dump_file)
dump_sa_points_to_info (dump_file);
varinfo_t v;
int i;
+ htab_delete (shared_bitmap_table);
if (dump_file && (dump_flags & TDF_STATS))
fprintf (dump_file, "Points to sets created:%d\n",
stats.points_to_sets_created);
- htab_delete (vi_for_tree);
+ pointer_map_destroy (vi_for_tree);
bitmap_obstack_release (&pta_obstack);
VEC_free (constraint_t, heap, constraints);
for (i = 0; VEC_iterate (varinfo_t, varmap, i, v); i++)
VEC_free (constraint_t, heap, graph->complex[i]);
+ free (graph->complex);
free (graph->rep);
free (graph->succs);
block_stmt_iterator bsi;
tree phi;
- for (phi = phi_nodes (bb); phi; phi = TREE_CHAIN (phi))
+ for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
{
if (is_gimple_reg (PHI_RESULT (phi)))
{