+
+/* Dump the liveness information for a graph. */
+void be_liveness_dumpto(ir_graph *irg, const char *cls_name)
+{
+ FILE *f;
+ char buf[128];
+ ir_snprintf(buf, sizeof(buf), "%F_%s-live.txt", irg, cls_name);
+ if((f = fopen(buf, "wt")) != NULL) {
+ be_liveness_dump(irg, f);
+ fclose(f);
+ }
+}
+
+/**
+ * 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))) {
+ int i, n;
+ ir_node *bl = get_nodes_block(irn);
+
+ for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
+ ir_node *op = get_irn_n(irn, i);
+ ir_node *def_bl = get_nodes_block(op);
+ ir_node *use_bl = bl;
+
+ if(is_Phi(irn))
+ use_bl = get_Block_cfgpred_block(bl, i);
+
+ if(!block_dominates(def_bl, use_bl)) {
+ ir_fprintf(stderr, "%+F in %+F must dominate %+F for user %+F\n", op, def_bl, use_bl, irn);
+ assert(0);
+ }
+ }
+ }
+}
+
+/* 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)
+{
+ int i, n;
+ ir_node *x;
+ FIRM_DBG_REGISTER(firm_dbg_module_t *dbg, DBG_MODULE);
+
+ 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)
+{
+ 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;
+}