+
+ obstack_ptr_grow(&cloud->obst, NULL);
+ ci->mst_childs = (co2_cloud_irn_t**)obstack_finish(&cloud->obst);
+ }
+ del_pdeq(q);
+ free(mst_edges);
+
+
+ DBG((env->dbg, LEVEL_3, "mst:\n"));
+ for (i = 0; i < cloud->n_memb; ++i) {
+ DEBUG_ONLY(co2_cloud_irn_t *ci = cloud->seq[i];)
+ DBG((env->dbg, LEVEL_3, "\t%+F -> %+F\n", ci->inh.irn, ci->mst_parent->inh.irn));
+ }
+
+ for (i = 0; i < cloud->n_memb; ++i) {
+ co2_cloud_irn_t *ci = cloud->seq[i];
+ int n_childs = ci->mst_n_childs;
+ int j;
+
+ ci->col_costs = OALLOCNZ(&cloud->obst, int, n_regs);
+ ci->tmp_coloring = OALLOCNZ(&cloud->obst, col_cost_pair_t, n_regs);
+ ci->fronts = OALLOCNZ(&cloud->obst, int, n_regs * n_childs);
+ ci->color_badness = OALLOCNZ(&cloud->obst, int, n_regs);
+
+ for (j = 0; j < env->n_regs; j++)
+ ci->col_costs[j] = INT_MAX;
+ }
+
+ determine_color_badness(cloud->mst_root, 0);
+ best_col = coalesce_top_down(cloud->mst_root, -1, 0);
+ unfix_subtree(cloud->mst_root);
+ apply_coloring(cloud->mst_root, best_col, 0);
+
+ /* The coloring should represent the one with the best costs. */
+ //materialize_coloring(&changed);
+ DBG((env->dbg, LEVEL_2, "\tbest coloring for root %+F was %d costing %d\n",
+ cloud->mst_root->inh.irn, best_col, examine_subtree_coloring(cloud->mst_root, best_col)));
+
+ /* Fix all nodes in the cloud. */
+ for (i = 0; i < cloud->n_memb; ++i)
+ cloud->seq[i]->inh.fixed = 1;
+
+ /* Free all space used while optimizing this cloud. */
+ obstack_free(&cloud->obst, NULL);
+}
+
+static int cloud_costs(co2_cloud_t *cloud)
+{
+ int i, costs = 0;
+ neighb_t *n;
+
+ for (i = 0; i < cloud->n_memb; ++i) {
+ co2_irn_t *ci = (co2_irn_t *) cloud->seq[i];
+ col_t col = get_col(cloud->env, ci->irn);
+ co_gs_foreach_neighb(ci->aff, n) {
+ col_t n_col = get_col(cloud->env, n->irn);
+ costs += col != n_col ? n->costs : 0;
+ }
+ }
+
+ return costs / 2;
+}
+
+static void writeback_colors(co2_t *env)
+{
+ co2_irn_t *irn;
+
+ for (irn = env->touched; irn; irn = irn->touched_next) {
+ const arch_register_t *reg = arch_register_for_index(env->co->cls, irn->orig_col);
+ arch_set_irn_register((ir_node*)irn->irn, reg);