X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbeinsn.c;h=9afe833373d0ef156c6f9a85d72114e783348e93;hb=8056dd449bd30b35879d86e0a0a37a3bf0821c5b;hp=c219a82f6c974b706837e4c8924a459301fc0a1d;hpb=4d5c3365a58cba59993045a9e08e686d8ae079a7;p=libfirm diff --git a/ir/be/beinsn.c b/ir/be/beinsn.c index c219a82f6..9afe83337 100644 --- a/ir/be/beinsn.c +++ b/ir/be/beinsn.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -17,130 +17,98 @@ * PURPOSE. */ -#ifdef HAVE_CONFIG_H +/** + * @file + * @brief A data structure to treat nodes and node-proj collections uniformly. + * @author Sebastian Hack + */ #include "config.h" -#endif #include "irgraph_t.h" #include "irmode_t.h" #include "irnode_t.h" +#include "iredges.h" -#include "besched_t.h" +#include "bechordal_t.h" +#include "besched.h" #include "beinsn_t.h" -#include "beirg_t.h" #include "beabi.h" #include "raw_bitset.h" -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 *const env, ir_node *const irn) { - const arch_env_t *arch_env = env->aenv; - struct obstack *obst = env->obst; + struct obstack *obst = env->obst; be_operand_t o; - be_insn_t *insn; int i, n; - int pre_colored = 0; - insn = obstack_alloc(obst, sizeof(insn[0])); - memset(insn, 0, sizeof(insn[0])); + be_insn_t *insn = OALLOCZ(obst, be_insn_t); + + bool has_constraints = false; - insn->irn = irn; - insn->next_insn = sched_next(irn); - if(get_irn_mode(irn) == mode_T) { + insn->irn = irn; + if (get_irn_mode(irn) == mode_T) { ir_node *p; - for(p = sched_next(irn); is_Proj(p); p = sched_next(p)) { - if(arch_irn_consider_in_reg_alloc(arch_env, env->cls, p)) { - o.req = arch_get_register_req(arch_env, p, -1); + /* 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); + + /* 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); + + if (arch_irn_consider_in_reg_alloc(env->cls, p)) { + /* 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); obstack_grow(obst, &o, sizeof(o)); insn->n_ops++; - insn->out_constraints |= o.has_constraints; - pre_colored += arch_get_irn_register(arch_env, p) != NULL; + has_constraints |= arch_register_req_is(o.req, limited) | (o.req->width > 1); } } - - insn->next_insn = p; - } else if(arch_irn_consider_in_reg_alloc(arch_env, env->cls, irn)) { - o.req = arch_get_register_req(arch_env, irn, -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); obstack_grow(obst, &o, sizeof(o)); insn->n_ops++; - insn->out_constraints |= o.has_constraints; - pre_colored += arch_get_irn_register(arch_env, 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; - for(i = 0, n = get_irn_arity(irn); i < n; ++i) { + /* 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(!arch_irn_consider_in_reg_alloc(arch_env, env->cls, op)) - continue; - - o.req = arch_get_register_req(arch_env, 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; + if (arch_irn_consider_in_reg_alloc(env->cls, op)) { + /* found a register use, create an operand */ + o.req = arch_get_irn_register_req_in(irn, i); + o.carrier = op; + o.partner = NULL; + obstack_grow(obst, &o, sizeof(o)); + insn->n_ops++; + has_constraints |= arch_register_req_is(o.req, limited); + } } - insn->has_constraints = insn->in_constraints | insn->out_constraints; - insn->ops = obstack_finish(obst); + if (!has_constraints) + return NULL; + + 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); - - op->regs = bitset_obstack_alloc(obst, env->cls->n_regs); + be_operand_t *const op = &insn->ops[i]; + arch_register_req_t const *const req = op->req; + assert(req->cls == env->cls); - if (type & arch_register_req_type_limited) { - rbitset_copy_to_bitset(req->limited, op->regs); - } else { - arch_put_non_ignore_regs(arch_env, env->cls, op->regs); - if (env->ignore_colors) - bitset_andnot(op->regs, env->ignore_colors); - } + op->regs = arch_register_req_is(req, limited) ? + req->limited : env->allocatable_regs->data; } return insn; } - -be_insn_env_t *be_insn_env_init(be_insn_env_t *ie, const be_irg_t *birg, - const arch_register_class_t *cls, - struct obstack *obst) -{ - ie->aenv = be_get_birg_arch_env(birg); - ie->cls = cls; - ie->obst = obst; - ie->ignore_colors = bitset_obstack_alloc(obst, cls->n_regs); - be_abi_put_ignore_regs(birg->abi, cls, ie->ignore_colors); - - return ie; -}