bescripts: Copy all common node attributes into the constructor variants.
[libfirm] / ir / be / bepbqpcoloring.c
index 542dfd4..f9de569 100644 (file)
@@ -37,7 +37,7 @@
 #include "irgwalk.h"
 #include "irtools.h"
 #include "time.h"
-#include "execfreq.h"
+#include "execfreq_t.h"
 #include "bipartite.h"
 
 /* libfirm/ir/be includes */
@@ -90,6 +90,7 @@ typedef struct be_pbqp_alloc_env_t {
        plist_t                     *rpeo;
        unsigned                    *restr_nodes;
        unsigned                    *ife_edge_num;
+       ir_execfreq_int_factors      execfreq_factors;
        be_chordal_env_t            *env;
 } be_pbqp_alloc_env_t;
 
@@ -100,11 +101,6 @@ typedef struct be_pbqp_alloc_env_t {
 #define insert_edge(pbqp, src_node, trg_node, template_matrix) (add_edge_costs(pbqp, get_irn_idx(src_node), get_irn_idx(trg_node), pbqp_matrix_copy(pbqp, template_matrix)))
 #define get_free_regs(restr_nodes, cls, irn)                   (arch_register_class_n_regs(cls) - restr_nodes[get_irn_idx(irn)])
 
-static inline int is_2addr_code(const arch_register_req_t *req)
-{
-       return (req->type & arch_register_req_type_should_be_same) != 0;
-}
-
 static const lc_opt_table_entry_t options[] = {
        LC_OPT_ENT_BOOL("exec_freq", "use exec_freq",  &use_exec_freq),
        LC_OPT_ENT_BOOL("late_decision", "use late decision for register allocation",  &use_late_decision),
@@ -218,10 +214,9 @@ static void insert_afe_edge(be_pbqp_alloc_env_t *pbqp_alloc_env, ir_node *src_no
        if (get_edge(pbqp, get_irn_idx(src_node), get_irn_idx(trg_node)) == NULL) {
                if (use_exec_freq) {
                        /* get exec_freq for copy_block */
-                       ir_node       *root_bl   = get_nodes_block(src_node);
-                       ir_node       *copy_bl   = is_Phi(src_node) ? get_Block_cfgpred_block(root_bl, pos) : root_bl;
-                       ir_exec_freq  *exec_freq = be_get_irg_exec_freq(pbqp_alloc_env->irg);
-                       unsigned long  res       = get_block_execfreq_ulong(exec_freq, copy_bl);
+                       ir_node *root_bl = get_nodes_block(src_node);
+                       ir_node *copy_bl = is_Phi(src_node) ? get_Block_cfgpred_block(root_bl, pos) : root_bl;
+                       int      res     = get_block_execfreq_int(&pbqp_alloc_env->execfreq_factors, copy_bl);
 
                        /* create afe-matrix */
                        unsigned row, col;
@@ -286,25 +281,22 @@ static void create_affinity_edges(ir_node *irn, void *env)
                        return;
 
                insert_afe_edge(pbqp_alloc_env, irn, arg, -1);
-       }
-       else { /* 2-address code */
-               if (is_2addr_code(req)) {
-                       const unsigned other = req->other_same;
-                       int            i;
-
-                       for (i = 0; 1U << i <= other; ++i) {
-                               if (other & (1U << i)) {
-                                       ir_node *other = get_irn_n(skip_Proj(irn), i);
-                                       if (!arch_irn_consider_in_reg_alloc(cls, other))
-                                               continue;
-
-                                       /* no edges to itself */
-                                       if (irn == other) {
-                                               continue;
-                                       }
+       } else if (arch_register_req_is(req, should_be_same)) {
+               const unsigned other = req->other_same;
+               int            i;
+
+               for (i = 0; 1U << i <= other; ++i) {
+                       if (other & (1U << i)) {
+                               ir_node *other = get_irn_n(skip_Proj(irn), i);
+                               if (!arch_irn_consider_in_reg_alloc(cls, other))
+                                       continue;
 
-                                       insert_afe_edge(pbqp_alloc_env, irn, other, i);
+                               /* no edges to itself */
+                               if (irn == other) {
+                                       continue;
                                }
+
+                               insert_afe_edge(pbqp_alloc_env, irn, other, i);
                        }
                }
        }
@@ -340,57 +332,27 @@ static void create_pbqp_coloring_instance(ir_node *block, void *data)
 
        /* create pbqp nodes, interference edges and reverse perfect elimination order */
        sched_foreach_reverse(block, irn) {
-               if (get_irn_mode(irn) == mode_T) {
-                       foreach_out_edge(irn, edge) {
-                               ir_node *proj = get_edge_src_irn(edge);
-                               if (!arch_irn_consider_in_reg_alloc(cls, proj))
-                                       continue;
-
-                               /* create pbqp source node if it dosn't exist */
-                               if (get_node(pbqp_inst, get_irn_idx(proj)) == NULL) {
-                                       create_pbqp_node(pbqp_alloc_env, proj);
-                               }
-
-                               /* create nodes and interference edges */
-                               foreach_ir_nodeset(&live_nodes, live, iter) {
-                                       /* create pbqp source node if it dosn't exist */
-                                       if (get_node(pbqp_inst, get_irn_idx(live)) == NULL) {
-                                               create_pbqp_node(pbqp_alloc_env, live);
-                                       }
+               be_foreach_value(irn, value,
+                       if (!arch_irn_consider_in_reg_alloc(cls, value))
+                               continue;
 
-                                       /* no edges to itself */
-                                       if (proj == live) {
-                                               continue;
-                                       }
+                       /* create pbqp source node if it dosn't exist */
+                       if (!get_node(pbqp_inst, get_irn_idx(value)))
+                               create_pbqp_node(pbqp_alloc_env, value);
 
-                                       insert_ife_edge(pbqp_alloc_env, proj, live);
-                               }
-                       }
-               }
-               else {
-                       if (arch_irn_consider_in_reg_alloc(cls, irn)) {
+                       /* create nodes and interference edges */
+                       foreach_ir_nodeset(&live_nodes, live, iter) {
                                /* create pbqp source node if it dosn't exist */
-                               if (get_node(pbqp_inst, get_irn_idx(irn)) == NULL) {
-                                       create_pbqp_node(pbqp_alloc_env, irn);
-                               }
-
-                               /* create nodes and interference edges */
-                               foreach_ir_nodeset(&live_nodes, live, iter) {
-                                       /* create pbqp source node if it dosn't exist */
-                                       if (get_node(pbqp_inst, get_irn_idx(live)) == NULL) {
-                                               create_pbqp_node(pbqp_alloc_env, live);
-                                       }
+                               if (!get_node(pbqp_inst, get_irn_idx(live)))
+                                       create_pbqp_node(pbqp_alloc_env, live);
 
-                                       /* no edges to itself */
-                                       if (irn == live) {
-                                               continue;
-                                       }
+                               /* no edges to itself */
+                               if (value == live)
+                                       continue;
 
-                                       /* insert interference edge */
-                                       insert_ife_edge(pbqp_alloc_env, irn, live);
-                               }
+                               insert_ife_edge(pbqp_alloc_env, value, live);
                        }
-               }
+               );
 
                /* get living nodes for next step */
                if (!is_Phi(irn)) {
@@ -595,13 +557,12 @@ static void insert_perms(ir_node *block, void *data)
        ir_node          *irn;
 
        for (irn = sched_first(block); !sched_is_end(irn);) {
-               be_insn_t *insn = chordal_scan_insn(env, irn);
-               irn             = insn->next_insn;
-
-               if (!insn->has_constraints)
-                       continue;
+               ir_node   *const next = sched_next(irn);
+               be_insn_t *      insn = be_scan_insn(env, irn);
+               if (insn)
+                       pre_process_constraints(env, &insn);
 
-               pre_process_constraints(env, &insn);
+               irn = next;
        }
 }
 
@@ -641,6 +602,7 @@ static void be_pbqp_coloring(be_chordal_env_t *env)
                dump_ir_graph(irg, buf);
        }
 
+       ir_calculate_execfreq_int_factors(&pbqp_alloc_env.execfreq_factors, irg);
 
        /* initialize pbqp allocation data structure */
        pbqp_alloc_env.pbqp_inst        = alloc_pbqp(get_irg_last_idx(irg));  /* initialize pbqp instance */