2 * This is the C implementation of the trivial mst algo
3 * originally written in Java by Sebastian Hack.
4 * Performs simple copy minimzation.
6 * @author Christian Wuerdig
13 #endif /* HAVE_CONFIG_H */
20 #include "raw_bitset.h"
21 #include "irphase_t.h"
30 #include "becopyopt_t.h"
33 #define COL_COST_INFEASIBLE DBL_MAX
34 #define AFF_NEIGHBOUR_FIX_BENEFIT 128.0
35 #define NEIGHBOUR_CONSTR_COSTS 64.0
37 typedef struct _col_cost_t {
42 typedef struct _aff_chunk_t {
45 unsigned weight_consistent : 1;
48 typedef struct _aff_edge_t {
54 /* main coalescing environment*/
55 typedef struct _co_mst_env_t {
56 int n_regs; /**< number of regs in class */
57 int k; /**< number of non-ignore registers in class */
58 bitset_t *ignore_regs; /**< set containing all global ignore registers */
59 ir_phase ph; /**< phase object holding data for nodes */
60 pqueue *chunks; /**< priority queue for chunks */
61 pset_new_t chunkset; /**< set holding all chunks */
62 be_ifg_t *ifg; /**< the interference graph */
63 const arch_env_t *aenv; /**< the arch environment */
64 copy_opt_t *co; /**< the copy opt object */
67 /* stores coalescing related information for a node */
68 typedef struct _co_mst_irn_t {
76 unsigned tmp_fixed : 1;
80 #define get_co_mst_irn(mst_env, irn) (phase_get_or_set_irn_data(&(mst_env)->ph, (irn)))
82 typedef int decide_func_t(co_mst_irn_t *node, int col);
84 static INLINE int get_mst_irn_col(co_mst_irn_t *node) {
85 return node->tmp_fixed ? node->tmp_col : node->col;
89 * @return 1 if node @p node has color @p col, 0 otherwise.
91 static int decider_has_color(co_mst_irn_t *node, int col) {
92 return get_mst_irn_col(node) == col;
96 * @return 1 if node @p node has not color @p col, 0 otherwise.
98 static int decider_hasnot_color(co_mst_irn_t *node, int col) {
99 return get_mst_irn_col(node) != col;
103 * Always returns true.
105 static int decider_always_yes(co_mst_irn_t *node, int col) {
109 /* compares two affinity edges */
110 static int cmp_aff_edge(const void *a, const void *b) {
111 const aff_edge_t *e1 = a;
112 const aff_edge_t *e2 = b;
114 /* sort in descending order */
115 return e1->weight < e2->weight ? 1 : -1;
118 /* compares to color-cost pairs */
119 static int cmp_col_cost(const void *a, const void *b) {
120 const col_cost_t *c1 = a;
121 const col_cost_t *c2 = b;
123 return c1->cost < c2->cost ? -1 : 1;
127 * In case there is no phase information for irn, initialize it.
129 static void *co_mst_irn_init(ir_phase *ph, ir_node *irn, void *old) {
130 co_mst_irn_t *res = old ? old : phase_alloc(ph, sizeof(res[0]));
131 co_mst_env_t *env = ph->priv;
134 void *neigh_it = be_ifg_neighbours_iter_alloca(env->ifg);
135 const arch_register_req_t *req;
144 res->col = arch_register_get_index(arch_get_irn_register(env->aenv, irn));
146 /* set admissible registers */
147 res->adm_colors = bitset_obstack_alloc(phase_obst(ph), env->n_regs);
149 /* Exclude colors not assignable to the irn */
150 req = arch_get_register_req(env->aenv, irn, -1);
151 if (arch_register_req_is(req, limited))
152 rbitset_copy_to_bitset(req->limited, res->adm_colors);
154 /* exclude global ignore registers as well */
155 bitset_andnot(res->adm_colors, env->ignore_regs);
157 /* calculate the number of interfering neighbours */
158 be_ifg_foreach_neighbour(env->ifg, neigh_it, irn, m) {
159 if (! arch_irn_is(env->aenv, m, ignore))
169 * Creates a new affinity chunk
171 static INLINE aff_chunk_t *new_aff_chunk(co_mst_env_t *env) {
172 aff_chunk_t *c = xmalloc(sizeof(*c));
173 c->weight_consistent = 0;
174 c->nodes = bitset_irg_malloc(env->co->irg);
175 pset_new_insert(&env->chunkset, c);
180 * Frees all memory allocated by an affinity chunk.
182 static INLINE void delete_aff_chunk(co_mst_env_t *env, aff_chunk_t *c) {
183 pset_new_remove(&env->chunkset, c);
184 bitset_free(c->nodes);
189 * Adds a node to an affinity chunk
191 static INLINE void aff_chunk_add_node(aff_chunk_t *c, co_mst_irn_t *node) {
192 c->weight_consistent = 0;
194 bitset_set(c->nodes, get_irn_idx(node->irn));
198 * Check if there are interference edges from c1 to c2.
199 * @param env The global co_mst environment
201 * @param c2 Another chunk
202 * @return 1 if there are interferences between nodes of c1 and c2, 0 otherwise.
204 static INLINE int aff_chunks_interfere(co_mst_env_t *env, aff_chunk_t *c1, aff_chunk_t *c2) {
205 void *nodes_it = be_ifg_nodes_iter_alloca(env->ifg);
208 /* check if there is a node in c1 having an interfering neighbour in c2 */
209 bitset_foreach(c1->nodes, idx) {
210 ir_node *n = get_idx_irn(env->co->irg, idx);
213 be_ifg_foreach_neighbour(env->ifg, nodes_it, n, neigh) {
214 if (bitset_is_set(c2->nodes, get_irn_idx(neigh)))
223 * Let c1 absorb the nodes of c2 (only possible when there
224 * are no interference edges from c1 to c2).
225 * @return 1 if successful, 0 if not possible
227 static INLINE int aff_chunk_absorb(co_mst_env_t *env, aff_chunk_t *c1, aff_chunk_t *c2) {
228 if (! aff_chunks_interfere(env, c1, c2)) {
231 bitset_or(c1->nodes, c2->nodes);
232 c1->weight_consistent = 0;
234 bitset_foreach(c2->nodes, idx) {
235 ir_node *n = get_idx_irn(env->co->irg, idx);
236 co_mst_irn_t *mn = get_co_mst_irn(env, n);
240 delete_aff_chunk(env, c2);
247 * Returns the affinity chunk of @p irn or creates a new
248 * one with @p irn as element if there is none assigned.
250 static INLINE aff_chunk_t *get_or_set_aff_chunk(co_mst_env_t *env, ir_node *irn) {
251 co_mst_irn_t *node = get_co_mst_irn(env, irn);
253 if (node->chunk == NULL) {
254 node->chunk = new_aff_chunk(env);
255 aff_chunk_add_node(node->chunk, node);
262 * Assures that the weight of the given chunk is consistent.
264 static void aff_chunk_assure_weight(co_mst_env_t *env, aff_chunk_t *c) {
265 if (! c->weight_consistent) {
269 bitset_foreach(c->nodes, idx) {
270 ir_node *n = get_idx_irn(env->co->irg, idx);
271 affinity_node_t *an = get_affinity_info(env->co, n);
272 co_mst_irn_t *n1 = get_co_mst_irn(env, n);
276 co_gs_foreach_neighb(an, neigh) {
277 ir_node *m = neigh->irn;
278 int m_idx = get_irn_idx(m);
281 /* skip ignore nodes */
282 if (arch_irn_is(env->aenv, m, ignore))
285 n2 = get_co_mst_irn(env, m);
287 /* record the edge in only one direction */
289 w += (double)neigh->costs / (double)(1 + n1->int_neigh + n2->int_neigh);
295 c->weight_consistent = 1;
300 * Build chunks of nodes connected by affinity edges.
301 * We start at the heaviest affinity edge.
302 * The chunks of the two edge-defining nodes will be
303 * merged if there are no interference edges from one
304 * chunk to the other.
306 static void build_affinity_chunks(co_mst_env_t *env) {
307 void *nodes_it = be_ifg_nodes_iter_alloca(env->ifg);
308 aff_edge_t *edges = NEW_ARR_F(aff_edge_t, 0);
311 aff_chunk_t *curr_chunk;
312 pset_new_iterator_t iter;
314 /* at first we create the affinity edge objects */
315 be_ifg_foreach_node(env->ifg, nodes_it, n) {
316 int n_idx = get_irn_idx(n);
320 /* skip ignore nodes */
321 if (arch_irn_is(env->aenv, n, ignore))
324 n1 = get_co_mst_irn(env, n);
325 an = get_affinity_info(env->co, n);
329 co_gs_foreach_neighb(an, neigh) {
330 ir_node *m = neigh->irn;
331 int m_idx = get_irn_idx(m);
334 /* skip ignore nodes */
335 if (arch_irn_is(env->aenv, m, ignore))
338 n2 = get_co_mst_irn(env, m);
340 /* record the edge in only one direction */
346 edge.weight = (double)neigh->costs / (double)(1 + n1->int_neigh + n2->int_neigh);
347 ARR_APP1(aff_edge_t, edges, edge);
353 /* now: sort edges and build the affinity chunks */
354 qsort(edges, ARR_LEN(edges), sizeof(edges[0]), cmp_aff_edge);
355 for (i = 0; i < ARR_LEN(edges); ++i) {
356 aff_chunk_t *c1 = get_or_set_aff_chunk(env, edges[i].src);
357 aff_chunk_t *c2 = get_or_set_aff_chunk(env, edges[i].tgt);
359 (void)aff_chunk_absorb(env, c1, c2);
362 /* now insert all chunks into a priority queue */
363 foreach_pset_new(&env->chunkset, curr_chunk, iter) {
364 aff_chunk_assure_weight(env, curr_chunk);
365 pqueue_put(env->chunks, curr_chunk, curr_chunk->weight);
372 * Greedy collect affinity neighbours into thew new chunk @p chunk starting at node @p node.
374 static void expand_chunk_from(co_mst_env_t *env, co_mst_irn_t *node, bitset_t *visited,
375 aff_chunk_t *chunk, aff_chunk_t *orig_chunk, decide_func_t *decider, int col)
377 waitq *nodes = new_waitq();
379 /* init queue and chunk */
380 waitq_put(nodes, node);
381 bitset_set(visited, get_irn_idx(node->irn));
382 aff_chunk_add_node(chunk, node);
384 /* as long as there are nodes in the queue */
385 while (! waitq_empty(nodes)) {
386 co_mst_irn_t *n = waitq_get(nodes);
387 affinity_node_t *an = get_affinity_info(env->co, n->irn);
388 int n_idx = get_irn_idx(n->irn);
390 /* check all affinity neighbors */
393 co_gs_foreach_neighb(an, neigh) {
394 ir_node *m = neigh->irn;
395 int m_idx = get_irn_idx(m);
398 /* skip ignore nodes */
399 if (arch_irn_is(env->aenv, m, ignore))
402 n2 = get_co_mst_irn(env, m);
405 ! bitset_is_set(visited, m_idx) &&
408 ! aff_chunks_interfere(env, chunk, n2->chunk) &&
409 bitset_is_set(orig_chunk->nodes, m_idx))
412 following conditions are met:
413 - neighbour is not visited
414 - neighbour likes the color
415 - neighbour has not yet a fixed color
416 - the new chunk doesn't interfere with the chunk of the neighbour
417 - neighbour belongs or belonged once to the original chunk
419 bitset_set(visited, m_idx);
420 aff_chunk_add_node(chunk, n2);
421 /* enqueue for further search */
422 waitq_put(nodes, n2);
432 * Fragment the given chunk into chunks having given color and not having given color.
434 static aff_chunk_t *fragment_chunk(co_mst_env_t *env, int col, aff_chunk_t *c, waitq *tmp) {
435 bitset_t *visited = bitset_irg_malloc(env->co->irg);
437 aff_chunk_t *best = NULL;
439 bitset_foreach(c->nodes, idx) {
442 aff_chunk_t *tmp_chunk;
443 decide_func_t *decider;
445 if (bitset_is_set(visited, idx))
448 irn = get_idx_irn(env->co->irg, idx);
449 node = get_co_mst_irn(env, irn);
451 /* create a new chunk starting at current node */
452 tmp_chunk = new_aff_chunk(env);
453 waitq_put(tmp, tmp_chunk);
454 decider = get_mst_irn_col(node) == col ? decider_has_color : decider_hasnot_color;
455 expand_chunk_from(env, node, visited, tmp_chunk, c, decider, col);
456 assert(bitset_popcnt(tmp_chunk->nodes) > 0 && "No nodes added to chunk");
458 /* remember the local best */
459 aff_chunk_assure_weight(env, tmp_chunk);
460 if (! best || best->weight < tmp_chunk->weight)
464 assert(best && "No chunk found?");
465 bitset_free(visited);
470 * Initializes an array of color-cost pairs.
471 * Sets forbidden colors to costs COL_COST_INFEASIBLE and all others to @p c.
473 static INLINE void col_cost_init(co_mst_env_t *env, col_cost_t *cost, double c) {
476 for (i = 0; i < env->n_regs; ++i) {
478 if (bitset_is_set(env->ignore_regs, i))
479 cost[i].cost = COL_COST_INFEASIBLE;
486 * Initializes an array of color-cost pairs.
487 * Sets all colors except color @p col to COL_COST_INFEASIBLE and @p col to 0.0
489 static INLINE void col_cost_init_single(co_mst_env_t *env, col_cost_t *cost, int col) {
490 assert(! bitset_is_set(env->ignore_regs, col) && "Attempt to use forbidden color.");
491 col_cost_init(env, cost, COL_COST_INFEASIBLE);
498 * Resets the temporary fixed color of all nodes within wait queue @p nodes.
499 * ATTENTION: the queue is empty after calling this function!
501 static INLINE void reject_coloring(waitq *nodes) {
502 while (! waitq_empty(nodes)) {
503 co_mst_irn_t *n = waitq_get(nodes);
509 * Determines the costs for each color if it would be assigned to node @p node.
511 static void determine_color_costs(co_mst_env_t *env, co_mst_irn_t *node, col_cost_t *costs) {
512 affinity_node_t *an = get_affinity_info(env->co, node->irn);
513 void *nodes_it = be_ifg_nodes_iter_alloca(env->ifg);
518 col_cost_init(env, costs, 0.0);
520 /* calculate (negative) costs for affinity neighbours */
521 co_gs_foreach_neighb(an, aff_neigh) {
522 ir_node *m = aff_neigh->irn;
523 co_mst_irn_t *neigh = get_co_mst_irn(env, m);
524 double c = (double)aff_neigh->costs;
526 /* calculate costs for fixed affinity neighbours */
527 if (neigh->tmp_fixed || neigh->fixed) {
528 int col = get_mst_irn_col(neigh);
529 costs[col].cost -= c * AFF_NEIGHBOUR_FIX_BENEFIT;
533 /* calculate (positive) costs for interfering neighbours */
534 be_ifg_foreach_neighbour(env->ifg, nodes_it, node->irn, int_neigh) {
535 co_mst_irn_t *neigh = get_co_mst_irn(env, int_neigh);
536 int col = get_mst_irn_col(neigh);
537 int col_cnt = bitset_popcnt(neigh->adm_colors);
539 if (neigh->tmp_fixed || neigh->fixed) {
540 /* colors of fixed interfering neighbours are infeasible */
541 costs[col].cost = COL_COST_INFEASIBLE;
543 else if (col_cnt < env->k) {
544 /* calculate costs for constrained interfering neighbours */
545 double ratio = 1.0 - ((double)col_cnt / (double)env->k);
547 bitset_foreach_clear(neigh->adm_colors, idx) {
548 /* check only explicitly forbidden colors (skip global forbidden ones) */
549 if (! bitset_is_set(env->ignore_regs, idx)) {
550 costs[col].cost += ratio * NEIGHBOUR_CONSTR_COSTS;
556 /* set all not admissible colors to COL_COST_INFEASIBLE */
557 bitset_foreach_clear(node->adm_colors, idx)
558 costs[idx].cost = COL_COST_INFEASIBLE;
561 /* need forward declaration due to recursive call */
562 static int recolor_nodes(co_mst_env_t *env, co_mst_irn_t *node, col_cost_t *costs, waitq *changed_ones);
565 * Tries to change node to a color but @p explude_col.
566 * @return 1 if succeeded, 0 otherwise.
568 static int change_node_color_excluded(co_mst_env_t *env, co_mst_irn_t *node, int exclude_col, waitq *changed_ones) {
569 int col = get_mst_irn_col(node);
572 /* neighbours has already a different color -> good, temporary fix it */
573 if (col != exclude_col) {
576 waitq_put(changed_ones, node);
580 /* The node has the color it should not have _and_ has not been visited yet. */
581 if (! (node->tmp_fixed || node->fixed)) {
582 col_cost_t *costs = alloca(env->n_regs * sizeof(costs[0]));
584 /* Get the costs for giving the node a specific color. */
585 determine_color_costs(env, node, costs);
587 /* Since the node must not have the not_col, set the costs for that color to "infinity" */
588 costs[exclude_col].cost = COL_COST_INFEASIBLE;
590 /* sort the colors according costs, cheapest first. */
591 qsort(costs, env->n_regs, sizeof(costs[0]), cmp_col_cost);
593 /* Try recoloring the node using the color list. */
594 res = recolor_nodes(env, node, costs, changed_ones);
601 * Tries to bring node @p node to cheapest color and color all interfering neighbours with other colors.
602 * ATTENTION: Expect @p costs already sorted by increasing costs.
603 * @return 1 if coloring could be applied, 0 otherwise.
605 static int recolor_nodes(co_mst_env_t *env, co_mst_irn_t *node, col_cost_t *costs, waitq *changed_ones) {
607 waitq *local_changed = new_waitq();
609 for (i = 0; i < env->n_regs; ++i) {
610 void *nodes_it = be_ifg_nodes_iter_alloca(env->ifg);
611 int tgt_col = costs[i].col;
615 /* If the costs for that color (and all successive) are infinite, bail out we won't make it anyway. */
616 if (costs[i].cost == COL_COST_INFEASIBLE) {
618 del_waitq(local_changed);
622 /* Set the new color of the node and mark the node as temporarily fixed. */
623 assert(! node->tmp_fixed && "Node must not have been temporary fixed.");
625 node->tmp_col = tgt_col;
627 assert(waitq_empty(local_changed) && "Node queue should be empty here.");
628 waitq_put(local_changed, node);
630 /* try to color all interfering neighbours with current color forbidden */
631 be_ifg_foreach_neighbour(env->ifg, nodes_it, node->irn, neigh) {
632 co_mst_irn_t *nn = get_co_mst_irn(env, neigh);
634 Try to change the color of the neighbor and record all nodes which
635 get changed in the tmp list. Add this list to the "changed" list for
636 that color. If we did not succeed to change the color of the neighbor,
637 we bail out and try the next color.
639 if (get_mst_irn_col(nn) == tgt_col) {
640 waitq *tmp = new_waitq();
642 /* try to color neighbour with tgt_col forbidden */
643 neigh_ok = change_node_color_excluded(env, nn, tgt_col, tmp);
645 /* join lists of changed nodes */
646 while (! waitq_empty(tmp))
647 waitq_put(local_changed, waitq_get(tmp));
656 We managed to assign the target color to all neighbors, so from the perspective
657 of the current node, every thing was ok and we can return safely.
660 /* append the local_changed ones to global ones */
661 while (! waitq_empty(local_changed))
662 waitq_put(changed_ones, waitq_get(local_changed));
663 del_waitq(local_changed);
667 /* coloring of neighbours failed, so we try next color */
668 reject_coloring(local_changed);
672 del_waitq(local_changed);
677 * Tries to bring node @p node and all it's neighbours to color @p tgt_col.
678 * @return 1 if color @p col could be applied, 0 otherwise
680 static int change_node_color(co_mst_env_t *env, co_mst_irn_t *node, int tgt_col, waitq *changed_ones) {
681 int col = get_mst_irn_col(node);
683 /* if node already has the target color -> good, temporary fix it */
684 if (col == tgt_col) {
685 if (! node->tmp_fixed) {
687 node->tmp_col = tgt_col;
688 waitq_put(changed_ones, node);
694 Node has not yet a fixed color and target color is admissible
695 -> try to recolor node and it's affinity neighbours
697 if (! (node->fixed || node->tmp_fixed) && bitset_is_set(node->adm_colors, tgt_col)) {
698 col_cost_t *costs = alloca(env->n_regs * sizeof(costs[0]));
699 col_cost_init_single(env, costs, tgt_col);
700 return recolor_nodes(env, node, costs, changed_ones);
707 * Tries to color an affinity chunk (or at least a part of it).
708 * Inserts uncolored parts of the chunk as a new chunk into the priority queue.
710 static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c) {
711 aff_chunk_t *best_chunk = NULL;
713 waitq *changed_ones = new_waitq();
714 waitq *tmp_chunks = new_waitq();
718 /* check which color is the "best" for the given chunk */
719 for (col = 0; col < env->k; ++col) {
721 aff_chunk_t *local_best;
723 /* try to bring all nodes of given chunk to the current color. */
724 bitset_foreach(c->nodes, idx) {
725 ir_node *irn = get_idx_irn(env->co->irg, idx);
726 co_mst_irn_t *node = get_co_mst_irn(env, irn);
728 assert(! node->fixed && "Node must not have a fixed color.");
730 one_good = change_node_color(env, node, col, changed_ones);
736 /* try next color when failed */
740 /* fragment the chunk according to the coloring */
741 local_best = fragment_chunk(env, col, c, tmp_chunks);
743 /* check if the local best is global best */
745 aff_chunk_assure_weight(env, local_best);
747 if (! best_chunk || best_chunk->weight < local_best->weight) {
748 /* kill the old best */
750 delete_aff_chunk(env, best_chunk);
751 best_chunk = local_best;
756 /* reject the coloring and bring the coloring to the initial state */
757 reject_coloring(changed_ones);
760 /* free all intermediate created chunks except best one */
761 while (! waitq_empty(tmp_chunks)) {
762 aff_chunk_t *tmp = waitq_get(tmp_chunks);
763 if (tmp != best_chunk)
764 delete_aff_chunk(env, tmp);
766 del_waitq(tmp_chunks);
768 /* return if coloring failed */
770 delete_aff_chunk(env, c);
771 del_waitq(changed_ones);
775 /* get the best fragment from the best list and color it */
776 bitset_foreach(best_chunk->nodes, idx) {
777 ir_node *irn = get_idx_irn(env->co->irg, idx);
778 co_mst_irn_t *node = get_co_mst_irn(env, irn);
781 res = change_node_color(env, node, best_color, changed_ones);
782 assert(res && "Coloring failed");
784 node->col = node->tmp_col;
785 node->chunk = best_chunk;
789 while (! waitq_empty(changed_ones)) {
790 co_mst_irn_t *n = waitq_get(changed_ones);
795 /* remove the nodes in best chunk from original chunk */
796 bitset_andnot(c->nodes, best_chunk->nodes);
798 /* fragment the remaining chunk */
799 visited = bitset_irg_malloc(env->co->irg);
800 bitset_or(visited, best_chunk->nodes);
801 bitset_foreach(c->nodes, idx) {
802 if (! bitset_is_set(visited, idx)) {
803 aff_chunk_t *new_chunk = new_aff_chunk(env);
804 ir_node *irn = get_idx_irn(env->co->irg, idx);
805 co_mst_irn_t *node = get_co_mst_irn(env, irn);
807 expand_chunk_from(env, node, visited, new_chunk, c, decider_always_yes, 0);
808 aff_chunk_assure_weight(env, new_chunk);
809 pqueue_put(env->chunks, new_chunk, new_chunk->weight);
813 /* clear obsolete chunks and free some memory */
814 delete_aff_chunk(env, c);
815 delete_aff_chunk(env, best_chunk);
816 bitset_free(visited);
817 del_waitq(changed_ones);
821 * Main driver for mst safe coalescing algorithm.
823 int co_solve_heuristic_mst(copy_opt_t *co)
825 unsigned n_regs = co->cenv->cls->n_regs;
826 bitset_t *ignore_regs = bitset_alloca(n_regs);
828 co_mst_env_t mst_env;
830 memset(&mst_env, 0, sizeof(mst_env));
833 phase_init(&mst_env.ph, "co_mst", co->irg, PHASE_DEFAULT_GROWTH, co_mst_irn_init, &mst_env);
835 k = be_put_ignore_regs(co->cenv->birg, co->cenv->cls, ignore_regs);
838 mst_env.n_regs = n_regs;
840 mst_env.chunks = new_pqueue();
842 mst_env.ignore_regs = ignore_regs;
843 mst_env.ifg = co->cenv->ifg;
844 mst_env.aenv = co->aenv;
845 pset_new_init(&mst_env.chunkset);
847 /* build affinity chunks */
848 build_affinity_chunks(&mst_env);
850 /* color chunks as long as there are some */
851 while (! pqueue_empty(mst_env.chunks)) {
852 aff_chunk_t *chunk = pqueue_get(mst_env.chunks);
853 color_aff_chunk(&mst_env, chunk);
856 /* free allocated memory */
857 del_pqueue(mst_env.chunks);
858 phase_free(&mst_env.ph);
859 pset_new_destroy(&mst_env.chunkset);