+ be_chordal_env_t *env = alloc_env->chordal_env;
+ void *base = obstack_base(&env->obst);
+ insn_t *insn = scan_insn(env, irn, &env->obst);
+ ir_node *res = insn->next_insn;
+
+ if(insn->has_constraints) {
+ firm_dbg_module_t *dbg = firm_dbg_register("firm.be.chordal.constr");
+ const arch_env_t *aenv = env->birg->main_env->arch_env;
+ int n_regs = env->cls->n_regs;
+ bitset_t *bs = bitset_alloca(n_regs);
+ ir_node **alloc_nodes = alloca(n_regs * sizeof(alloc_nodes[0]));
+ bipartite_t *bp = bipartite_new(n_regs, n_regs);
+ int *assignment = alloca(n_regs * sizeof(assignment[0]));
+ pmap *partners = pmap_create();
+
+ int i, n_alloc;
+ long col;
+ const ir_edge_t *edge;
+ ir_node *perm = insert_Perm_after(aenv, env->cls, env->dom_front, sched_prev(irn));
+
+ /* Registers are propagated by insert_Perm_after(). Clean them here! */
+ if(perm) {
+ foreach_out_edge(perm, edge) {
+ ir_node *proj = get_edge_src_irn(edge);
+ arch_set_irn_register(aenv, proj, NULL);
+ }
+ }
+
+
+ be_liveness(env->irg);
+ insn = scan_insn(env, irn, &env->obst);
+
+ DBG((dbg, LEVEL_1, "handling constraints for %+F\n", irn));
+
+ /*
+ * If there was no Perm made, nothing was alive in this register class.
+ * This means, that the node has no operands, thus no input constraints.
+ * so it had output constraints. The other results then can be assigned freeliy.
+ */
+
+ pair_up_operands(insn);
+
+ for(i = 0, n_alloc = 0; i < insn->n_ops; ++i) {
+ operand_t *op = &insn->ops[i];
+ if(arch_register_req_is(&op->req, limited)) {
+ pmap_insert(partners, op->carrier, op->partner ? op->partner->carrier : NULL);
+ alloc_nodes[n_alloc] = op->carrier;
+
+ DBG((dbg, LEVEL_2, "\tassociating %+F and %+F\n", op->carrier, pmap_get(partners, op->carrier)));
+
+ bitset_clear_all(bs);
+ op->req.limited(op->req.limited_env, bs);
+
+ DBG((dbg, LEVEL_2, "\tallowed registers for %+F: %B\n", op->carrier, bs));
+
+ bitset_foreach(bs, col)
+ bipartite_add(bp, n_alloc, col);
+
+ n_alloc++;
+ }
+ }
+
+ if(perm) {
+ foreach_out_edge(perm, edge) {
+ ir_node *proj = get_edge_src_irn(edge);
+
+ assert(is_Proj(proj));
+
+ if(values_interfere(proj, irn)) {
+ assert(n_alloc < n_regs);
+ alloc_nodes[n_alloc] = proj;
+ pmap_insert(partners, proj, NULL);
+
+ bitset_clear_all(bs);
+ arch_get_allocatable_regs(aenv, proj, -1, bs);
+ bitset_foreach(bs, col)
+ bipartite_add(bp, n_alloc, col);
+
+ n_alloc++;
+ }
+ }
+ }
+
+ bipartite_matching(bp, assignment);
+
+ for(i = 0; i < n_alloc; ++i) {
+ int j;
+ ir_node *nodes[2];
+ const arch_register_t *reg;
+
+ assert(assignment[i] >= 0 && "there must have been a register assigned");
+ reg = arch_register_for_index(env->cls, assignment[i]);
+
+ nodes[0] = alloc_nodes[i];
+ nodes[1] = pmap_get(partners, alloc_nodes[i]);
+
+ for(j = 0; j < 2; ++j) {
+ if(!nodes[j])
+ continue;
+
+ arch_set_irn_register(aenv, nodes[j], reg);
+ pset_hinsert_ptr(alloc_env->pre_colored, nodes[j]);
+ DBG((dbg, LEVEL_2, "\tsetting %+F to register %s\n", nodes[j], reg->name));
+ }
+ }