Commit a7d04a53 by Richard Guenther Committed by Richard Biener

tree-ssa-sccvn.c (get_or_alloc_constant_value_id): Allocate a new entry only if needed.

2010-01-04  Richard Guenther  <rguenther@suse.de>

	* tree-ssa-sccvn.c (get_or_alloc_constant_value_id): Allocate
	a new entry only if needed.
	* tree-ssa-dom.c (lookup_avail_expr): Likewise.
	* tree-ssa-coalesce.c (find_coalesce_pair): Avoid one
	hashtable lookup.
	* tree-ssa-pre.c (sorted_array_from_bitmap_set): Pre-allocate
	the result array.
	(phi_translate): Handle CONSTANTs early.

From-SVN: r155633
parent d6de356a
2010-01-04 Richard Guenther <rguenther@suse.de>
* tree-ssa-sccvn.c (get_or_alloc_constant_value_id): Allocate
a new entry only if needed.
* tree-ssa-dom.c (lookup_avail_expr): Likewise.
* tree-ssa-coalesce.c (find_coalesce_pair): Avoid one
hashtable lookup.
* tree-ssa-pre.c (sorted_array_from_bitmap_set): Pre-allocate
the result array.
(phi_translate): Handle CONSTANTs early.
2010-01-04 Martin Jambor <mjambor@suse.cz> 2010-01-04 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/42398 PR tree-optimization/42398
......
...@@ -256,7 +256,7 @@ delete_coalesce_list (coalesce_list_p cl) ...@@ -256,7 +256,7 @@ delete_coalesce_list (coalesce_list_p cl)
static coalesce_pair_p static coalesce_pair_p
find_coalesce_pair (coalesce_list_p cl, int p1, int p2, bool create) find_coalesce_pair (coalesce_list_p cl, int p1, int p2, bool create)
{ {
struct coalesce_pair p, *pair; struct coalesce_pair p;
void **slot; void **slot;
unsigned int hash; unsigned int hash;
...@@ -272,22 +272,23 @@ find_coalesce_pair (coalesce_list_p cl, int p1, int p2, bool create) ...@@ -272,22 +272,23 @@ find_coalesce_pair (coalesce_list_p cl, int p1, int p2, bool create)
p.second_element = p2; p.second_element = p2;
} }
hash = coalesce_pair_map_hash (&p); hash = coalesce_pair_map_hash (&p);
pair = (struct coalesce_pair *) htab_find_with_hash (cl->list, &p, hash); slot = htab_find_slot_with_hash (cl->list, &p, hash,
create ? INSERT : NO_INSERT);
if (!slot)
return NULL;
if (create && !pair) if (!*slot)
{ {
struct coalesce_pair * pair = XNEW (struct coalesce_pair);
gcc_assert (cl->sorted == NULL); gcc_assert (cl->sorted == NULL);
pair = XNEW (struct coalesce_pair);
pair->first_element = p.first_element; pair->first_element = p.first_element;
pair->second_element = p.second_element; pair->second_element = p.second_element;
pair->cost = 0; pair->cost = 0;
slot = htab_find_slot_with_hash (cl->list, pair, hash, INSERT); *slot = (void *)pair;
*(struct coalesce_pair **)slot = pair;
} }
return pair; return (struct coalesce_pair *) *slot;
} }
static inline void static inline void
......
...@@ -2229,50 +2229,47 @@ lookup_avail_expr (gimple stmt, bool insert) ...@@ -2229,50 +2229,47 @@ lookup_avail_expr (gimple stmt, bool insert)
void **slot; void **slot;
tree lhs; tree lhs;
tree temp; tree temp;
struct expr_hash_elt *element = XNEW (struct expr_hash_elt); struct expr_hash_elt element;
/* Get LHS of assignment or call, else NULL_TREE. */ /* Get LHS of assignment or call, else NULL_TREE. */
lhs = gimple_get_lhs (stmt); lhs = gimple_get_lhs (stmt);
initialize_hash_element (stmt, lhs, element); initialize_hash_element (stmt, lhs, &element);
if (dump_file && (dump_flags & TDF_DETAILS)) if (dump_file && (dump_flags & TDF_DETAILS))
{ {
fprintf (dump_file, "LKUP "); fprintf (dump_file, "LKUP ");
print_expr_hash_elt (dump_file, element); print_expr_hash_elt (dump_file, &element);
} }
/* Don't bother remembering constant assignments and copy operations. /* Don't bother remembering constant assignments and copy operations.
Constants and copy operations are handled by the constant/copy propagator Constants and copy operations are handled by the constant/copy propagator
in optimize_stmt. */ in optimize_stmt. */
if (element->expr.kind == EXPR_SINGLE if (element.expr.kind == EXPR_SINGLE
&& (TREE_CODE (element->expr.ops.single.rhs) == SSA_NAME && (TREE_CODE (element.expr.ops.single.rhs) == SSA_NAME
|| is_gimple_min_invariant (element->expr.ops.single.rhs))) || is_gimple_min_invariant (element.expr.ops.single.rhs)))
{ return NULL_TREE;
free (element);
return NULL_TREE;
}
/* Finally try to find the expression in the main expression hash table. */ /* Finally try to find the expression in the main expression hash table. */
slot = htab_find_slot_with_hash (avail_exprs, element, element->hash, slot = htab_find_slot_with_hash (avail_exprs, &element, element.hash,
(insert ? INSERT : NO_INSERT)); (insert ? INSERT : NO_INSERT));
if (slot == NULL) if (slot == NULL)
{ return NULL_TREE;
free (element);
return NULL_TREE;
}
if (*slot == NULL) if (*slot == NULL)
{ {
*slot = (void *) element; struct expr_hash_elt *element2 = XNEW (struct expr_hash_elt);
*element2 = element;
element2->stamp = element2;
*slot = (void *) element2;
if (dump_file && (dump_flags & TDF_DETAILS)) if (dump_file && (dump_flags & TDF_DETAILS))
{ {
fprintf (dump_file, "2>>> "); fprintf (dump_file, "2>>> ");
print_expr_hash_elt (dump_file, element); print_expr_hash_elt (dump_file, element2);
} }
VEC_safe_push (expr_hash_elt_t, heap, avail_exprs_stack, element); VEC_safe_push (expr_hash_elt_t, heap, avail_exprs_stack, element2);
return NULL_TREE; return NULL_TREE;
} }
...@@ -2289,8 +2286,6 @@ lookup_avail_expr (gimple stmt, bool insert) ...@@ -2289,8 +2286,6 @@ lookup_avail_expr (gimple stmt, bool insert)
lhs = temp; lhs = temp;
} }
free (element);
if (dump_file && (dump_flags & TDF_DETAILS)) if (dump_file && (dump_flags & TDF_DETAILS))
{ {
fprintf (dump_file, "FIND: "); fprintf (dump_file, "FIND: ");
......
...@@ -684,7 +684,10 @@ sorted_array_from_bitmap_set (bitmap_set_t set) ...@@ -684,7 +684,10 @@ sorted_array_from_bitmap_set (bitmap_set_t set)
{ {
unsigned int i, j; unsigned int i, j;
bitmap_iterator bi, bj; bitmap_iterator bi, bj;
VEC(pre_expr, heap) *result = NULL; VEC(pre_expr, heap) *result;
/* Pre-allocate roughly enough space for the array. */
result = VEC_alloc (pre_expr, heap, bitmap_count_bits (set->values));
FOR_EACH_VALUE_ID_IN_SET (set, i, bi) FOR_EACH_VALUE_ID_IN_SET (set, i, bi)
{ {
...@@ -1446,6 +1449,10 @@ phi_translate (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2, ...@@ -1446,6 +1449,10 @@ phi_translate (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2,
if (!expr) if (!expr)
return NULL; return NULL;
/* Constants contain no values that need translation. */
if (expr->kind == CONSTANT)
return expr;
if (value_id_constant_p (get_expr_value_id (expr))) if (value_id_constant_p (get_expr_value_id (expr)))
return expr; return expr;
...@@ -1455,10 +1462,6 @@ phi_translate (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2, ...@@ -1455,10 +1462,6 @@ phi_translate (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2,
switch (expr->kind) switch (expr->kind)
{ {
/* Constants contain no values that need translation. */
case CONSTANT:
return expr;
case NARY: case NARY:
{ {
unsigned int i; unsigned int i;
......
...@@ -357,21 +357,23 @@ unsigned int ...@@ -357,21 +357,23 @@ unsigned int
get_or_alloc_constant_value_id (tree constant) get_or_alloc_constant_value_id (tree constant)
{ {
void **slot; void **slot;
vn_constant_t vc = XNEW (struct vn_constant_s); struct vn_constant_s vc;
vn_constant_t vcp;
vc->hashcode = vn_hash_constant_with_type (constant); vc.hashcode = vn_hash_constant_with_type (constant);
vc->constant = constant; vc.constant = constant;
slot = htab_find_slot_with_hash (constant_to_value_id, vc, slot = htab_find_slot_with_hash (constant_to_value_id, &vc,
vc->hashcode, INSERT); vc.hashcode, INSERT);
if (*slot) if (*slot)
{ return ((vn_constant_t)*slot)->value_id;
free (vc);
return ((vn_constant_t)*slot)->value_id; vcp = XNEW (struct vn_constant_s);
} vcp->hashcode = vc.hashcode;
vc->value_id = get_next_value_id (); vcp->constant = constant;
*slot = vc; vcp->value_id = get_next_value_id ();
bitmap_set_bit (constant_value_ids, vc->value_id); *slot = (void *) vcp;
return vc->value_id; bitmap_set_bit (constant_value_ids, vcp->value_id);
return vcp->value_id;
} }
/* Return true if V is a value id for a constant. */ /* Return true if V is a value id for a constant. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment