bearch: Disallow passing Projs to get_irn_ops().
[libfirm] / ir / be / becopyilp2.c
index 2f7e752..455fa1a 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.
  */
 
 /**
  */
 #include "config.h"
 
+#include "be_t.h"
+#include "beintlive_t.h"
+#include "beirg.h"
 #include "bitset.h"
+#include "error.h"
 #include "raw_bitset.h"
 #include "pdeq.h"
 
@@ -68,11 +58,8 @@ static unsigned check_alignment_constraints(ir_node *node)
 {
        const arch_register_req_t *req = arch_get_irn_register_req(node);
        // For larger than 1 variables, support only aligned constraints
-       assert(((!(req->type & arch_register_req_type_aligned)
-                        && req->width == 1)
-                       || (req->type & arch_register_req_type_aligned))
-                  && "Unaligned large (width > 1) variables not supported");
-       return (req->type & arch_register_req_type_aligned) && req->width > 1;
+       assert((arch_register_req_is(req, aligned) || req->width == 1) && "Unaligned large (width > 1) variables not supported");
+       return arch_register_req_is(req, aligned) && req->width > 1;
 }
 
 static void make_color_var_name(char *buf, size_t buf_size,
@@ -88,21 +75,17 @@ static void build_coloring_cstr(ilp_env_t *ienv)
        be_ifg_t       *ifg    = ienv->co->cenv->ifg;
        unsigned        n_regs = arch_register_class_n_regs(ienv->co->cls);
        const unsigned *allocatable_colors = lenv->allocatable_colors;
-       nodes_iter_t    iter;
-       unsigned       *colors;
-       ir_node        *irn;
        char            buf[32];
 
-       rbitset_alloca(colors, n_regs);
-
-       be_ifg_foreach_node(ifg, &iter, irn) {
+       unsigned *const colors = rbitset_alloca(n_regs);
+       be_ifg_foreach_node(ifg, irn) {
                const arch_register_req_t *req;
                unsigned                   col;
                int                        cst_idx;
                unsigned                   curr_node_color;
                unsigned                   has_alignment_cstr;
 
-               if (sr_is_removed(ienv->sr, irn))
+               if (sr_is_removed(ienv, irn))
                        continue;
 
                has_alignment_cstr = check_alignment_constraints(irn);
@@ -177,7 +160,7 @@ static void build_interference_cstr(ilp_env_t *ienv)
                unsigned realsize = 0;
 
                for (i=0; i<size; ++i) {
-                       if (!sr_is_removed(ienv->sr, clique[i]))
+                       if (!sr_is_removed(ienv, clique[i]))
                                ++realsize;
                }
 
@@ -199,7 +182,7 @@ static void build_interference_cstr(ilp_env_t *ienv)
                                int      var_idx;
                                unsigned aligment_offset = 0;
 
-                               if (sr_is_removed(ienv->sr, irn))
+                               if (sr_is_removed(ienv, irn))
                                        continue;
 
                                // Use the first part of the large registers for all
@@ -240,7 +223,6 @@ static void make_affinity_var_name(char *buf, size_t buf_size,
 static void build_affinity_cstr(ilp_env_t *ienv)
 {
        unsigned  n_colors = arch_register_class_n_regs(ienv->co->cls);
-       unit_t   *curr;
 
        /* for all optimization units */
        list_for_each_entry(unit_t, curr, &ienv->co->units, units) {
@@ -348,7 +330,7 @@ static inline void remove_edge(set *edges, ir_node *n1, ir_node *n2, size_t *cou
        }
 }
 
-#define pset_foreach(pset, irn)  for (irn=(ir_node*)pset_first(pset); irn; irn=(ir_node*)pset_next(pset))
+#define pset_foreach(pset, irn) foreach_pset((pset), ir_node, (irn))
 
 /**
  * Search for an interference clique and an external node
@@ -358,9 +340,9 @@ static inline void remove_edge(set *edges, ir_node *n1, ir_node *n2, size_t *cou
 static void build_clique_star_cstr(ilp_env_t *ienv)
 {
        /* for each node with affinity edges */
+       be_lv_t *const lv = be_get_irg_liveness(ienv->co->irg);
        co_gs_foreach_aff_node(ienv->co, aff) {
                struct obstack ob;
-               neighb_t *nbr;
                const ir_node *center = aff->irn;
                ir_node **nodes;
                set *edges;
@@ -387,7 +369,7 @@ static void build_clique_star_cstr(ilp_env_t *ienv)
                n_edges = 0;
                for (i=0; i<n_nodes; ++i) {
                        for (o=0; o<i; ++o) {
-                               if (be_ifg_connected(ienv->co->cenv->ifg, nodes[i], nodes[o]))
+                               if (be_values_interfere(lv, nodes[i], nodes[o]))
                                        add_edge(edges, nodes[i], nodes[o], &n_edges);
                        }
                }
@@ -415,7 +397,6 @@ static void build_clique_star_cstr(ilp_env_t *ienv)
                                /* search for a candidate to extend the clique */
                                for (i=0; i<n_nodes; ++i) {
                                        ir_node *cand = nodes[i];
-                                       ir_node *member;
                                        bool     is_cand;
 
                                        /* if its already in the clique try the next */
@@ -448,10 +429,9 @@ static void build_clique_star_cstr(ilp_env_t *ienv)
 
                        /* now the clique is maximal. Finally add the constraint */
                        {
-                               ir_node *member;
-                               int      var_idx;
-                               int      cst_idx;
-                               char     buf[32];
+                               int  var_idx;
+                               int  cst_idx;
+                               char buf[32];
 
                                cst_idx = lpp_add_cst(ienv->lp, NULL, lpp_greater_equal, pset_count(clique)-1);
 
@@ -472,11 +452,9 @@ static void build_clique_star_cstr(ilp_env_t *ienv)
 
 static void extend_path(ilp_env_t *ienv, pdeq *path, const ir_node *irn)
 {
-       be_ifg_t *ifg = ienv->co->cenv->ifg;
        int i, len;
        ir_node **curr_path;
        affinity_node_t *aff;
-       neighb_t *nbr;
 
        /* do not walk backwards or in circles */
        if (pdeq_contains(path, irn))
@@ -493,13 +471,14 @@ static void extend_path(ilp_env_t *ienv, pdeq *path, const ir_node *irn)
        curr_path = ALLOCAN(ir_node*, len);
        pdeq_copyl(path, (const void **)curr_path);
 
+       be_lv_t *const lv = be_get_irg_liveness(ienv->co->irg);
        for (i=1; i<len; ++i) {
-               if (be_ifg_connected(ifg, irn, curr_path[i]))
+               if (be_values_interfere(lv, irn, curr_path[i]))
                        goto end;
        }
 
        /* check for terminating interference */
-       if (be_ifg_connected(ifg, irn, curr_path[0])) {
+       if (be_values_interfere(lv, irn, curr_path[0])) {
                /* One node is not a path. */
                /* And a path of length 2 is covered by a clique star constraint. */
                if (len > 2) {
@@ -552,7 +531,7 @@ static void ilp2_build(ilp_env_t *ienv)
 {
        int lower_bound;
 
-       ienv->lp = lpp_new(ienv->co->name, lpp_minimize);
+       ienv->lp = lpp_new("copyilp", lpp_minimize);
        build_coloring_cstr(ienv);
        build_interference_cstr(ienv);
        build_affinity_cstr(ienv);
@@ -576,8 +555,7 @@ static void ilp2_apply(ilp_env_t *ienv)
                int              i;
 
                if (state != lpp_optimal) {
-                       printf("WARNING %s: Solution state is not 'optimal': %d\n",
-                              ienv->co->name, (int)state);
+                       ir_printf("WARNING: Solution state of %F register class %s is not 'optimal': %d\n", ienv->co->irg, ienv->co->cls->name, (int)state);
                        if (state < lpp_feasible) {
                                panic("Copy coalescing solution not feasible!");
                        }
@@ -620,7 +598,6 @@ static void ilp2_apply(ilp_env_t *ienv)
  */
 static int co_solve_ilp2(copy_opt_t *co)
 {
-       unsigned       *allocatable_colors;
        unsigned        n_regs = arch_register_class_n_regs(co->cls);
        lpp_sol_state_t sol_state;
        ilp_env_t      *ienv;
@@ -633,7 +610,7 @@ static int co_solve_ilp2(copy_opt_t *co)
        my.last_x_var  = -1;
        FIRM_DBG_REGISTER(dbg, "firm.be.coilp2");
 
-       rbitset_alloca(allocatable_colors, n_regs);
+       unsigned *const allocatable_colors = rbitset_alloca(n_regs);
        be_set_allocatable_regs(co->irg, co->cls, allocatable_colors);
        my.allocatable_colors = allocatable_colors;