X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbenode.c;h=9e3e2fe6e76e1fb1971dfcf53092ffd502d85648;hb=c7c9e568001eed38d54ef24036784ef0fb90df03;hp=686fb7c107c89643b8594d364faed4d7edf2062f;hpb=282607ae076ae3534bb6aa86bff165fd5525f5ea;p=libfirm diff --git a/ir/be/benode.c b/ir/be/benode.c index 686fb7c10..9e3e2fe6e 100644 --- a/ir/be/benode.c +++ b/ir/be/benode.c @@ -59,9 +59,16 @@ typedef struct { int *pos; } be_op_t; +typedef struct { + arch_register_req_t req; + unsigned negate_limited : 1; + void (*old_limited)(void *ptr, bitset_t *bs); + void *old_limited_env; +} be_req_t; + typedef struct { const arch_register_t *reg; - arch_register_req_t req; + be_req_t req; } be_reg_data_t; typedef struct { @@ -73,8 +80,7 @@ typedef struct { typedef struct { be_node_attr_t node_attr; ir_node *spill_ctx; /**< The node in whose context this spill was introduced. */ - unsigned offset; /**< The offset of the memory location the spill writes to - in the spill area. */ + entity *ent; /**< The entity in the stack frame the spill writes to. */ } be_spill_attr_t; static ir_op *op_Spill; @@ -129,8 +135,8 @@ static void *init_node_attr(ir_node* irn, const arch_register_class_t *cls, ir_g a->reg_data = NEW_ARR_D(be_reg_data_t, get_irg_obstack(irg), n_outs); memset(a->reg_data, 0, n_outs * sizeof(a->reg_data[0])); for(i = 0; i < n_outs; ++i) { - a->reg_data[i].req.cls = cls; - a->reg_data[i].req.type = arch_register_req_type_normal; + a->reg_data[i].req.req.cls = cls; + a->reg_data[i].req.req.type = arch_register_req_type_normal; } } @@ -156,7 +162,7 @@ ir_node *be_new_Spill(const arch_register_class_t *cls, ir_graph *irg, ir_node * in[0] = to_spill; res = new_ir_node(NULL, irg, bl, op_Spill, mode_M, 1, in); a = init_node_attr(res, cls, irg, 0); - a->offset = BE_SPILL_NO_OFFSET; + a->ent = NULL; a->spill_ctx = ctx; return res; } @@ -225,20 +231,38 @@ int be_is_Keep(const ir_node *irn) return get_irn_be_opcode(irn) == beo_Keep; } -void be_set_Perm_out_req(ir_node *irn, int pos, const arch_register_req_t *req) +static void be_limited(void *data, bitset_t *bs) { - be_node_attr_t *a = get_irn_attr(irn); + be_req_t *req = data; + + req->old_limited(req->old_limited_env, bs); + if(req->negate_limited) + bitset_flip_all(bs); +} + +void be_set_Perm_out_req(ir_node *irn, int pos, const arch_register_req_t *req, unsigned negate_limited) +{ + be_node_attr_t *a = get_irn_attr(irn); + be_req_t *r = &a->reg_data[pos].req; assert(be_is_Perm(irn)); assert(pos >= 0 && pos < get_irn_arity(irn)); - memcpy(&a->reg_data[pos].req, req, sizeof(req[0])); + memcpy(&r->req, req, sizeof(req[0])); + + if(arch_register_req_is(req, limited)) { + r->old_limited = r->req.limited; + r->old_limited_env = r->req.limited_env; + r->req.limited = be_limited; + r->req.limited_env = r; + r->negate_limited = negate_limited; + } } -void be_set_Spill_offset(ir_node *irn, unsigned offset) +void be_set_Spill_entity(ir_node *irn, entity *ent) { be_spill_attr_t *a = get_irn_attr(irn); assert(be_is_Spill(irn)); - a->offset = offset; + a->ent = ent; } static ir_node *find_a_spill_walker(ir_node *irn, unsigned visited_nr) @@ -284,24 +308,23 @@ static INLINE ir_node *find_a_spill(ir_node *irn) return find_a_spill_walker(irn, visited_nr); } - -unsigned be_get_spill_offset(ir_node *irn) +entity *be_get_spill_entity(ir_node *irn) { int opc = get_irn_opcode(irn); switch(get_irn_be_opcode(irn)) { case beo_Reload: - return be_get_spill_offset(find_a_spill(irn)); + return be_get_spill_entity(find_a_spill(irn)); case beo_Spill: { be_spill_attr_t *a = get_irn_attr(irn); - return a->offset; + return a->ent; } default: assert(0 && "Must give spill/reload node"); } - return (unsigned) -1; + return NULL; } ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn, ir_node *ctx) @@ -399,7 +422,7 @@ static void *put_in_reg_req(arch_register_req_t *req, const ir_node *irn, int po } static const arch_register_req_t * -be_node_get_irn_reg_req(const arch_irn_ops_t *self, arch_register_req_t *req, const ir_node *irn, int pos) +be_node_get_irn_reg_req(const void *self, arch_register_req_t *req, const ir_node *irn, int pos) { int out_pos = pos; @@ -420,12 +443,12 @@ be_node_get_irn_reg_req(const arch_irn_ops_t *self, arch_register_req_t *req, co } static void -be_node_set_irn_reg(const arch_irn_ops_t *_self, ir_node *irn, const arch_register_t *reg) +be_node_set_irn_reg(const void *_self, ir_node *irn, const arch_register_t *reg) { int out_pos; be_node_attr_t *a; - out_pos = redir_proj(&irn, -1); + out_pos = redir_proj((const ir_node **) &irn, -1); a = get_irn_attr(irn); assert(is_be_node(irn)); @@ -434,12 +457,12 @@ be_node_set_irn_reg(const arch_irn_ops_t *_self, ir_node *irn, const arch_regist } const arch_register_t * -be_node_get_irn_reg(const arch_irn_ops_t *_self, const ir_node *irn) +be_node_get_irn_reg(const void *_self, const ir_node *irn) { int out_pos; be_node_attr_t *a; - out_pos = redir_proj(&irn, -1); + out_pos = redir_proj((const ir_node **) &irn, -1); a = get_irn_attr(irn); assert(is_be_node(irn)); @@ -448,9 +471,9 @@ be_node_get_irn_reg(const arch_irn_ops_t *_self, const ir_node *irn) return a->reg_data[out_pos].reg; } -arch_irn_class_t be_node_classify(const arch_irn_ops_t *_self, const ir_node *irn) +arch_irn_class_t be_node_classify(const void *_self, const ir_node *irn) { - redir_proj(&irn, -1); + redir_proj((const ir_node **) &irn, -1); switch(get_irn_be_opcode(irn)) { #define XXX(a,b) case beo_ ## a: return arch_irn_class_ ## b; @@ -466,12 +489,12 @@ arch_irn_class_t be_node_classify(const arch_irn_ops_t *_self, const ir_node *ir return 0; } -arch_irn_class_t be_node_get_flags(const arch_irn_ops_t *_self, const ir_node *irn) +arch_irn_class_t be_node_get_flags(const void *_self, const ir_node *irn) { return 0; } -static const arch_irn_ops_t be_node_irn_ops = { +static const arch_irn_ops_if_t be_node_irn_ops_if = { be_node_get_irn_reg_req, be_node_set_irn_reg, be_node_get_irn_reg, @@ -479,7 +502,11 @@ static const arch_irn_ops_t be_node_irn_ops = { be_node_get_flags, }; -const arch_irn_ops_t *be_node_get_arch_ops(const arch_irn_handler_t *self, const ir_node *irn) +static const arch_irn_ops_t be_node_irn_ops = { + &be_node_irn_ops_if +}; + +const void *be_node_get_arch_ops(const arch_irn_handler_t *self, const ir_node *irn) { redir_proj((const ir_node **) &irn, -1); return is_be_node(irn) ? &be_node_irn_ops : NULL; @@ -514,8 +541,9 @@ static int dump_node(ir_node *irn, FILE *f, dump_reason_t reason) if(get_irn_be_opcode(irn) == beo_Spill) { be_spill_attr_t *a = (be_spill_attr_t *) at; + unsigned ofs = get_entity_offset_bytes(a->ent); ir_fprintf(f, "spill context: %+F\n", a->spill_ctx); - ir_fprintf(f, "spill offset: %04x (%u)\n", a->offset); + ir_fprintf(f, "spill entity: %+F offset %x (%d)\n", a->ent, ofs, ofs); } break; } @@ -539,38 +567,29 @@ static const ir_op_ops be_node_op_ops = { NULL }; -ir_node *insert_Perm_after(const arch_env_t *arch_env, - const arch_register_class_t *cls, - dom_front_info_t *dom_front, - ir_node *pos) +pset *nodes_live_at(const arch_env_t *arch_env, const arch_register_class_t *cls, const ir_node *pos, pset *live) { - ir_node *bl = is_Block(pos) ? pos : get_nodes_block(pos); - ir_graph *irg = get_irn_irg(bl); - pset *live = pset_new_ptr_default(); - firm_dbg_module_t *dbg = firm_dbg_register("be.node"); - + firm_dbg_module_t *dbg = firm_dbg_register("firm.be.node"); + ir_node *bl = get_nodes_block(pos); + ir_node *irn; irn_live_t *li; - ir_node *curr, *irn, *perm, **nodes; - int i, n; - - DBG((dbg, LEVEL_1, "Insert Perm after: %+F\n", pos)); - live_foreach(bl, li) { ir_node *irn = (ir_node *) li->irn; - if(live_is_end(li) && arch_irn_has_reg_class(arch_env, irn, -1, cls)) + if(live_is_end(li) && arch_irn_consider_in_reg_alloc(arch_env, cls, irn)) pset_insert_ptr(live, irn); } sched_foreach_reverse(bl, irn) { + int i, n; ir_node *x; - /* - * If we encounter the node we want to insert the Perm after, - * exit immediately, so that this node is still live - */ + /* + * If we encounter the node we want to insert the Perm after, + * exit immediately, so that this node is still live + */ if(irn == pos) - break; + return live; DBG((dbg, LEVEL_1, "%+F\n", irn)); for(x = pset_first(live); x; x = pset_next(live)) @@ -582,11 +601,32 @@ ir_node *insert_Perm_after(const arch_env_t *arch_env, for(i = 0, n = get_irn_arity(irn); i < n; ++i) { ir_node *op = get_irn_n(irn, i); - if(arch_irn_has_reg_class(arch_env, op, -1, cls)) + if(arch_irn_consider_in_reg_alloc(arch_env, cls, op)) pset_insert_ptr(live, op); } } + return NULL; +} + +ir_node *insert_Perm_after(const arch_env_t *arch_env, + const arch_register_class_t *cls, + dom_front_info_t *dom_front, + ir_node *pos) +{ + ir_node *bl = is_Block(pos) ? pos : get_nodes_block(pos); + ir_graph *irg = get_irn_irg(bl); + pset *live = pset_new_ptr_default(); + firm_dbg_module_t *dbg = firm_dbg_register("be.node"); + + ir_node *curr, *irn, *perm, **nodes; + int i, n; + + DBG((dbg, LEVEL_1, "Insert Perm after: %+F\n", pos)); + + if(!nodes_live_at(arch_env, cls, pos, live)) + assert(0 && "position not found"); + n = pset_count(live); if(n == 0)