- split get_pairidx_for_regidx(), always called with constant parameter
[libfirm] / ir / be / beschednormal.c
index dacc5a6..6b83ee5 100644 (file)
@@ -22,9 +22,7 @@
  * @author  Christoph Mallon
  * @version $Id$
  */
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #include <stdlib.h>
 
@@ -36,7 +34,7 @@
 #include "irtools.h"
 #include "irgwalk.h"
 #include "benode_t.h"
-
+#include "array_t.h"
 
 // XXX there is no one time init for schedulers
 //#define NORMAL_DBG
@@ -49,9 +47,6 @@ static int must_be_scheduled(const ir_node* const irn)
 }
 
 
-static const arch_env_t *cur_arch_env;
-
-
 static ir_node *normal_select(void *block_env, ir_nodeset_t *ready_set,
                               ir_nodeset_t *live_set)
 {
@@ -72,7 +67,7 @@ static ir_node *normal_select(void *block_env, ir_nodeset_t *ready_set,
        for (; sched_count-- != 0; ++sched) {
                ir_node* irn = *sched;
                if (ir_nodeset_contains(ready_set, irn) &&
-                               !arch_irn_class_is(cur_arch_env, irn, branch)) {
+                               !arch_irn_class_is(irn, branch)) {
 #if defined NORMAL_DBG
                        ir_fprintf(stderr, "scheduling %+F\n", irn);
 #endif
@@ -95,8 +90,10 @@ static int cost_cmp(const void* a, const void* b)
        const irn_cost_pair* const a1 = a;
        const irn_cost_pair* const b1 = b;
        int ret = b1->cost - a1->cost;
+       if (ret == 0)
+               ret = (int)get_irn_idx(a1->irn) - (int)get_irn_idx(b1->irn);
 #if defined NORMAL_DBG
-       ir_fprintf(stderr, "%+F %s %+F\n", a1->irn, ret < 0 ? "<" : ret > 0 ? ">" : "=", b1->irn);
+       ir_fprintf(stderr, "cost %+F %s %+F\n", a1->irn, ret < 0 ? "<" : ret > 0 ? ">" : "=", b1->irn);
 #endif
        return ret;
 }
@@ -114,7 +111,7 @@ static int count_result(const ir_node* irn)
        return
                mode != mode_M &&
                mode != mode_X &&
-               !arch_irn_is(cur_arch_env, irn, ignore);
+               !arch_irn_is(irn, ignore);
 }
 
 
@@ -127,6 +124,7 @@ static int normal_tree_cost(ir_node* irn)
        flag_and_cost* fc    = get_irn_link(irn);
        ir_node*       block = get_nodes_block(irn);
        int            arity = get_irn_arity(irn);
+       ir_node*       last;
        int            n_res;
        int            cost;
        int            n_op_res = 0;
@@ -161,7 +159,7 @@ static int normal_tree_cost(ir_node* irn)
 
                                cost = normal_tree_cost(pred);
                                if (be_is_Barrier(pred)) cost = 1; // XXX hack: the barrier causes all users to have a reguse of #regs
-                               if (!arch_irn_is(cur_arch_env, pred, ignore)) {
+                               if (!arch_irn_is(pred, ignore)) {
                                        real_pred = (is_Proj(pred) ? get_Proj_pred(pred) : pred);
                                        pred_fc = get_irn_link(real_pred);
                                        pred_fc->no_root = 1;
@@ -180,10 +178,14 @@ static int normal_tree_cost(ir_node* irn)
        }
 
        cost = 0;
+       last = 0;
        for (i = 0; i < arity; ++i) {
-               if (get_irn_mode(fc->costs[i].irn) == mode_M) continue;
-               if (arch_irn_is(cur_arch_env, fc->costs[i].irn, ignore)) continue;
+               ir_node* op = fc->costs[i].irn;
+               if (op == last)                 continue;
+               if (get_irn_mode(op) == mode_M) continue;
+               if (arch_irn_is(op, ignore))    continue;
                cost = MAX(fc->costs[i].cost + n_op_res, cost);
+               last = op;
                ++n_op_res;
        }
        n_res = count_result(irn);
@@ -245,8 +247,8 @@ static ir_node** sched_node(ir_node** sched, ir_node* irn)
        int            arity = get_irn_arity(irn);
        int            i;
 
-       if (irn_visited(irn)) return sched;
-       if (is_End(irn))      return sched;
+       if (irn_visited_else_mark(irn)) return sched;
+       if (is_End(irn))                return sched;
 
        if (!is_Phi(irn) && !be_is_Keep(irn)) {
                for (i = 0; i < arity; ++i) {
@@ -258,7 +260,6 @@ static ir_node** sched_node(ir_node** sched, ir_node* irn)
                }
        }
 
-       mark_irn_visited(irn);
        ARR_APP1(ir_node*, sched, irn);
        return sched;
 }
@@ -281,7 +282,7 @@ static int root_cmp(const void* a, const void* b)
                }
        }
 #if defined NORMAL_DBG
-       ir_fprintf(stderr, "%+F %s %+F\n", a1->irn, ret < 0 ? "<" : ret > 0 ? ">" : "=", b1->irn);
+       ir_fprintf(stderr, "root %+F %s %+F\n", a1->irn, ret < 0 ? "<" : ret > 0 ? ">" : "=", b1->irn);
 #endif
        return ret;
 }
@@ -362,8 +363,6 @@ static void *normal_init_graph(const list_sched_selector_t *vtab,
 
        (void)vtab;
 
-       cur_arch_env = be_get_birg_arch_env(birg);
-
        be_clear_links(irg);
 
        heights = heights_new(irg);