2012-08-19  Dimitrios Apostolou  <ji...@gmx.net>

        * gcc/tree-ssa-pre.c (phi_translate_pool): New static global
        alloc_pool, used for allocating struct expr_pred_trans_d for
        phi_translate_table.
        (phi_trans_add, init_pre, fini_pre): Use it, avoids thousand of
        malloc() and free() calls.


This avoids lots of malloc/free calls and slow iterations during numerous htab_delete() in fini_pre(). Tested on pre C++-snapshot, will update info as soon as a post C++ one is available.


Thanks,
Dimitris
2012-08-19  Dimitrios Apostolou  <ji...@gmx.net>

        * gcc/tree-ssa-pre.c (phi_translate_pool): New static global
        alloc_pool, used for allocating struct expr_pred_trans_d for
        phi_translate_table.
        (phi_trans_add, init_pre, fini_pre): Use it, avoids thousand of
        malloc() and free() calls.

=== modified file 'gcc/tree-ssa-pre.c'
--- gcc/tree-ssa-pre.c  2012-08-17 08:03:54 +0000
+++ gcc/tree-ssa-pre.c  2012-08-18 16:43:02 +0000
@@ -486,7 +486,7 @@ static bitmap need_ab_cleanup;
 /* A three tuple {e, pred, v} used to cache phi translations in the
    phi_translate_table.  */
 
-typedef struct expr_pred_trans_d : typed_free_remove<expr_pred_trans_d>
+typedef struct expr_pred_trans_d : typed_noop_remove<expr_pred_trans_d>
 {
   /* The expression.  */
   pre_expr e;
@@ -508,6 +508,12 @@ typedef struct expr_pred_trans_d : typed
 } *expr_pred_trans_t;
 typedef const struct expr_pred_trans_d *const_expr_pred_trans_t;
 
+/* Pool of memory for the above */
+
+static alloc_pool phi_translate_pool;
+
+/* Return the hash value for a phi translation table entry.  */
+
 inline hashval_t
 expr_pred_trans_d::hash (const expr_pred_trans_d *e)
 {
@@ -561,7 +567,8 @@ static inline void
 phi_trans_add (pre_expr e, pre_expr v, basic_block pred)
 {
   expr_pred_trans_t *slot;
-  expr_pred_trans_t new_pair = XNEW (struct expr_pred_trans_d);
+  expr_pred_trans_t new_pair =
+    (expr_pred_trans_t) pool_alloc (phi_translate_pool);
   new_pair->e = e;
   new_pair->pred = pred;
   new_pair->v = v;
@@ -570,7 +577,8 @@ phi_trans_add (pre_expr e, pre_expr v, b
 
   slot = phi_translate_table.find_slot_with_hash (new_pair,
                                   new_pair->hashcode, INSERT);
-  free (*slot);
+  if (*slot)
+    pool_free (phi_translate_pool, *slot);
   *slot = new_pair;
 }
 
@@ -4798,6 +4806,9 @@ init_pre (bool do_fre)
   calculate_dominance_info (CDI_DOMINATORS);
 
   bitmap_obstack_initialize (&grand_bitmap_obstack);
+  phi_translate_pool = create_alloc_pool ("phi_translate_table",
+                                         sizeof (struct expr_pred_trans_d),
+                                         512);
   phi_translate_table.create (5110);
   expression_to_id.create (num_ssa_names * 3);
   bitmap_set_pool = create_alloc_pool ("Bitmap sets",
@@ -4832,6 +4843,7 @@ fini_pre (bool do_fre)
   free_alloc_pool (bitmap_set_pool);
   free_alloc_pool (pre_expr_pool);
   phi_translate_table.dispose ();
+  free_alloc_pool (phi_translate_pool);
   expression_to_id.dispose ();
   VEC_free (unsigned, heap, name_to_id);
 

Reply via email to