removed wrong const
[libfirm] / ir / ir / iredges.c
index 13c568d..f2795cb 100644 (file)
@@ -20,6 +20,24 @@ static firm_dbg_module_t *dbg;
 
 #if FIRM_EDGES_INPLACE
 
+/**
+ * This flag is set to 1, if the edges get initialized for an irg.
+ * Then register additional data is forbidden.
+ */
+static int edges_used = 0;
+
+static int edges_private_size = 0;
+
+int edges_register_private_data(size_t n)
+{
+       int res = edges_private_size;
+
+       assert(!edges_used && "you cannot register private edge data, if edges have been initialized");
+
+       edges_private_size += n;
+       return res;
+}
+
 #define TIMES37(x) (((x) << 5) + ((x) << 2) + (x))
 
 #define get_irn_out_list_head(irn) (&get_irn_out_info(irn)->outs)
@@ -33,12 +51,7 @@ static int edge_cmp(const void *p1, const void *p2, size_t len)
        return !res;
 }
 
-static INLINE unsigned edge_hash(const ir_edge_t *edge)
-{
-       unsigned result = HASH_PTR(edge->src);
-       result = TIMES37(result) + edge->pos;
-       return result;
-}
+#define edge_hash(edge) (TIMES37((edge)->pos) + HASH_PTR((edge)->src))
 
 /**
  * Initialize the out information for a graph.
@@ -50,6 +63,8 @@ void edges_init_graph(ir_graph *irg)
                irg_edge_info_t *info = _get_irg_edge_info(irg);
                int amount = 2048;
 
+               edges_used = 1;
+
                if(info->edges) {
                        amount = set_count(info->edges);
                        del_set(info->edges);
@@ -59,6 +74,28 @@ void edges_init_graph(ir_graph *irg)
        }
 }
 
+/**
+ * Get the edge object of an outgoing edge at a node.
+ * @param   irg The graph, the node is in.
+ * @param   src The node at which the edge originates.
+ * @param   pos The position of the edge.
+ * @return      The corresponding edge object or NULL,
+ *              if no such edge exists.
+ */
+const ir_edge_t *get_irn_edge(ir_graph *irg, const ir_node *src, int pos)
+{
+       if(edges_activated(irg)) {
+               irg_edge_info_t *info = _get_irg_edge_info(irg);
+               ir_edge_t templ;
+
+               templ.src = (ir_node *) src;
+               templ.pos = pos;
+               return set_find(info->edges, &templ, sizeof(templ), edge_hash(&templ));
+       }
+
+       return NULL;
+}
+
 void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir_graph *irg)
 {
        const char *msg = "";
@@ -85,8 +122,12 @@ void edges_notify_edge(ir_node *src, int pos, ir_node *tgt, ir_node *old_tgt, ir
      * treated as unequal, ignoring the comparison function.
      * So, edges from blocks have extra storage (they are
      * ir_block_edge_t's).
+                *
+                * Also add the amount of registered private data to the
+                * size of the edge.
      */
-    size = is_block_edge ? sizeof(ir_block_edge_t) : sizeof(ir_edge_t);
+    size = edges_private_size +
+                       is_block_edge ? sizeof(ir_block_edge_t) : sizeof(ir_edge_t);
 
                /* Initialize the edge template to search in the set. */
     memset(templ, 0, size);
@@ -236,9 +277,9 @@ static void build_edges_walker(ir_node *irn, void *data)
 
 static void init_lh_walker(ir_node *irn, void *data)
 {
-        INIT_LIST_HEAD(_get_irn_outs_head(irn));
-        if(is_Block(irn))
-                INIT_LIST_HEAD(_get_block_succ_head(irn));
+       INIT_LIST_HEAD(_get_irn_outs_head(irn));
+       if(is_Block(irn))
+               INIT_LIST_HEAD(_get_block_succ_head(irn));
 }
 
 void edges_activate(ir_graph *irg)