From: Sebastian Hack Date: Wed, 10 May 2006 16:34:43 +0000 (+0000) Subject: Added index -> node map to irgs X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=6708a4bc2bbc035dcc84752a1e34c2edeef07c2d;p=libfirm Added index -> node map to irgs [r7719] --- diff --git a/ir/ir/irgraph.c b/ir/ir/irgraph.c index f9454a1e8..810007bcb 100644 --- a/ir/ir/irgraph.c +++ b/ir/ir/irgraph.c @@ -37,6 +37,8 @@ #include "iredges_t.h" #include "type_t.h" +#define INITIAL_IDX_IRN_MAP_SIZE 1024 + /** * Indicates, whether additional data can be registered to graphs. * If set to 1, this is not possible anymore. @@ -138,6 +140,10 @@ new_r_ir_graph (entity *ent, int n_loc) edges_init_graph(res); + /* initialize the idx->node map. */ + res->idx_irn_map = NEW_ARR_F(ir_node *, INITIAL_IDX_IRN_MAP_SIZE); + memset(res->idx_irn_map, 0, INITIAL_IDX_IRN_MAP_SIZE * sizeof(res->idx_irn_map[0])); + /* inform statistics here, as blocks will be already build on this graph */ hook_new_graph(res, ent); @@ -267,6 +273,10 @@ ir_graph *new_const_code_irg(void) { res = alloc_graph(); + /* initialize the idx->node map. */ + res->idx_irn_map = NEW_ARR_F(ir_node *, INITIAL_IDX_IRN_MAP_SIZE); + memset(res->idx_irn_map, 0, INITIAL_IDX_IRN_MAP_SIZE * sizeof(res->idx_irn_map[0])); + /* inform statistics here, as blocks will be already build on this graph */ hook_new_graph(res, NULL); diff --git a/ir/ir/irgraph_t.h b/ir/ir/irgraph_t.h index 19aaef3c5..034d1afe6 100644 --- a/ir/ir/irgraph_t.h +++ b/ir/ir/irgraph_t.h @@ -141,7 +141,8 @@ struct ir_graph { unsigned long block_visited; /**< same as visited, for a complete block */ unsigned estimated_node_count; /**< estimated number of nodes in this graph, updated after every walk */ - irg_edge_info_t edge_info; /**< edge info for automatic outs */ + irg_edge_info_t edge_info; /**< edge info for automatic outs */ + ir_node **idx_irn_map; /**< Array mapping node indexes to nodes. */ #ifdef DEBUG_libfirm int n_outs; /**< Size wasted for outs */ @@ -524,11 +525,20 @@ _get_irg_estimated_node_cnt(const ir_graph *irg) { } /** - * Returns the next IR node index for the given graph. + * Allocates a new idx in the irg for the node and adds the irn to the idx -> irn map. + * @param irg The graph. + * @param irn The node. + * @return The index allocated for the node. */ static INLINE unsigned -get_irg_next_node_idx(ir_graph *irg) { - return irg->last_node_idx++; +irg_register_node_idx(ir_graph *irg, ir_node *irn) +{ + unsigned idx = irg->last_node_idx++; + if(idx >= (unsigned) ARR_LEN(irg->idx_irn_map)) + ARR_RESIZE(ir_node *, irg->idx_irn_map, idx + 1); + + irg->idx_irn_map[idx] = irn; + return idx; } /** @@ -537,9 +547,24 @@ get_irg_next_node_idx(ir_graph *irg) { */ static INLINE void irg_kill_node(ir_graph *irg, ir_node *n) { - if (get_irn_idx(n) + 1 == irg->last_node_idx) - --irg->last_node_idx; - obstack_free(irg->obst, n); + unsigned idx = get_irn_idx(n); + if (idx + 1 == irg->last_node_idx) + --irg->last_node_idx; + irg->idx_irn_map[idx] = NULL; + obstack_free(irg->obst, n); +} + +/** + * Get the node for an index. + * @param irg The graph. + * @param idx The index you want the node for. + * @return The node with that index or NULL, if there is no node with that index. + * @note The node you got might be dead. + */ +static INLINE ir_node * +get_idx_irn(ir_graph *irg, unsigned idx) { + assert(idx < (unsigned) ARR_LEN(irg->idx_irn_map)); + return irg->idx_irn_map[idx]; } #define get_interprocedural_view() _get_interprocedural_view() diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index 904bd7110..37f320e43 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -142,7 +142,7 @@ new_ir_node (dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mo res->op = op; res->mode = mode; res->visited = 0; - res->node_idx = get_irg_next_node_idx(irg); + res->node_idx = irg_register_node_idx(irg, res); res->link = NULL; if (arity < 0) { res->in = NEW_ARR_F (ir_node *, 1); /* 1: space for block */