the partly done generic assemblerdumper
[libfirm] / ir / be / bephicoal.c
1 /**
2  * @author Daniel Grund
3  * @date 04.01.2005
4  */
5 #ifdef HAVE_CONFIG_H
6 #include "config.h"
7 #endif
8
9 #include <stdlib.h>
10
11 #include "obst.h"
12 #include "set.h"
13 #include "pset.h"
14 #include "bitset.h"
15 #include "debug.h"
16 #include "irouts.h"
17 #include "irdom.h"
18
19 #include "bechordal.h"
20 #include "belive_t.h"
21 #include "bera_t.h"
22 #include "phiclass_t.h"
23 #include "bephicoal_t.h"
24
25 #define DEBUG_LVL 0
26 //SET_LEVEL_1
27 #define MAX_COLORS 16
28
29 #define INITIAL_SLOTS_PINNED_GLOBAL 256
30 //#define INITIAL_SLOTS_FREE_NODES    128
31 #define INITIAL_SLOTS_CHANGED_NODES 32
32
33 /* some things for readable code */
34 #define CHANGE_SAVE NULL
35 #define CHANGE_IMPOSSIBLE (ir_node *)1
36 #define CHANGE_NYI (ir_node *)2
37 #define is_conflicting_node(n) (((int)n) > 2)
38
39 /**
40  * Models conflicts between nodes. These may be life range conflicts or
41  * pinning conflicts, which may occur while changing colors
42  */
43 typedef struct _conflict_t {
44         ir_node *n1, *n2;
45 } conflict_t;
46
47 /**
48  * If an irn is changed, the changes first get stored in a node_stat_t,
49  * to allow undo of changes in case of conflicts.
50  */
51 typedef struct _node_stat_t {
52         ir_node *irn;
53         int color;
54         int undo_color;
55         char status;            /**< Bit 0: pinned, Bit 1: removed */
56 } node_stat_t;
57
58 #define _set_pinned(nodestat)    nodestat->status |= 1
59 #define _set_removed(nodestat)   nodestat->status |= 2
60 #define _clear_pinned(nodestat)  nodestat->status &= 255 ^ 1
61 #define _clear_removed(nodestat) nodestat->status &= 255 ^ 2
62 #define _is_pinned(nodestat)     (nodestat->status & 1)
63 #define _is_removed(nodestat)    (nodestat->status & 2)
64
65 /**
66  * Central data structure. Contains infos needed during coalescing of the
67  * corresponding phi class.
68  */
69 typedef struct _phi_unit_t {
70         unsigned char phi_count;                        /**< the number of phi nodes in this unit */
71         /* 1 phi */
72         unsigned char node_count;                       /**< size of the nodes-array */
73         unsigned char conflict_count;           /**< size of the conflicts-array */
74         unsigned char conflict_count_org;       /**< initial size of the conflicts-array */
75         ir_node **nodes;                                        /**< [0] is the phi node. [1..node_count-1] the arguments of the phi not interfering with it */
76         conflict_t *conflicts;                          /**< pairs of conflicting ir_nodes. */
77         set *changed_nodes;                                     /**< contains node_stat_t's. */
78 } phi_unit_t;
79
80 static firm_dbg_module_t *dbgphi = NULL;
81
82 /**
83  * Contains ir_nodes of phi-classes whose colors may change unlimited times.
84  * These nodes are not optimizable, so there is no need to pin their color.
85  */
86 //static pset *free_nodes = NULL;
87
88 /**
89  * Contains already optimized ir_nodes of phi-classes fully processed.
90  * So one can perform a check not to switch them twice or more.
91  */
92 static pset *pinned_global = NULL;
93
94 static int set_cmp_node_stat_t(const void *x, const void *y, size_t size) {
95         return ((node_stat_t *)x)->irn != ((node_stat_t *)y)->irn;
96 }
97
98 /**
99  * Finds a node status entry of a node if existent.
100  */
101 static INLINE node_stat_t *pu_find_node(phi_unit_t *pu, ir_node *irn) {
102         node_stat_t find;
103         find.irn = irn;
104         return set_find(pu->changed_nodes, &find, sizeof(find), HASH_PTR(irn));
105 }
106
107 /**
108  * Finds a node status entry of a node if existent. Otherwise it will return
109  * an initialized new entry for this node.
110  */
111 static INLINE node_stat_t *pu_find_or_insert_node(phi_unit_t *pu, ir_node *irn) {
112         node_stat_t find;
113         find.irn = irn;
114         find.color = NO_COLOR;
115         find.undo_color = NO_COLOR;
116         find.status = 0;
117         return set_insert(pu->changed_nodes, &find, sizeof(find), HASH_PTR(irn));
118 }
119
120 /**
121  * @return The virtual color of a node, if set before, else just the real color.
122  */
123 static INLINE int pu_get_new_color(phi_unit_t *pu, ir_node *irn) {
124         node_stat_t *found = pu_find_node(pu, irn);
125         if (found)
126                 return found->color;
127         else
128                 return get_irn_color(irn);
129 }
130
131 /**
132  * Sets the virtual color of a node.
133  */
134 static INLINE void pu_set_new_color(phi_unit_t *pu, ir_node *irn, int color) {
135         node_stat_t *found = pu_find_or_insert_node(pu, irn);
136         found->undo_color = found->color;
137         found->color = color;
138         DBG((dbgphi, LEVEL_4, "%n %d\n", irn, color));
139 }
140
141 /**
142  * Sets the virtual color of a node to the color it had,
143  * before the last call to pu_set_new_color
144  */
145 static INLINE void pu_undo_color(phi_unit_t *pu, ir_node *irn) {
146         node_stat_t *ns = pu_find_node(pu, irn);
147         assert(ns && "Nodes whose colors are undone must be in pu->changed_nodes");
148         ns->color = ns->undo_color;
149         DBG((dbgphi, LEVEL_3, "\t\tUndo: col(%n) := %d\n", irn, ns->undo_color));
150 }
151
152 /**
153  * Checks if a node is removed from consideration respectively building
154  * a maximum independent set.
155  */
156 static INLINE int pu_is_node_removed(phi_unit_t *pu, ir_node *irn) {
157         node_stat_t *found = pu_find_node(pu, irn);
158         if (found)
159                 return _is_removed(found);
160         else
161                 return 0;
162 }
163
164 /**
165  * Removes a node from the base set, out of which a maximum independet
166  * set gets build from.
167  */
168 static INLINE void pu_remove_node(phi_unit_t *pu, ir_node *irn) {
169         node_stat_t *found = pu_find_or_insert_node(pu, irn);
170         _set_removed(found);
171         DBG((dbgphi, LEVEL_4, "%n\n", irn));
172 }
173
174 /**
175  * Checks if a node is local pinned; i.e. it belongs to the same phi unit and
176  * has been optimized before the current processed one.
177  */
178 static INLINE int pu_is_node_pinned(phi_unit_t *pu, ir_node *irn) {
179         node_stat_t *found = pu_find_node(pu, irn);
180         if (found)
181                 return _is_pinned(found);
182         else
183                 return 0;
184 }
185
186 /**
187  * Local-pins a node, so optimizations of further nodes of the same phi unit
188  * can handle situations in which a color change would undo prior optimizations.
189  */
190 static INLINE void pu_pin_node(phi_unit_t *pu, ir_node *irn) {
191         node_stat_t *found = pu_find_or_insert_node(pu, irn);
192         _set_pinned(found);
193         DBG((dbgphi, LEVEL_4, "%n\n", irn));
194 }
195
196 /**
197  * If a local pinned conflict occurs, a new edge in the conflict graph is added.
198  * The next maximum independent set build, will regard it.
199  */
200 static INLINE void pu_add_conflict(phi_unit_t *pu, ir_node *n1, ir_node *n2) {
201         int count = pu->conflict_count;
202
203         DBG((dbgphi, LEVEL_3, "\t    %n -- %n\n", n1, n2));
204         assert(count != 255 && "Too much conflicts. Can hold max 255 entries");
205         if ((count & 15) == 0)
206                 pu->conflicts = realloc(pu->conflicts, (count + 16)*sizeof(*pu->conflicts));
207
208         if ((int)n1 < (int)n2) {
209                 pu->conflicts[count].n1 = n1;
210                 pu->conflicts[count].n2 = n2;
211         } else {
212                 pu->conflicts[count].n1 = n2;
213                 pu->conflicts[count].n2 = n1;
214         }
215
216         pu->conflict_count++;
217 }
218
219 /**
220  * Checks if two nodes are in a conflict.
221  */
222 static INLINE int pu_are_conflicting(phi_unit_t *pu, ir_node *n1, ir_node *n2) {
223         const ir_node *o1, *o2;
224         int i;
225
226         if ((int)n1 < (int)n2) {
227                 o1 = n1;
228                 o2 = n2;
229         } else {
230                 o1 = n2;
231                 o2 = n1;
232         }
233
234         for (i = 0; i < pu->conflict_count; ++i)
235                 if (pu->conflicts[i].n1 == o1 && pu->conflicts[i].n2 == o2)
236                         return 1;
237         return 0;
238 }
239
240 /**
241  * Checks if a node is a member of a phi unit.
242  * Other nodes should not be pinned global.
243  */
244 static INLINE int pu_is_global_pinnable(phi_unit_t *pu, ir_node *irn) {
245         int i;
246         for (i = 0; i < pu->node_count; ++i)
247                 if (pu->nodes[i] == irn)
248                         return 1;
249         return 0;
250 }
251
252 /**
253  * Determines a maximum independent set with respect to the conflict edges
254  * in pu->conflicts and the nodes beeing all non-removed nodes of pu->nodes.
255  * TODO: make this 'un-greedy'
256  * TODO: be aware that phi nodes should find their way in the set.
257  *       for 1 phi in greedy version this is no prob, cause is comes first at [0].
258  */
259 static int pu_get_mis(phi_unit_t *pu, struct obstack *res) {
260         int i, o, size = 0;
261         ir_node **mis;
262
263         DBG((dbgphi, LEVEL_2, "\t    Max indep set:\n"));
264         for (i = 0; i < pu->node_count; ++i) {
265                 int intf_det = 0;
266                 if (pu_is_node_removed(pu, pu->nodes[i]))
267                         continue;
268                 mis = (ir_node**) obstack_base(res);
269                 for (o = 0; o < size; ++o)
270                         if (pu_are_conflicting(pu, pu->nodes[i], mis[o])) {
271                                 intf_det = 1;
272                                 break;
273                         }
274
275                 if (!intf_det) {
276                         DBG((dbgphi, LEVEL_2, "\t\t%n\n", pu->nodes[i]));
277                         obstack_ptr_grow(res, pu->nodes[i]);
278                         size++;
279                 }
280         }
281         return size;
282 }
283
284 /**
285  * Performs virtual re-coloring of node @p n to color @p col. Virtual colors of
286  * other nodes are changed too, as required to preserve correctness. Function is
287  * aware of local and global pinning. Recursive.
288  * @param  irn The node to set the color for
289  * @param  col The color to set.
290  * @param  trigger The irn that caused the wish to change the color of the irn
291  * @param  changed_nodes An obstack on which all ir_nodes get growed on, which are changed
292  * @return CHANGE_SAVE iff setting the color is possible, with all transiteve effects.
293  *         CHANGE_IMPOSSIBLE iff conflicts with reg-constraintsis occured.
294  *         CHANGE_NYI iff an unhandled situation occurs.
295  *         Else the first conflicting ir_node encountered is returned.
296  *
297  * ASSUMPTION: Assumes that a life range of a single value can't be spilt into
298  *                         several smaller intervals where other values can live in between.
299  */
300 static ir_node *_pu_color_irn(phi_unit_t *pu, ir_node *irn, int col, const ir_node *trigger, struct obstack *changed_nodes) {
301         ir_node *res;
302         struct obstack confl_ob;
303         ir_node **confl, *cn;
304         int i, irn_col;
305
306         DBG((dbgphi, LEVEL_3, "\t\t%n \tcaused col(%n) \t%2d --> %2d\n", trigger, irn, pu_get_new_color(pu, irn), col));
307         obstack_init(&confl_ob);
308         irn_col = pu_get_new_color(pu, irn);
309
310         if (irn_col == col)
311                 goto ret_save;
312         if (pset_find_ptr(pinned_global, irn) || pu_is_node_pinned(pu, irn)) {
313                 res = irn;
314                 goto ret_confl;
315         }
316
317         /* get all nodes which would conflict with this change */
318         {
319                 struct obstack q;
320                 int in, out;
321                 ir_node *irn_bl;
322
323                 irn_bl = get_nodes_block(irn);
324
325                 /* first check for a conflicting node which is 'living in' the irns block */
326                 {
327                         ir_node *n;
328                         pset *live_ins = get_live_in(irn_bl);
329                         for (n = pset_first(live_ins); n; n = pset_next(live_ins))
330                                 if (is_allocatable_irn(n) && n != trigger && pu_get_new_color(pu, n) == col && phi_ops_interfere(irn, n)) {
331                                         DBG((dbgphi, LEVEL_4, "\t\t    %n\ttroubles\n", n));
332                                         obstack_ptr_grow(&confl_ob, n);
333                                         pset_break(live_ins);
334                                         break;
335                                 }
336                 }
337
338                 /* setup the queue of blocks. */
339                 obstack_init(&q);
340                 obstack_ptr_grow(&q, irn_bl);
341                 in = 1;
342                 out = 0;
343
344                 /* process the queue. The code below looks for every block dominated
345                  * by the irns one, and in which the irn is live, if there are
346                  * conflicting nodes */
347                 while (out < in) {
348                         ir_node *curr_bl, *sub_bl;
349                         int i, max;
350
351                         curr_bl = ((ir_node **)obstack_base(&q))[out++];
352
353                         /* Add to the result all nodes in the block, which have
354                          * the target color and interfere with the irn */
355                         for (i = 0, max = get_irn_n_outs(curr_bl); i < max; ++i) {
356                                 ir_node *n = get_irn_out(curr_bl, i);
357                                 if (is_allocatable_irn(n) && n != trigger && pu_get_new_color(pu, n) == col && phi_ops_interfere(irn, n)) {
358                                         DBG((dbgphi, LEVEL_4, "\t\t    %n\ttroubles\n", n));
359                                         obstack_ptr_grow(&confl_ob, n);
360                                 }
361                         }
362
363                         /* If irn lives out check i-dominated blocks where the irn lives in */
364                         /* Fill the queue */
365                         if (is_live_out(curr_bl, irn)) {
366                                 dominates_for_each(curr_bl, sub_bl)
367                                         if (is_live_in(sub_bl, irn)) {
368                                                 obstack_ptr_grow(&q, sub_bl);
369                                                 in++;
370                                         }
371                         }
372                 }
373                 obstack_free(&q, NULL);
374                 obstack_ptr_grow(&confl_ob, NULL);
375                 confl = (ir_node **) obstack_finish(&confl_ob);
376         }
377
378         /* process all nodes which would conflict with this change */
379         for (i = 0, cn = confl[0]; cn; cn = confl[++i]) {
380                 ir_node *sub_res;
381
382                 /* try to color the conflicting node cn with the color of the irn itself */
383                 sub_res = _pu_color_irn(pu, cn, irn_col, irn, changed_nodes);
384                 if (sub_res != CHANGE_SAVE) {
385                         res = sub_res;
386                         goto ret_confl;
387                 }
388         }
389         /* if we arrive here all sub changes can be applied, so it's save to change this irn */
390
391 ret_save:
392         DBG((dbgphi, LEVEL_3, "\t\t%n save\n", irn));
393         obstack_free(&confl_ob, NULL);
394         pu_set_new_color(pu, irn, col);
395         obstack_ptr_grow(changed_nodes, irn);
396         return CHANGE_SAVE;
397
398 ret_confl:
399         DBG((dbgphi, LEVEL_3, "\t\t%n conflicting\n", irn));
400         obstack_free(&confl_ob, NULL);
401         return res;
402 }
403
404 static ir_node *pu_color_irn(phi_unit_t *pu, ir_node *irn, int col) {
405         ir_node *res;
406         struct obstack ob_undo;
407
408         obstack_init(&ob_undo);
409         res = _pu_color_irn(pu, irn, col, irn, &ob_undo);
410
411         if (res != CHANGE_SAVE) { /* undo virtual changes caused by the last call */
412                 int i;
413                 ir_node *undo_node, **undo_nodes;
414
415                 obstack_ptr_grow(&ob_undo, NULL);
416                 undo_nodes = obstack_finish(&ob_undo);
417                 for (i = 0, undo_node = undo_nodes[0]; undo_node; undo_node = undo_nodes[++i])
418                         pu_undo_color(pu, undo_node);
419         }
420
421         obstack_free(&ob_undo, NULL);
422         return res;
423 }
424
425 /**
426  * Tries to set as much members of a phi unit as possible to color @p col.
427  * All changes taken together are guaranteed to be conflict free.
428  */
429 static int pu_try_color(phi_unit_t *pu, int col, int b_size) {
430         struct obstack ob_mis;
431         int i, redo, mis_size;
432         ir_node **mis;
433
434         obstack_init(&ob_mis);
435         redo = 1;
436         while (redo) {
437                 redo = 0;
438                 /* get a max independent set regarding current conflicts */
439                 mis_size = pu_get_mis(pu, &ob_mis);
440                 mis = obstack_finish(&ob_mis);
441
442                 /* shortcut: if mis size is worse than best, then mis won't be better. */
443                 if (mis_size < b_size)
444                         goto ret;
445
446                 /* check if its possible to set the color for all members of the maximum set*/
447                 for (i = 0; i < mis_size; ++i) {
448                         ir_node *test_node, *confl_node;
449
450                         test_node = mis[i];
451                         DBG((dbgphi, LEVEL_2, "\t    Testing %n\n", test_node));
452                         confl_node = pu_color_irn(pu, test_node, col);
453
454                         if (confl_node == CHANGE_SAVE) {
455                                 DBG((dbgphi, LEVEL_2, "\t    Save\n"));
456                                 //if (!pset_find_ptr(free_nodes, test_node))
457                                         pu_pin_node(pu, test_node);
458                         } else if (confl_node == CHANGE_NYI) {
459                                 DBG((dbgphi, 0, "\t    NYI\n"));
460                         } else if (confl_node == CHANGE_IMPOSSIBLE) {
461                                 /* TODO: this may happen due to reg constraints --> remove from set ?? */
462                         } else {
463                                 DBG((dbgphi, LEVEL_2, "\t    Conflicting\n"));
464                                 assert(is_conflicting_node(confl_node));
465
466                                 if (pu_is_node_pinned(pu, confl_node)) {
467                                         /* changing test_node would change back a node of current phi unit */
468                                         pu_add_conflict(pu, confl_node, test_node);
469                                         redo = 1;
470                                 }
471                                 if (pset_find_ptr(pinned_global, confl_node)) {
472                                         /* changing test_node would change back a node of a prior phi unit */
473                                         pu_remove_node(pu, test_node);
474                                         redo = 1;
475                                 }
476                         }
477
478                         if (confl_node != CHANGE_SAVE) {
479                                 /* shortcut: color not possible for phi node (phi comes first) ==> exit */
480                                 if (i == 0) {
481                                         mis_size = 0;
482                                         goto ret;
483                                 }
484                                 /* break iteration over current mis, because it will change */
485                                 break;
486                         }
487                 }
488                 obstack_free(&ob_mis, mis);
489         }
490
491 ret:
492         obstack_free(&ob_mis, NULL);
493         return mis_size;
494 }
495
496 /**
497  * Tries to re-allocate colors of nodes in this phi unit, to achieve a lower
498  * number of copy instructions placed during phi destruction. Optimized version.
499  * Works only for phi-classes/phi-units with exactly 1 phi node, which is the
500  * case for approximately 80% of all phi units.
501  */
502 static void pu_coal_1_phi(phi_unit_t *pu) {
503         int size, col, b_size, b_color;
504         set *b_changes;
505
506         /* init best search result */
507         b_changes = NULL;
508         b_size = 0;
509         b_color = NO_COLOR;
510
511         /* find optimum of all colors */
512         for (col = MAX_COLORS-1; col >= 0; --col) {
513                 DBG((dbgphi, 1, "\tTrying color %d\n", col));
514                 size = pu_try_color(pu, col, b_size);
515
516                 /* did we find a better max ind. set? */
517                 if (size > b_size) {
518                         DBG((dbgphi, 1, "\tBetter size: %d\n", size));
519                         if (b_changes)
520                                 del_set(b_changes);
521                         b_changes = pu->changed_nodes;
522                         b_size = size;
523                         b_color = col;
524                 } else {
525                         del_set(pu->changed_nodes);
526                 }
527
528                 /* reset the phi unit to original state for next color */
529                 pu->changed_nodes = new_set(set_cmp_node_stat_t, INITIAL_SLOTS_CHANGED_NODES);
530                 pu->conflict_count = pu->conflict_count_org;
531
532                 /* shortcut: if all members can be colored we are (very) happy */
533                 if (b_size == pu->node_count)
534                         break;
535         }
536
537         /* now apply the found optimum */
538         if (b_changes) {
539                 node_stat_t *ns;
540                 DBG((dbgphi, 0, "\tBest color: %d  Copies: %d/%d\n", b_color, pu->node_count-b_size, pu->node_count-1));
541                 for (ns = set_first(b_changes); ns; ns = set_next(b_changes)) {
542                         /* NO_COLOR is possible, if we had an undo; so the irn stays in the
543                          * pu->changed_nodes with new color set to NO_COLOR. */
544                         if (ns->color != NO_COLOR) {
545                                 DBG((dbgphi, 1, "\t    color(%n) := %d\n", ns->irn, ns->color));
546                                 set_irn_color(ns->irn, ns->color);
547                                 if (pu_is_global_pinnable(pu, ns->irn) && ns->color == pu_get_new_color(pu, pu->nodes[0]))
548                                         pset_insert_ptr(pinned_global, ns->irn);
549                         }
550                 }
551                 free(b_changes);
552         } else {
553                 DBG((dbgphi, 1, "\tBest color: none\n"));
554         }
555 }
556
557 /**
558  * Tries to re-allocate colors of nodes in this phi unit, to achieve a lower
559  * number of copy instructions placed during phi destruction.
560  * General purpose version.
561  */
562 static void pu_coal_n_phi(phi_unit_t *pu) {
563         /* TODO */
564 }
565
566 /**
567  * Prepares a phi class for further processing as a phi unit.
568  * @param pc The phi class to prepare.
569  * @return A so called phi unit containing some prepared informations
570  *         needed by the following coalescing phase.
571  */
572 static phi_unit_t *new_pu(pset *pc) {
573         phi_unit_t *pu;
574         ir_node *n, *phi = NULL;
575
576         /* get the phi count of this class */
577         pu = calloc(1, sizeof(*pu));
578         for (n = pset_first(pc); n; n = pset_next(pc))
579                 if (is_Phi(n)) {
580                         phi = n;
581                         pu->phi_count++;
582                 }
583
584         if (pu->phi_count == 1) {
585                 ir_node **tmp;
586                 int i, o;
587                 struct obstack ob;
588
589                 obstack_init(&ob);
590
591                 /* build member set not containing phi interferers */
592                 DBG((dbgphi, 1, "\tPhi-1 unit:\n"));
593
594                 DBG((dbgphi, 1, "\t    %n\n", phi));
595                 obstack_ptr_grow(&ob, phi);
596                 pu->node_count = 1;
597
598                 for (n = pset_first(pc); n; n = pset_next(pc)) {
599                         if (is_Phi(n))
600                                 continue;
601                         if (!phi_ops_interfere(phi, n)) {
602                                 DBG((dbgphi, 1, "\t    %n\n", n));
603                                 obstack_ptr_grow(&ob, n);
604                                 pu->node_count++;
605                         } else {
606                                 DBG((dbgphi, 1, "\t    %n \tdropped\n", n));
607                                 /* TODO: What if the irn is only free wrt one phi class? */
608                                 //pset_insert_ptr(free_nodes, n);
609                         }
610                 }
611                 tmp = obstack_finish(&ob);
612                 pu->nodes = malloc(pu->node_count * sizeof(*pu->nodes));
613                 memcpy(&pu->nodes[0], tmp, pu->node_count * sizeof(*tmp));
614
615                 /* init conlict graph to life range interference */
616                 DBG((dbgphi, 1, "\tInitial conflicts:\n"));
617                 for (i = 0; i < pu->node_count; ++i)
618                         for (o = i+1; o < pu->node_count; ++o)
619                                 if (phi_ops_interfere(pu->nodes[i], pu->nodes[o]))
620                                         pu_add_conflict(pu, pu->nodes[i], pu->nodes[o]);
621                 pu->conflict_count_org = pu->conflict_count;
622
623                 pu->changed_nodes = new_set(set_cmp_node_stat_t, INITIAL_SLOTS_CHANGED_NODES);
624
625                 obstack_free(&ob, NULL);
626         } else {
627                 DBG((dbgphi, 1, "\tPhi-n unit:\n"));
628                 /* TODO */
629         }
630
631         return pu;
632 }
633
634
635 /**
636  * Deletes a phi unit
637  */
638 static void free_pu(phi_unit_t *pu) {
639         if (pu->phi_count == 1) {
640                 free(pu->nodes);
641                 free(pu->changed_nodes);
642                 if (pu->conflicts)
643                         free(pu->conflicts);
644         } else {
645                 /* TODO */
646         }
647         free(pu);
648 }
649
650
651 void be_phi_coalesce(pset *all_phi_classes) {
652         pset *pc;
653
654         pinned_global = pset_new_ptr(INITIAL_SLOTS_PINNED_GLOBAL);
655 //      free_nodes = pset_new_ptr(INITIAL_SLOTS_FREE_NODES);
656
657         for (pc = pset_first(all_phi_classes); pc; pc = pset_next(all_phi_classes)) {
658                 phi_unit_t *pu = new_pu(pc);
659                 if (pu->phi_count == 1)
660                         pu_coal_1_phi(pu);
661                 else
662                         pu_coal_n_phi(pu);
663                 free_pu(pu);
664         }
665
666 //      del_pset(free_nodes);
667         del_pset(pinned_global);
668 }
669
670
671 void be_phi_coal_init(void) {
672         dbgphi = firm_dbg_register("ir.be.phicoal");
673         firm_dbg_set_mask(dbgphi, DEBUG_LVL);
674 }