removed chordal_env from be lowering
[libfirm] / ir / be / beraextern.c
index f0dd304..09cc290 100644 (file)
@@ -86,6 +86,7 @@ alloc         ::= node-nr reg-nr .
 #include "irdom_t.h"
 #include "phiclass.h"
 
+#include "bemodule.h"
 #include "beraextern.h"
 #include "beabi.h"
 #include "bearch.h"
@@ -106,8 +107,8 @@ alloc               ::= node-nr reg-nr .
 typedef struct _be_raext_env_t {
        arch_env_t *aenv;
        const arch_register_class_t *cls;
+       be_irg_t *birg;
        ir_graph *irg;
-       dom_front_info_t *dom_info;
 
        FILE *f;                                /**< file handle used for out- and input file */
        set *vars;                              /**< contains all be_var_info_t */
@@ -360,6 +361,7 @@ static void dump_interferences(be_raext_env_t *raenv) {
        be_var_info_t *vi1, *vi2;
        ir_node *irn1, *irn2;
        FILE *f = raenv->f;
+       be_lv_t *lv = raenv->birg->lv;
 
        fprintf(f, "\ninterferences {\n");
 
@@ -377,7 +379,7 @@ static void dump_interferences(be_raext_env_t *raenv) {
 
                        pset_foreach(vi1->values, irn1)
                                pset_foreach(vi2->values, irn2)
-                                       if (values_interfere(irn1, irn2)) {
+                                       if (values_interfere(lv, irn1, irn2)) {
                                                pset_break(vi1->values);
                                                pset_break(vi2->values);
                                                fprintf(f, "(%d, %d)\n", vi1->var_nr, vi2->var_nr);
@@ -402,7 +404,7 @@ static void dump_affinities_walker(ir_node *irn, void *env) {
        vi1 = be_get_var_info(irn);
 
        /* copies have affinities */
-       if (arch_irn_classify(raenv->aenv, irn) == arch_irn_class_copy) {
+       if (arch_irn_class_is(raenv->aenv, irn, copy)) {
                ir_node *other = be_get_Copy_op(irn);
 
                if (! arch_irn_is(raenv->aenv, other, ignore)) {
@@ -503,6 +505,8 @@ static INLINE void var_add_spills_and_reloads(be_raext_env_t *raenv, int var_nr)
        const ir_edge_t *edge, *ne;
        pset *spills  = pset_new_ptr(4);        /* the spills of this variable */
        pset *reloads = pset_new_ptr(4);        /* the reloads of this variable */
+       be_lv_t *lv = raenv->birg->lv;
+       be_dom_front_info_t *dom_front = raenv->birg->dom_front;
        int new_size, n_spills, n_reloads;
 
        assert(vi && "Variable nr does not exist!");
@@ -527,7 +531,7 @@ static INLINE void var_add_spills_and_reloads(be_raext_env_t *raenv, int var_nr)
 
                /* all ordinary nodes must be spilled */
                DBG((raenv->dbg, LEVEL_2, "  spilling %+F\n", irn));
-               spill = be_spill(raenv->aenv, irn, ctx);
+               spill = be_spill(raenv->aenv, irn);
 
                /* remember the spill */
                pset_insert_ptr(spills, spill);
@@ -554,7 +558,7 @@ static INLINE void var_add_spills_and_reloads(be_raext_env_t *raenv, int var_nr)
                }
 
        /* correct the reload->spill pointers... */
-       be_ssa_constr_set(raenv->dom_info, spills);
+       be_ssa_constr_set(dom_front, lv, spills);
 
 
        /****** correct the variable <--> values mapping: ******
@@ -650,6 +654,7 @@ static int read_and_apply_results(be_raext_env_t *raenv, char *filename) {
 
 static void check_allocation(be_raext_env_t *raenv) {
        int i, o;
+       be_lv_t *lv = raenv->birg->lv;
 
        for (i=0; i<raenv->n_cls_vars; ++i) {
                be_var_info_t *vi1 = raenv->cls_vars[i];
@@ -666,9 +671,9 @@ static void check_allocation(be_raext_env_t *raenv) {
 
                        pset_foreach(vi1->values, irn1)
                                pset_foreach(vi2->values, irn2)
-                                       if (values_interfere(irn1, irn2) && arch_get_irn_register(raenv->aenv, irn1) == arch_get_irn_register(raenv->aenv, irn2)) {
+                                       if (values_interfere(lv, irn1, irn2) && arch_get_irn_register(raenv->aenv, irn1) == arch_get_irn_register(raenv->aenv, irn2)) {
                                                dump_ir_block_graph_sched(raenv->irg, "ERROR");
-                                               ir_fprintf(stdout, "SSA values %+F and %+F interfere. They belong to varible %d and %d respectively.\n", irn1, irn2, vi1->var_nr, vi2->var_nr);
+                                               ir_fprintf(stdout, "SSA values %+F and %+F interfere. They belong to variable %d and %d respectively.\n", irn1, irn2, vi1->var_nr, vi2->var_nr);
                                                assert(0 && "ERROR graph dumped");
                                        }
                }
@@ -687,7 +692,6 @@ static void check_allocation(be_raext_env_t *raenv) {
 /**
  * Default values for options
  */
-static set* (*ssa_destr)(ir_graph*,const arch_env_t*) = be_ssa_destr_simple;
 static char callee[128] = "\"E:/user/kimohoff/public/register allocator\"";
 //static char callee[128] = "/ben/kimohoff/ipd-registerallocator/register_allocator";
 
@@ -701,19 +705,20 @@ static char callee[128] = "\"E:/user/kimohoff/public/register allocator\"";
  * Read in results and apply them
  *
  */
-static void be_ra_extern_main(const be_irg_t *bi) {
-       be_main_env_t *env = bi->main_env;
-       ir_graph *irg = bi->irg;
+static void be_ra_extern_main(be_irg_t *birg) {
+       be_main_env_t *env = birg->main_env;
+       ir_graph *irg = birg->irg;
 
        be_raext_env_t raenv;
        int clsnr, clss;
 
-       compute_doms(irg);
+       be_assure_dom_front(birg);
+       be_assure_liveness(birg);
        edges_assure(irg);
 
        raenv.irg      = irg;
+       raenv.birg     = birg;
        raenv.aenv     = env->arch_env;
-       raenv.dom_info = be_compute_dominance_frontiers(irg);
        FIRM_DBG_REGISTER(raenv.dbg, "firm.be.raextern");
 
        /* Insert copies for constraints */
@@ -747,7 +752,7 @@ static void be_ra_extern_main(const be_irg_t *bi) {
                        dump_to_file(&raenv, out);
                        execute(callee, out, in);
                        done = read_and_apply_results(&raenv, in);
-                       be_abi_fix_stack_nodes(bi->abi);
+                       be_abi_fix_stack_nodes(birg->abi, birg->lv);
 
                        ir_snprintf(in, sizeof(in), "-extern-%s-round-%d", raenv.cls->name, round);
                        be_dump(irg, in, dump_ir_block_graph_sched);
@@ -764,7 +769,8 @@ static void be_ra_extern_main(const be_irg_t *bi) {
 
        /* Clean up */
        free_ssa_destr_simple(raenv.vars);
-       be_free_dominance_frontiers(raenv.dom_info);
+
+       be_invalidate_liveness(birg);
 }
 
 /******************************************************************************
@@ -782,12 +788,14 @@ static void be_ra_extern_main(const be_irg_t *bi) {
 
 
 static const lc_opt_enum_func_ptr_items_t ssa_destr_items[] = {
-       { "simple",     (int (*)()) be_ssa_destr_simple }, /* TODO make (void*) casts nicer */
+       { "simple",     (int (*)(void)) be_ssa_destr_simple }, /* TODO make (void*) casts nicer */
        { NULL,      NULL }
 };
 
+static set* (*ssa_destr)(ir_graph*,const arch_env_t*) = be_ssa_destr_simple;
+
 static lc_opt_enum_func_ptr_var_t ssa_destr_var = {
-        (int (**)()) &ssa_destr, ssa_destr_items
+        (int (**)(void)) &ssa_destr, ssa_destr_items
 };
 
 static const lc_opt_table_entry_t be_ra_extern_options[] = {
@@ -796,17 +804,19 @@ static const lc_opt_table_entry_t be_ra_extern_options[] = {
        { NULL }
 };
 
-static void be_ra_extern_register_options(lc_opt_entry_t *root) {
-       lc_opt_entry_t *grp = lc_opt_get_grp(root, "ext");
+static be_ra_t be_ra_external_allocator = {
+       be_ra_extern_main
+};
+
+void be_init_raextern(void) {
+       lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
+       lc_opt_entry_t *blocksched_grp = lc_opt_get_grp(be_grp, "ra");
+       lc_opt_entry_t *ext_grp = lc_opt_get_grp(blocksched_grp, "ext");
 
-       lc_opt_add_table(grp, be_ra_extern_options);
+       lc_opt_add_table(ext_grp, be_ra_extern_options);
+
+       be_register_allocator("ext", &be_ra_external_allocator);
 }
+BE_REGISTER_MODULE_CONSTRUCTOR(be_init_raextern);
 
 #endif /* WITH_LIBCORE */
-
-const be_ra_t be_ra_external_allocator = {
-#ifdef WITH_LIBCORE
-       be_ra_extern_register_options,
-#endif
-       be_ra_extern_main
-};