bearch: Disallow passing Projs to get_irn_ops().
[libfirm] / ir / be / bepbqpcoloring.c
index 5a6a637..f22d15a 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * Copyright (C) 1995-2008 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.
  */
 
 /**
@@ -48,6 +34,7 @@
 #include "bechordal_common.h"
 #include "bechordal.h"
 #include "bechordal_t.h"
+#include "becopyopt_t.h"
 #include "beinsn_t.h"
 #include "benode.h"
 #include "belive.h"
@@ -55,7 +42,6 @@
 #include "beutil.h"
 #include "plist.h"
 #include "pqueue.h"
-#include "becopyopt.h"
 
 /* pbqp includes */
 #include "kaps.h"
@@ -84,7 +70,7 @@ typedef struct be_pbqp_alloc_env_t {
        ir_graph                    *irg;               /**< The graph under examination. */
        const arch_register_class_t *cls;               /**< Current processed register class */
        be_lv_t                     *lv;
-       bitset_t                    *allocatable_regs;
+       bitset_t              const *allocatable_regs;
        pbqp_matrix_t               *ife_matrix_template;
        pbqp_matrix_t               *aff_matrix_template;
        plist_t                     *rpeo;
@@ -95,9 +81,6 @@ typedef struct be_pbqp_alloc_env_t {
 } be_pbqp_alloc_env_t;
 
 
-#define is_Reg_Phi(irn)                                        (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
-#define get_Perm_src(irn)                                      (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
-#define is_Perm_Proj(irn)                                      (is_Proj(irn) && be_is_Perm(get_Proj_pred(irn)))
 #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)])
 
@@ -138,11 +121,11 @@ static FILE *my_open(const be_chordal_env_t *env, const char *prefix, const char
 
 static void create_pbqp_node(be_pbqp_alloc_env_t *pbqp_alloc_env, ir_node *irn)
 {
-       const arch_register_class_t *cls = pbqp_alloc_env->cls;
-       pbqp_t   *pbqp_inst              = pbqp_alloc_env->pbqp_inst;
-       bitset_t *allocatable_regs       = pbqp_alloc_env->allocatable_regs;
-       unsigned  colors_n               = arch_register_class_n_regs(cls);
-       unsigned  cntConstrains          = 0;
+       arch_register_class_t const *const cls              = pbqp_alloc_env->cls;
+       pbqp_t                      *const pbqp_inst        = pbqp_alloc_env->pbqp_inst;
+       bitset_t              const *const allocatable_regs = pbqp_alloc_env->allocatable_regs;
+       unsigned                     const colors_n         = arch_register_class_n_regs(cls);
+       unsigned                           cntConstrains    = 0;
 
        /* create costs vector depending on register constrains */
        vector_t *costs_vector = vector_alloc(pbqp_inst, colors_n);
@@ -260,7 +243,7 @@ static void create_affinity_edges(ir_node *irn, void *env)
        unsigned                     pos;
        unsigned                     max;
 
-       if (is_Reg_Phi(irn)) { /* Phis */
+       if (is_Phi(irn)) { /* Phis */
                for (pos = 0, max = get_irn_arity(irn); pos < max; ++pos) {
                        ir_node *arg = get_irn_n(irn, pos);
 
@@ -554,15 +537,11 @@ static void create_pbqp_coloring_instance(ir_node *block, void *data)
 static void insert_perms(ir_node *block, void *data)
 {
        be_chordal_env_t *env    = (be_chordal_env_t*)data;
-       ir_node          *irn;
 
-       for (irn = sched_first(block); !sched_is_end(irn);) {
-               ir_node   *const next = sched_next(irn);
-               be_insn_t *      insn = be_scan_insn(env, irn);
+       sched_foreach_safe(block, irn) {
+               be_insn_t *insn = be_scan_insn(env, irn);
                if (insn)
                        pre_process_constraints(env, &insn);
-
-               irn = next;
        }
 }
 
@@ -609,13 +588,11 @@ static void be_pbqp_coloring(be_chordal_env_t *env)
        pbqp_alloc_env.cls              = cls;
        pbqp_alloc_env.irg              = irg;
        pbqp_alloc_env.lv               = lv;
-       pbqp_alloc_env.allocatable_regs = bitset_malloc(colors_n);
+       pbqp_alloc_env.allocatable_regs = env->allocatable_regs;
        pbqp_alloc_env.rpeo             = plist_new();
        pbqp_alloc_env.restr_nodes      = XMALLOCNZ(unsigned, get_irg_last_idx(irg));
        pbqp_alloc_env.ife_edge_num     = XMALLOCNZ(unsigned, get_irg_last_idx(irg));
        pbqp_alloc_env.env              = env;
-       be_put_allocatable_regs(irg, cls, pbqp_alloc_env.allocatable_regs);
-
 
        /* create costs matrix template for interference edges */
        ife_matrix = pbqp_matrix_alloc(pbqp_alloc_env.pbqp_inst, colors_n, colors_n);
@@ -729,7 +706,6 @@ static void be_pbqp_coloring(be_chordal_env_t *env)
 #if KAPS_DUMP
        fclose(file_before);
 #endif
-       bitset_free(pbqp_alloc_env.allocatable_regs);
        free_pbqp(pbqp_alloc_env.pbqp_inst);
        plist_free(pbqp_alloc_env.rpeo);
        xfree(pbqp_alloc_env.restr_nodes);