- const be_chordal_env_t *chordal_env;
- struct obstack obst;
- set *spill_ctxs;
- set *spills; /**< all spill_info_t's, which must be placed */
- pset *mem_phis; /**< set of all special spilled phis. allocated and freed seperately */
- decide_irn_t is_mem_phi; /**< callback func to decide if a phi needs special spilling */
- void *data; /**< data passed to all callbacks */
-};
-
-static int cmp_spillctx(const void *a, const void *b, size_t n) {
- const spill_ctx_t *p = a;
- const spill_ctx_t *q = b;
- return !(p->user == q->user && p->spilled == q->spilled);
-}
-
-static int cmp_spillinfo(const void *x, const void *y, size_t size) {
- const spill_info_t *xx = x;
- const spill_info_t *yy = y;
- return ! (xx->spilled_node == yy->spilled_node);
-}
-
-spill_env_t *be_new_spill_env(firm_dbg_module_t *dbg,
- const be_chordal_env_t *chordal_env,
- decide_irn_t is_mem_phi, void *data) {
-
- spill_env_t *env = malloc(sizeof(env[0]));
- env->spill_ctxs = new_set(cmp_spillctx, 1024);
- env->spills = new_set(cmp_spillinfo, 1024);
- env->cls = chordal_env->cls;
- env->dbg = dbg;
- env->is_mem_phi = is_mem_phi;
- env->data = data;
- env->chordal_env = chordal_env;
- obstack_init(&env->obst);
- return env;
-}
-
-void be_delete_spill_env(spill_env_t *senv) {
- del_set(senv->spill_ctxs);
- del_set(senv->spills);
- obstack_free(&senv->obst, NULL);
- free(senv);
-}
-
-static spill_ctx_t *be_get_spill_ctx(set *sc, ir_node *to_spill, ir_node *ctx_irn) {
- spill_ctx_t templ;
-
- templ.spilled = to_spill;
- templ.user = ctx_irn;
- templ.spill = NULL;
-
- return set_insert(sc, &templ, sizeof(templ), HASH_COMBINE(HASH_PTR(to_spill), HASH_PTR(ctx_irn)));
-}
-
-static ir_node *be_spill_irn(spill_env_t *senv, ir_node *irn, ir_node *ctx_irn) {
- spill_ctx_t *ctx;
- DBG((senv->dbg, LEVEL_1, "%+F in ctx %+F\n", irn, ctx_irn));
-
- ctx = be_get_spill_ctx(senv->spill_ctxs, irn, ctx_irn);
- if(!ctx->spill) {
- const be_main_env_t *env = senv->chordal_env->birg->main_env;
- ctx->spill = be_spill(env->arch_env, irn, ctx_irn);
- }
-
- return ctx->spill;
-}
-
-/**
- * If the first usage of a phi result would be out of memory
- * there is no sense in allocating a register for it.
- * Thus we spill it and all its operands to the same spill slot.
- * Therefore the phi/dataB becomes a phi/Memory
- */
-static ir_node *be_spill_phi(spill_env_t *senv, ir_node *phi, ir_node *ctx_irn) {
- int i, n = get_irn_arity(phi);
- ir_node **ins, *bl = get_nodes_block(phi);
- ir_graph *irg = senv->chordal_env->irg;
- spill_ctx_t *ctx;
-
- assert(is_Phi(phi));
- DBG((senv->dbg, LEVEL_1, "%+F in ctx %+F\n", phi, ctx_irn));
-
- /* search an existing spill for this context */
- ctx = be_get_spill_ctx(senv->spill_ctxs, phi, ctx_irn);
-
- /* if not found spill the phi */
- if(!ctx->spill) {
- /* build a new PhiM with dummy in-array */
- ins = malloc(n * sizeof(ins[0]));
- for(i=0; i<n; ++i)
- ins[i] = new_r_Unknown(irg, mode_M);
- ctx->spill = new_r_Phi(senv->chordal_env->irg, bl, n, ins, mode_M);
- free(ins);
-
- /* re-wire the phiM */
- for(i=0; i<n; ++i) {
- ir_node *arg = get_irn_n(phi, i);
- ir_node *sub_res;
-
- if(is_Phi(arg) && pset_find_ptr(senv->mem_phis, arg))
- sub_res = be_spill_phi(senv, arg, ctx_irn);
- else
- sub_res = be_spill_irn(senv, arg, ctx_irn);
-
- set_irn_n(ctx->spill, i, sub_res);
- }
- }
- return ctx->spill;
-}
-
-static ir_node *be_spill_node(spill_env_t *senv, ir_node *to_spill) {
- ir_node *res;
- if (pset_find_ptr(senv->mem_phis, to_spill))
- res = be_spill_phi(senv, to_spill, to_spill);
- else
- res = be_spill_irn(senv, to_spill, to_spill);
-
- return res;
-}
-
-static void phi_walker(ir_node *irn, void *env) {
- spill_env_t *senv = env;
- const arch_env_t *arch = senv->chordal_env->birg->main_env->arch_env;
-
- if (is_Phi(irn) && arch_irn_has_reg_class(arch, irn, 0, senv->cls)
- && senv->is_mem_phi(irn, senv->data)) {
- DBG((senv->dbg, LEVEL_1, " %+F\n", irn));
- pset_insert_ptr(senv->mem_phis, irn);
+} be_pre_spill_env_t;
+
+static void prepare_constr_insn(be_pre_spill_env_t *env, ir_node *node)
+{
+ const arch_register_class_t *cls = env->cls;
+ ir_node *block = get_nodes_block(node);
+ const ir_graph *irg = env->irg;
+ be_irg_t *birg = be_birg_from_irg(irg);
+ be_lv_t *lv = be_get_irg_liveness(irg);
+ unsigned *tmp = NULL;
+ unsigned *def_constr = NULL;
+ int arity = get_irn_arity(node);
+ ir_node *def;
+
+ int i, i2;
+
+ /* Insert a copy for constraint inputs attached to a value which can't
+ * fulfill the constraint
+ * (typical example: stack pointer as input to copyb)
+ * TODO: This really just checks precolored registers at the moment and
+ * ignores the general case of not matching in/out constraints
+ */
+ for (i = 0; i < arity; ++i) {
+ ir_node *op = get_irn_n(node, i);
+ const arch_register_req_t *req = arch_get_irn_register_req_in(node, i);
+ const arch_register_t *reg;
+ ir_node *copy;
+
+ if (req->cls != cls)
+ continue;
+ reg = arch_get_irn_register(op);
+ if (reg == NULL)
+ continue;
+
+ /* precolored with an ignore register (which is not a joker like
+ unknown/noreg) */
+ if ((reg->type & arch_register_type_joker) ||
+ rbitset_is_set(birg->allocatable_regs, reg->global_index))
+ continue;
+
+ if (! (req->type & arch_register_req_type_limited))
+ continue;
+ if (rbitset_is_set(req->limited, reg->index))
+ continue;
+
+ copy = be_new_Copy(block, op);
+ stat_ev_int("constr_copy", 1);
+ sched_add_before(node, copy);
+ set_irn_n(node, i, copy);
+ DBG((dbg, LEVEL_3, "inserting ignore arg copy %+F for %+F pos %d\n",
+ copy, node, i));