diff options
author | Daniel Berlin <dberlin@dberlin.org> | 2006-12-04 19:07:05 +0000 |
---|---|---|
committer | Daniel Berlin <dberlin@gcc.gnu.org> | 2006-12-04 19:07:05 +0000 |
commit | c58936b6b75bfea1b486a7040081e423e58a56de (patch) | |
tree | 8dbfc56117f5c8e2683fa7f0f2fb59efb7c301b4 | |
parent | 2c05d05ede8e14d8e709b172e83004c53fb30187 (diff) | |
download | gcc-c58936b6b75bfea1b486a7040081e423e58a56de.zip gcc-c58936b6b75bfea1b486a7040081e423e58a56de.tar.gz gcc-c58936b6b75bfea1b486a7040081e423e58a56de.tar.bz2 |
tree-ssa-alias.c (compute_may_aliases): Compute flow sensitive before flow insensitive.
2006-12-04 Daniel Berlin <dberlin@dberlin.org>
* tree-ssa-alias.c (compute_may_aliases):
Compute flow sensitive before flow insensitive.
(compute_flow_sensitive_aliasing): Don't try to add
a symbol memory tag to itself.
* alias.h (alias_set_subset_of): New prototype.
* alias.c (alias_set_subset_of): New function.
* tree-ssa-structalias.c: Update comments.
(struct variable_info): Add finished_solution.
(new_varinfo): Set finished solution to NULL.
(var_escaped_vars): Remove.
(escaped_vars_tree): Remove.
(escaped_vars_id): Remove.
(nonlocal_vars_id): Remove.
(constraint_expr_type): Add INCLUDES.
(graph_size): Removed.
(dump_constraint): Support INCLUDES.
(build_constraint_graph): Ditto.
(collapse_nodes): Add merge_solutions argument.
Don't merge attributes.
(process_unification_queue): Just use collapse_nodes.
(perform_var_substitution): Update call to collapse_nodes.
(get_constraint_exp_from_ssa_var): Use INCLUDES.
(process_constraint): Fix non-field sensitive handling
Handle includes.
(get_constraint_for): Use INCLUDES.
(make_constraint_from_anything): Renamed from
make_constraint_from_escaped.
(make_constraint_to_escaped): Removed.
(find_global_initializers): Removed.
(create_variable_info_for): Do not make constraints to escaped
vars anymore.
(dump_solution_for_var): Don't print out the equivalent points-to
sets, just use the name of the variable it shares it with.
(intra_create_variable_infos): Use INCLUDES.
Change nonlocal variable sets to anything sets.
(init_base_vars): Remove escaped_vars and nonlocal_var
initialization.
(find_escape_constraints): Removed.
(delete_points_to_sets): Remove dead code.
(used_smt_calculated): New variable.
(set_used_smts): New function.
(merge_smts_into): New function.
(find_what_p_points_to): Modify to use SMTs.
(create_nonlocal_var): Remove.
* tree-ssa-operands.c (access_can_touch_variable): Remove
reference to nonlocal_all.
* tree-ssa.c (verify_name_tags): Remove.
From-SVN: r119502
-rw-r--r-- | gcc/ChangeLog | 47 | ||||
-rw-r--r-- | gcc/Makefile.in | 2 | ||||
-rw-r--r-- | gcc/alias.c | 20 | ||||
-rw-r--r-- | gcc/alias.h | 1 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/20031015-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/20040517-1.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/pr26421.c | 3 | ||||
-rw-r--r-- | gcc/tree-ssa-alias.c | 13 | ||||
-rw-r--r-- | gcc/tree-ssa-operands.c | 5 | ||||
-rw-r--r-- | gcc/tree-ssa-structalias.c | 1141 | ||||
-rw-r--r-- | gcc/tree-ssa.c | 126 |
11 files changed, 599 insertions, 764 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a36a042..3fbc38a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,50 @@ +2006-12-04 Daniel Berlin <dberlin@dberlin.org> + + * tree-ssa-alias.c (compute_may_aliases): + Compute flow sensitive before flow insensitive. + (compute_flow_sensitive_aliasing): Don't try to add + a symbol memory tag to itself. + * alias.h (alias_set_subset_of): New prototype. + * alias.c (alias_set_subset_of): New function. + * tree-ssa-structalias.c: Update comments. + (struct variable_info): Add finished_solution. + (new_varinfo): Set finished solution to NULL. + (var_escaped_vars): Remove. + (escaped_vars_tree): Remove. + (escaped_vars_id): Remove. + (constraint_expr_type): Add INCLUDES. + (graph_size): Removed. + (dump_constraint): Support INCLUDES. + (build_constraint_graph): Ditto. + (collapse_nodes): Add merge_solutions argument. + Don't merge attributes. + (process_unification_queue): Just use collapse_nodes. + (perform_var_substitution): Update call to collapse_nodes. + (get_constraint_exp_from_ssa_var): Use INCLUDES. + (process_constraint): Fix non-field sensitive handling + Handle includes. + (get_constraint_for): Use INCLUDES. + (make_constraint_from_escaped): Use nonlocal_vars_id. + (make_constraint_to_escaped): Removed. + (find_global_initializers): Removed. + (create_variable_info_for): Do not make constraints to escaped + vars anymore. + (dump_solution_for_var): Don't print out the equivalent points-to + sets, just use the name of the variable it shares it with. + (intra_create_variable_infos): Use INCLUDES. + Move initialization of nonlocal variable to init_base_vars. + (init_base_vars): Init nonlocal variable here. + Remove escaped_vars initialization. + (find_escape_constraints): Removed. + (delete_points_to_sets): Remove dead code. + (used_smt_calculated): New variable. + (set_used_smts): New function. + (merge_smts_into): New function. + (find_what_p_points_to): Modify to use SMTs. + * tree-ssa-operands.c (access_can_touch_variable): Remove + reference to nonlocal_all. + * tree-ssa.c (verify_name_tags): Remove. + 2006-12-04 Carlos O'Donell <carlos@codesourcery.com> * config/arm/unwind-arm.c: Adjust __cxa_type_match declaration. diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 4c46cd3..76e29b0 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1837,7 +1837,7 @@ stor-layout.o : stor-layout.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ tree-ssa-structalias.o: tree-ssa-structalias.c tree-ssa-structalias.h \ $(SYSTEM_H) $(CONFIG_H) $(GGC_H) $(TREE_H) $(TREE_FLOW_H) \ $(TM_H) coretypes.h $(CGRAPH_H) tree-pass.h $(TIMEVAR_H) \ - gt-tree-ssa-structalias.h $(PARAMS_H) + gt-tree-ssa-structalias.h $(PARAMS_H) $(ALIAS_H) tree-ssa.o : tree-ssa.c $(TREE_FLOW_H) $(CONFIG_H) $(SYSTEM_H) \ $(RTL_H) $(TREE_H) $(TM_P_H) $(EXPR_H) output.h $(DIAGNOSTIC_H) \ toplev.h $(FUNCTION_H) $(TIMEVAR_H) $(TM_H) coretypes.h \ diff --git a/gcc/alias.c b/gcc/alias.c index 7a36284..ba7f948c 100644 --- a/gcc/alias.c +++ b/gcc/alias.c @@ -293,6 +293,26 @@ insert_subset_children (splay_tree_node node, void *data) return 0; } +/* Return true if the first alias set is a subset of the second. */ + +bool +alias_set_subset_of (HOST_WIDE_INT set1, HOST_WIDE_INT set2) +{ + alias_set_entry ase; + + /* Everything is a subset of the "aliases everything" set. */ + if (set2 == 0) + return true; + + /* Otherwise, check if set1 is a subset of set2. */ + ase = get_alias_set_entry (set2); + if (ase != 0 + && (splay_tree_lookup (ase->children, + (splay_tree_key) set1))) + return true; + return false; +} + /* Return 1 if the two specified alias sets may conflict. */ int diff --git a/gcc/alias.h b/gcc/alias.h index f4ba839..46130e8 100644 --- a/gcc/alias.h +++ b/gcc/alias.h @@ -25,6 +25,7 @@ extern HOST_WIDE_INT new_alias_set (void); extern HOST_WIDE_INT get_varargs_alias_set (void); extern HOST_WIDE_INT get_frame_alias_set (void); extern bool component_uses_parent_alias_set (tree); +extern bool alias_set_subset_of (HOST_WIDE_INT, HOST_WIDE_INT); /* This alias set can be used to force a memory to conflict with all other memories, creating a barrier across which no memory reference diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20031015-1.c b/gcc/testsuite/gcc.dg/tree-ssa/20031015-1.c index a7e78a4..3021656 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/20031015-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/20031015-1.c @@ -14,5 +14,5 @@ main(void) } /* The V_*_DEF comes from the initial assignment and the asm. */ -/* { dg-final { scan-tree-dump-times "_DEF" 3 "alias1" } } */ +/* { dg-final { scan-tree-dump-times "_DEF" 2 "alias1" } } */ /* { dg-final { cleanup-tree-dump "alias1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20040517-1.c b/gcc/testsuite/gcc.dg/tree-ssa/20040517-1.c index e500f11..543e5cd 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/20040517-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/20040517-1.c @@ -17,5 +17,6 @@ void bar (void) malloc functions may clobber global memory. Only the function result does not alias any other pointer. Hence, we must have a VDEF for a before and after the call to foo(). */ -/* { dg-final { scan-tree-dump-times "V_MAY_DEF" 2 "alias1"} } */ +/* { dg-final { scan-tree-dump-times "V_MAY_DEF" 1 "alias1"} } */ +/* { dg-final { scan-tree-dump-times "V_MUST_DEF" 1 "alias1"} } */ /* { dg-final { cleanup-tree-dump "alias1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr26421.c b/gcc/testsuite/gcc.dg/tree-ssa/pr26421.c index 47f62212..d8631f8 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr26421.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr26421.c @@ -16,5 +16,6 @@ int foo(void) return a.i; } -/* { dg-final { scan-tree-dump-times "V_MAY_DEF" 2 "alias1" } } */ +/* { dg-final { scan-tree-dump-times "V_MAY_DEF" 1 "alias1" } } */ +/* { dg-final { scan-tree-dump-times "V_MUST_DEF" 1 "alias1" } } */ /* { dg-final { cleanup-tree-dump "alias1" } } */ diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 65a8417..d4f1590 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -646,15 +646,13 @@ compute_may_aliases (void) not needed anymore. */ setup_pointers_and_addressables (ai); - /* Compute flow-sensitive, points-to based aliasing for all the name - memory tags. Note that this pass needs to be done before flow - insensitive analysis because it uses the points-to information - gathered before to mark call-clobbered symbol tags. */ - compute_flow_sensitive_aliasing (ai); - /* Compute type-based flow-insensitive aliasing for all the type memory tags. */ compute_flow_insensitive_aliasing (ai); + + /* Compute flow-sensitive, points-to based aliasing for all the name + memory tags. */ + compute_flow_sensitive_aliasing (ai); /* Compute call clobbering information. */ compute_call_clobbered (ai); @@ -1121,7 +1119,8 @@ compute_flow_sensitive_aliasing (struct alias_info *ai) EXECUTE_IF_SET_IN_BITMAP (pi->pt_vars, 0, j, bi) { add_may_alias (pi->name_mem_tag, referenced_var (j)); - add_may_alias (v_ann->symbol_mem_tag, referenced_var (j)); + if (j != DECL_UID (v_ann->symbol_mem_tag)) + add_may_alias (v_ann->symbol_mem_tag, referenced_var (j)); } } } diff --git a/gcc/tree-ssa-operands.c b/gcc/tree-ssa-operands.c index a3c453d..5c4e100 100644 --- a/gcc/tree-ssa-operands.c +++ b/gcc/tree-ssa-operands.c @@ -1056,11 +1056,6 @@ access_can_touch_variable (tree ref, tree alias, HOST_WIDE_INT offset, if (alias == gimple_global_var (cfun)) return true; - /* We cannot prune nonlocal aliases because they are not type - specific. */ - if (alias == gimple_nonlocal_all (cfun)) - return true; - /* If ALIAS is an SFT, it can't be touched if the offset and size of the access is not overlapping with the SFT offset and size. This is only true if we are accessing through a pointer diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index 30769ec..6a27972 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -51,10 +51,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "params.h" #include "tree-ssa-structalias.h" #include "cgraph.h" +#include "alias.h" /* The idea behind this analyzer is to generate set constraints from the program, then solve the resulting constraints in order to generate the - points-to sets. + points-to sets. Set constraints are a way of modeling program analysis problems that involve sets. They consist of an inclusion constraint language, @@ -70,33 +71,38 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also see "Ultra-fast Aliasing Analysis using CLA: A Million Lines of C Code in a Second" by ""Nevin Heintze and Olivier Tardieu" at - http://citeseer.ist.psu.edu/heintze01ultrafast.html + http://citeseer.ist.psu.edu/heintze01ultrafast.html + + There are three types of real constraint expressions, DEREF, + ADDRESSOF, and SCALAR. There is one type of fake constraint + expression, called INCLUDES. Each constraint expression consists + of a constraint type, a variable, and an offset. - There are three types of constraint expressions, DEREF, ADDRESSOF, and - SCALAR. Each constraint expression consists of a constraint type, - a variable, and an offset. - SCALAR is a constraint expression type used to represent x, whether it appears on the LHS or the RHS of a statement. DEREF is a constraint expression type used to represent *x, whether - it appears on the LHS or the RHS of a statement. + it appears on the LHS or the RHS of a statement. ADDRESSOF is a constraint expression used to represent &x, whether it appears on the LHS or the RHS of a statement. - + INCLUDES is a constraint expression type used to represent just a + setting of a bit in the points-to set without having the address + taken. It exists mainly for abstraction sake, and is used for + initializing fake variables like the ESCAPED_VARS set. + Each pointer variable in the program is assigned an integer id, and each field of a structure variable is assigned an integer id as well. - + Structure variables are linked to their list of fields through a "next field" in each variable that points to the next field in offset - order. - Each variable for a structure field has + order. + Each variable for a structure field has 1. "size", that tells the size in bits of that field. 2. "fullsize, that tells the size in bits of the entire structure. 3. "offset", that tells the offset in bits from the beginning of the structure to this field. - Thus, + Thus, struct f { int a; @@ -110,51 +116,51 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA foo.b -> id 2, size 32, offset 32, fullsize 64, next NULL bar -> id 3, size 32, offset 0, fullsize 32, next NULL - + In order to solve the system of set constraints, the following is done: 1. Each constraint variable x has a solution set associated with it, Sol(x). - + 2. Constraints are separated into direct, copy, and complex. Direct constraints are ADDRESSOF constraints that require no extra processing, such as P = &Q Copy constraints are those of the form P = Q. Complex constraints are all the constraints involving dereferences and offsets (including offsetted copies). - + 3. All direct constraints of the form P = &Q are processed, such - that Q is added to Sol(P) + that Q is added to Sol(P) 4. All complex constraints for a given constraint variable are stored in a - linked list attached to that variable's node. + linked list attached to that variable's node. 5. A directed graph is built out of the copy constraints. Each - constraint variable is a node in the graph, and an edge from + constraint variable is a node in the graph, and an edge from Q to P is added for each copy constraint of the form P = Q - + 6. The graph is then walked, and solution sets are propagated along the copy edges, such that an edge from Q to P causes Sol(P) <- Sol(P) union Sol(Q). - + 7. As we visit each node, all complex constraints associated with that node are processed by adding appropriate copy edges to the graph, or the - appropriate variables to the solution set. + appropriate variables to the solution set. 8. The process of walking the graph is iterated until no solution sets change. Prior to walking the graph in steps 6 and 7, We perform static - cycle elimination on the constraint graph, as well + cycle elimination on the constraint graph, as well as off-line variable substitution. - + TODO: Adding offsets to pointer-to-structures can be handled (IE not punted on and turned into anything), but isn't. You can just see what offset inside the pointed-to struct it's going to access. - + TODO: Constant bounded arrays can be handled as if they were structs of the - same number of elements. + same number of elements. TODO: Modeling heap and incoming pointers becomes much better if we add fields to them as we discover them, which we could do. @@ -162,7 +168,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA TODO: We could handle unions, but to be honest, it's probably not worth the pain or slowdown. */ -static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) +static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) htab_t heapvar_for_stmt; static bool use_field_sensitive = true; @@ -203,7 +209,7 @@ struct variable_info tree decl; /* Offset of this variable, in bits, from the base variable */ - unsigned HOST_WIDE_INT offset; + unsigned HOST_WIDE_INT offset; /* Size of the variable, in bits. */ unsigned HOST_WIDE_INT size; @@ -225,7 +231,7 @@ struct variable_info /* True if this variable is the target of a dereference. Needed for variable substitution. */ unsigned int indirect_target:1; - + /* True if the variable is directly the target of a dereference. This is used to track which variables are *actually* dereferenced so we can prune their points to listed. This is equivalent to the @@ -235,13 +241,13 @@ struct variable_info /* True if this is a variable created by the constraint analysis, such as heap variables and constraints we had to break up. */ unsigned int is_artificial_var:1; - + /* True if this is a special variable whose solution set should not be changed. */ unsigned int is_special_var:1; /* True for variables whose size is not known or variable. */ - unsigned int is_unknown_size_var:1; + unsigned int is_unknown_size_var:1; /* True for variables that have unions somewhere in them. */ unsigned int has_union:1; @@ -252,13 +258,17 @@ struct variable_info /* Points-to set for this variable. */ bitmap solution; + /* 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; /* Vector of complex constraints for this node. Complex constraints are those involving dereferences. */ VEC(constraint_t,heap) *complex; - + /* Variable id this was collapsed to due to type unsafety. This should be unused completely after build_constraint_graph, or something is broken. */ @@ -320,19 +330,9 @@ static varinfo_t var_integer; static tree integer_tree; static unsigned int integer_id; -/* Variable that represents escaped variables. This is used to give - incoming pointer variables a better set than ANYTHING. */ -static varinfo_t var_escaped_vars; -static tree escaped_vars_tree; -static unsigned int escaped_vars_id; - -/* Variable that represents non-local variables before we expand it to - one for each type. */ -static unsigned int nonlocal_vars_id; - /* Lookup a heap var for FROM, and return it if we find one. */ -static tree +static tree heapvar_lookup (tree from) { struct tree_map *h, in; @@ -383,17 +383,18 @@ new_var_info (tree t, unsigned int id, const char *name, unsigned int node) ret->has_union = false; ret->solution = BITMAP_ALLOC (&ptabitmap_obstack); ret->variables = BITMAP_ALLOC (&ptabitmap_obstack); + ret->finished_solution = NULL; ret->complex = NULL; ret->next = NULL; ret->collapsed_to = NULL; return ret; } -typedef enum {SCALAR, DEREF, ADDRESSOF} constraint_expr_type; +typedef enum {SCALAR, DEREF, ADDRESSOF, INCLUDES} constraint_expr_type; /* An expression that appears in a constraint. */ -struct constraint_expr +struct constraint_expr { /* Constraint type. */ constraint_expr_type type; @@ -416,7 +417,7 @@ static void get_constraint_for (tree, VEC(ce_s, heap) **); static void do_deref (VEC (ce_s, heap) **); /* Our set constraints are made up of two constraint expressions, one - LHS, and one RHS. + LHS, and one RHS. As described in the introduction, our set constraints each represent an operation between set valued variables. @@ -445,11 +446,10 @@ struct constraint_graph typedef struct constraint_graph *constraint_graph_t; static constraint_graph_t graph; -static int graph_size; /* Create a new constraint consisting of LHS and RHS expressions. */ -static constraint_t +static constraint_t new_constraint (const struct constraint_expr lhs, const struct constraint_expr rhs) { @@ -467,7 +467,7 @@ dump_constraint (FILE *file, constraint_t c) if (c->lhs.type == ADDRESSOF) fprintf (file, "&"); else if (c->lhs.type == DEREF) - fprintf (file, "*"); + fprintf (file, "*"); fprintf (file, "%s", get_varinfo_fc (c->lhs.var)->name); if (c->lhs.offset != 0) fprintf (file, " + " HOST_WIDE_INT_PRINT_DEC, c->lhs.offset); @@ -476,9 +476,13 @@ dump_constraint (FILE *file, constraint_t c) fprintf (file, "&"); else if (c->rhs.type == DEREF) fprintf (file, "*"); + else if (c->rhs.type == INCLUDES) + fprintf (file, "{"); fprintf (file, "%s", get_varinfo_fc (c->rhs.var)->name); if (c->rhs.offset != 0) fprintf (file, " + " HOST_WIDE_INT_PRINT_DEC, c->rhs.offset); + if (c->rhs.type == INCLUDES) + fprintf (file, "}"); fprintf (file, "\n"); } @@ -509,11 +513,11 @@ debug_constraints (void) dump_constraints (stderr); } -/* SOLVER FUNCTIONS +/* SOLVER FUNCTIONS The solver is a simple worklist solver, that works on the following algorithm: - + sbitmap changed_nodes = all ones; changed_count = number of nodes; For each node that was already collapsed: @@ -522,10 +526,10 @@ debug_constraints (void) while (changed_count > 0) { compute topological ordering for constraint graph - + find and collapse cycles in the constraint graph (updating changed if necessary) - + for each node (n) in the graph in topological order: changed_count--; @@ -578,11 +582,11 @@ constraint_less (const constraint_t a, const constraint_t b) } /* Return true if two constraints A and B are equal. */ - + static bool constraint_equal (struct constraint a, struct constraint b) { - return constraint_expr_equal (a.lhs, b.lhs) + return constraint_expr_equal (a.lhs, b.lhs) && constraint_expr_equal (a.rhs, b.rhs); } @@ -593,7 +597,7 @@ static constraint_t constraint_vec_find (VEC(constraint_t,heap) *vec, struct constraint lookfor) { - unsigned int place; + unsigned int place; constraint_t found; if (vec == NULL) @@ -643,7 +647,7 @@ solution_set_add (bitmap set, unsigned HOST_WIDE_INT offset) /* If this is a properly sized variable, only add offset if it's less than end. Otherwise, it is globbed to a single variable. */ - + if ((get_varinfo (i)->offset + offset) < get_varinfo (i)->fullsize) { unsigned HOST_WIDE_INT fieldoffset = get_varinfo (i)->offset + offset; @@ -652,15 +656,15 @@ solution_set_add (bitmap set, unsigned HOST_WIDE_INT offset) continue; bitmap_set_bit (result, v->id); } - else if (get_varinfo (i)->is_artificial_var + else if (get_varinfo (i)->is_artificial_var || get_varinfo (i)->has_union || get_varinfo (i)->is_unknown_size_var) { bitmap_set_bit (result, i); } } - - bitmap_copy (set, result); + + bitmap_copy (set, result); BITMAP_FREE (result); } @@ -701,7 +705,7 @@ insert_into_complex (unsigned int var, constraint_t c) /* Condense two variable nodes into a single variable node, by moving all associated info from SRC to TO. */ -static void +static void condense_varmap_nodes (unsigned int to, unsigned int src) { varinfo_t tovi = get_varinfo (to); @@ -709,23 +713,23 @@ condense_varmap_nodes (unsigned int to, unsigned int src) unsigned int i; constraint_t c; bitmap_iterator bi; - + /* the src node, and all its variables, are now the to node. */ srcvi->node = to; EXECUTE_IF_SET_IN_BITMAP (srcvi->variables, 0, i, bi) get_varinfo (i)->node = to; - + /* Merge the src node variables and the to node variables. */ bitmap_set_bit (tovi->variables, src); bitmap_ior_into (tovi->variables, srcvi->variables); bitmap_clear (srcvi->variables); - + /* Move all complex constraints from src node into to node */ for (i = 0; VEC_iterate (constraint_t, srcvi->complex, i, c); i++) { /* In complex constraints for node src, we may have either a = *src, and *src = a. */ - + if (c->rhs.type == DEREF) c->rhs.var = to; else @@ -746,24 +750,24 @@ clear_edges_for_node (constraint_graph_t graph, unsigned int node) unsigned int j; /* Walk the successors, erase the associated preds. */ - + EXECUTE_IF_IN_NONNULL_BITMAP (graph->succs[node], 0, j, bi) if (j != node) bitmap_clear_bit (graph->preds[j], node); - + /* Walk the preds, erase the associated succs. */ EXECUTE_IF_IN_NONNULL_BITMAP (graph->preds[node], 0, j, bi) if (j != node) bitmap_clear_bit (graph->succs[j], node); - + if (graph->preds[node]) { BITMAP_FREE (graph->preds[node]); graph->preds[node] = NULL; - } + } if (graph->succs[node]) { @@ -777,7 +781,7 @@ static bool edge_added = false; /* Merge GRAPH nodes FROM and TO into node TO. */ static void -merge_graph_nodes (constraint_graph_t graph, unsigned int to, +merge_graph_nodes (constraint_graph_t graph, unsigned int to, unsigned int from) { unsigned int j; @@ -788,7 +792,7 @@ merge_graph_nodes (constraint_graph_t graph, unsigned int to, { if (!graph->preds[to]) graph->preds[to] = BITMAP_ALLOC (&predbitmap_obstack); - + EXECUTE_IF_SET_IN_BITMAP (graph->preds[from], 0, j, bi) { if (j != to) @@ -797,7 +801,7 @@ merge_graph_nodes (constraint_graph_t graph, unsigned int to, bitmap_set_bit (graph->succs[j], to); } } - bitmap_ior_into (graph->preds[to], + bitmap_ior_into (graph->preds[to], graph->preds[from]); } @@ -811,7 +815,7 @@ merge_graph_nodes (constraint_graph_t graph, unsigned int to, bitmap_clear_bit (graph->preds[j], from); bitmap_set_bit (graph->preds[j], to); } - bitmap_ior_into (graph->succs[to], + bitmap_ior_into (graph->succs[to], graph->succs[from]); } @@ -833,7 +837,7 @@ add_graph_edge (constraint_graph_t graph, unsigned int to, else { bool r = false; - + if (!graph->preds[to]) graph->preds[to] = BITMAP_ALLOC (&predbitmap_obstack); if (!graph->succs[from]) @@ -854,10 +858,10 @@ add_graph_edge (constraint_graph_t graph, unsigned int to, /* Return true if {DEST.SRC} is an existing graph edge in GRAPH. */ static bool -valid_graph_edge (constraint_graph_t graph, unsigned int src, +valid_graph_edge (constraint_graph_t graph, unsigned int src, unsigned int dest) { - return (graph->succs[dest] + return (graph->succs[dest] && bitmap_bit_p (graph->succs[dest], src)); } @@ -868,6 +872,7 @@ build_constraint_graph (void) { int i = 0; constraint_t c; + int graph_size; graph = XNEW (struct constraint_graph); graph_size = VEC_length (varinfo_t, varmap) + 1; @@ -893,7 +898,7 @@ build_constraint_graph (void) if (!(get_varinfo (lhsvar)->is_special_var)) insert_into_complex (rhsvar, c); } - else if (rhs.type == ADDRESSOF) + else if (rhs.type == ADDRESSOF || rhs.type == INCLUDES) { /* x = &y */ bitmap_set_bit (get_varinfo (lhsvar)->solution, rhsvar); @@ -909,7 +914,7 @@ build_constraint_graph (void) else add_graph_edge (graph, lhs.var, rhs.var); } - + } } } @@ -939,9 +944,9 @@ struct scc_info /* Recursive routine to find strongly connected components in GRAPH. SI is the SCC info to store the information in, and N is the id of current graph node we are processing. - + This is Tarjan's strongly connected component finding algorithm, as - modified by Nuutila to keep only non-root nodes on the stack. + modified by Nuutila to keep only non-root nodes on the stack. The algorithm can be found in "On finding the strongly connected connected components in a directed graph" by Esko Nuutila and Eljas Soisalon-Soininen, in Information Processing Letters volume 49, @@ -957,7 +962,7 @@ scc_visit (constraint_graph_t graph, struct scc_info *si, unsigned int n) SET_BIT (si->visited, n); RESET_BIT (si->in_component, n); si->visited_index[n] = si->current_index ++; - + /* Visit all the successors. */ EXECUTE_IF_IN_NONNULL_BITMAP (graph->succs[n], 0, i, bi) { @@ -972,13 +977,13 @@ scc_visit (constraint_graph_t graph, struct scc_info *si, unsigned int n) get_varinfo (n)->node = t; } } - + /* See if any components have been identified. */ if (get_varinfo (n)->node == n) { unsigned int t = si->visited_index[n]; SET_BIT (si->in_component, n); - while (VEC_length (unsigned, si->scc_stack) != 0 + while (VEC_length (unsigned, si->scc_stack) != 0 && t < si->visited_index[VEC_last (unsigned, si->scc_stack)]) { unsigned int w = VEC_pop (unsigned, si->scc_stack); @@ -986,25 +991,31 @@ scc_visit (constraint_graph_t graph, struct scc_info *si, unsigned int n) SET_BIT (si->in_component, w); /* Mark this node for collapsing. */ VEC_safe_push (unsigned, heap, si->unification_queue, w); - } + } } else VEC_safe_push (unsigned, heap, si->scc_stack, n); } -/* Collapse two variables into one variable. */ +/* Collapse two variables into one variable, merging solutions if + requested. */ static void -collapse_nodes (constraint_graph_t graph, unsigned int to, unsigned int from) +collapse_nodes (constraint_graph_t graph, unsigned int to, unsigned int from, + bool merge_solutions) { bitmap tosol, fromsol; - condense_varmap_nodes (to, from); - tosol = get_varinfo (to)->solution; - fromsol = get_varinfo (from)->solution; - bitmap_ior_into (tosol, fromsol); merge_graph_nodes (graph, to, from); + condense_varmap_nodes (to, from); + if (merge_solutions) + { + tosol = get_varinfo (to)->solution; + fromsol = get_varinfo (from)->solution; + bitmap_ior_into (tosol, fromsol); + BITMAP_FREE (fromsol); + } if (valid_graph_edge (graph, to, to)) { @@ -1014,9 +1025,6 @@ collapse_nodes (constraint_graph_t graph, unsigned int to, unsigned int from) bitmap_clear_bit (graph->succs[to], to); } } - BITMAP_FREE (fromsol); - get_varinfo (to)->address_taken |= get_varinfo (from)->address_taken; - get_varinfo (to)->indirect_target |= get_varinfo (from)->indirect_target; } @@ -1039,14 +1047,14 @@ process_unification_queue (constraint_graph_t graph, struct scc_info *si, For each component in the queue (components are delineated by when current_queue_element->node != next_queue_element->node): - rep = representative node for component + rep = representative node for component - For each node (tounify) to be unified in the component, - merge the solution for tounify into tmp bitmap + For each node (tounify) to be unified in the component, + merge the solution for tounify into tmp bitmap - clear solution for tounify + clear solution for tounify - merge edges from tounify into rep + merge edges from tounify into rep merge complex constraints from tounify into rep @@ -1055,7 +1063,7 @@ process_unification_queue (constraint_graph_t graph, struct scc_info *si, Merge tmp into solution for rep, marking rep changed if this changed rep's solution. - + Delete any self-edges we now have for rep. */ while (i != VEC_length (unsigned, si->unification_queue)) { @@ -1063,7 +1071,7 @@ process_unification_queue (constraint_graph_t graph, struct scc_info *si, unsigned int n = get_varinfo (tounify)->node; if (dump_file && (dump_flags & TDF_DETAILS)) - fprintf (dump_file, "Unifying %s to %s\n", + fprintf (dump_file, "Unifying %s to %s\n", get_varinfo (tounify)->name, get_varinfo (n)->name); if (update_changed) @@ -1071,9 +1079,8 @@ process_unification_queue (constraint_graph_t graph, struct scc_info *si, else stats.unified_vars_static++; bitmap_ior_into (tmp, get_varinfo (tounify)->solution); - merge_graph_nodes (graph, n, tounify); - condense_varmap_nodes (n, tounify); - + collapse_nodes (graph, n, tounify, false); + if (update_changed && TEST_BIT (changed, tounify)) { RESET_BIT (changed, tounify); @@ -1172,7 +1179,7 @@ topo_visit (constraint_graph_t graph, struct topo_info *ti, SET_BIT (ti->visited, n); temp = graph->succs[n]; - if (temp) + if (temp) EXECUTE_IF_SET_IN_BITMAP (temp, 0, j, bi) { if (!TEST_BIT (ti->visited, j)) @@ -1183,7 +1190,7 @@ topo_visit (constraint_graph_t graph, struct topo_info *ti, /* Return true if variable N + OFFSET is a legal field of N. */ -static bool +static bool type_safe (unsigned int n, unsigned HOST_WIDE_INT *offset) { varinfo_t ninfo = get_varinfo (n); @@ -1229,7 +1236,7 @@ do_da_constraint (constraint_graph_t graph ATTRIBUTE_UNUSED, t = v->node; sol = get_varinfo (t)->solution; if (!bitmap_bit_p (sol, rhs)) - { + { bitmap_set_bit (sol, rhs); if (!TEST_BIT (changed, t)) { @@ -1240,7 +1247,7 @@ do_da_constraint (constraint_graph_t graph ATTRIBUTE_UNUSED, } else if (0 && dump_file && !(get_varinfo (j)->is_special_var)) fprintf (dump_file, "Untypesafe usage in do_da_constraint.\n"); - + } } @@ -1264,7 +1271,7 @@ do_sd_constraint (constraint_graph_t graph, constraint_t c, bitmap_set_bit (sol, anything_id); goto done; } - /* For each variable j in delta (Sol(y)), add + /* For each variable j in delta (Sol(y)), add an edge in the graph from j to x, and union Sol(j) into Sol(x). */ EXECUTE_IF_SET_IN_BITMAP (delta, 0, j, bi) { @@ -1289,7 +1296,7 @@ do_sd_constraint (constraint_graph_t graph, constraint_t c, } else if (0 && dump_file && !(get_varinfo (j)->is_special_var)) fprintf (dump_file, "Untypesafe usage in do_sd_constraint\n"); - + } done: @@ -1302,7 +1309,7 @@ done: SET_BIT (changed, lhs); changed_count++; } - } + } } /* Process a constraint C that represents *x = y. */ @@ -1330,7 +1337,7 @@ do_ds_constraint (constraint_t c, bitmap delta) if (!v) continue; t = v->node; - + if (!bitmap_bit_p (get_varinfo (t)->solution, anything_id)) { bitmap_set_bit (get_varinfo (t)->solution, anything_id); @@ -1355,7 +1362,7 @@ do_ds_constraint (constraint_t c, bitmap delta) unsigned int t; unsigned HOST_WIDE_INT fieldoffset = get_varinfo (j)->offset + loff; bitmap tmp; - + v = first_vi_for_offset (get_varinfo (j), fieldoffset); if (!v) continue; @@ -1381,7 +1388,7 @@ do_ds_constraint (constraint_t c, bitmap delta) /* Handle a non-simple (simple meaning requires no iteration), non-copy constraint (IE *x = &y, x = *y, and *x = y). */ - + static void do_complex_constraint (constraint_graph_t graph, constraint_t c, bitmap delta) { @@ -1404,9 +1411,9 @@ do_complex_constraint (constraint_graph_t graph, constraint_t c, bitmap delta) if (!(get_varinfo (c->lhs.var)->is_special_var)) do_sd_constraint (graph, c, delta); } - else + else { - bitmap tmp; + bitmap tmp; bitmap solution; bool flag = false; unsigned int t; @@ -1418,7 +1425,7 @@ do_complex_constraint (constraint_graph_t graph, constraint_t c, bitmap delta) tmp = get_varinfo (t)->solution; flag = set_union_with_increment (tmp, solution, c->rhs.offset); - + if (flag) { get_varinfo (t)->solution = tmp; @@ -1454,13 +1461,13 @@ init_scc_info (void) static void free_scc_info (struct scc_info *si) -{ +{ sbitmap_free (si->visited); sbitmap_free (si->in_component); free (si->visited_index); VEC_free (unsigned, heap, si->scc_stack); VEC_free (unsigned, heap, si->unification_queue); - free(si); + free(si); } @@ -1479,7 +1486,7 @@ find_and_collapse_graph_cycles (constraint_graph_t graph, bool update_changed) for (i = 0; i != size; ++i) if (!TEST_BIT (si->visited, i) && get_varinfo (i)->node == i) scc_visit (graph, si, i); - + process_unification_queue (graph, si, update_changed); free_scc_info (si); } @@ -1487,20 +1494,20 @@ find_and_collapse_graph_cycles (constraint_graph_t graph, bool update_changed) /* Compute a topological ordering for GRAPH, and store the result in the topo_info structure TI. */ -static void +static void compute_topo_order (constraint_graph_t graph, struct topo_info *ti) { unsigned int i; unsigned int size = VEC_length (varinfo_t, varmap); - + for (i = 0; i != size; ++i) if (!TEST_BIT (ti->visited, i) && get_varinfo (i)->node == i) topo_visit (graph, ti, i); } /* Perform offline variable substitution. - + This is a linear time way of identifying variables that must have equivalent points-to sets, including those caused by static cycles, and single entry subgraphs, in the constraint graph. @@ -1513,12 +1520,12 @@ static void perform_var_substitution (constraint_graph_t graph) { struct topo_info *ti = init_topo_info (); - + bitmap_obstack_initialize (&iteration_obstack); /* Compute the topological ordering of the graph, then visit each node in topological order. */ compute_topo_order (graph, ti); - + while (VEC_length (unsigned, ti->topo_order) != 0) { unsigned int i = VEC_pop (unsigned, ti->topo_order); @@ -1555,7 +1562,7 @@ perform_var_substitution (constraint_graph_t graph) /* Theorem 4 in Rountev and Chandra: If i is a direct node, then Solution(i) is a subset of Solution (w), where w is a - predecessor in the graph. + predecessor in the graph. Corollary: If all predecessors of i have the same points-to set, then i has that same points-to set as those predecessors. */ @@ -1571,13 +1578,13 @@ perform_var_substitution (constraint_graph_t graph) BITMAP_FREE (tmp); } - /* See if the root is different than the original node. + /* See if the root is different than the original node. If so, we've found an equivalence. */ if (root != get_varinfo (i)->node && okay_to_elim) { /* Found an equivalence */ get_varinfo (i)->node = root; - collapse_nodes (graph, root, i); + collapse_nodes (graph, root, i, true); if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "Collapsing %s into %s\n", get_varinfo (i)->name, @@ -1606,13 +1613,13 @@ solve_graph (constraint_graph_t graph) changed_count = size; changed = sbitmap_alloc (size); sbitmap_ones (changed); - + /* The already collapsed/unreachable nodes will never change, so we need to account for them in changed_count. */ for (i = 0; i < size; i++) if (get_varinfo (i)->node != i) changed_count--; - + while (changed_count > 0) { unsigned int i; @@ -1620,7 +1627,7 @@ solve_graph (constraint_graph_t graph) stats.iterations++; bitmap_obstack_initialize (&iteration_obstack); - + if (edge_added) { /* We already did cycle elimination once, when we did @@ -1672,16 +1679,16 @@ solve_graph (constraint_graph_t graph) if (!solution_empty) { /* Propagate solution to all successors. */ - EXECUTE_IF_IN_NONNULL_BITMAP (graph->succs[i], + EXECUTE_IF_IN_NONNULL_BITMAP (graph->succs[i], 0, j, bi) { bitmap tmp = get_varinfo (j)->solution; bool flag = false; - + gcc_assert (get_varinfo (j)->node == j); - + flag = set_union_with_increment (tmp, solution, 0); - + if (flag) { get_varinfo (j)->solution = tmp; @@ -1698,14 +1705,14 @@ solve_graph (constraint_graph_t graph) free_topo_info (ti); bitmap_obstack_release (&iteration_obstack); } - + sbitmap_free (changed); } /* CONSTRAINT AND VARIABLE GENERATION FUNCTIONS */ -/* Map from trees to variable ids. */ +/* Map from trees to variable ids. */ static htab_t id_for_tree; typedef struct tree_id @@ -1716,7 +1723,7 @@ typedef struct tree_id /* Hash a tree id structure. */ -static hashval_t +static hashval_t tree_id_hash (const void *p) { const tree_id_t ta = (tree_id_t) p; @@ -1735,13 +1742,13 @@ tree_id_eq (const void *p1, const void *p2) /* Insert ID as the variable id for tree T in the hashtable. */ -static void +static void insert_id_for_tree (tree t, int id) { void **slot; struct tree_id finder; tree_id_t new_pair; - + finder.t = t; slot = htab_find_slot (id_for_tree, &finder, INSERT); gcc_assert (*slot == NULL); @@ -1787,7 +1794,7 @@ alias_get_name (tree decl) if (TREE_CODE (decl) == SSA_NAME) { - num_printed = asprintf (&temp, "%s_%u", + num_printed = asprintf (&temp, "%s_%u", alias_get_name (SSA_NAME_VAR (decl)), SSA_NAME_VERSION (decl)); } @@ -1816,7 +1823,7 @@ get_id_for_tree (tree t) pair = htab_find (id_for_tree, &finder); if (pair == NULL) return create_variable_info_for (t, alias_get_name (t)); - + return pair->id; } @@ -1831,22 +1838,22 @@ get_constraint_exp_from_ssa_var (tree t) /* For parameters, get at the points-to set for the actual parm decl. */ - if (TREE_CODE (t) == SSA_NAME - && TREE_CODE (SSA_NAME_VAR (t)) == PARM_DECL + if (TREE_CODE (t) == SSA_NAME + && TREE_CODE (SSA_NAME_VAR (t)) == PARM_DECL && gimple_default_def (cfun, SSA_NAME_VAR (t)) == t) return get_constraint_exp_from_ssa_var (SSA_NAME_VAR (t)); cexpr.type = SCALAR; - + cexpr.var = get_id_for_tree (t); /* If we determine the result is "anything", and we know this is readonly, say it points to readonly memory instead. */ if (cexpr.var == anything_id && TREE_READONLY (t)) { - cexpr.type = ADDRESSOF; + cexpr.type = INCLUDES; cexpr.var = readonly_id; } - + cexpr.offset = 0; return cexpr; } @@ -1859,27 +1866,36 @@ process_constraint (constraint_t t) { struct constraint_expr rhs = t->rhs; struct constraint_expr lhs = t->lhs; - + gcc_assert (rhs.var < VEC_length (varinfo_t, varmap)); gcc_assert (lhs.var < VEC_length (varinfo_t, varmap)); + gcc_assert (lhs.type != INCLUDES); + if (lhs.type == DEREF) get_varinfo (lhs.var)->directly_dereferenced = true; if (rhs.type == DEREF) get_varinfo (rhs.var)->directly_dereferenced = true; - + + if (!use_field_sensitive) + { + t->rhs.offset = 0; + t->lhs.offset = 0; + } + /* ANYTHING == ANYTHING is pointless. */ if (lhs.var == anything_id && rhs.var == anything_id) return; /* If we have &ANYTHING = something, convert to SOMETHING = &ANYTHING) */ - else if (lhs.var == anything_id && lhs.type == ADDRESSOF) + else if (lhs.var == anything_id + && (lhs.type == INCLUDES || lhs.type == ADDRESSOF)) { rhs = t->lhs; t->lhs = t->rhs; t->rhs = rhs; process_constraint (t); - } + } /* This can happen in our IR with things like n->a = *p */ else if (rhs.type == DEREF && lhs.type == DEREF && rhs.var != anything_id) { @@ -1889,13 +1905,13 @@ process_constraint (constraint_t t) tree pointedtotype = TREE_TYPE (pointertype); tree tmpvar = create_tmp_var_raw (pointedtotype, "doubledereftmp"); struct constraint_expr tmplhs = get_constraint_exp_from_ssa_var (tmpvar); - + /* If this is an aggregate of known size, we should have passed this off to do_structure_copy, and it should have broken it up. */ - gcc_assert (!AGGREGATE_TYPE_P (pointedtotype) + gcc_assert (!AGGREGATE_TYPE_P (pointedtotype) || get_varinfo (rhs.var)->is_unknown_size_var); - + process_constraint (new_constraint (tmplhs, rhs)); process_constraint (new_constraint (lhs, tmplhs)); } @@ -1903,12 +1919,9 @@ process_constraint (constraint_t t) { varinfo_t vi; gcc_assert (rhs.offset == 0); - - /* No need to mark address taken simply because of escaped vars - constraints. */ - if (lhs.var != escaped_vars_id) - for (vi = get_varinfo (rhs.var); vi != NULL; vi = vi->next) - vi->address_taken = true; + + for (vi = get_varinfo (rhs.var); vi != NULL; vi = vi->next) + vi->address_taken = true; VEC_safe_push (constraint_t, heap, constraints, t); } @@ -1927,7 +1940,7 @@ static bool could_have_pointers (tree t) { tree type = TREE_TYPE (t); - + if (POINTER_TYPE_P (type) || AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE) return true; @@ -1944,9 +1957,9 @@ bitpos_of_field (const tree fdecl) if (TREE_CODE (DECL_FIELD_OFFSET (fdecl)) != INTEGER_CST || TREE_CODE (DECL_FIELD_BIT_OFFSET (fdecl)) != INTEGER_CST) return -1; - - return (tree_low_cst (DECL_FIELD_OFFSET (fdecl), 1) * 8) - + tree_low_cst (DECL_FIELD_BIT_OFFSET (fdecl), 1); + + return (tree_low_cst (DECL_FIELD_OFFSET (fdecl), 1) * 8) + + tree_low_cst (DECL_FIELD_BIT_OFFSET (fdecl), 1); } @@ -1965,7 +1978,7 @@ offset_overlaps_with_access (const unsigned HOST_WIDE_INT fieldpos, return true; if (accesspos < fieldpos && (accesspos + accesssize > fieldpos)) return true; - + return false; } @@ -1988,17 +2001,17 @@ get_constraint_for_component_ref (tree t, VEC(ce_s, heap) **results) while (!SSA_VAR_P (forzero) && !CONSTANT_CLASS_P (forzero)) forzero = TREE_OPERAND (forzero, 0); - if (CONSTANT_CLASS_P (forzero) && integer_zerop (forzero)) + if (CONSTANT_CLASS_P (forzero) && integer_zerop (forzero)) { struct constraint_expr temp; - + temp.offset = 0; temp.var = integer_id; temp.type = SCALAR; VEC_safe_push (ce_s, heap, *results, &temp); return; } - + t = get_ref_base_and_extent (t, &bitpos, &bitsize, &bitmaxsize); /* String constants are readonly, so there is nothing to really do @@ -2015,21 +2028,21 @@ get_constraint_for_component_ref (tree t, VEC(ce_s, heap) **results) /* This can also happen due to weird offsetof type macros. */ if (TREE_CODE (t) != ADDR_EXPR && result->type == ADDRESSOF) result->type = SCALAR; - + if (result->type == SCALAR) { /* In languages like C, you can access one past the end of an array. You aren't allowed to dereference it, so we can ignore this constraint. When we handle pointer subtraction, we may have to do something cute here. */ - + if (result->offset < get_varinfo (result->var)->fullsize && bitmaxsize != 0) { /* It's also not true that the constraint will actually start at the right offset, it may start in some padding. We only care about setting the constraint to the first actual field it touches, so - walk to find it. */ + walk to find it. */ varinfo_t curr; for (curr = get_varinfo (result->var); curr; curr = curr->next) { @@ -2072,6 +2085,7 @@ do_deref (VEC (ce_s, heap) **constraints) { struct constraint_expr *c; unsigned int i = 0; + for (i = 0; VEC_iterate (ce_s, *constraints, i, c); i++) { if (c->type == SCALAR) @@ -2090,21 +2104,6 @@ do_deref (VEC (ce_s, heap) **constraints) } } -/* Create a nonlocal variable of TYPE to represent nonlocals we can - alias. */ - -static tree -create_nonlocal_var (tree type) -{ - tree nonlocal = create_tmp_var_raw (type, "NONLOCAL"); - - if (gimple_referenced_vars (cfun)) - add_referenced_var (nonlocal); - - DECL_EXTERNAL (nonlocal) = 1; - return nonlocal; -} - /* Given a tree T, return the constraint expression for it. */ static void @@ -2165,7 +2164,7 @@ get_constraint_for (tree t, VEC (ce_s, heap) **results) if (VEC_length (ce_s, *results) == 0) return; - + gcc_assert (VEC_length (ce_s, *results) == 1); origrhs = VEC_last (ce_s, *results); tmp = *origrhs; @@ -2196,12 +2195,12 @@ get_constraint_for (tree t, VEC (ce_s, heap) **results) VEC_safe_push (ce_s, heap, *results, &tmp); } } - + for (i = 0; VEC_iterate (ce_s, *results, i, c); i++) { if (c->type == DEREF) c->type = SCALAR; - else + else c->type = ADDRESSOF; } return; @@ -2215,9 +2214,9 @@ get_constraint_for (tree t, VEC (ce_s, heap) **results) { varinfo_t vi; tree heapvar = heapvar_lookup (t); - + if (heapvar == NULL) - { + { heapvar = create_tmp_var_raw (ptr_type_node, "HEAP"); DECL_EXTERNAL (heapvar) = 1; get_var_ann (heapvar)->is_heapvar = 1; @@ -2228,18 +2227,18 @@ get_constraint_for (tree t, VEC (ce_s, heap) **results) temp.var = create_variable_info_for (heapvar, alias_get_name (heapvar)); - + vi = get_varinfo (temp.var); vi->is_artificial_var = 1; vi->is_heap_var = 1; - temp.type = ADDRESSOF; + temp.type = INCLUDES; temp.offset = 0; VEC_safe_push (ce_s, heap, *results, &temp); return; } else { - temp.var = escaped_vars_id; + temp.var = anything_id; temp.type = SCALAR; temp.offset = 0; VEC_safe_push (ce_s, heap, *results, &temp); @@ -2290,7 +2289,7 @@ get_constraint_for (tree t, VEC (ce_s, heap) **results) case NON_LVALUE_EXPR: { tree op = TREE_OPERAND (t, 0); - + /* Cast from non-pointer to pointers are bad news for us. Anything else, we see through */ if (!(POINTER_TYPE_P (TREE_TYPE (t)) @@ -2316,7 +2315,7 @@ get_constraint_for (tree t, VEC (ce_s, heap) **results) { switch (TREE_CODE (t)) { - case PHI_NODE: + case PHI_NODE: { get_constraint_for (PHI_RESULT (t), results); return; @@ -2360,8 +2359,8 @@ get_constraint_for (tree t, VEC (ce_s, heap) **results) /* Handle the structure copy case where we have a simple structure copy - between LHS and RHS that is of SIZE (in bits) - + between LHS and RHS that is of SIZE (in bits) + For each field of the lhs variable (lhsfield) For each field of the rhs variable at lhsfield.offset (rhsfield) add the constraint lhsfield = rhsfield @@ -2386,7 +2385,7 @@ do_simple_structure_copy (const struct constraint_expr lhs, struct constraint_expr temprhs = rhs; unsigned HOST_WIDE_INT fieldoffset; - templhs.var = p->id; + templhs.var = p->id; q = get_varinfo (temprhs.var); fieldoffset = p->offset - pstart; q = first_vi_for_offset (q, q->offset + fieldoffset); @@ -2401,8 +2400,8 @@ do_simple_structure_copy (const struct constraint_expr lhs, /* Handle the structure copy case where we have a structure copy between a aggregate on the LHS and a dereference of a pointer on the RHS - that is of SIZE (in bits) - + that is of SIZE (in bits) + For each field of the lhs variable (lhsfield) rhs.offset = lhsfield->offset add the constraint lhsfield = rhs @@ -2427,12 +2426,12 @@ do_rhs_deref_structure_copy (const struct constraint_expr lhs, if (templhs.type == SCALAR) - templhs.var = p->id; + templhs.var = p->id; else templhs.offset = p->offset; - + q = get_varinfo (temprhs.var); - fieldoffset = p->offset - pstart; + fieldoffset = p->offset - pstart; temprhs.offset += fieldoffset; process_constraint (new_constraint (templhs, temprhs)); } @@ -2440,7 +2439,7 @@ do_rhs_deref_structure_copy (const struct constraint_expr lhs, /* Handle the structure copy case where we have a structure copy between a aggregate on the RHS and a dereference of a pointer on - the LHS that is of SIZE (in bits) + the LHS that is of SIZE (in bits) For each field of the rhs variable (rhsfield) lhs.offset = rhsfield->offset @@ -2466,12 +2465,12 @@ do_lhs_deref_structure_copy (const struct constraint_expr lhs, if (temprhs.type == SCALAR) - temprhs.var = p->id; + temprhs.var = p->id; else temprhs.offset = p->offset; - + q = get_varinfo (templhs.var); - fieldoffset = p->offset - pstart; + fieldoffset = p->offset - pstart; templhs.offset += fieldoffset; process_constraint (new_constraint (templhs, temprhs)); } @@ -2479,7 +2478,7 @@ do_lhs_deref_structure_copy (const struct constraint_expr lhs, /* Sometimes, frontends like to give us bad type information. This function will collapse all the fields from VAR to the end of VAR, - into VAR, so that we treat those fields as a single variable. + into VAR, so that we treat those fields as a single variable. We return the variable they were collapsed into. */ static unsigned int @@ -2491,16 +2490,16 @@ collapse_rest_of_var (unsigned int var) for (field = currvar->next; field; field = field->next) { if (dump_file) - fprintf (dump_file, "Type safety: Collapsing var %s into %s\n", + fprintf (dump_file, "Type safety: Collapsing var %s into %s\n", field->name, currvar->name); - + gcc_assert (!field->collapsed_to); field->collapsed_to = currvar; } currvar->next = NULL; currvar->size = currvar->fullsize - currvar->offset; - + return currvar->id; } @@ -2522,7 +2521,7 @@ do_structure_copy (tree lhsop, tree rhsop) gcc_assert (VEC_length (ce_s, rhsc) == 1); lhs = *(VEC_last (ce_s, lhsc)); rhs = *(VEC_last (ce_s, rhsc)); - + VEC_free (ce_s, heap, lhsc); VEC_free (ce_s, heap, rhsc); @@ -2533,7 +2532,7 @@ do_structure_copy (tree lhsop, tree rhsop) lhs = rhs; rhs = tmp; } - + /* This is fairly conservative for the RHS == ADDRESSOF case, in that it's possible it's something we could handle. However, most cases falling into this are dealing with transparent unions, which are slightly @@ -2599,11 +2598,11 @@ do_structure_copy (tree lhsop, tree rhsop) else lhssize = TREE_INT_CST_LOW (lhstypesize); - - if (rhs.type == SCALAR && lhs.type == SCALAR) + + if (rhs.type == SCALAR && lhs.type == SCALAR) { if (!do_simple_structure_copy (lhs, rhs, MIN (lhssize, rhssize))) - { + { lhs.var = collapse_rest_of_var (lhs.var); rhs.var = collapse_rest_of_var (rhs.var); lhs.offset = 0; @@ -2620,7 +2619,7 @@ do_structure_copy (tree lhsop, tree rhsop) else { tree pointedtotype = lhstype; - tree tmpvar; + tree tmpvar; gcc_assert (rhs.type == DEREF && lhs.type == DEREF); tmpvar = create_tmp_var_raw (pointedtotype, "structcopydereftmp"); @@ -2705,7 +2704,7 @@ update_alias_info (tree stmt, struct alias_info *ai) Currently, they are treated as second-class statements. */ add_to_addressable_set (TREE_OPERAND (op, 0), - &addressable_vars); + &addressable_vars); continue; } @@ -2810,7 +2809,8 @@ update_alias_info (tree stmt, struct alias_info *ai) /* If the statement makes a function call, assume that pointer OP will be dereferenced in a store operation inside the called function. */ - if (get_call_expr_in (stmt)) + if (get_call_expr_in (stmt) + || stmt_escape_type == ESCAPE_STORED_IN_GLOBAL) { bitmap_set_bit (ai->dereferenced_ptrs_store, DECL_UID (var)); pi->is_dereferenced = 1; @@ -2831,9 +2831,9 @@ update_alias_info (tree stmt, struct alias_info *ai) bitmap_set_bit (ai->written_vars, DECL_UID (var)); if (may_be_aliased (var)) NUM_REFERENCES_INC (ann); - + } - + /* Mark variables in V_MAY_DEF operands as being written to. */ FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_VIRTUAL_DEFS) { @@ -2885,7 +2885,7 @@ handle_ptr_arith (VEC (ce_s, heap) *lhsc, tree expr) { rhsoffset = TREE_INT_CST_LOW (op1) * BITS_PER_UNIT; } - + for (i = 0; VEC_iterate (ce_s, lhsc, i, c); i++) for (j = 0; VEC_iterate (ce_s, temp, j, c2); j++) @@ -2940,12 +2940,12 @@ find_func_aliases (tree origt) { int i; unsigned int j; - + /* For a phi node, assign all the arguments to the result. */ get_constraint_for (PHI_RESULT (t), &lhsc); for (i = 0; i < PHI_NUM_ARGS (t); i++) - { + { tree rhstype; tree strippedrhs = PHI_ARG_DEF (t, i); @@ -2963,7 +2963,7 @@ find_func_aliases (tree origt) VEC_pop (ce_s, rhsc); } } - } + } } } /* In IPA mode, we need to generate constraints to pass call @@ -2971,12 +2971,12 @@ find_func_aliases (tree origt) modify_expr when we are returning a value, or just a plain call_expr when we are not. */ else if (in_ipa_mode - && ((TREE_CODE (t) == MODIFY_EXPR + && ((TREE_CODE (t) == MODIFY_EXPR && TREE_CODE (TREE_OPERAND (t, 1)) == CALL_EXPR - && !(call_expr_flags (TREE_OPERAND (t, 1)) + && !(call_expr_flags (TREE_OPERAND (t, 1)) & (ECF_MALLOC | ECF_MAY_BE_ALLOCA))) - || (TREE_CODE (t) == CALL_EXPR - && !(call_expr_flags (t) + || (TREE_CODE (t) == CALL_EXPR + && !(call_expr_flags (t) & (ECF_MALLOC | ECF_MAY_BE_ALLOCA))))) { tree lhsop; @@ -3015,7 +3015,7 @@ find_func_aliases (tree origt) parameters of the function. */ fi = get_varinfo (varid); arglist = TREE_OPERAND (rhsop, 1); - + for (;arglist; arglist = TREE_CHAIN (arglist)) { tree arg = TREE_VALUE (arglist); @@ -3049,7 +3049,7 @@ find_func_aliases (tree origt) struct constraint_expr rhs; struct constraint_expr *lhsp; unsigned int j = 0; - + get_constraint_for (lhsop, &lhsc); if (TREE_CODE (decl) != FUNCTION_DECL) { @@ -3065,7 +3065,7 @@ find_func_aliases (tree origt) } for (j = 0; VEC_iterate (ce_s, lhsc, j, lhsp); j++) process_constraint (new_constraint (*lhsp, rhs)); - } + } } /* Otherwise, just a regular assignment statement. */ else if (TREE_CODE (t) == MODIFY_EXPR) @@ -3074,7 +3074,7 @@ find_func_aliases (tree origt) tree rhsop = TREE_OPERAND (t, 1); int i; - if ((AGGREGATE_TYPE_P (TREE_TYPE (lhsop)) + if ((AGGREGATE_TYPE_P (TREE_TYPE (lhsop)) || TREE_CODE (TREE_TYPE (lhsop)) == COMPLEX_TYPE) && (AGGREGATE_TYPE_P (TREE_TYPE (rhsop)) || TREE_CODE (TREE_TYPE (lhsop)) == COMPLEX_TYPE)) @@ -3093,7 +3093,7 @@ find_func_aliases (tree origt) { /* RHS that consist of unary operations, exceptional types, or bare decls/constants, get - handled directly by get_constraint_for. */ + handled directly by get_constraint_for. */ case tcc_reference: case tcc_declaration: case tcc_constant: @@ -3108,7 +3108,7 @@ find_func_aliases (tree origt) { struct constraint_expr *c2; unsigned int k; - + for (k = 0; VEC_iterate (ce_s, rhsc, k, c2); k++) process_constraint (new_constraint (*c, *c2)); } @@ -3150,7 +3150,7 @@ find_func_aliases (tree origt) } } } - } + } } } } @@ -3158,7 +3158,7 @@ find_func_aliases (tree origt) /* After promoting variables and computing aliasing we will need to re-scan most statements. FIXME: Try to minimize the number of statements re-scanned. It's not really necessary to - re-scan *all* statements. */ + re-scan *all* statements. */ mark_stmt_modified (origt); VEC_free (ce_s, heap, rhsc); VEC_free (ce_s, heap, lhsc); @@ -3171,7 +3171,7 @@ find_func_aliases (tree origt) first field that overlaps with OFFSET. Return NULL if we can't find one. */ -static varinfo_t +static varinfo_t first_vi_for_offset (varinfo_t start, unsigned HOST_WIDE_INT offset) { varinfo_t curr = start; @@ -3197,7 +3197,7 @@ insert_into_field_list (varinfo_t base, varinfo_t field) { varinfo_t prev = base; varinfo_t curr = base->next; - + field->next = curr; prev->next = field; } @@ -3210,7 +3210,7 @@ insert_into_field_list_sorted (varinfo_t base, varinfo_t field) { varinfo_t prev = base; varinfo_t curr = base->next; - + if (curr == NULL) { prev->next = field; @@ -3232,13 +3232,13 @@ insert_into_field_list_sorted (varinfo_t base, varinfo_t field) /* qsort comparison function for two fieldoff's PA and PB */ -static int +static int fieldoff_compare (const void *pa, const void *pb) { const fieldoff_s *foa = (const fieldoff_s *)pa; const fieldoff_s *fob = (const fieldoff_s *)pb; HOST_WIDE_INT foasize, fobsize; - + if (foa->offset != fob->offset) return foa->offset - fob->offset; @@ -3251,8 +3251,8 @@ fieldoff_compare (const void *pa, const void *pb) void sort_fieldstack (VEC(fieldoff_s,heap) *fieldstack) { - qsort (VEC_address (fieldoff_s, fieldstack), - VEC_length (fieldoff_s, fieldstack), + qsort (VEC_address (fieldoff_s, fieldstack), + VEC_length (fieldoff_s, fieldstack), sizeof (fieldoff_s), fieldoff_compare); } @@ -3266,12 +3266,12 @@ sort_fieldstack (VEC(fieldoff_s,heap) *fieldstack) TYPE. */ int -push_fields_onto_fieldstack (tree type, VEC(fieldoff_s,heap) **fieldstack, +push_fields_onto_fieldstack (tree type, VEC(fieldoff_s,heap) **fieldstack, HOST_WIDE_INT offset, bool *has_union) { tree field; int count = 0; - + if (TREE_CODE (type) == COMPLEX_TYPE) { fieldoff_s *real_part, *img_part; @@ -3280,13 +3280,13 @@ push_fields_onto_fieldstack (tree type, VEC(fieldoff_s,heap) **fieldstack, real_part->size = TYPE_SIZE (TREE_TYPE (type)); real_part->offset = offset; real_part->decl = NULL_TREE; - + 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; - + return 2; } @@ -3313,12 +3313,12 @@ push_fields_onto_fieldstack (tree type, VEC(fieldoff_s,heap) **fieldstack, { bool push = false; int pushed = 0; - - if (has_union + + if (has_union && (TREE_CODE (TREE_TYPE (type)) == QUAL_UNION_TYPE || TREE_CODE (TREE_TYPE (type)) == UNION_TYPE)) *has_union = true; - + if (!AGGREGATE_TYPE_P (TREE_TYPE (type))) /* var_can_have_subvars */ push = true; else if (!(pushed = push_fields_onto_fieldstack @@ -3352,12 +3352,12 @@ push_fields_onto_fieldstack (tree type, VEC(fieldoff_s,heap) **fieldstack, { bool push = false; int pushed = 0; - - if (has_union + + if (has_union && (TREE_CODE (TREE_TYPE (field)) == QUAL_UNION_TYPE || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)) *has_union = true; - + if (!var_can_have_subvars (field)) push = true; else if (!(pushed = push_fields_onto_fieldstack @@ -3369,7 +3369,7 @@ push_fields_onto_fieldstack (tree type, VEC(fieldoff_s,heap) **fieldstack, see if we didn't push any subfields and the size is nonzero, push the field onto the stack */ push = true; - + if (push) { fieldoff_s *pair; @@ -3388,34 +3388,19 @@ push_fields_onto_fieldstack (tree type, VEC(fieldoff_s,heap) **fieldstack, return count; } -/* Create a constraint from ESCAPED_VARS variable to VI. */ +/* Create a constraint from ANYTHING variable to VI. */ static void -make_constraint_from_escaped (varinfo_t vi) +make_constraint_from_anything (varinfo_t vi) { struct constraint_expr lhs, rhs; - - lhs.var = vi->id; - lhs.offset = 0; - lhs.type = SCALAR; - - rhs.var = escaped_vars_id; - rhs.offset = 0; - rhs.type = SCALAR; - process_constraint (new_constraint (lhs, rhs)); -} -/* Create a constraint to the ESCAPED_VARS variable from constraint - expression RHS. */ - -static void -make_constraint_to_escaped (struct constraint_expr rhs) -{ - struct constraint_expr lhs; - - lhs.var = escaped_vars_id; + lhs.var = vi->id; lhs.offset = 0; lhs.type = SCALAR; + rhs.var = anything_id; + rhs.offset = 0; + rhs.type = INCLUDES; process_constraint (new_constraint (lhs, rhs)); } @@ -3428,15 +3413,15 @@ count_num_arguments (tree decl, bool *is_varargs) unsigned int i = 0; tree t; - for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); + for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t)) - { + { if (TREE_VALUE (t) == void_type_node) break; i++; } - + if (!t) *is_varargs = true; return i; @@ -3450,7 +3435,7 @@ create_function_info_for (tree decl, const char *name) { unsigned int index = VEC_length (varinfo_t, varmap); varinfo_t vi; - tree arg; + tree arg; unsigned int i; bool is_varargs = false; @@ -3462,7 +3447,7 @@ create_function_info_for (tree decl, const char *name) vi->has_union = 0; vi->size = 1; vi->fullsize = count_num_arguments (decl, &is_varargs) + 1; - insert_id_for_tree (vi->decl, index); + insert_id_for_tree (vi->decl, index); VEC_safe_push (varinfo_t, heap, varmap, vi); stats.total_vars++; @@ -3478,12 +3463,12 @@ create_function_info_for (tree decl, const char *name) return index; } - + arg = DECL_ARGUMENTS (decl); /* Set up variables for each argument. */ for (i = 1; i < vi->fullsize; i++) - { + { varinfo_t argvi; const char *newname; char *tempname; @@ -3492,7 +3477,7 @@ create_function_info_for (tree decl, const char *name) if (arg) argdecl = arg; - + newindex = VEC_length (varinfo_t, varmap); asprintf (&tempname, "%s.arg%d", name, i-1); newname = ggc_strdup (tempname); @@ -3528,7 +3513,7 @@ create_function_info_for (tree decl, const char *name) if (DECL_RESULT (decl)) resultdecl = DECL_RESULT (decl); - + newindex = VEC_length (varinfo_t, varmap); asprintf (&tempname, "%s.result", name); newname = ggc_strdup (tempname); @@ -3547,10 +3532,10 @@ create_function_info_for (tree decl, const char *name) insert_id_for_tree (DECL_RESULT (decl), newindex); } return index; -} +} -/* Return true if FIELDSTACK contains fields that overlap. +/* Return true if FIELDSTACK contains fields that overlap. FIELDSTACK is assumed to be sorted by offset. */ static bool @@ -3569,59 +3554,6 @@ check_for_overlaps (VEC (fieldoff_s,heap) *fieldstack) return false; } -/* This function is called through walk_tree to walk global - initializers looking for constraints we need to add to the - constraint list. */ - -static tree -find_global_initializers (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, - void *viv) -{ - varinfo_t vi = (varinfo_t)viv; - tree t = *tp; - - switch (TREE_CODE (t)) - { - /* Dereferences and addressofs are the only important things - here, and i don't even remember if dereferences are legal - here in initializers. */ - case INDIRECT_REF: - case ADDR_EXPR: - { - struct constraint_expr *c; - size_t i; - - VEC(ce_s, heap) *rhsc = NULL; - get_constraint_for (t, &rhsc); - for (i = 0; VEC_iterate (ce_s, rhsc, i, c); i++) - { - struct constraint_expr lhs; - - lhs.var = vi->id; - lhs.type = SCALAR; - lhs.offset = 0; - process_constraint (new_constraint (lhs, *c)); - } - - VEC_free (ce_s, heap, rhsc); - } - break; - case VAR_DECL: - /* We might not have walked this because we skip - DECL_EXTERNALs during the initial scan. */ - if (gimple_referenced_vars (cfun)) - { - get_var_ann (t); - if (referenced_var_check_and_insert (t)) - mark_sym_for_renaming (t); - } - break; - default: - break; - } - return NULL_TREE; -} - /* Create a varinfo structure for NAME and DECL, and add it to VARMAP. This will also create any varinfo structures necessary for fields of DECL. */ @@ -3637,12 +3569,12 @@ create_variable_info_for (tree decl, const char *name) bool hasunion; bool is_global = DECL_P (decl) ? is_global_var (decl) : false; VEC (fieldoff_s,heap) *fieldstack = NULL; - + if (TREE_CODE (decl) == FUNCTION_DECL && in_ipa_mode) return create_function_info_for (decl, name); hasunion = TREE_CODE (decltype) == UNION_TYPE - || TREE_CODE (decltype) == QUAL_UNION_TYPE; + || TREE_CODE (decltype) == QUAL_UNION_TYPE; if (var_can_have_subvars (decl) && use_field_sensitive && !hasunion) { push_fields_onto_fieldstack (decltype, &fieldstack, 0, &hasunion); @@ -3652,7 +3584,7 @@ create_variable_info_for (tree decl, const char *name) notokay = true; } } - + /* If the variable doesn't have subvars, we may end up needing to sort the field list and create fake variables for all the @@ -3675,36 +3607,16 @@ create_variable_info_for (tree decl, const char *name) vi->fullsize = TREE_INT_CST_LOW (declsize); vi->size = vi->fullsize; } - - insert_id_for_tree (vi->decl, index); + + insert_id_for_tree (vi->decl, index); VEC_safe_push (varinfo_t, heap, varmap, vi); if (is_global && (!flag_whole_program || !in_ipa_mode)) - { - make_constraint_from_escaped (vi); - - /* If the variable can't be aliased, there is no point in - putting it in the set of nonlocal vars. */ - if (may_be_aliased (vi->decl)) - { - struct constraint_expr rhs; - rhs.var = index; - rhs.type = ADDRESSOF; - rhs.offset = 0; - make_constraint_to_escaped (rhs); - } - - if (TREE_CODE (decl) != FUNCTION_DECL && DECL_INITIAL (decl)) - { - walk_tree_without_duplicates (&DECL_INITIAL (decl), - find_global_initializers, - (void *)vi); - } - } + make_constraint_from_anything (vi); stats.total_vars++; - if (use_field_sensitive - && !notokay - && !vi->is_unknown_size_var + if (use_field_sensitive + && !notokay + && !vi->is_unknown_size_var && var_can_have_subvars (decl) && VEC_length (fieldoff_s, fieldstack) <= MAX_FIELDS_FOR_FIELD_SENSITIVE) { @@ -3728,7 +3640,7 @@ create_variable_info_for (tree decl, const char *name) without creating varinfos for the fields anyway, so sorting them is a waste to boot. */ if (!notokay) - { + { sort_fieldstack (fieldstack); /* Due to some C++ FE issues, like PR 22488, we might end up what appear to be overlapping fields even though they, @@ -3736,8 +3648,8 @@ create_variable_info_for (tree decl, const char *name) we will simply disable field-sensitivity for these cases. */ notokay = check_for_overlaps (fieldstack); } - - + + if (VEC_length (fieldoff_s, fieldstack) != 0) fo = VEC_index (fieldoff_s, fieldstack, 0); @@ -3749,11 +3661,11 @@ create_variable_info_for (tree decl, const char *name) VEC_free (fieldoff_s, heap, fieldstack); return index; } - + vi->size = TREE_INT_CST_LOW (fo->size); vi->offset = fo->offset; - for (i = VEC_length (fieldoff_s, fieldstack) - 1; - i >= 1 && VEC_iterate (fieldoff_s, fieldstack, i, fo); + for (i = VEC_length (fieldoff_s, fieldstack) - 1; + i >= 1 && VEC_iterate (fieldoff_s, fieldstack, i, fo); i--) { varinfo_t newvi; @@ -3764,10 +3676,10 @@ create_variable_info_for (tree decl, const char *name) if (dump_file) { if (fo->decl) - asprintf (&tempname, "%s.%s", + asprintf (&tempname, "%s.%s", vi->name, alias_get_name (fo->decl)); else - asprintf (&tempname, "%s." HOST_WIDE_INT_PRINT_DEC, + asprintf (&tempname, "%s." HOST_WIDE_INT_PRINT_DEC, vi->name, fo->offset); newname = ggc_strdup (tempname); free (tempname); @@ -3779,21 +3691,8 @@ create_variable_info_for (tree decl, const char *name) insert_into_field_list (vi, newvi); VEC_safe_push (varinfo_t, heap, varmap, newvi); if (is_global && (!flag_whole_program || !in_ipa_mode)) - { - /* If the variable can't be aliased, there is no point in - putting it in the set of nonlocal vars. */ - if (may_be_aliased (vi->decl)) - { - struct constraint_expr rhs; - - rhs.var = newindex; - rhs.type = ADDRESSOF; - rhs.offset = 0; - make_constraint_to_escaped (rhs); - } - make_constraint_from_escaped (newvi); - } - + make_constraint_from_anything (newvi); + stats.total_vars++; } VEC_free (fieldoff_s, heap, fieldstack); @@ -3808,14 +3707,22 @@ dump_solution_for_var (FILE *file, unsigned int var) { varinfo_t vi = get_varinfo (var); unsigned int i; - bitmap_iterator bi; - - fprintf (file, "%s = { ", vi->name); - EXECUTE_IF_SET_IN_BITMAP (get_varinfo (vi->node)->solution, 0, i, bi) + bitmap_iterator bi; + + if (vi->node != var) { - fprintf (file, "%s ", get_varinfo (i)->name); + varinfo_t vipt = get_varinfo (vi->node); + fprintf (file, "%s = same as %s\n", vi->name, vipt->name); + } + else + { + fprintf (file, "%s = { ", vi->name); + EXECUTE_IF_SET_IN_BITMAP (get_varinfo (vi->node)->solution, 0, i, bi) + { + fprintf (file, "%s ", get_varinfo (i)->name); + } + fprintf (file, "}\n"); } - fprintf (file, "}\n"); } /* Print the points-to solution for VAR to stdout. */ @@ -3834,37 +3741,36 @@ intra_create_variable_infos (void) { tree t; struct constraint_expr lhs, rhs; - varinfo_t nonlocal_vi; - /* For each incoming pointer argument arg, ARG = ESCAPED_VARS or a + /* For each incoming pointer argument arg, ARG = ANYTHING or a dummy variable if flag_argument_noalias > 2. */ for (t = DECL_ARGUMENTS (current_function_decl); t; t = TREE_CHAIN (t)) { varinfo_t p; unsigned int arg_id; - + if (!could_have_pointers (t)) continue; - + arg_id = get_id_for_tree (t); /* With flag_argument_noalias greater than two means that the incoming - argument cannot alias anything except for itself so create a HEAP - variable. */ + argument cannot alias anything except for itself so create a HEAP + variable. */ if (POINTER_TYPE_P (TREE_TYPE (t)) && flag_argument_noalias > 2) { varinfo_t vi; tree heapvar = heapvar_lookup (t); unsigned int id; - + lhs.offset = 0; lhs.type = SCALAR; lhs.var = get_id_for_tree (t); - + if (heapvar == NULL_TREE) { - heapvar = create_tmp_var_raw (TREE_TYPE (TREE_TYPE (t)), + heapvar = create_tmp_var_raw (TREE_TYPE (TREE_TYPE (t)), "PARM_NOALIAS"); get_var_ann (heapvar)->is_heapvar = 1; DECL_EXTERNAL (heapvar) = 1; @@ -3877,44 +3783,21 @@ intra_create_variable_infos (void) vi->is_artificial_var = 1; vi->is_heap_var = 1; rhs.var = id; - rhs.type = ADDRESSOF; + rhs.type = INCLUDES; rhs.offset = 0; - for (p = get_varinfo (lhs.var); p; p = p->next) + for (p = get_varinfo (lhs.var); p; p = p->next) { struct constraint_expr temp = lhs; temp.var = p->id; process_constraint (new_constraint (temp, rhs)); } } - else + else { for (p = get_varinfo (arg_id); p; p = p->next) - make_constraint_from_escaped (p); + make_constraint_from_anything (p); } } - if (!gimple_nonlocal_all (cfun)) - cfun->gimple_df->nonlocal_all = create_nonlocal_var (void_type_node); - - /* Create variable info for the nonlocal var if it does not - exist. */ - nonlocal_vars_id = create_variable_info_for (gimple_nonlocal_all (cfun), - get_name (gimple_nonlocal_all - (cfun))); - nonlocal_vi = get_varinfo (nonlocal_vars_id); - nonlocal_vi->is_artificial_var = 1; - nonlocal_vi->is_heap_var = 1; - nonlocal_vi->is_unknown_size_var = 1; - nonlocal_vi->directly_dereferenced = true; - - rhs.var = nonlocal_vars_id; - rhs.type = ADDRESSOF; - rhs.offset = 0; - - lhs.var = escaped_vars_id; - lhs.type = SCALAR; - lhs.offset = 0; - - process_constraint (new_constraint (lhs, rhs)); } /* Set bits in INTO corresponding to the variable uids in solution set @@ -3928,18 +3811,18 @@ set_uids_in_ptset (tree ptr, bitmap into, bitmap from) unsigned int i; bitmap_iterator bi; subvar_t sv; - unsigned HOST_WIDE_INT ptr_alias_set = get_alias_set (TREE_TYPE (ptr)); + HOST_WIDE_INT ptr_alias_set = get_alias_set (TREE_TYPE (ptr)); EXECUTE_IF_SET_IN_BITMAP (from, 0, i, bi) { varinfo_t vi = get_varinfo (i); unsigned HOST_WIDE_INT var_alias_set; - + /* The only artificial variables that are allowed in a may-alias set are heap variables. */ if (vi->is_artificial_var && !vi->is_heap_var) continue; - + if (vi->has_union && get_subvars_for_var (vi->decl) != NULL) { /* Variables containing unions may need to be converted to @@ -3947,7 +3830,7 @@ set_uids_in_ptset (tree ptr, bitmap into, bitmap from) for (sv = get_subvars_for_var (vi->decl); sv; sv = sv->next) bitmap_set_bit (into, DECL_UID (sv->var)); } - else if (TREE_CODE (vi->decl) == VAR_DECL + else if (TREE_CODE (vi->decl) == VAR_DECL || TREE_CODE (vi->decl) == PARM_DECL) { if (var_can_have_subvars (vi->decl) @@ -3985,8 +3868,123 @@ set_uids_in_ptset (tree ptr, bitmap into, bitmap from) static bool have_alias_info = false; +/* The list of SMT's that are in use by our pointer variables. This + is the set of SMT's for all pointers that can point to anything. */ +static bitmap used_smts; + +/* Due to the ordering of points-to set calculation and SMT + calculation being a bit co-dependent, we can't just calculate SMT + used info whenever we want, we have to calculate it around the time + that find_what_p_points_to is called. */ +static bool used_smt_calculated; + +/* Mark which SMT's are in use by points-to anything variables. */ + +static void +set_used_smts (void) +{ + int i; + varinfo_t vi; + used_smts = BITMAP_ALLOC (&ptabitmap_obstack); + + for (i = 0; VEC_iterate (varinfo_t, varmap, i, vi); i++) + { + tree var = vi->decl; + tree smt; + bitmap_iterator bi; + unsigned int j; + var_ann_t va; + struct ptr_info_def *pi = NULL; + + if (TREE_CODE (vi->decl) == SSA_NAME) + pi = SSA_NAME_PTR_INFO (var); + + /* Skip the special variables and those without their own + solution set. */ + if (vi->is_special_var || vi->node != vi->id || !SSA_VAR_P (var) + || (pi && !pi->is_dereferenced) + || (DECL_P (var) && !may_be_aliased (var))) + continue; + + if (TREE_CODE (var) == SSA_NAME) + var = SSA_NAME_VAR (var); + + va = var_ann (var); + if (!va) + continue; + + smt = va->symbol_mem_tag; + if (smt) + { + EXECUTE_IF_SET_IN_BITMAP (vi->solution, 0, j, bi) + { + if (get_varinfo (j)->is_artificial_var) + { + bitmap_set_bit (used_smts, DECL_UID (smt)); + break; + } + } + } + } + used_smt_calculated = true; +} + +/* Merge the necessary SMT's into the solution set for VI, 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) +{ + unsigned int i; + bitmap_iterator bi; + tree smt; + VEC(tree, gc) *aliases; + tree var = p; + + if (TREE_CODE (p) == SSA_NAME) + var = SSA_NAME_VAR (p); + + smt = var_ann (var)->symbol_mem_tag; + if (smt) + { + HOST_WIDE_INT smtset = get_alias_set (TREE_TYPE (smt)); + + /* Need to set the SMT subsets first before this + will work properly. */ + bitmap_set_bit (vi->finished_solution, DECL_UID (smt)); + EXECUTE_IF_SET_IN_BITMAP (used_smts, 0, i, bi) + { + tree newsmt = referenced_var (i); + tree newsmttype = TREE_TYPE (newsmt); + + if (alias_set_subset_of (get_alias_set (newsmttype), + smtset)) + bitmap_set_bit (vi->finished_solution, i); + } + + aliases = var_ann (smt)->may_aliases; + if (aliases) + { + size_t k; + tree al; + for (k = 0; VEC_iterate (tree, aliases, k, al); k++) + bitmap_set_bit (vi->finished_solution, + DECL_UID (al)); + } + } +} + /* Given a pointer variable P, fill in its points-to set, or return - false if we can't. */ + false if we can't. + Rather than return false for variables that point-to anything, we + instead find the corresponding SMT, and merge in it's aliases. In + addition to these aliases, we also set the bits for the SMT's + themselves and their subsets, as SMT's are still in use by + non-SSA_NAME's, and pruning may eliminate every one of their + aliases. In such a case, if we did not include the right set of + SMT's in the points-to set of the variable, we'd end up with + statements that do not conflict but should. */ bool find_what_p_points_to (tree p) @@ -3999,8 +3997,8 @@ find_what_p_points_to (tree p) /* For parameters, get at the points-to set for the actual parm decl. */ - if (TREE_CODE (p) == SSA_NAME - && TREE_CODE (SSA_NAME_VAR (p)) == PARM_DECL + if (TREE_CODE (p) == SSA_NAME + && TREE_CODE (SSA_NAME_VAR (p)) == PARM_DECL && gimple_default_def (cfun, SSA_NAME_VAR (p)) == p) lookup_p = SSA_NAME_VAR (p); @@ -4020,17 +4018,21 @@ find_what_p_points_to (tree p) if (!var_can_have_subvars (vi->decl) || get_subvars_for_var (vi->decl) == NULL) return false; - } + } else { struct ptr_info_def *pi = get_ptr_info (p); unsigned int i; bitmap_iterator bi; + bool was_pt_anything = false; + + if (!pi->is_dereferenced) + return false; /* This variable may have been collapsed, let's get the real variable. */ vi = get_varinfo (vi->node); - + /* Translate artificial variables into SSA_NAME_PTR_INFO attributes. */ EXECUTE_IF_SET_IN_BITMAP (vi->solution, 0, i, bi) @@ -4045,23 +4047,44 @@ find_what_p_points_to (tree p) if (vi->id == nothing_id) pi->pt_null = 1; else if (vi->id == anything_id) - pi->pt_anything = 1; + was_pt_anything = 1; else if (vi->id == readonly_id) - pi->pt_anything = 1; + was_pt_anything = 1; else if (vi->id == integer_id) - pi->pt_anything = 1; + was_pt_anything = 1; else if (vi->is_heap_var) pi->pt_global_mem = 1; } } - if (pi->pt_anything) - 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 + { + vi->finished_solution = BITMAP_GGC_ALLOC (); - if (!pi->pt_vars) - pi->pt_vars = BITMAP_GGC_ALLOC (); + /* Instead of using pt_anything, we instead merge in the SMT + aliases for the underlying SMT. */ + if (was_pt_anything) + { + if (!used_smt_calculated) + set_used_smts (); + merge_smts_into (p, vi); + pi->pt_global_mem = 1; - set_uids_in_ptset (vi->decl, pi->pt_vars, vi->solution); + } + set_uids_in_ptset (vi->decl, vi->finished_solution, vi->solution); + pi->pt_vars = vi->finished_solution; + } if (bitmap_empty_p (pi->pt_vars)) pi->pt_vars = NULL; @@ -4135,7 +4158,7 @@ init_base_vars (void) /* Create the ANYTHING variable, used to represent that a variable points to some unknown piece of memory. */ anything_tree = create_tmp_var_raw (void_type_node, "ANYTHING"); - var_anything = new_var_info (anything_tree, 1, "ANYTHING", 1); + var_anything = new_var_info (anything_tree, 1, "ANYTHING", 1); insert_id_for_tree (anything_tree, 1); var_anything->is_artificial_var = 1; var_anything->size = ~0; @@ -4146,13 +4169,13 @@ init_base_vars (void) anything_id = 1; /* Anything points to anything. This makes deref constraints just - work in the presence of linked list and other p = *p type loops, + work in the presence of linked list and other p = *p type loops, by saying that *ANYTHING = ANYTHING. */ VEC_safe_push (varinfo_t, heap, varmap, var_anything); lhs.type = SCALAR; lhs.var = anything_id; lhs.offset = 0; - rhs.type = ADDRESSOF; + rhs.type = INCLUDES; rhs.var = anything_id; rhs.offset = 0; var_anything->address_taken = true; @@ -4161,7 +4184,7 @@ init_base_vars (void) process_constraint ignores all anything = anything constraints, since all but this one are redundant. */ VEC_safe_push (constraint_t, heap, constraints, new_constraint (lhs, rhs)); - + /* Create the READONLY variable, used to represent that a variable points to readonly memory. */ readonly_tree = create_tmp_var_raw (void_type_node, "READONLY"); @@ -4183,12 +4206,12 @@ init_base_vars (void) lhs.type = SCALAR; lhs.var = readonly_id; lhs.offset = 0; - rhs.type = ADDRESSOF; + rhs.type = INCLUDES; rhs.var = anything_id; rhs.offset = 0; - + process_constraint (new_constraint (lhs, rhs)); - + /* Create the INTEGER variable, used to represent that a variable points to an INTEGER. */ integer_tree = create_tmp_var_raw (void_type_node, "INTEGER"); @@ -4208,34 +4231,11 @@ init_base_vars (void) lhs.type = SCALAR; lhs.var = integer_id; lhs.offset = 0; - rhs.type = ADDRESSOF; + rhs.type = INCLUDES; rhs.var = anything_id; rhs.offset = 0; process_constraint (new_constraint (lhs, rhs)); - - /* Create the ESCAPED_VARS variable used to represent variables that - escape this function. */ - escaped_vars_tree = create_tmp_var_raw (void_type_node, "ESCAPED_VARS"); - var_escaped_vars = new_var_info (escaped_vars_tree, 4, "ESCAPED_VARS", 4); - insert_id_for_tree (escaped_vars_tree, 4); - var_escaped_vars->is_artificial_var = 1; - var_escaped_vars->size = ~0; - var_escaped_vars->fullsize = ~0; - var_escaped_vars->offset = 0; - var_escaped_vars->next = NULL; - escaped_vars_id = 4; - VEC_safe_push (varinfo_t, heap, varmap, var_escaped_vars); - - /* ESCAPED_VARS = *ESCAPED_VARS */ - lhs.type = SCALAR; - lhs.var = escaped_vars_id; - lhs.offset = 0; - rhs.type = DEREF; - rhs.var = escaped_vars_id; - rhs.offset = 0; - process_constraint (new_constraint (lhs, rhs)); - -} +} /* Initialize things necessary to perform PTA */ @@ -4245,7 +4245,7 @@ init_alias_vars (void) bitmap_obstack_initialize (&ptabitmap_obstack); bitmap_obstack_initialize (&predbitmap_obstack); - constraint_pool = create_alloc_pool ("Constraint pool", + constraint_pool = create_alloc_pool ("Constraint pool", sizeof (struct constraint), 30); variable_info_pool = create_alloc_pool ("Variable info pool", sizeof (struct variable_info), 30); @@ -4257,105 +4257,6 @@ init_alias_vars (void) init_base_vars (); } -/* Given a statement STMT, generate necessary constraints to - escaped_vars for the escaping variables. */ - -static void -find_escape_constraints (tree stmt) -{ - enum escape_type stmt_escape_type = is_escape_site (stmt); - tree rhs; - VEC(ce_s, heap) *rhsc = NULL; - struct constraint_expr *c; - size_t i; - - if (stmt_escape_type == NO_ESCAPE) - return; - - if (TREE_CODE (stmt) == RETURN_EXPR) - { - /* Returns are either bare, with an embedded MODIFY_EXPR, or - just a plain old expression. */ - if (!TREE_OPERAND (stmt, 0)) - return; - if (TREE_CODE (TREE_OPERAND (stmt, 0)) == MODIFY_EXPR) - rhs = TREE_OPERAND (TREE_OPERAND (stmt, 0), 1); - else - rhs = TREE_OPERAND (stmt, 0); - - get_constraint_for (rhs, &rhsc); - for (i = 0; VEC_iterate (ce_s, rhsc, i, c); i++) - make_constraint_to_escaped (*c); - VEC_free (ce_s, heap, rhsc); - return; - } - else if (TREE_CODE (stmt) == ASM_EXPR) - { - /* Whatever the inputs of the ASM are, escape. */ - tree arg; - - for (arg = ASM_INPUTS (stmt); arg; arg = TREE_CHAIN (arg)) - { - rhsc = NULL; - get_constraint_for (TREE_VALUE (arg), &rhsc); - for (i = 0; VEC_iterate (ce_s, rhsc, i, c); i++) - make_constraint_to_escaped (*c); - VEC_free (ce_s, heap, rhsc); - } - return; - } - else if (TREE_CODE (stmt) == CALL_EXPR - || (TREE_CODE (stmt) == MODIFY_EXPR - && TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)) - { - /* Calls cause all of the arguments passed in to escape. */ - tree arg; - - if (TREE_CODE (stmt) == MODIFY_EXPR) - stmt = TREE_OPERAND (stmt, 1); - for (arg = TREE_OPERAND (stmt, 1); arg; arg = TREE_CHAIN (arg)) - { - if (POINTER_TYPE_P (TREE_TYPE (TREE_VALUE (arg)))) - { - rhsc = NULL; - get_constraint_for (TREE_VALUE (arg), &rhsc); - for (i = 0; VEC_iterate (ce_s, rhsc, i, c); i++) - make_constraint_to_escaped (*c); - VEC_free (ce_s, heap, rhsc); - } - } - return; - } - else - { - gcc_assert (TREE_CODE (stmt) == MODIFY_EXPR); - } - - gcc_assert (stmt_escape_type == ESCAPE_BAD_CAST - || stmt_escape_type == ESCAPE_STORED_IN_GLOBAL - || stmt_escape_type == ESCAPE_UNKNOWN); - rhs = TREE_OPERAND (stmt, 1); - - /* Look through casts for the real escaping variable. - Constants don't really escape, so ignore them. - Otherwise, whatever escapes must be on our RHS. */ - if (TREE_CODE (rhs) == NOP_EXPR - || TREE_CODE (rhs) == CONVERT_EXPR - || TREE_CODE (rhs) == NON_LVALUE_EXPR) - { - get_constraint_for (TREE_OPERAND (rhs, 0), &rhsc); - } - else if (CONSTANT_CLASS_P (rhs)) - return; - else - { - get_constraint_for (rhs, &rhsc); - } - for (i = 0; VEC_iterate (ce_s, rhsc, i, c); i++) - make_constraint_to_escaped (*c); - VEC_free (ce_s, heap, rhsc); -} - /* Create points-to sets for the current function. See the comments at the start of the file for an algorithmic overview. */ @@ -4373,7 +4274,7 @@ compute_points_to_sets (struct alias_info *ai) /* Now walk all statements and derive aliases. */ FOR_EACH_BB (bb) { - block_stmt_iterator bsi; + block_stmt_iterator bsi; tree phi; for (phi = phi_nodes (bb); phi; phi = TREE_CHAIN (phi)) @@ -4394,7 +4295,6 @@ compute_points_to_sets (struct alias_info *ai) tree stmt = bsi_stmt (bsi); find_func_aliases (stmt); - find_escape_constraints (stmt); /* Update various related attributes like escaped addresses, pointer dereferences for loads and stores. This is used when creating name tags and alias @@ -4410,23 +4310,25 @@ compute_points_to_sets (struct alias_info *ai) fprintf (dump_file, "Points-to analysis\n\nConstraints:\n\n"); dump_constraints (dump_file); } - + if (dump_file) fprintf (dump_file, "\nCollapsing static cycles and doing variable " "substitution:\n"); - + find_and_collapse_graph_cycles (graph, false); perform_var_substitution (graph); - + if (dump_file) fprintf (dump_file, "\nSolving graph:\n"); - + solve_graph (graph); - + + used_smt_calculated = false; + if (dump_file) dump_sa_points_to_info (dump_file); - + have_alias_info = true; timevar_pop (TV_TREE_PTA); @@ -4440,27 +4342,22 @@ delete_points_to_sets (void) { varinfo_t v; int i; - + htab_delete (id_for_tree); bitmap_obstack_release (&ptabitmap_obstack); bitmap_obstack_release (&predbitmap_obstack); VEC_free (constraint_t, heap, constraints); - + for (i = 0; VEC_iterate (varinfo_t, varmap, i, v); i++) - { - /* Nonlocal vars may add more varinfos. */ - if (i >= graph_size) - break; + VEC_free (constraint_t, heap, v->complex); - VEC_free (constraint_t, heap, v->complex); - } free (graph->preds); free (graph->succs); free (graph); VEC_free (varinfo_t, heap, varmap); free_alloc_pool (variable_info_pool); - free_alloc_pool (constraint_pool); + free_alloc_pool (constraint_pool); have_alias_info = false; } @@ -4469,7 +4366,7 @@ static bool gate_ipa_pta (void) { return (flag_unit_at_a_time != 0 - && flag_ipa_pta + && flag_ipa_pta /* Don't bother doing anything if the program has errors. */ && !(errorcount || sorrycount)); } @@ -4482,20 +4379,20 @@ ipa_pta_execute (void) in_ipa_mode = 1; init_alias_heapvars (); init_alias_vars (); - + for (node = cgraph_nodes; node; node = node->next) { if (!node->analyzed || cgraph_is_master_clone (node)) { unsigned int varid; - - varid = create_function_info_for (node->decl, + + varid = create_function_info_for (node->decl, cgraph_node_name (node)); if (node->local.externally_visible) { varinfo_t fi = get_varinfo (varid); for (; fi; fi = fi->next) - make_constraint_from_escaped (fi); + make_constraint_from_anything (fi); } } } @@ -4507,17 +4404,17 @@ ipa_pta_execute (void) basic_block bb; tree old_func_decl = current_function_decl; if (dump_file) - fprintf (dump_file, - "Generating constraints for %s\n", - cgraph_node_name (node)); + fprintf (dump_file, + "Generating constraints for %s\n", + cgraph_node_name (node)); push_cfun (cfun); current_function_decl = node->decl; FOR_EACH_BB_FN (bb, cfun) { - block_stmt_iterator bsi; + block_stmt_iterator bsi; tree phi; - + for (phi = phi_nodes (bb); phi; phi = TREE_CHAIN (phi)) { if (is_gimple_reg (PHI_RESULT (phi))) @@ -4525,15 +4422,15 @@ ipa_pta_execute (void) find_func_aliases (phi); } } - + for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi)) { tree stmt = bsi_stmt (bsi); find_func_aliases (stmt); } - } + } current_function_decl = old_func_decl; - pop_cfun (); + pop_cfun (); } else { @@ -4548,28 +4445,30 @@ ipa_pta_execute (void) fprintf (dump_file, "Points-to analysis\n\nConstraints:\n\n"); dump_constraints (dump_file); } - + if (dump_file) - fprintf (dump_file, + fprintf (dump_file, "\nCollapsing static cycles and doing variable " "substitution:\n"); - + find_and_collapse_graph_cycles (graph, false); perform_var_substitution (graph); - + if (dump_file) fprintf (dump_file, "\nSolving graph:\n"); - + solve_graph (graph); - + set_used_smts (); + if (dump_file) dump_sa_points_to_info (dump_file); + in_ipa_mode = 0; delete_alias_heapvars (); delete_points_to_sets (); return 0; } - + struct tree_opt_pass pass_ipa_pta = { "pta", /* name */ @@ -4593,15 +4492,13 @@ init_alias_heapvars (void) { heapvar_for_stmt = htab_create_ggc (11, tree_map_hash, tree_map_eq, NULL); - cfun->gimple_df->nonlocal_all = NULL_TREE; } void delete_alias_heapvars (void) { - cfun->gimple_df->nonlocal_all = NULL_TREE; htab_delete (heapvar_for_stmt); } - + #include "gt-tree-ssa-structalias.h" diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index 4914510..4704271 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -488,131 +488,6 @@ err: internal_error ("verify_flow_sensitive_alias_info failed"); } -DEF_VEC_P (bitmap); -DEF_VEC_ALLOC_P (bitmap,heap); - -/* Verify that all name tags have different points to sets. - This algorithm takes advantage of the fact that every variable with the - same name tag must have the same points-to set. - So we check a single variable for each name tag, and verify that its - points-to set is different from every other points-to set for other name - tags. - - Additionally, given a pointer P_i with name tag NMT and symbol tag - SMT, this function verified the alias set of SMT is a superset of - the alias set of NMT. */ - -static void -verify_name_tags (void) -{ - size_t i; - size_t j; - bitmap first, second; - VEC(tree,heap) *name_tag_reps = NULL; - VEC(bitmap,heap) *pt_vars_for_reps = NULL; - bitmap type_aliases = BITMAP_ALLOC (NULL); - - /* First we compute the name tag representatives and their points-to sets. */ - for (i = 0; i < num_ssa_names; i++) - { - struct ptr_info_def *pi; - tree smt, ptr = ssa_name (i); - - if (ptr == NULL_TREE) - continue; - - pi = SSA_NAME_PTR_INFO (ptr); - - if (!TREE_VISITED (ptr) - || !POINTER_TYPE_P (TREE_TYPE (ptr)) - || !pi - || !pi->name_mem_tag - || TREE_VISITED (pi->name_mem_tag)) - continue; - - TREE_VISITED (pi->name_mem_tag) = 1; - - if (pi->pt_vars == NULL) - continue; - - VEC_safe_push (tree, heap, name_tag_reps, ptr); - VEC_safe_push (bitmap, heap, pt_vars_for_reps, pi->pt_vars); - - /* Verify that alias set of PTR's symbol tag is a superset of the - alias set of PTR's name tag. */ - smt = var_ann (SSA_NAME_VAR (ptr))->symbol_mem_tag; - if (smt) - { - size_t i; - VEC(tree,gc) *aliases = var_ann (smt)->may_aliases; - tree alias; - - bitmap_clear (type_aliases); - for (i = 0; VEC_iterate (tree, aliases, i, alias); i++) - bitmap_set_bit (type_aliases, DECL_UID (alias)); - - /* When grouping, we may have added PTR's symbol tag into the - alias set of PTR's name tag. To prevent a false - positive, pretend that SMT is in its own alias set. */ - bitmap_set_bit (type_aliases, DECL_UID (smt)); - - if (bitmap_equal_p (type_aliases, pi->pt_vars)) - continue; - - if (!bitmap_intersect_compl_p (type_aliases, pi->pt_vars)) - { - error ("alias set of a pointer's symbol tag should be a superset of the corresponding name tag"); - debug_variable (smt); - debug_variable (pi->name_mem_tag); - goto err; - } - } - } - - /* Now compare all the representative bitmaps with all other representative - bitmaps, to verify that they are all different. */ - for (i = 0; VEC_iterate (bitmap, pt_vars_for_reps, i, first); i++) - { - for (j = i + 1; VEC_iterate (bitmap, pt_vars_for_reps, j, second); j++) - { - if (bitmap_equal_p (first, second)) - { - error ("two different pointers with identical points-to sets but different name tags"); - debug_variable (VEC_index (tree, name_tag_reps, j)); - goto err; - } - } - } - - /* Lastly, clear out the visited flags. */ - for (i = 0; i < num_ssa_names; i++) - { - if (ssa_name (i)) - { - tree ptr = ssa_name (i); - struct ptr_info_def *pi = SSA_NAME_PTR_INFO (ptr); - if (!TREE_VISITED (ptr) - || !POINTER_TYPE_P (TREE_TYPE (ptr)) - || !pi - || !pi->name_mem_tag) - continue; - TREE_VISITED (pi->name_mem_tag) = 0; - } - } - - /* We do not have to free the bitmaps or trees in the vectors, as - they are not owned by us. */ - VEC_free (bitmap, heap, pt_vars_for_reps); - VEC_free (tree, heap, name_tag_reps); - BITMAP_FREE (type_aliases); - return; - -err: - debug_variable (VEC_index (tree, name_tag_reps, i)); - internal_error ("verify_name_tags failed"); -} - - /* Verify the consistency of call clobbering information. */ static void verify_call_clobbering (void) @@ -659,7 +534,6 @@ static void verify_alias_info (void) { verify_flow_sensitive_alias_info (); - verify_name_tags (); verify_call_clobbering (); verify_flow_insensitive_alias_info (); } |