From a7d04a5357719127b0ac3b8f139ccabf188f30b4 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Mon, 4 Jan 2010 21:02:42 +0000 Subject: [PATCH] tree-ssa-sccvn.c (get_or_alloc_constant_value_id): Allocate a new entry only if needed. 2010-01-04 Richard Guenther * 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 --- gcc/ChangeLog | 11 +++++++++++ gcc/tree-ssa-coalesce.c | 17 +++++++++-------- gcc/tree-ssa-dom.c | 35 +++++++++++++++-------------------- gcc/tree-ssa-pre.c | 13 ++++++++----- gcc/tree-ssa-sccvn.c | 28 +++++++++++++++------------- 5 files changed, 58 insertions(+), 46 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e622c8f35129..370fb4582694 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2010-01-04 Richard Guenther + + * 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 PR tree-optimization/42398 diff --git a/gcc/tree-ssa-coalesce.c b/gcc/tree-ssa-coalesce.c index 867e15c06e06..b96d0913f075 100644 --- a/gcc/tree-ssa-coalesce.c +++ b/gcc/tree-ssa-coalesce.c @@ -256,7 +256,7 @@ delete_coalesce_list (coalesce_list_p cl) static coalesce_pair_p find_coalesce_pair (coalesce_list_p cl, int p1, int p2, bool create) { - struct coalesce_pair p, *pair; + struct coalesce_pair p; void **slot; unsigned int hash; @@ -272,22 +272,23 @@ find_coalesce_pair (coalesce_list_p cl, int p1, int p2, bool create) p.second_element = p2; } - 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); - pair = XNEW (struct coalesce_pair); pair->first_element = p.first_element; pair->second_element = p.second_element; pair->cost = 0; - slot = htab_find_slot_with_hash (cl->list, pair, hash, INSERT); - *(struct coalesce_pair **)slot = pair; + *slot = (void *)pair; } - return pair; + return (struct coalesce_pair *) *slot; } static inline void diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index 48f423bec611..bbe453963b7c 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -2229,50 +2229,47 @@ lookup_avail_expr (gimple stmt, bool insert) void **slot; tree lhs; 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. */ lhs = gimple_get_lhs (stmt); - initialize_hash_element (stmt, lhs, element); + initialize_hash_element (stmt, lhs, &element); if (dump_file && (dump_flags & TDF_DETAILS)) { 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. Constants and copy operations are handled by the constant/copy propagator in optimize_stmt. */ - if (element->expr.kind == EXPR_SINGLE - && (TREE_CODE (element->expr.ops.single.rhs) == SSA_NAME - || is_gimple_min_invariant (element->expr.ops.single.rhs))) - { - free (element); - return NULL_TREE; - } + if (element.expr.kind == EXPR_SINGLE + && (TREE_CODE (element.expr.ops.single.rhs) == SSA_NAME + || is_gimple_min_invariant (element.expr.ops.single.rhs))) + return NULL_TREE; /* 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)); if (slot == NULL) - { - free (element); - return NULL_TREE; - } + return NULL_TREE; 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)) { 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; } @@ -2289,8 +2286,6 @@ lookup_avail_expr (gimple stmt, bool insert) lhs = temp; } - free (element); - if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, "FIND: "); diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index 3087fe38ae9e..82964428fbbe 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -684,7 +684,10 @@ sorted_array_from_bitmap_set (bitmap_set_t set) { unsigned int i, j; 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) { @@ -1446,6 +1449,10 @@ phi_translate (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2, if (!expr) 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))) return expr; @@ -1455,10 +1462,6 @@ phi_translate (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2, switch (expr->kind) { - /* Constants contain no values that need translation. */ - case CONSTANT: - return expr; - case NARY: { unsigned int i; diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 2994bffd76ef..79ce3c20a25a 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -357,21 +357,23 @@ unsigned int get_or_alloc_constant_value_id (tree constant) { 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->constant = constant; - slot = htab_find_slot_with_hash (constant_to_value_id, vc, - vc->hashcode, INSERT); + vc.hashcode = vn_hash_constant_with_type (constant); + vc.constant = constant; + slot = htab_find_slot_with_hash (constant_to_value_id, &vc, + vc.hashcode, INSERT); if (*slot) - { - free (vc); - return ((vn_constant_t)*slot)->value_id; - } - vc->value_id = get_next_value_id (); - *slot = vc; - bitmap_set_bit (constant_value_ids, vc->value_id); - return vc->value_id; + return ((vn_constant_t)*slot)->value_id; + + vcp = XNEW (struct vn_constant_s); + vcp->hashcode = vc.hashcode; + vcp->constant = constant; + vcp->value_id = get_next_value_id (); + *slot = (void *) vcp; + bitmap_set_bit (constant_value_ids, vcp->value_id); + return vcp->value_id; } /* Return true if V is a value id for a constant. */