bearch: Disallow passing Projs to get_irn_ops().
[libfirm] / ir / be / beinfo.c
index 05f1b95..d17e59c 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
 #include "bearch.h"
 #include "benode.h"
 #include "besched.h"
+#include "bedump.h"
+#include "belive_t.h"
 #include "irgwalk.h"
 #include "irnode_t.h"
 #include "irdump_t.h"
+#include "irhooks.h"
 #include "error.h"
 
 static copy_attr_func old_phi_copy_attr;
@@ -67,13 +56,9 @@ void be_info_new_node(ir_graph *irg, ir_node *node)
        case iro_End:
        case iro_Unknown:
                info->flags |= arch_irn_flags_not_scheduled;
-               info->out_infos = NEW_ARR_D(reg_out_info_t, obst, 1);
-               memset(info->out_infos, 0, 1 * sizeof(info->out_infos[0]));
-               info->out_infos[0].req = arch_no_register_req;
-               break;
+               /* FALLTHROUGH */
        case iro_Phi:
-               info->out_infos = NEW_ARR_D(reg_out_info_t, obst, 1);
-               memset(info->out_infos, 0, 1 * sizeof(info->out_infos[0]));
+               info->out_infos        = NEW_ARR_DZ(reg_out_info_t, obst, 1);
                info->out_infos[0].req = arch_no_register_req;
                break;
        default:
@@ -130,7 +115,26 @@ static void init_walker(ir_node *node, void *data)
        be_info_new_node(irg, node);
 }
 
-static bool initialized = false;
+static bool         initialized = false;
+static hook_entry_t hook_liveness_info;
+
+static void dump_liveness_info_hook(void *context, FILE *F, const ir_node *node)
+{
+       (void)context;
+       if (!is_Block(node))
+               return;
+       ir_graph *irg = get_irn_irg(node);
+       if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND))
+               return;
+
+       be_lv_t *lv = be_get_irg_liveness(irg);
+       if (lv == NULL)
+               return;
+       if (!lv->sets_valid)
+               return;
+
+       be_dump_liveness_block(lv, F, node);
+}
 
 void be_info_init(void)
 {
@@ -144,6 +148,9 @@ void be_info_init(void)
        /* phis have register and register requirements now which we want to dump */
        assert(op_Phi->ops.dump_node == NULL);
        op_Phi->ops.dump_node = be_dump_phi_reg_reqs;
+
+       hook_liveness_info.hook._hook_node_info = dump_liveness_info_hook;
+       register_hook(hook_node_info, &hook_liveness_info);
 }
 
 /**
@@ -151,23 +158,26 @@ void be_info_init(void)
  */
 static void sched_edge_hook(FILE *F, const ir_node *irn)
 {
-       if (get_irn_irg(irn)->be_data == NULL)
+       ir_graph *irg = get_irn_irg(irn);
+       if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_BACKEND))
+               return;
+
+       if (is_Proj(irn) || is_Block(irn) || !sched_is_scheduled(irn))
                return;
 
-       if (sched_is_scheduled(irn) && !is_Block(irn)) {
-               ir_node *const prev = sched_prev(irn);
-               if (!sched_is_begin(prev)) {
-                       fprintf(F, "edge:{sourcename: ");
-                       print_nodeid(F, irn);
-                       fprintf(F, " targetname: ");
-                       print_nodeid(F, prev);
-                       fprintf(F, " color:magenta}\n");
-               }
+       ir_node *const prev = sched_prev(irn);
+       if (!sched_is_begin(prev)) {
+               fprintf(F, "edge:{sourcename: ");
+               print_nodeid(F, irn);
+               fprintf(F, " targetname: ");
+               print_nodeid(F, prev);
+               fprintf(F, " color:magenta}\n");
        }
 }
 
 void be_info_init_irg(ir_graph *irg)
 {
+       add_irg_constraints(irg, IR_GRAPH_CONSTRAINT_BACKEND);
        irg_walk_anchors(irg, init_walker, NULL, NULL);
 
        set_dump_node_edge_hook(sched_edge_hook);
@@ -184,4 +194,6 @@ void be_info_free(void)
 
        assert(op_Phi->ops.dump_node == be_dump_phi_reg_reqs);
        op_Phi->ops.dump_node = NULL;
+
+       unregister_hook(hook_node_info, &hook_liveness_info);
 }