slightly optimize liveness code
authorMatthias Braun <matze@braunis.de>
Mon, 26 Nov 2012 18:01:40 +0000 (19:01 +0100)
committerMatthias Braun <matze@braunis.de>
Mon, 26 Nov 2012 18:04:19 +0000 (19:04 +0100)
- save ir_node* instead of irn_idx in the map (saves irn_idx_map
  lookups)
- in liveness_transfer check register class on the inputs (which is
  cheaper) and only then check the operand

ir/be/bedump.c
ir/be/belive.c
ir/be/belive_t.h
ir/be/beverify.c

index 1e43f38..486ca8a 100644 (file)
@@ -161,7 +161,7 @@ void be_dump_liveness_block(void *context, FILE *F, const ir_node *bl)
 
                        for (i = 0; i < n; ++i) {
                                be_lv_info_node_t *n = &info[i+1].node;
-                               ir_fprintf(F, "%s %+F\n", lv_flags_to_str(n->flags), get_idx_irn(lv->irg, n->idx));
+                               ir_fprintf(F, "%s %+F\n", lv_flags_to_str(n->flags), n->node);
                        }
                }
        }
index bcc28f5..6d18c32 100644 (file)
@@ -83,7 +83,7 @@ int (be_is_live_end)(const be_lv_t *lv, const ir_node *block, const ir_node *irn
        return _be_is_live_xxx(lv, block, irn, be_lv_state_end);
 }
 
-static inline unsigned _be_liveness_bsearch(be_lv_info_t *arr, unsigned idx)
+static inline unsigned _be_liveness_bsearch(be_lv_info_t *arr, const ir_node *node)
 {
        be_lv_info_t *payload = arr + 1;
 
@@ -96,16 +96,15 @@ static inline unsigned _be_liveness_bsearch(be_lv_info_t *arr, unsigned idx)
                return 0;
 
        do {
-               int md          = lo + ((hi - lo) >> 1);
-               unsigned md_idx = payload[md].node.idx;
+               int md           = lo + ((hi - lo) >> 1);
+               ir_node *md_node = payload[md].node.node;
 
-               if (idx > md_idx)
+               if (node > md_node)
                        lo = md + 1;
-               else if (idx < md_idx)
+               else if (node < md_node)
                        hi = md;
                else {
                        res = md;
-                       assert(payload[res].node.idx == idx);
                        break;
                }
 
@@ -124,16 +123,14 @@ be_lv_info_node_t *be_lv_get(const be_lv_t *li, const ir_node *bl,
        stat_ev_tim_push();
        irn_live = ir_nodehashmap_get(be_lv_info_t, &li->map, bl);
        if (irn_live != NULL) {
-               unsigned idx = get_irn_idx(irn);
-
                /* Get the position of the index in the array. */
-               int pos = _be_liveness_bsearch(irn_live, idx);
+               int pos = _be_liveness_bsearch(irn_live, irn);
 
                /* Get the record in question. 1 must be added, since the first record contains information about the array and must be skipped. */
                be_lv_info_node_t *rec = &irn_live[pos + 1].node;
 
                /* Check, if the irn is in deed in the array. */
-               if (rec->idx == idx)
+               if (rec->node == irn)
                        res = rec;
        }
        stat_ev_tim_pop("be_lv_get");
@@ -151,16 +148,14 @@ static be_lv_info_node_t *be_lv_get_or_set(be_lv_t *li, ir_node *bl,
                ir_nodehashmap_insert(&li->map, bl, irn_live);
        }
 
-       unsigned idx = get_irn_idx(irn);
-
        /* Get the position of the index in the array. */
-       unsigned pos = _be_liveness_bsearch(irn_live, idx);
+       unsigned pos = _be_liveness_bsearch(irn_live, irn);
 
        /* Get the record in question. 1 must be added, since the first record contains information about the array and must be skipped. */
        be_lv_info_node_t *res = &irn_live[pos + 1].node;
 
        /* Check, if the irn is in deed in the array. */
-       if (res->idx != idx) {
+       if (res->node != irn) {
                be_lv_info_t *payload;
                unsigned n_members = irn_live[0].head.n_members;
                unsigned n_size    = irn_live[0].head.n_size;
@@ -188,9 +183,9 @@ static be_lv_info_node_t *be_lv_get_or_set(be_lv_t *li, ir_node *bl,
 
                ++irn_live[0].head.n_members;
 
-               res = &payload[pos].node;
-               res->idx    = idx;
-               res->flags  = 0;
+               res        = &payload[pos].node;
+               res->node  = irn;
+               res->flags = 0;
        }
 
        return res;
@@ -207,19 +202,18 @@ static int be_lv_remove(be_lv_t *li, const ir_node *bl,
 
        if (irn_live != NULL) {
                unsigned n   = irn_live[0].head.n_members;
-               unsigned idx = get_irn_idx(irn);
-               unsigned pos = _be_liveness_bsearch(irn_live, idx);
+               unsigned pos = _be_liveness_bsearch(irn_live, irn);
                be_lv_info_t *payload  = irn_live + 1;
                be_lv_info_node_t *res = &payload[pos].node;
 
                /* The node is in deed in the block's array. Let's remove it. */
-               if (res->idx == idx) {
+               if (res->node == irn) {
                        unsigned i;
 
                        for (i = pos + 1; i < n; ++i)
                                payload[i - 1] = payload[i];
 
-                       payload[n - 1].node.idx   = 0;
+                       payload[n - 1].node.node  = NULL;
                        payload[n - 1].node.flags = 0;
 
                        --irn_live[0].head.n_members;
@@ -519,8 +513,12 @@ void be_liveness_transfer(const arch_register_class_t *cls,
 
        int arity = get_irn_arity(node);
        for (int i = 0; i < arity; ++i) {
-               ir_node *op = get_irn_n(node, i);
-               if (!arch_irn_consider_in_reg_alloc(cls, op))
+               const arch_register_req_t *in_req = arch_get_irn_register_req_in(node, i);
+               if (in_req->cls != cls)
+                       continue;
+               ir_node                   *op     = get_irn_n(node, i);
+               const arch_register_req_t *op_req = arch_get_irn_register_req(op);
+               if (op_req->type & arch_register_req_type_ignore)
                        continue;
                ir_nodeset_insert(nodeset, op);
        }
index e573e35..4e1d22f 100644 (file)
@@ -47,7 +47,7 @@ struct be_lv_t {
 
 typedef struct be_lv_info_node_t be_lv_info_node_t;
 struct be_lv_info_node_t {
-       unsigned idx;
+       ir_node *node;
        unsigned flags;
 };
 
@@ -82,35 +82,31 @@ static inline unsigned _be_is_live_xxx(const be_lv_t *li, const ir_node *block,
 typedef struct lv_iterator_t
 {
        be_lv_info_t *info;
-       ir_graph     *irg;
-       be_lv_state_t flags;
        size_t        i;
 } lv_iterator_t;
 
 static inline lv_iterator_t be_lv_iteration_begin(const be_lv_t *lv,
-       const ir_node *block, be_lv_state_t flags)
+       const ir_node *block)
 {
        lv_iterator_t res;
        res.info  = ir_nodehashmap_get(be_lv_info_t, &lv->map, block);
-       res.irg   = get_Block_irg(block);
-       res.flags = flags;
        res.i     = res.info != NULL ? res.info[0].head.n_members : 0;
        return res;
 }
 
-static inline ir_node *be_lv_iteration_next(lv_iterator_t *iterator)
+static inline ir_node *be_lv_iteration_next(lv_iterator_t *iterator, be_lv_state_t flags)
 {
        while (iterator->i != 0) {
                const be_lv_info_t *info = iterator->info + iterator->i--;
-               if (info->node.flags & iterator->flags)
-                       return get_idx_irn(iterator->irg, info->node.idx);
+               if (info->node.flags & flags)
+                       return info->node.node;
        }
        return NULL;
 }
 
 #define be_lv_foreach(lv, block, flags, node) \
        for (bool once = true; once;) \
-               for (lv_iterator_t iter = be_lv_iteration_begin((lv), (block), (flags)); once; once = false) \
-                       for (ir_node *node; (node = be_lv_iteration_next(&iter)) != NULL;)
+               for (lv_iterator_t iter = be_lv_iteration_begin((lv), (block)); once; once = false) \
+                       for (ir_node *node; (node = be_lv_iteration_next(&iter, (flags))) != NULL;)
 
 #endif
index 44c4b34..dcda129 100644 (file)
@@ -836,7 +836,6 @@ static const char *lv_flags_to_str(unsigned flags)
 static void lv_check_walker(ir_node *bl, void *data)
 {
        lv_walker_t *w     = (lv_walker_t*)data;
-       be_lv_t     *lv    = w->lv;
        be_lv_t     *fresh = (be_lv_t*)w->data;
 
        be_lv_info_t *curr = ir_nodehashmap_get(be_lv_info_t, &fresh->map, bl);
@@ -845,7 +844,7 @@ static void lv_check_walker(ir_node *bl, void *data)
        if (!fr && curr && curr[0].head.n_members > 0) {
                ir_fprintf(stderr, "%+F liveness should be empty but current liveness contains:\n", bl);
                for (unsigned i = 0; i < curr[0].head.n_members; ++i) {
-                       ir_fprintf(stderr, "\t%+F\n", get_idx_irn(lv->irg, curr[1 + i].node.idx));
+                       ir_fprintf(stderr, "\t%+F\n", curr[1 + i].node.node);
                }
        } else if (curr) {
                unsigned n_curr  = curr[0].head.n_members;
@@ -857,13 +856,13 @@ static void lv_check_walker(ir_node *bl, void *data)
                        ir_fprintf(stderr, "current:\n");
                        for (unsigned i = 0; i < n_curr; ++i) {
                                be_lv_info_node_t *n = &curr[1 + i].node;
-                               ir_fprintf(stderr, "%+F %u %+F %s\n", bl, i, get_idx_irn(lv->irg, n->idx), lv_flags_to_str(n->flags));
+                               ir_fprintf(stderr, "%+F %u %+F %s\n", bl, i, n->node, lv_flags_to_str(n->flags));
                        }
 
                        ir_fprintf(stderr, "correct:\n");
                        for (unsigned i = 0; i < n_fresh; ++i) {
                                be_lv_info_node_t *n = &fr[1 + i].node;
-                               ir_fprintf(stderr, "%+F %u %+F %s\n", bl, i, get_idx_irn(lv->irg, n->idx), lv_flags_to_str(n->flags));
+                               ir_fprintf(stderr, "%+F %u %+F %s\n", bl, i, n->node, lv_flags_to_str(n->flags));
                        }
                }
        }