+2005-11-08 Daniel Berlin <dberlin@dberlin.org>
+
+ Fix PR tree-optimization/23382
+
+ * tree-ssa-alias.c (compute_may_aliases): Call
+ delete_old_heap_vars.
+ * tree-dfa.c (referenced_var_remove): New function.
+ * tree-ssa.c (delete_tree_ssa): Call delete_old_heap_vars.
+ * tree-flow.h (referenced_var_remove): Add prototype.
+ (delete_old_heap_vars): Ditto.
+ * tree-ssa-structalias.c (heapvars): New variable.
+ (oldheapvars): Ditto.
+ (get_constraint_for): Put heap vars on heapvars list.
+ (delete_old_heap_vars): New function.
+
2005-11-08 Jason Merrill <jason@redhat.com>
* tree.h (CALL_FROM_THUNK_P): Add CALL_EXPR_CHECK.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-alias-vops" } */
+struct a
+{
+ int length;
+ int a1[256];
+};
+
+void *malloc(long size) __attribute__((malloc));
+
+void f(void)
+{
+ struct a *a = malloc(sizeof(struct a));
+}
+/* { dg-final { scan-tree-dump-times "V_MAY_DEF <HEAP" 1 "alias1"} } */
+/* { dg-final { scan-tree-dump-times "V_MAY_DEF <HEAP" 1 "alias2"} } */
+/* { dg-final { scan-tree-dump-times "V_MAY_DEF <HEAP" 1 "alias3"} } */
+/* { dg-final { scan-tree-dump-times "V_MAY_DEF <HEAP" 1 "alias4"} } */
+/* { dg-final { scan-tree-dump-times "V_MAY_DEF <HEAP" 1 "alias5"} } */
+/* { dg-final { cleanup-tree-dump "alias1" } } */
+/* { dg-final { cleanup-tree-dump "alias2" } } */
+/* { dg-final { cleanup-tree-dump "alias3" } } */
+/* { dg-final { cleanup-tree-dump "alias4" } } */
+/* { dg-final { cleanup-tree-dump "alias5" } } */
*(struct int_tree_map **) loc = h;
}
+/* Remove the pair DECL_UID (TO), TO from the referenced vars
+ hashtable. */
+
+void
+referenced_var_remove (tree to)
+{
+ struct int_tree_map in;
+ in.uid = DECL_UID (to);
+ in.to = to;
+ htab_remove_elt_with_hash (referenced_vars, &in, in.uid);
+}
+
/* Add VAR to the list of dereferenced variables.
WALK_STATE contains a hash table used to avoid adding the same
extern tree referenced_var_lookup (unsigned int);
extern tree referenced_var_lookup_if_exists (unsigned int);
+extern void referenced_var_remove (tree);
#define num_referenced_vars htab_elements (referenced_vars)
#define referenced_var(i) referenced_var_lookup (i)
HOST_WIDE_INT, bool *);
void sort_fieldstack (VEC(fieldoff_s,heap) *);
+void delete_old_heap_vars (void);
#include "tree-flow-inline.h"
#endif /* _TREE_FLOW_H */
memset (&alias_stats, 0, sizeof (alias_stats));
+ delete_old_heap_vars ();
+
/* Initialize aliasing information. */
ai = init_alias_info ();
TODO: We could handle unions, but to be honest, it's probably not
worth the pain or slowdown. */
+static VEC(tree, heap) *heapvars = NULL;
+static VEC(tree, heap) *oldheapvars = NULL;
+
static bool use_field_sensitive = true;
static unsigned int create_variable_info_for (tree, const char *);
static struct constraint_expr get_constraint_for (tree, bool *);
tree heapvar;
heapvar = create_tmp_var_raw (ptr_type_node, "HEAP");
+ VEC_safe_push (tree, heap, heapvars, heapvar);
DECL_EXTERNAL (heapvar) = 1;
add_referenced_tmp_var (heapvar);
temp.var = create_variable_info_for (heapvar,
have_alias_info = false;
}
+
+/* Delete old heap vars, since nothing else will remove them for
+ us. */
+void
+delete_old_heap_vars (void)
+{
+ if (!in_ssa_p)
+ {
+ VEC_free (tree, heap, heapvars);
+ VEC_free (tree, heap, oldheapvars);
+ heapvars = NULL;
+ oldheapvars = NULL;
+ }
+ /* Why is this complicated?
+ We can't remove the heapvars from the referenced var array until
+ they go away from the ssa form, and we can't remove them from the
+ ssa form until we've renamed it. We can't renamed it if it's not
+ in the referenced vars array.
+ Thus, we have to first mark it for renaming, and then the *next*
+ time after that we call this function, we can remove it from
+ referenced vars. */
+
+ if (!VEC_empty (tree, heapvars))
+ {
+ int i;
+ tree heapvar;
+ for (i = 0; VEC_iterate (tree, heapvars, i, heapvar); i++)
+ {
+ if (in_ssa_p)
+ mark_sym_for_renaming (heapvar);
+ DECL_EXTERNAL (heapvar) = false;
+ bitmap_clear_bit (call_clobbered_vars, DECL_UID (heapvar));
+ }
+ if (!VEC_empty (tree, oldheapvars))
+ {
+ for (i = 0; VEC_iterate (tree, oldheapvars, i, heapvar); i++)
+ referenced_var_remove (heapvar);
+ }
+ VEC_free (tree, heap, oldheapvars);
+ oldheapvars = heapvars;
+ heapvars = NULL;
+ }
+}
set_phi_nodes (bb, NULL);
}
+ delete_old_heap_vars ();
/* Remove annotations from every referenced variable. */
FOR_EACH_REFERENCED_VAR (var, rvi)
{