X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbeinsn.c;h=bbe72e92a1399230240f9d08e78effff34651b87;hb=fef8dc3eff6468d7d65485af8e1ac9884c504e1a;hp=4eee0429573ad920c547e3c90da9c2ff23d9ad6e;hpb=1a3b7d363474ab544c13093a2f0b578718d37c7a;p=libfirm diff --git a/ir/be/beinsn.c b/ir/be/beinsn.c index 4eee04295..bbe72e92a 100644 --- a/ir/be/beinsn.c +++ b/ir/be/beinsn.c @@ -21,7 +21,6 @@ * @file * @brief A data structure to treat nodes and node-proj collections uniformly. * @author Sebastian Hack - * @version $Id$ */ #include "config.h" @@ -30,159 +29,58 @@ #include "irnode_t.h" #include "iredges.h" +#include "bechordal_t.h" #include "besched.h" #include "beinsn_t.h" -#include "beirg.h" #include "beabi.h" #include "raw_bitset.h" -/** - * Add machine operands to the instruction uses. - * - * @param env the insn construction environment - * @param insn the be_insn that is build - * @param mach_op the machine operand for which uses are added - */ -static void add_machine_operands(const be_insn_env_t *env, be_insn_t *insn, ir_node *mach_op) -{ - struct obstack *obst = env->obst; - int i, n; - - for (i = 0, n = get_irn_arity(mach_op); i < n; ++i) { - ir_node *op = get_irn_n(mach_op, i); - - if (is_irn_machine_operand(op)) { - add_machine_operands(env, insn, op); - } else if (arch_irn_consider_in_reg_alloc(env->cls, op)) { - be_operand_t o; - - /* found a register use, create an operand */ - o.req = arch_get_register_req(mach_op, i); - o.carrier = op; - o.irn = insn->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->in_constraints |= o.has_constraints; - } - } -} - -/** - * Create a be_insn_t for an IR node. - * - * @param env the insn construction environment - * @param irn the irn for which the be_insn should be build - * - * @return the be_insn for the IR node - */ -be_insn_t *be_scan_insn(const be_insn_env_t *env, ir_node *irn) +be_insn_t *be_scan_insn(be_chordal_env_t *const env, ir_node *const irn) { - struct obstack *obst = env->obst; + struct obstack *const obst = &env->obst; be_operand_t o; - be_insn_t *insn; - int i, n; - int pre_colored = 0; - - insn = OALLOCZ(obst, be_insn_t); - - insn->irn = irn; - insn->next_insn = sched_next(irn); - if (get_irn_mode(irn) == mode_T) { - const ir_edge_t *edge; - ir_node *p; - /* This instruction might create more than one def. These are handled - by Proj's, find them. */ - foreach_out_edge(irn, edge) { - p = get_edge_src_irn(edge); + be_insn_t *insn = OALLOCZ(obst, be_insn_t); - /* did not work if the result is a ProjT. This should NOT happen - in the backend, but check it for now. */ - assert(get_irn_mode(p) != mode_T); + bool has_constraints = false; - if (arch_irn_consider_in_reg_alloc(env->cls, p)) { - /* found a def: create a new operand */ - o.req = arch_get_register_req_out(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); - obstack_grow(obst, &o, sizeof(o)); - insn->n_ops++; - insn->out_constraints |= o.has_constraints; - pre_colored += arch_get_irn_register(p) != NULL; - } + const arch_register_class_t *cls = env->cls; + insn->irn = irn; + be_foreach_definition(irn, cls, p, req, + /* found a def: create a new operand */ + if (arch_register_req_is(req, limited)) { + o.regs = req->limited; + has_constraints = true; + } else { + o.regs = env->allocatable_regs->data; + has_constraints |= req->width > 1; } - } else if (arch_irn_consider_in_reg_alloc(env->cls, irn)) { - /* only one def, create one operand */ - o.req = arch_get_register_req_out(irn); - o.carrier = irn; - o.irn = irn; - o.pos = -1; + o.carrier = p; o.partner = NULL; - o.has_constraints = arch_register_req_is(o.req, limited); obstack_grow(obst, &o, sizeof(o)); insn->n_ops++; - insn->out_constraints |= o.has_constraints; - pre_colored += arch_get_irn_register(irn) != NULL; - } + ); - 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) { - ir_node *op = get_irn_n(irn, i); - - if (is_irn_machine_operand(op)) { - add_machine_operands(env, insn, op); - } else if (arch_irn_consider_in_reg_alloc(env->cls, op)) { - /* found a register use, create an operand */ - o.req = arch_get_register_req(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->in_constraints |= o.has_constraints; - } - } - - insn->has_constraints = insn->in_constraints | insn->out_constraints; - insn->ops = (be_operand_t*)obstack_finish(obst); - - /* Compute the admissible registers bitsets. */ - for (i = 0; i < insn->n_ops; ++i) { - be_operand_t *op = &insn->ops[i]; - const arch_register_req_t *req = op->req; - const arch_register_class_t *cls = req->cls; - arch_register_req_type_t type = req->type; - - /* If there is no special requirement, we allow current class here */ - if (cls == NULL && req->type == arch_register_req_type_none) { - cls = env->cls; - type = arch_register_req_type_normal; - } - - assert(cls == env->cls); - - if (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; + be_foreach_use(irn, cls, in_req, op, op_req, + /* found a register use, create an operand */ + if (arch_register_req_is(in_req, limited)) { + o.regs = in_req->limited; + has_constraints = true; } else { - op->regs = env->allocatable_regs; + o.regs = env->allocatable_regs->data; } - } + o.carrier = op; + o.partner = NULL; + obstack_grow(obst, &o, sizeof(o)); + insn->n_ops++; + ); + + if (!has_constraints) + return NULL; + insn->ops = (be_operand_t*)obstack_finish(obst); return insn; }