Commit 64afff5b by Martin Liska Committed by Martin Liska

Change use to type-based pool allocator in et-forest.c.

	* et-forest.c (et_new_occ): Use new type-based pool allocator.
	(et_new_tree): Likewise.
	(et_free_tree): Likewise.
	(et_free_tree_force): Likewise.
	(et_free_pools): Likewise.
	(et_split): Likewise.

From-SVN: r223943
parent 7d50111b
2015-06-01 Martin Liska <mliska@suse.cz> 2015-06-01 Martin Liska <mliska@suse.cz>
* et-forest.c (et_new_occ): Use new type-based pool allocator.
(et_new_tree): Likewise.
(et_free_tree): Likewise.
(et_free_tree_force): Likewise.
(et_free_pools): Likewise.
(et_split): Likewise.
2015-06-01 Martin Liska <mliska@suse.cz>
* alloc-pool.c (struct alloc_pool_descriptor): Move definition * alloc-pool.c (struct alloc_pool_descriptor): Move definition
to header file. to header file.
* alloc-pool.h (pool_allocator::pool_allocator): New function. * alloc-pool.h (pool_allocator::pool_allocator): New function.
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "cfganal.h" #include "cfganal.h"
#include "basic-block.h" #include "basic-block.h"
#include "diagnostic-core.h" #include "diagnostic-core.h"
#include "alloc-pool.h"
#include "et-forest.h" #include "et-forest.h"
#include "timevar.h" #include "timevar.h"
#include "hash-map.h" #include "hash-map.h"
......
...@@ -25,8 +25,8 @@ License along with libiberty; see the file COPYING3. If not see ...@@ -25,8 +25,8 @@ License along with libiberty; see the file COPYING3. If not see
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "coretypes.h" #include "coretypes.h"
#include "et-forest.h"
#include "alloc-pool.h" #include "alloc-pool.h"
#include "et-forest.h"
/* We do not enable this with ENABLE_CHECKING, since it is awfully slow. */ /* We do not enable this with ENABLE_CHECKING, since it is awfully slow. */
#undef DEBUG_ET #undef DEBUG_ET
...@@ -59,10 +59,26 @@ struct et_occ ...@@ -59,10 +59,26 @@ struct et_occ
on the path to the root. */ on the path to the root. */
struct et_occ *min_occ; /* The occurrence in the subtree with the minimal struct et_occ *min_occ; /* The occurrence in the subtree with the minimal
depth. */ depth. */
/* Pool allocation new operator. */
inline void *operator new (size_t)
{
return pool.allocate ();
}
/* Delete operator utilizing pool allocation. */
inline void operator delete (void *ptr)
{
pool.remove ((et_occ *) ptr);
}
/* Memory allocation pool. */
static pool_allocator<et_occ> pool;
}; };
static alloc_pool et_nodes; pool_allocator<et_node> et_node::pool ("et_nodes pool", 300);
static alloc_pool et_occurrences; pool_allocator<et_occ> et_occ::pool ("et_occ pool", 300);
/* Changes depth of OCC to D. */ /* Changes depth of OCC to D. */
...@@ -449,11 +465,7 @@ et_splay (struct et_occ *occ) ...@@ -449,11 +465,7 @@ et_splay (struct et_occ *occ)
static struct et_occ * static struct et_occ *
et_new_occ (struct et_node *node) et_new_occ (struct et_node *node)
{ {
struct et_occ *nw; et_occ *nw = new et_occ;
if (!et_occurrences)
et_occurrences = create_alloc_pool ("et_occ pool", sizeof (struct et_occ), 300);
nw = (struct et_occ *) pool_alloc (et_occurrences);
nw->of = node; nw->of = node;
nw->parent = NULL; nw->parent = NULL;
...@@ -474,9 +486,7 @@ et_new_tree (void *data) ...@@ -474,9 +486,7 @@ et_new_tree (void *data)
{ {
struct et_node *nw; struct et_node *nw;
if (!et_nodes) nw = new et_node;
et_nodes = create_alloc_pool ("et_node pool", sizeof (struct et_node), 300);
nw = (struct et_node *) pool_alloc (et_nodes);
nw->data = data; nw->data = data;
nw->father = NULL; nw->father = NULL;
...@@ -501,8 +511,8 @@ et_free_tree (struct et_node *t) ...@@ -501,8 +511,8 @@ et_free_tree (struct et_node *t)
if (t->father) if (t->father)
et_split (t); et_split (t);
pool_free (et_occurrences, t->rightmost_occ); delete t->rightmost_occ;
pool_free (et_nodes, t); delete t;
} }
/* Releases et tree T without maintaining other nodes. */ /* Releases et tree T without maintaining other nodes. */
...@@ -510,10 +520,10 @@ et_free_tree (struct et_node *t) ...@@ -510,10 +520,10 @@ et_free_tree (struct et_node *t)
void void
et_free_tree_force (struct et_node *t) et_free_tree_force (struct et_node *t)
{ {
pool_free (et_occurrences, t->rightmost_occ); delete t->rightmost_occ;
if (t->parent_occ) if (t->parent_occ)
pool_free (et_occurrences, t->parent_occ); delete t->parent_occ;
pool_free (et_nodes, t); delete t;
} }
/* Release the alloc pools, if they are empty. */ /* Release the alloc pools, if they are empty. */
...@@ -521,8 +531,8 @@ et_free_tree_force (struct et_node *t) ...@@ -521,8 +531,8 @@ et_free_tree_force (struct et_node *t)
void void
et_free_pools (void) et_free_pools (void)
{ {
free_alloc_pool_if_empty (&et_occurrences); et_occ::pool.release_if_empty ();
free_alloc_pool_if_empty (&et_nodes); et_node::pool.release_if_empty ();
} }
/* Sets father of et tree T to FATHER. */ /* Sets father of et tree T to FATHER. */
...@@ -614,7 +624,7 @@ et_split (struct et_node *t) ...@@ -614,7 +624,7 @@ et_split (struct et_node *t)
rmost->depth = 0; rmost->depth = 0;
rmost->min = 0; rmost->min = 0;
pool_free (et_occurrences, p_occ); delete p_occ;
/* Update the tree. */ /* Update the tree. */
if (father->son == t) if (father->son == t)
......
...@@ -66,6 +66,21 @@ struct et_node ...@@ -66,6 +66,21 @@ struct et_node
struct et_occ *rightmost_occ; /* The rightmost occurrence. */ struct et_occ *rightmost_occ; /* The rightmost occurrence. */
struct et_occ *parent_occ; /* The occurrence of the parent node. */ struct et_occ *parent_occ; /* The occurrence of the parent node. */
/* Pool allocation new operator. */
inline void *operator new (size_t)
{
return pool.allocate ();
}
/* Delete operator utilizing pool allocation. */
inline void operator delete (void *ptr)
{
pool.remove ((et_node *) ptr);
}
/* Memory allocation pool. */
static pool_allocator<et_node> pool;
}; };
struct et_node *et_new_tree (void *data); struct et_node *et_new_tree (void *data);
......
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