+static void chunk_order_nodes(co_mst_env_t *env, aff_chunk_t *chunk)
+{
+ pqueue *grow = new_pqueue();
+ int i;
+ int max_weight = 0;
+ ir_node *max_node = NULL;
+
+ for (i = ARR_LEN(chunk->n) - 1; i >= 0; i--) {
+ ir_node *irn = chunk->n[i];
+ affinity_node_t *an = get_affinity_info(env->co, irn);
+ int w = 0;
+ neighb_t *neigh;
+
+ if (arch_irn_is(env->aenv, irn, ignore))
+ continue;
+
+ if (an) {
+ co_gs_foreach_neighb(an, neigh)
+ w += neigh->costs;
+
+ if (w > max_weight) {
+ max_weight = w;
+ max_node = irn;
+ }
+ }
+ }
+
+ if (max_node) {
+ bitset_t *visited = bitset_irg_malloc(env->co->irg);
+
+ for (i = ARR_LEN(chunk->n) - 1; i >= 0; --i)
+ bitset_add_irn(visited, chunk->n[i]);
+
+ pqueue_put(grow, max_node, max_weight);
+ bitset_remv_irn(visited, max_node);
+ i = 0;
+ while (!pqueue_empty(grow)) {
+ ir_node *irn = pqueue_get(grow);
+ affinity_node_t *an = get_affinity_info(env->co, irn);
+ neighb_t *neigh;
+
+ if (arch_irn_is(env->aenv, irn, ignore))
+ continue;
+
+ assert(i <= ARR_LEN(chunk->n));
+ chunk->n[i++] = irn;
+
+ assert(an);
+
+ /* build the affinity edges */
+ co_gs_foreach_neighb(an, neigh) {
+ co_mst_irn_t *node = get_co_mst_irn(env, neigh->irn);
+
+ if (bitset_contains_irn(visited, node->irn)) {
+ pqueue_put(grow, neigh->irn, neigh->costs);
+ bitset_remv_irn(visited, node->irn);
+ }
+ }
+ }
+
+ del_pqueue(grow);
+ bitset_free(visited);
+ }
+}
+