adapted (some parts) to abi changes
[libfirm] / ir / be / beraextern.c
index be43239..922235e 100644 (file)
@@ -471,8 +471,10 @@ static void values_to_vars(ir_node *irn, void *env) {
        }
 
        /* values <--> var mapping */
-       pset_foreach(vals, irn)
+       pset_foreach(vals, irn) {
+               DBG((raenv->dbg, 0, "Var %d contains %+F\n", nr, irn));
                var_add_value(raenv, nr, irn);
+       }
 }
 
 
@@ -524,14 +526,16 @@ static INLINE void dump_constraint(be_raext_env_t *raenv, ir_node *irn, int pos)
        }
 }
 
-static INLINE unsigned int get_spill_costs(be_raext_env_t *raenv, var_info_t *vi) {
+#define UNSPILLABLE -1
+
+static INLINE int get_spill_costs(be_raext_env_t *raenv, var_info_t *vi) {
        ir_node *irn;
        int c_spills=0, c_reloads=0;
 
        pset_foreach(vi->values, irn) {
-               if (arch_irn_is_ignore(raenv->aenv, irn)) {
+               if (arch_irn_is_ignore(raenv->aenv, irn) || be_is_Reload(irn)) {
                        pset_break(vi->values);
-                       return -1;
+                       return UNSPILLABLE;
                }
 
                if (is_Phi(irn)) {
@@ -561,12 +565,13 @@ static void dump_nodes(be_raext_env_t *raenv) {
                if (vi->var_nr == SET_REMOVED)
                        continue;
 
-               fprintf(f, "%d %u", vi->var_nr, get_spill_costs(raenv, vi));
+               fprintf(f, "%d %d", vi->var_nr, get_spill_costs(raenv, vi));
                dump_constraint(raenv, get_first_non_phi(vi->values), -1);
                fprintf(f, "\n");
        }
 
        fprintf(f, "}\n");
+       fflush(f);
 }
 
 
@@ -596,7 +601,10 @@ static void dump_interferences(be_raext_env_t *raenv) {
                                                pset_break(vi1->values);
                                                pset_break(vi2->values);
                                                fprintf(f, "(%d, %d)\n", vi1->var_nr, vi2->var_nr);
+                                               goto NextVar;
                                        }
+
+NextVar: ;
                }
        }
        fprintf(f, "}\n");
@@ -615,7 +623,7 @@ static void dump_affinities_walker(ir_node *irn, void *env) {
 
        /* copies have affinities */
        if (arch_irn_classify(raenv->aenv, irn) == arch_irn_class_copy) {
-               ir_node *other = get_irn_n(irn, 0);
+               ir_node *other = get_irn_n(irn, be_pos_Copy_orig);
 
                if (! arch_irn_is_ignore(raenv->aenv, other)) {
                        vi2 = get_var_info(other);
@@ -690,6 +698,7 @@ static void execute(char *prog_to_call, char *out_file, char *result_file) {
 
        ret_status = system(cmd_line);
        assert(ret_status != -1 && "Invokation of external register allocator failed");
+       assert(ret_status == 0 && "External register allocator is unhappy with sth.");
 }
 
 /******************************************************************************
@@ -745,7 +754,7 @@ static INLINE void var_add_spills_and_reloads(be_raext_env_t *raenv, int var_nr)
 
        assert(spill && "There must be at least one non-phi-node");
 
-       mode = get_irn_mode(get_irn_n(spill, 0));
+       mode = get_irn_mode(get_irn_n(spill, be_pos_Spill_val));
 
        /* insert reloads and wire them arbitrary*/
        pset_foreach(vi->values, irn)
@@ -787,14 +796,16 @@ static INLINE void var_add_spills_and_reloads(be_raext_env_t *raenv, int var_nr)
 
                /* ...add new vars for each non-phi-member */
                pset_foreach(spills, irn) {
-                       ir_node *spilled = get_irn_n(irn, 0);
+                       ir_node *spilled = get_irn_n(irn, be_pos_Spill_val);
                        raenv->cls_vars[raenv->n_cls_vars++] = var_add_value(raenv, get_irn_node_nr(spilled), spilled);
                }
        }
 
        /* add new variables for all reloads */
-       pset_foreach(reloads, irn)
+       pset_foreach(reloads, irn) {
+               assert(get_irn_node_nr(irn) != 1089);
                raenv->cls_vars[raenv->n_cls_vars++] = var_add_value(raenv, get_irn_node_nr(irn), irn);
+       }
 
        del_pset(spills);
        del_pset(reloads);
@@ -874,7 +885,7 @@ static void check_allocation(be_raext_env_t *raenv) {
 
                        pset_foreach(vi1->values, irn1)
                                pset_foreach(vi2->values, irn2)
-                                       if (values_interfere(irn1, irn2)) {
+                                       if (values_interfere(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);
                                                assert(0 && "ERROR graph dumped");
@@ -896,7 +907,7 @@ static void check_allocation(be_raext_env_t *raenv) {
  * Default values for options
  */
 static void (*ssa_destr)(be_raext_env_t*) = ssa_destr_simple;
-static char callee[128] = "\"E:/user/kimohoff/ipd-registerallocator/win32/register allocator\"";
+static char callee[128] = "\"E:/user/kimohoff/public/register allocator\"";
 //static char callee[128] = "/ben/kimohoff/ipd-registerallocator/register_allocator";
 
 
@@ -913,7 +924,7 @@ static void be_ra_extern_main(const be_irg_t *bi) {
        be_main_env_t *env = bi->main_env;
        ir_graph *irg = bi->irg;
 
-       be_raext_env_t raenv;
+       be_raext_env_t raenv;
        int clsnr, clss;
        var_info_t *vi;