+
+/*
+ ___ _ ____
+ |_ _|_ __ ___ ___ _ __| |_ | _ \ ___ _ __ _ __ ___
+ | || '_ \/ __|/ _ \ '__| __| | |_) / _ \ '__| '_ ` _ \
+ | || | | \__ \ __/ | | |_ | __/ __/ | | | | | | |
+ |___|_| |_|___/\___|_| \__| |_| \___|_| |_| |_| |_|
+
+*/
+
+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(!be_liveness_nodes_live_at(arch_env, cls, pos, live));
+
+ n = pset_count(live);
+
+ if(n == 0)
+ return NULL;
+
+ nodes = malloc(n * sizeof(nodes[0]));
+
+ DBG((dbg, LEVEL_1, "live:\n"));
+ for(irn = pset_first(live), i = 0; irn; irn = pset_next(live), i++) {
+ DBG((dbg, LEVEL_1, "\t%+F\n", irn));
+ nodes[i] = irn;
+ }
+
+ perm = be_new_Perm(cls, irg, bl, n, nodes);
+ sched_add_after(pos, perm);
+ free(nodes);
+
+ curr = perm;
+ for(i = 0; i < n; ++i) {
+ ir_node *copies[2];
+ ir_node *perm_op = get_irn_n(perm, i);
+ const arch_register_t *reg = arch_get_irn_register(arch_env, perm_op);
+
+ ir_mode *mode = get_irn_mode(perm_op);
+ ir_node *proj = new_r_Proj(irg, bl, perm, mode, i);
+ arch_set_irn_register(arch_env, proj, reg);
+
+ sched_add_after(curr, proj);
+ curr = proj;
+
+ copies[0] = perm_op;
+ copies[1] = proj;
+ be_ssa_constr(dom_front, 2, copies);
+ }
+ return perm;
+}