obstack_init(res->obst);
res->extbb_obst = NULL;
+ res->last_node_idx = 0;
+
res->value_table = new_identities (); /* value table for global value
numbering for optimizing use in
iropt.c */
obstack_init (res->obst);
res->extbb_obst = NULL;
+ res->last_node_idx = 0;
+
res->phase_state = phase_building;
res->irg_pinned_state = op_pin_state_pinned;
res->extblk_state = ir_extblk_info_none;
ir_node *current_block; /**< block for newly gen_*()-erated ir_nodes */
struct obstack *extbb_obst; /**< obstack for extended basic block info */
+ unsigned last_node_idx; /**< last IR node index for this graph */
+
/* -- Fields for graph properties -- */
irg_inline_property inline_property; /**< How to handle inlineing. */
unsigned additional_properties; /**< additional graph properties. */
return irg->estimated_node_count;
}
+/**
+ * Returns the next IR node index for the given graph.
+ */
+static INLINE unsigned
+get_irg_next_node_idx(ir_graph *irg) {
+ return irg->last_node_idx++;
+}
+
+/**
+ * Kill a node from the irg. BEWARE: this kills
+ * all later created nodes.
+ */
+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);
+}
+
#define get_interprocedural_view() _get_interprocedural_view()
#define is_ir_graph(thing) _is_ir_graph(thing)
#define get_irg_start_block(irg) _get_irg_start_block(irg)
*/
void irg_walk(ir_node *node, irg_walk_func *pre, irg_walk_func *post, void *env)
{
- assert(node && node->kind==k_ir_node);
+ assert(is_ir_node(node));
if (get_interprocedural_view()) {
eset * irg_set = eset_create();
memset(p, 0, node_size);
res = (ir_node *) (p + firm_add_node_size);
- res->kind = k_ir_node;
- res->op = op;
- res->mode = mode;
- res->visited = 0;
- res->link = NULL;
+ res->kind = k_ir_node;
+ res->op = op;
+ res->mode = mode;
+ res->visited = 0;
+ res->node_idx = get_irg_next_node_idx(irg);
+ res->link = NULL;
if (arity < 0) {
res->in = NEW_ARR_F (ir_node *, 1); /* 1: space for block */
} else {
return &node->attr;
}
+unsigned (get_irn_idx)(const ir_node *node) {
+ assert(is_ir_node(node));
+ return _get_irn_idx(node);
+}
+
/** manipulate fields of individual nodes **/
/* this works for all except Block */
*/
void *get_irn_generic_attr(ir_node *node);
+/**
+ * Returns the unique node index for the node in its graph.
+ * This index is used to access phase information for this node.
+ */
+unsigned get_irn_idx(const ir_node *node);
+
/*-----------------------------------------------------------------*/
/** Debug aides **/
/*-----------------------------------------------------------------*/
ir_mode *mode; /**< Mode of this node. */
struct ir_node **in; /**< array with predecessors / operands */
unsigned long visited; /**< visited counter for walks of the graph */
+ unsigned node_idx; /**< the node index of this node in its graph */
void *link; /**< to attach additional information to the node, e.g.
used while construction to link Phi0 nodes and
- during optimization to link to nodes that
- shall replace a node. */
+ during optimization to link to nodes that
+ shall replace a node. */
/* ------- Fields for optimizations / analysis information ------- */
struct ir_node **out; /**< @deprecated array of out edges. */
struct dbg_info* dbi; /**< A pointer to information for debug support. */
/* ------- For debugging ------- */
#ifdef DEBUG_libfirm
- int out_valid;
+ int out_valid;
long node_nr; /**< a unique node number for each node to make output
- readable. */
+ readable. */
#endif
/* ------- For analyses -------- */
ir_loop *loop; /**< the loop the node is in. Access routines in irloop.h */
return _get_irn_arity(node) >> 1;
}
+static INLINE unsigned _get_irn_idx(const ir_node *node) {
+ return node->node_idx;
+}
+
/* this section MUST contain all inline functions */
#define is_ir_node(thing) _is_ir_node(thing)
#define get_irn_intra_arity(node) _get_irn_intra_arity(node)
#define get_Cond_jmp_pred(node) _get_Cond_jmp_pred(node)
#define set_Cond_jmp_pred(node, pred) _set_Cond_jmp_pred(node, pred)
#define get_Psi_n_conds(node) _get_Psi_n_conds(node)
+#define get_irn_idx(node) _get_irn_idx(node)
# endif /* _IRNODE_T_H_ */
edges_node_deleted(n, current_ir_graph);
/* evaluation was successful -- replace the node. */
- obstack_free(current_ir_graph->obst, n);
+ irg_kill_node(current_ir_graph, n);
nw = new_Const(get_tarval_mode (tv), tv);
if (old_tp && get_type_mode(old_tp) == get_tarval_mode (tv))
edges_node_deleted(oldn, current_ir_graph);
/* We found an existing, better node, so we can deallocate the old node. */
- obstack_free (current_ir_graph->obst, oldn);
-
+ irg_kill_node(current_ir_graph, oldn);
return n;
}
#define obstack_grow_str(obst,s) obstack_grow((obst), (s), strlen((s)))
#define obstack_grow_str_const(obst,s) obstack_grow((obst), (s), sizeof((s)))
-extern int obstack_printf(struct obstack *obst, const char *fmt, ...);
-
/**
* Get the number of bits set in a word.
*/