From ef14133086146c8a5454f193630b570ffc269776 Mon Sep 17 00:00:00 2001 From: Sebastian Hack Date: Thu, 4 May 2006 16:14:51 +0000 Subject: [PATCH] node data constructors can allocate the memory by themselves now. [r7693] --- ir/ir/irphase.c | 5 ++--- ir/ir/irphase_t.h | 13 +++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/ir/ir/irphase.c b/ir/ir/irphase.c index 28f5ac378..44e1841ff 100644 --- a/ir/ir/irphase.c +++ b/ir/ir/irphase.c @@ -18,16 +18,16 @@ #include "irnode_t.h" #include "irphase_t.h" -phase_t *phase_init(phase_t *ph, const char *name, ir_graph *irg, size_t data_size, unsigned growth_factor, phase_irn_data_init_t *data_init) +phase_t *phase_init(phase_t *ph, const char *name, ir_graph *irg, unsigned growth_factor, phase_irn_data_init_t *data_init) { assert(growth_factor >= 1.0 && "growth factor must greater or equal to 1.0"); + assert(data_init && "You must provide a data constructor"); obstack_init(&ph->obst); ph->name = name; ph->growth_factor = growth_factor; ph->data_init = data_init; - ph->data_size = data_size; ph->irg = irg; ph->n_data_ptr = 0; ph->data_ptr = NULL; @@ -52,7 +52,6 @@ phase_stat_t *phase_stat(const phase_t *phase, phase_stat_t *stat) for(i = 0, n = phase->n_data_ptr; i < n; ++i) { if(phase->data_ptr[i] != NULL) { stat->node_slots_used++; - stat->node_data_bytes += phase->data_size; } } stat->overall_bytes = stat->node_map_bytes + obstack_memory_used(&((phase_t *)phase)->obst); diff --git a/ir/ir/irphase_t.h b/ir/ir/irphase_t.h index 801f8bf80..967608c8b 100644 --- a/ir/ir/irphase_t.h +++ b/ir/ir/irphase_t.h @@ -32,7 +32,7 @@ typedef struct { */ phase_stat_t *phase_stat(const phase_t *phase, phase_stat_t *stat); -typedef void (phase_irn_data_init_t)(phase_t *phase, ir_node *irn, void *data); +typedef void *(phase_irn_data_init_t)(phase_t *phase, ir_node *irn, void *old); /** * The default grow factor. @@ -49,7 +49,6 @@ struct _phase_t { ir_graph *irg; /**< The irg this phase will we applied to. */ unsigned growth_factor; /**< factor to leave room for add. nodes. 256 means 1.0. */ void *priv; /**< Some pointer private to the user of the phase. */ - size_t data_size; /**< The amount of bytes which shall be allocated for each irn. */ size_t n_data_ptr; /**< The length of the data_ptr array. */ void **data_ptr; /**< Map node indexes to irn data on the obstack. */ phase_irn_data_init_t *data_init; /**< A callback that is called to initialize newly created node data. */ @@ -59,14 +58,13 @@ struct _phase_t { * Initialize a phase object. * @param name The name of the phase. * @param irg The graph the phase will run on. - * @param data_size The amount of extra storage in bytes that should be allocated for each node. * @param growth_factor A factor denoting how many node slots will be additionally allocated, * if the node => data is full. 256 means 1.0. * @param irn_data_init A callback that is called to initialize newly created node data. * @param priv Some private pointer which is kept in the phase and can be retrieved with phase_get_private(). * @return A new phase object. */ -phase_t *phase_init(phase_t *ph, const char *name, ir_graph *irg, size_t data_size, unsigned growth_factor, phase_irn_data_init_t *data_init); +phase_t *phase_init(phase_t *ph, const char *name, ir_graph *irg, unsigned growth_factor, phase_irn_data_init_t *data_init); /** * Free the phase and all node data associated with it. @@ -166,11 +164,10 @@ static INLINE void *_phase_get_or_set_irn_data(phase_t *ph, ir_node *irn) /* If there has no irn data allocated yet, do that now. */ if(!res) { phase_irn_data_init_t *data_init = ph->data_init; - ph->data_ptr[idx] = res = phase_alloc(ph, ph->data_size); - /* Call the irn data callback, if there is one. */ - if(data_init) - data_init(ph, irn, res); + /* call the node data structure allocator/constructor. */ + res = ph->data_ptr[idx] = data_init(ph, irn, NULL); + } return res; } -- 2.20.1