beinsn: Avoid copying bitsets by using a raw bitset for the admissible registers.
[libfirm] / ir / be / beinsn.c
index e72fd89..9afe833 100644 (file)
@@ -32,7 +32,6 @@
 #include "bechordal_t.h"
 #include "besched.h"
 #include "beinsn_t.h"
-#include "beirg.h"
 #include "beabi.h"
 #include "raw_bitset.h"
 
@@ -41,10 +40,11 @@ be_insn_t *be_scan_insn(be_chordal_env_t const *const env, ir_node *const irn)
        struct obstack *obst = env->obst;
        be_operand_t o;
        int i, n;
-       int pre_colored = 0;
 
        be_insn_t *insn = OALLOCZ(obst, be_insn_t);
 
+       bool has_constraints = false;
+
        insn->irn = irn;
        if (get_irn_mode(irn) == mode_T) {
                ir_node *p;
@@ -62,35 +62,23 @@ be_insn_t *be_scan_insn(be_chordal_env_t const *const env, ir_node *const irn)
                                /* found a def: create a new operand */
                                o.req             = arch_get_irn_register_req(p);
                                o.carrier         = p;
-                               o.irn             = irn;
-                               o.pos             = -(get_Proj_proj(p) + 1);
                                o.partner         = NULL;
-                               o.has_constraints = arch_register_req_is(o.req, limited) | (o.req->width > 1);
                                obstack_grow(obst, &o, sizeof(o));
                                insn->n_ops++;
-                               insn->has_constraints |= o.has_constraints;
-                               pre_colored += arch_get_irn_register(p) != NULL;
+                               has_constraints |= arch_register_req_is(o.req, limited) | (o.req->width > 1);
                        }
                }
        } else if (arch_irn_consider_in_reg_alloc(env->cls, irn)) {
                /* only one def, create one operand */
                o.req     = arch_get_irn_register_req(irn);
                o.carrier = irn;
-               o.irn     = irn;
-               o.pos     = -1;
                o.partner = NULL;
-               o.has_constraints = arch_register_req_is(o.req, limited) | (o.req->width > 1);
                obstack_grow(obst, &o, sizeof(o));
                insn->n_ops++;
-               insn->has_constraints |= o.has_constraints;
-               pre_colored += arch_get_irn_register(irn) != NULL;
+               has_constraints |= arch_register_req_is(o.req, limited) | (o.req->width > 1);
        }
 
-       if (pre_colored > 0) {
-               assert(pre_colored == insn->n_ops && "partly pre-colored nodes not supported");
-               insn->pre_colored = 1;
-       }
-       insn->use_start   = insn->n_ops;
+       insn->use_start = insn->n_ops;
 
        /* now collect the uses for this node */
        for (i = 0, n = get_irn_arity(irn); i < n; ++i) {
@@ -100,16 +88,16 @@ be_insn_t *be_scan_insn(be_chordal_env_t const *const env, ir_node *const irn)
                        /* found a register use, create an operand */
                        o.req     = arch_get_irn_register_req_in(irn, i);
                        o.carrier = op;
-                       o.irn     = irn;
-                       o.pos     = i;
                        o.partner = NULL;
-                       o.has_constraints = arch_register_req_is(o.req, limited);
                        obstack_grow(obst, &o, sizeof(o));
                        insn->n_ops++;
-                       insn->has_constraints |= o.has_constraints;
+                       has_constraints |= arch_register_req_is(o.req, limited);
                }
        }
 
+       if (!has_constraints)
+               return NULL;
+
        insn->ops = (be_operand_t*)obstack_finish(obst);
 
        /* Compute the admissible registers bitsets. */
@@ -118,13 +106,8 @@ be_insn_t *be_scan_insn(be_chordal_env_t const *const env, ir_node *const irn)
                arch_register_req_t const *const req = op->req;
                assert(req->cls == env->cls);
 
-               if (req->type & arch_register_req_type_limited) {
-                       bitset_t *regs = bitset_obstack_alloc(obst, env->cls->n_regs);
-                       rbitset_copy_to_bitset(req->limited, regs);
-                       op->regs = regs;
-               } else {
-                       op->regs = env->allocatable_regs;
-               }
+               op->regs = arch_register_req_is(req, limited) ?
+                       req->limited : env->allocatable_regs->data;
        }
 
        return insn;