beinsn: Avoid copying bitsets by using a raw bitset for the admissible registers.
authorChristoph Mallon <christoph.mallon@gmx.de>
Sun, 25 Nov 2012 16:14:41 +0000 (17:14 +0100)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sun, 25 Nov 2012 16:14:41 +0000 (17:14 +0100)
ir/adt/raw_bitset.h
ir/be/bechordal.c
ir/be/beinsn.c
ir/be/beinsn_t.h

index 3c6e432..8af6662 100644 (file)
@@ -562,4 +562,13 @@ static inline void rbitset_copy_into(unsigned *dst, const unsigned *src,
        dst[n-1] = (src[n-1] & last_mask) | (dst[n-1] & ~last_mask);
 }
 
+/**
+ * Convenience macro for raw bitset iteration.
+ * @param bitset The bitset.
+ * @param size   Size of the bitset.
+ * @param elm    A size_t variable.
+ */
+#define rbitset_foreach(bitset, size, elm) \
+       for (size_t elm = 0; (elm = rbitset_next_max((bitset), elm, size, 1)) != (size_t)-1; ++elm)
+
 #endif
index 54e59b1..ed88821 100644 (file)
@@ -50,14 +50,14 @@ static int get_next_free_reg(bitset_t *const available)
        return bitset_next_set(available, 0);
 }
 
-static bitset_t const *get_decisive_partner_regs(be_operand_t const *const o1)
+static unsigned const *get_decisive_partner_regs(be_operand_t const *const o1, size_t const n_regs)
 {
        be_operand_t const *const o2 = o1->partner;
        assert(!o2 || o1->req->cls == o2->req->cls);
 
-       if (!o2 || bitset_contains(o1->regs, o2->regs)) {
+       if (!o2 || rbitset_contains(o1->regs, o2->regs, n_regs)) {
                return o1->regs;
-       } else if (bitset_contains(o2->regs, o1->regs)) {
+       } else if (rbitset_contains(o2->regs, o1->regs, n_regs)) {
                return o2->regs;
        } else {
                return NULL;
@@ -69,7 +69,7 @@ static void pair_up_operands(be_chordal_env_t const *const env, be_insn_t *const
        /* For each out operand, try to find an in operand which can be assigned the
         * same register as the out operand. */
        int       const n_regs = env->cls->n_regs;
-       bitset_t *const bs     = bitset_alloca(n_regs);
+       unsigned *const bs     = rbitset_alloca(n_regs);
        be_lv_t  *const lv     = be_get_irg_liveness(env->irg);
        for (int j = 0; j < insn->use_start; ++j) {
                /* Try to find an in operand which has ... */
@@ -81,10 +81,10 @@ static void pair_up_operands(be_chordal_env_t const *const env, be_insn_t *const
                        if (op->partner || be_values_interfere(lv, insn->irn, op->carrier))
                                continue;
 
-                       bitset_copy(bs, op->regs);
-                       bitset_and(bs, out_op->regs);
-                       int const n_total = bitset_popcount(op->regs);
-                       if (!bitset_is_empty(bs) && n_total < smallest_n_regs) {
+                       rbitset_copy(bs, op->regs, n_regs);
+                       rbitset_and(bs, out_op->regs, n_regs);
+                       int const n_total = rbitset_popcount(op->regs, n_regs);
+                       if (!rbitset_is_empty(bs, n_regs) && n_total < smallest_n_regs) {
                                smallest        = op;
                                smallest_n_regs = n_total;
                        }
@@ -162,11 +162,11 @@ static void handle_constraints(be_chordal_env_t *const env, ir_node *const irn)
 
                DBG((dbg, LEVEL_2, "\tassociating %+F and %+F\n", op->carrier, partner));
 
-               bitset_t const *const bs = get_decisive_partner_regs(op);
+               unsigned const *const bs = get_decisive_partner_regs(op, n_regs);
                if (bs) {
                        DBG((dbg, LEVEL_2, "\tallowed registers for %+F: %B\n", op->carrier, bs));
 
-                       bitset_foreach(bs, col) {
+                       rbitset_foreach(bs, n_regs, col) {
 #if USE_HUNGARIAN
                                hungarian_add(bp, n_alloc, col, 1);
 #else
index 78a9b6b..9afe833 100644 (file)
@@ -106,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;
index fec66ba..35c3bf7 100644 (file)
@@ -38,7 +38,7 @@ typedef struct be_insn_t     be_insn_t;
 struct be_operand_t {
        ir_node *carrier;               /**< node representing the operand value (Proj or the node itself for defs, the used value for uses) */
        be_operand_t *partner;          /**< used in bechordal later... (TODO what does it do?) */
-       const bitset_t *regs;           /**< admissible register bitset */
+       unsigned const *regs;           /**< admissible register bitset */
        const arch_register_req_t *req; /**< register constraints for the carrier node */
 };