added two functions:
[libfirm] / ir / ana / height.c
index 8a060ef..17c9d08 100644 (file)
@@ -1,3 +1,14 @@
+/*
+ * Project:     libFIRM
+ * File name:   ir/ana/height.c
+ * Purpose:     Compute heights of nodes inside basic blocks
+ * Author:      Sebastian Hack
+ * Modified by:
+ * Created:     19.04.2006
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 2006 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -26,11 +37,12 @@ typedef struct {
        struct list_head sink_list;
 } irn_height_t;
 
-static void irn_height_init(const phase_t *ph, const ir_node *irn, void *data)
+static void *irn_height_init(phase_t *ph, ir_node *irn, void *data)
 {
-       irn_height_t *h = data;
+       irn_height_t *h = data ? data : phase_alloc(ph, sizeof(h[0]));
        memset(h, 0, sizeof(h[0]));
        INIT_LIST_HEAD(&h->sink_list);
+       return h;
 }
 
 static void height_dump_cb(void *data, FILE *f, const ir_node *irn)
@@ -112,7 +124,7 @@ int heights_reachable_in_block(heights_t *h, const ir_node *n, const ir_node *m)
  * @param irn The node.
  * @param bl  The block.
  */
-static unsigned compute_height(heights_t *h, const ir_node *irn, const ir_node *bl)
+static unsigned compute_height(heights_t *h, ir_node *irn, const ir_node *bl)
 {
        irn_height_t *ih = phase_get_or_set_irn_data(&h->ph, irn);
        int is_sink;
@@ -179,7 +191,7 @@ void heights_recompute(heights_t *h)
 heights_t *heights_new(ir_graph *irg)
 {
        heights_t *res = xmalloc(sizeof(res[0]));
-       phase_init(&res->ph, "heights", irg, sizeof(irn_height_t), PHASE_DEFAULT_GROWTH, irn_height_init);
+       phase_init(&res->ph, "heights", irg, PHASE_DEFAULT_GROWTH, irn_height_init);
        res->dump_handle = dump_add_node_info_callback(height_dump_cb, res);
        heights_recompute(res);