fixed warning
[libfirm] / ir / be / belive.c
index d49d09b..2e6c821 100644 (file)
@@ -14,6 +14,9 @@
 
 #include "beutil.h"
 #include "belive_t.h"
+#include "besched_t.h"
+
+#define DBG_MODULE "firm.be.liveness"
 
 FIRM_IMPL2(is_live_in, int, const ir_node *, const ir_node *)
 FIRM_IMPL2(is_live_out, int, const ir_node *, const ir_node *)
@@ -27,16 +30,25 @@ void be_liveness_init(void)
   live_irg_data_offset = register_additional_graph_data(sizeof(irn_live_t));
 }
 
+/**
+ * Mark a node as live-in in a block.
+ */
 static INLINE void mark_live_in(ir_node *block, const ir_node *irn)
 {
   _get_or_set_live(block, irn, live_state_in);
 }
 
+/**
+ * Mark a node as live-out in a block.
+ */
 static INLINE void mark_live_out(ir_node *block, const ir_node *irn)
 {
   _get_or_set_live(block, irn, live_state_out | live_state_end);
 }
 
+/**
+ * Mark a node as live-end in a block.
+ */
 static INLINE void mark_live_end(ir_node *block, const ir_node *irn)
 {
   _get_or_set_live(block, irn, live_state_end);
@@ -143,6 +155,9 @@ static void liveness_for_node(ir_node *irn, void *env)
   del_pset(visited);
 }
 
+/**
+ * Compare two live entries.
+ */
 static int cmp_irn_live(const void *a, const void *b, size_t size)
 {
   const irn_live_t *p = a;
@@ -189,6 +204,7 @@ static int dump_block_func(ir_node *self, FILE *F, dump_reason_t reason)
        return 0;
 }
 
+/* Compute the inter block liveness for a graph. */
 void be_liveness(ir_graph *irg)
 {
   irg_live_info_t *live_info = get_irg_live_info(irg);
@@ -202,6 +218,9 @@ void be_liveness(ir_graph *irg)
   op_Block->ops.dump_node = dump_block_func;
 }
 
+/**
+ * Pre-walker: dump liveness data to a file
+ */
 static void dump_liveness_walker(ir_node *bl, void *data)
 {
        FILE *f = data;
@@ -225,11 +244,13 @@ static void dump_liveness_walker(ir_node *bl, void *data)
        }
 }
 
+/* Dump the liveness information for a graph. */
 void be_liveness_dump(ir_graph *irg, FILE *f)
 {
        irg_block_walk_graph(irg, dump_liveness_walker, NULL, f);
 }
 
+/* Dump the liveness information for a graph. */
 void be_liveness_dumpto(ir_graph *irg, const char *cls_name)
 {
        FILE *f;
@@ -241,6 +262,10 @@ void be_liveness_dumpto(ir_graph *irg, const char *cls_name)
        }
 }
 
+/**
+ * Walker: checks the every predecessors of a node dominate
+ * the note.
+ */
 static void dom_check(ir_node *irn, void *data)
 {
        if(!is_Block(irn) && irn != get_irg_end(get_irn_irg(irn))) {
@@ -263,7 +288,66 @@ static void dom_check(ir_node *irn, void *data)
        }
 }
 
+/* Check, if the SSA dominance property is fulfilled. */
 void be_check_dominance(ir_graph *irg)
 {
        irg_walk_graph(irg, dom_check, NULL, NULL);
 }
+
+pset *be_liveness_transfer(const arch_env_t *arch_env, const arch_register_class_t *cls, ir_node *irn, pset *live)
+{
+       firm_dbg_module_t *dbg = firm_dbg_register(DBG_MODULE);
+       int i, n;
+       ir_node *x;
+
+       DBG((dbg, LEVEL_1, "%+F\n", irn));
+       for(x = pset_first(live); x; x = pset_next(live))
+               DBG((dbg, LEVEL_1, "\tlive: %+F\n", x));
+
+       if(arch_irn_consider_in_reg_alloc(arch_env, cls, irn))
+               pset_remove_ptr(live, irn);
+
+       for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
+               ir_node *op = get_irn_n(irn, i);
+
+               if(arch_irn_consider_in_reg_alloc(arch_env, cls, op))
+                       pset_insert_ptr(live, op);
+       }
+
+       return live;
+}
+
+pset *be_liveness_end_of_block(const arch_env_t *arch_env, const arch_register_class_t *cls, const ir_node *bl, pset *live)
+{
+       irn_live_t *li;
+
+       live_foreach(bl, li) {
+               ir_node *irn = (ir_node *) li->irn;
+               if(live_is_end(li) && arch_irn_consider_in_reg_alloc(arch_env, cls, irn))
+                       pset_insert_ptr(live, irn);
+       }
+
+       return live;
+}
+
+pset *be_liveness_nodes_live_at(const arch_env_t *arch_env, const arch_register_class_t *cls, const ir_node *pos, pset *live)
+{
+       firm_dbg_module_t *dbg = firm_dbg_register(DBG_MODULE);
+       const ir_node *bl      = is_Block(pos) ? pos : get_nodes_block(pos);
+       ir_node *irn;
+
+       be_liveness_end_of_block(arch_env, cls, bl, live);
+
+       sched_foreach_reverse(bl, irn) {
+               /*
+                * If we encounter the node we want to insert the Perm after,
+                * exit immediately, so that this node is still live
+                */
+               if(irn == pos)
+                       return live;
+
+               be_liveness_transfer(arch_env, cls, irn, live);
+       }
+
+       return live;
+}