introduced node index: a small unique per graph node number
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Fri, 7 Apr 2006 12:24:58 +0000 (12:24 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Fri, 7 Apr 2006 12:24:58 +0000 (12:24 +0000)
[r7596]

ir/ir/irgraph.c
ir/ir/irgraph_t.h
ir/ir/irgwalk.c
ir/ir/irnode.c
ir/ir/irnode.h
ir/ir/irnode_t.h
ir/ir/iropt.c
ir/ir/irreflect.c

index 7d40491..00fa687 100644 (file)
@@ -173,6 +173,8 @@ new_r_ir_graph (entity *ent, int n_loc)
   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 */
@@ -280,6 +282,8 @@ ir_graph *new_const_code_irg(void) {
   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;
index 2bfc530..8d0d410 100644 (file)
@@ -87,6 +87,8 @@ struct ir_graph {
   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. */
@@ -519,6 +521,25 @@ _get_irg_estimated_node_cnt(const ir_graph *irg) {
   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)
index 10ae302..ceba751 100644 (file)
@@ -238,7 +238,7 @@ static unsigned nodes_touched = 0;
  */
 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();
index 3389ab6..2c3a5a6 100644 (file)
@@ -137,11 +137,12 @@ new_ir_node (dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mo
   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 {
@@ -563,6 +564,11 @@ get_irn_generic_attr (ir_node *node) {
   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 */
index d327f51..b0774ce 100644 (file)
@@ -1162,6 +1162,12 @@ unsigned register_additional_node_data(unsigned size);
  */
 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                                                   **/
 /*-----------------------------------------------------------------*/
index 817071a..1ec1f16 100644 (file)
@@ -240,18 +240,19 @@ struct ir_node {
   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 */
@@ -796,6 +797,10 @@ static INLINE int _get_Psi_n_conds(ir_node *node) {
   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)
@@ -852,5 +857,6 @@ static INLINE int _get_Psi_n_conds(ir_node *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_ */
index 3bfa9b3..35bacda 100644 (file)
@@ -3580,7 +3580,7 @@ optimize_node(ir_node *n)
         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))
@@ -3615,8 +3615,7 @@ optimize_node(ir_node *n)
     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;
   }
 
index fbd0d2c..8327812 100644 (file)
@@ -30,8 +30,6 @@
 #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.
  */