- belady spiller places its copy nodes smarter now
[libfirm] / ir / be / bespillbelady.c
1 /**
2  * Author:      Daniel Grund
3  * Date:                20.09.2005
4  * Copyright:   (c) Universitaet Karlsruhe
5  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6  *
7  */
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11
12 #ifdef HAVE_ALLOCA_H
13 #include <alloca.h>
14 #endif
15
16 #ifdef HAVE_MALLOC_H
17 #include <malloc.h>
18 #endif
19
20 #include "obst.h"
21 #include "set.h"
22 #include "pset.h"
23 #include "irprintf_t.h"
24 #include "irgraph.h"
25 #include "irnode.h"
26 #include "irmode.h"
27 #include "irgwalk.h"
28 #include "iredges_t.h"
29 #include "ircons_t.h"
30 #include "irprintf.h"
31
32 #include "beutil.h"
33 #include "bearch.h"
34 #include "bespillbelady.h"
35 #include "beuses_t.h"
36 #include "besched_t.h"
37 #include "beirgmod.h"
38 #include "belive_t.h"
39 #include "benode_t.h"
40 #include "bechordal_t.h"
41
42 #define DBG_SPILL   1
43 #define DBG_WSETS   2
44 #define DBG_FIX     4
45 #define DBG_DECIDE  8
46 #define DBG_START  16
47 #define DBG_SLOTS  32
48 #define DBG_TRACE  64
49 #define DBG_WORKSET 128
50 #define DEBUG_LVL 0 //(DBG_START | DBG_DECIDE | DBG_WSETS | DBG_FIX | DBG_SPILL)
51 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
52
53 typedef struct _workset_t workset_t;
54
55 typedef struct _belady_env_t {
56         struct obstack ob;
57         const arch_env_t *arch;
58         const arch_register_class_t *cls;
59         int n_regs;                     /** number of regs in this reg-class */
60
61         workset_t *ws;          /**< the main workset used while processing a block. ob-allocated */
62         be_uses_t *uses;        /**< env for the next-use magic */
63         ir_node *instr;         /**< current instruction */
64         unsigned instr_nr;      /**< current instruction number (relative to block start) */
65         pset *used;                     /**< holds the values used (so far) in the current BB */
66         ir_node **copies;       /**< holds all copies placed due to phi-spilling */
67
68         spill_env_t *senv;      /**< see bespill.h */
69 } belady_env_t;
70
71 struct _workset_t {
72         belady_env_t *bel;
73         int len;                        /**< current length */
74         loc_t vals[1];          /**< inlined array of the values/distances in this working set */
75 };
76
77 void workset_print(const workset_t *w)
78 {
79         int i;
80
81         for(i = 0; i < w->len; ++i) {
82                 ir_printf("%+F %d\n", w->vals[i].irn, w->vals[i].time);
83         }
84 }
85
86 /**
87  * Alloc a new workset on obstack @p ob with maximum size @p max
88  */
89 static INLINE workset_t *new_workset(struct obstack *ob, belady_env_t *bel) {
90         workset_t *res;
91         size_t size = sizeof(*res) + (bel->n_regs-1)*sizeof(res->vals[0]);
92         res = obstack_alloc(ob, size);
93         memset(res, 0, size);
94         res->bel = bel;
95         return res;
96 }
97
98 /**
99  * Alloc a new instance on obstack and make it equal to @param ws
100  */
101 static INLINE workset_t *workset_clone(struct obstack *ob, workset_t *ws) {
102         workset_t *res;
103         size_t size = sizeof(*res) + (ws->bel->n_regs-1)*sizeof(res->vals[0]);
104         res = obstack_alloc(ob, size);
105         memcpy(res, ws, size);
106         return res;
107 }
108
109 /**
110  * Do NOT alloc anything. Make @param tgt equal to @param src.
111  * returns @param tgt for convinience
112  */
113 static INLINE workset_t *workset_copy(workset_t *tgt, workset_t *src) {
114         size_t size = sizeof(*src) + (src->bel->n_regs-1)*sizeof(src->vals[0]);
115         memcpy(tgt, src, size);
116         return tgt;
117 }
118
119 /**
120  * Overwrites the current content array of @param ws with the
121  * @param count locations given at memory @param locs.
122  * Set the length of @param ws to count.
123  */
124 #define workset_bulk_fill(ws, count, locs) memcpy(&(ws)->vals[0], locs, ((ws)->len=count)*sizeof(locs[0]));
125
126
127 /**
128  * Inserts the value @p val into the workset, iff it is not
129  * already contained. The workset must not be full.
130  */
131 static INLINE void workset_insert(workset_t *ws, ir_node *val) {
132         int i;
133         /* check for current regclass */
134         if (arch_get_irn_reg_class(ws->bel->arch, val, -1) != ws->bel->cls) {
135                 DBG((dbg, DBG_WORKSET, "Dropped %+F\n", val));
136                 return;
137         }
138
139         /* check if val is already contained */
140         for(i=0; i<ws->len; ++i)
141                 if (ws->vals[i].irn == val)
142                         return;
143
144         /* insert val */
145         assert(ws->len < ws->bel->n_regs && "Workset already full!");
146         ws->vals[ws->len++].irn = val;
147 }
148
149 /**
150  * Inserts all values in array @p vals of length @p cnt
151  * into the workset. There must be enough space for the
152  * entries.
153  */
154 static INLINE void workset_bulk_insert(workset_t *ws, int cnt, ir_node **vals) {
155         int i, o;
156
157         for(o=0; o<cnt; ++o) {
158                 ir_node *val = vals[o];
159                 DBG((dbg, DBG_TRACE, "Bulk insert %+F\n", val));
160                 /* check for current regclass */
161                 if (arch_get_irn_reg_class(ws->bel->arch, val, -1) != ws->bel->cls) {
162                         DBG((dbg, DBG_TRACE, "Wrong reg class\n"));
163                         goto no_insert;
164                 }
165
166                 /* check if val is already contained */
167                 for(i=0; i<ws->len; ++i)
168                         if (ws->vals[i].irn == val) {
169                                 DBG((dbg, DBG_TRACE, "Already contained\n"));
170                                 goto no_insert;
171                         }
172
173                 /* insert val */
174                 assert(ws->len < ws->bel->n_regs && "Workset does not have enough room!");
175                 ws->vals[ws->len++].irn = val;
176                 DBG((dbg, DBG_TRACE, "Inserted\n"));
177
178 no_insert:
179                 /*epsilon statement :)*/;
180         }
181 }
182
183 /**
184  * Removes all entries from this workset
185  */
186 #define workset_clear(ws) (ws)->len = 0;
187
188 /**
189  * Removes the value @p val from the workset if present.
190  */
191 static INLINE void workset_remove(workset_t *ws, ir_node *val) {
192         int i;
193         for(i=0; i<ws->len; ++i)
194                 if (ws->vals[i].irn == val) {
195                         ws->vals[i] = ws->vals[--ws->len];
196                         return;
197                 }
198 }
199
200 static INLINE int workset_contains(const workset_t *ws, const ir_node *val) {
201         int i;
202         for(i=0; i<ws->len; ++i)
203                 if (ws->vals[i].irn == val)
204                         return 1;
205         return 0;
206 }
207
208 /**
209  * Iterates over all values in the working set.
210  * @p ws The workset to iterate
211  * @p v  A variable to put the current value in
212  * @p i  An integer for internal use
213  */
214 #define workset_foreach(ws, v, i)       for(i=0; \
215                                                                                 v=(i < ws->len) ? ws->vals[i].irn : NULL, i < ws->len; \
216                                                                                 ++i)
217
218 #define workset_set_time(ws, i, t) (ws)->vals[i].time=t
219 #define workset_set_length(ws, length) (ws)->len = length
220 #define workset_get_length(ws) ((ws)->len)
221 #define workset_get_val(ws, i) ((ws)->vals[i].irn)
222 #define workset_sort(ws) qsort((ws)->vals, (ws)->len, sizeof((ws)->vals[0]), loc_compare);
223
224 typedef struct _block_info_t {
225         workset_t *ws_start, *ws_end;
226 } block_info_t;
227
228
229 static INLINE void *new_block_info(struct obstack *ob) {
230         block_info_t *res = obstack_alloc(ob, sizeof(*res));
231         res->ws_start = NULL;
232         res->ws_end = NULL;
233
234         return res;
235 }
236
237 #define get_block_info(blk)                     ((block_info_t *)get_irn_link(blk))
238 #define set_block_info(blk, info)       set_irn_link(blk, info)
239
240 static int is_mem_phi(const ir_node *irn, void *data) {
241         workset_t *sws;
242         ir_node *blk = get_nodes_block(irn);
243
244         DBG((dbg, DBG_SPILL, "Is %+F a mem-phi?\n", irn));
245         sws = get_block_info(blk)->ws_start;
246         DBG((dbg, DBG_SPILL, "  %d\n", !workset_contains(sws, irn)));
247         return !workset_contains(sws, irn);
248 }
249
250 /**
251  * @return The distance to the next use
252  *         Or 0 if irn is an ignore node
253  */
254
255 static INLINE unsigned get_distance(belady_env_t *bel, const ir_node *from, unsigned from_step, const ir_node *def, int skip_from_uses)
256 {
257         arch_irn_flags_t fl = arch_irn_get_flags(bel->arch, def);
258         unsigned dist = be_get_next_use(bel->uses, from, from_step, def, skip_from_uses);
259
260         if(!USES_IS_INIFINITE(dist) && (fl & (arch_irn_flags_ignore | arch_irn_flags_dont_spill)) != 0)
261                 return 0;
262
263         return dist;
264 }
265
266 /**
267  * Performs the actions necessary to grant the request that:
268  * - new_vals can be held in registers
269  * - as few as possible other values are disposed
270  * - the worst values get disposed
271  *
272  * @p is_usage indicates that the values in new_vals are used (not defined)
273  * In this case reloads must be performed
274  */
275 static void displace(belady_env_t *bel, workset_t *new_vals, int is_usage) {
276         ir_node *val;
277         int i, len, max_allowed, demand, iter;
278         workset_t *ws = bel->ws;
279         ir_node **to_insert = alloca(bel->n_regs * sizeof(*to_insert));
280
281         /*
282          * 1. Identify the number of needed slots and the values to reload
283          */
284         demand = 0;
285         workset_foreach(new_vals, val, iter) {
286                 /* mark value as used */
287                 if (is_usage)
288                         pset_insert_ptr(bel->used, val);
289
290                 if (!workset_contains(ws, val)) {
291                         DBG((dbg, DBG_DECIDE, "    insert %+F\n", val));
292                         to_insert[demand++] = val;
293                         if (is_usage)
294                                 be_add_reload(bel->senv, val, bel->instr);
295                 } else {
296                         DBG((dbg, DBG_DECIDE, "    skip %+F\n", val));
297                 }
298         }
299         DBG((dbg, DBG_DECIDE, "    demand = %d\n", demand));
300
301         /*
302          * 2. Make room for at least 'demand' slots
303          */
304         len = workset_get_length(ws);
305         max_allowed = bel->n_regs - demand;
306
307         DBG((dbg, DBG_DECIDE, "    disposing %d values\n", ws->len - max_allowed));
308
309         /* Only make more free room if we do not have enough */
310         if (len > max_allowed) {
311                 /* get current next-use distance */
312                 for (i=0; i<ws->len; ++i)
313                         workset_set_time(ws, i, get_distance(bel, bel->instr, bel->instr_nr, workset_get_val(ws, i), !is_usage));
314
315                 /* sort entries by increasing nextuse-distance*/
316                 workset_sort(ws);
317
318                 /* Logic for not needed live-ins: If a value is disposed
319                    before its first usage, remove it from start workset */
320                 for (i=max_allowed; i<ws->len; ++i) {
321                         ir_node *irn = ws->vals[i].irn;
322
323                         if (!pset_find_ptr(bel->used, irn)) {
324                                 ir_node *curr_bb = get_nodes_block(bel->instr);
325                                 workset_t *ws_start = get_block_info(curr_bb)->ws_start;
326                                 workset_remove(ws_start, irn);
327
328                                 DBG((dbg, DBG_DECIDE, "    dispose %+F dumb\n", irn));
329                         } else {
330                                 DBG((dbg, DBG_DECIDE, "    dispose %+F\n", irn));
331                         }
332                 }
333
334                 /* kill the last 'demand' entries in the array */
335                 workset_set_length(ws, max_allowed);
336         }
337
338         /*
339          * 3. Insert the new values into the workset
340          */
341         workset_bulk_insert(bel->ws, demand, to_insert);
342 }
343
344 static void belady(ir_node *blk, void *env);
345
346 /**
347  * Inserts a spill of a value at the earliest possible location in a block.
348  * That is after the last use of the value or at the beginning of the block if
349  * there is no use
350  */
351 static ir_node *insert_copy(belady_env_t *env, ir_node *block, ir_node *value) {
352         ir_node* node;
353         ir_graph *irg = get_irn_irg(block);
354         ir_node *copy = be_new_Copy(env->cls, irg, block, value);
355
356         ARR_APP1(ir_node*, env->copies, copy);
357
358         // walk schedule backwards until we find a usage, or until we have reached the first phi
359         // TODO can we do this faster somehow? This makes insert_copy O(n) in block_size...
360         sched_foreach_reverse(block, node) {
361                 int i, arity;
362
363                 if(is_Phi(node)) {
364                         sched_add_after(node, copy);
365                         goto placed;
366                 }
367                 if(value == node) {
368                         sched_add_after(node, copy);
369                         goto placed;
370                 }
371                 for(i = 0, arity = get_irn_arity(node); i < arity; ++i) {
372                         ir_node *arg = get_irn_n(node, i);
373                         if(arg == value) {
374                                 sched_add_after(node, copy);
375                                 goto placed;
376                         }
377                 }
378         }
379         // we didn't find a use or a phi yet, so place the copy at the beginning of the block
380         sched_add_before(sched_first(block), copy);
381
382 placed:
383
384         return copy;
385 }
386
387 /**
388  * Collects all values live-in at block @p blk and all phi results in this block.
389  * Then it adds the best values (at most n_regs) to the blocks start_workset.
390  * The phis among the remaining values get spilled: Introduce psudo-copies of
391  *  their args to break interference and make it possible to spill them to the
392  *  same spill slot.
393  */
394 static block_info_t *compute_block_start_info(ir_node *blk, void *data) {
395         belady_env_t *env = data;
396         ir_node *irn, *first;
397         irn_live_t *li;
398         int i, count, ws_count;
399         loc_t loc, *starters;
400         ir_graph *irg = get_irn_irg(blk);
401         struct obstack ob;
402         block_info_t *res = get_block_info(blk);
403
404         /* Have we seen this block before? */
405         if (res)
406                 return res;
407
408         /* Create the block info for this block. */
409         res = new_block_info(&env->ob);
410         set_block_info(blk, res);
411
412
413         /* Get all values living at the block start sorted by next use*/
414         obstack_init(&ob);
415
416         DBG((dbg, DBG_START, "Living at start of %+F:\n", blk));
417         first = sched_first(blk);
418         count = 0;
419         sched_foreach(blk, irn) {
420                 if (is_Phi(irn) && arch_get_irn_reg_class(env->arch, irn, -1) == env->cls) {
421                         loc.irn = irn;
422                         loc.time = get_distance(env, first, 0, irn, 0);
423                         obstack_grow(&ob, &loc, sizeof(loc));
424                         DBG((dbg, DBG_START, "    %+F:\n", irn));
425                         count++;
426                 } else
427                         break;
428         }
429
430         live_foreach(blk, li) {
431                 if (live_is_in(li) && arch_get_irn_reg_class(env->arch, li->irn, -1) == env->cls) {
432                         loc.irn = (ir_node *)li->irn;
433                         loc.time = get_distance(env, first, 0, li->irn, 0);
434                         obstack_grow(&ob, &loc, sizeof(loc));
435                         DBG((dbg, DBG_START, "    %+F:\n", li->irn));
436                         count++;
437                 }
438         }
439
440         starters = obstack_finish(&ob);
441         qsort(starters, count, sizeof(starters[0]), loc_compare);
442
443
444         /* If we have only one predecessor, we want the start_set of blk to be the end_set of pred */
445         if (get_Block_n_cfgpreds(blk) == 1 && blk != get_irg_start_block(get_irn_irg(blk))) {
446                 ir_node *pred_blk       = get_Block_cfgpred_block(blk, 0);
447                 block_info_t *pred_info = get_block_info(pred_blk);
448
449                 /* if pred block has not been processed yet, do it now */
450                 if (! pred_info) {
451                         belady(pred_blk, env);
452                         pred_info = get_block_info(pred_blk);
453                 }
454
455                 /* now we have an end_set of pred */
456                 assert(pred_info->ws_end && "The recursive call (above) is supposed to compute an end_set");
457                 res->ws_start = workset_clone(&env->ob, pred_info->ws_end);
458
459         } else
460
461         /* Else we want the start_set to be the values used 'the closest' */
462         {
463                 /* Copy the best ones from starters to start workset */
464                 ws_count = MIN(count, env->n_regs);
465                 res->ws_start = new_workset(&env->ob, env);
466                 workset_bulk_fill(res->ws_start, ws_count, starters);
467         }
468
469
470
471         /* The phis of this block which are not in the start set have to be spilled later.
472          * Therefore we add temporary copies in the pred_blocks so the spills can spill
473          * into the same spill slot.
474          * After spilling these copies get deleted. */
475         for (i=workset_get_length(res->ws_start); i<count; ++i) {
476                 int o, max;
477
478                 irn = starters[i].irn;
479                 if (!is_Phi(irn) || get_nodes_block(irn) != blk)
480                         continue;
481
482                 DBG((dbg, DBG_START, "For %+F:\n", irn));
483
484                 for (max=get_irn_arity(irn), o=0; o<max; ++o) {
485                         ir_node *pred_block = get_Block_cfgpred_block(get_nodes_block(irn), o);
486                         ir_node *arg = get_irn_n(irn, o);
487                         ir_node* copy = insert_copy(env, pred_block, arg);
488
489                         set_irn_n(irn, o, copy);
490                 }
491         }
492
493         obstack_free(&ob, NULL);
494         return res;
495 }
496
497
498 /**
499  * For the given block @p blk, decide for each values
500  * whether it is used from a register or is reloaded
501  * before the use.
502  */
503 static void belady(ir_node *blk, void *env) {
504         belady_env_t *bel = env;
505         workset_t *new_vals;
506         ir_node *irn;
507         int iter;
508         block_info_t *blk_info;
509
510         /* Don't do a block twice */
511         if (get_block_info(blk))
512                 return;
513
514         /* get the starting workset for this block */
515         blk_info = compute_block_start_info(blk, bel);
516
517         DBG((dbg, DBG_DECIDE, "\n"));
518         DBG((dbg, DBG_DECIDE, "Decide for %+F\n", blk));
519
520         workset_copy(bel->ws, blk_info->ws_start);
521         DBG((dbg, DBG_WSETS, "Start workset for %+F:\n", blk));
522         workset_foreach(bel->ws, irn, iter)
523                 DBG((dbg, DBG_WSETS, "  %+F\n", irn));
524
525         /* process the block from start to end */
526         DBG((dbg, DBG_WSETS, "Processing...\n"));
527         bel->used = pset_new_ptr(32);
528         bel->instr_nr = 0;
529         new_vals = new_workset(&bel->ob, bel);
530         sched_foreach(blk, irn) {
531                 assert(workset_get_length(bel->ws) <= bel->n_regs && "Too much values in workset!");
532
533
534                 /* projs are handled with the tuple value.
535                  * Phis are no real instr (see insert_starters())
536                  * instr_nr does not increase */
537                 if (is_Proj(irn) || is_Phi(irn)) {
538                         DBG((dbg, DBG_DECIDE, "  ...%+F skipped\n", irn));
539                         continue;
540                 }
541                 DBG((dbg, DBG_DECIDE, "  ...%+F\n", irn));
542
543                 /* set instruction in the workset */
544                 bel->instr = irn;
545
546                 /* allocate all values _used_ by this instruction */
547                 workset_clear(new_vals);
548                 workset_bulk_insert(new_vals, get_irn_arity(irn)+1, get_irn_in(irn));
549                 displace(bel, new_vals, 1);
550
551                 /* allocate all values _defined_ by this instruction */
552                 workset_clear(new_vals);
553                 if (get_irn_mode(irn) == mode_T) { /* special handling for tuples and projs */
554                         ir_node *proj;
555                         for(proj=sched_next(irn); is_Proj(proj); proj=sched_next(proj))
556                                 workset_insert(new_vals, proj);
557                 } else {
558                         workset_insert(new_vals, irn);
559                 }
560                 displace(bel, new_vals, 0);
561
562                 bel->instr_nr++;
563         }
564         del_pset(bel->used);
565
566         /* Remember end-workset for this block */
567         blk_info->ws_end = workset_clone(&bel->ob, bel->ws);
568         DBG((dbg, DBG_WSETS, "End workset for %+F:\n", blk));
569         workset_foreach(blk_info->ws_end, irn, iter)
570                 DBG((dbg, DBG_WSETS, "  %+F\n", irn));
571 }
572
573 /**
574  * 'decide' is block-local and makes assumptions
575  * about the set of live-ins. Thus we must adapt the
576  * live-outs to the live-ins at each block-border.
577  */
578 static void fix_block_borders(ir_node *blk, void *env) {
579         workset_t *wsb;
580         belady_env_t *bel = env;
581         int i, max, iter, iter2;
582
583         DBG((dbg, DBG_FIX, "\n"));
584         DBG((dbg, DBG_FIX, "Fixing %+F\n", blk));
585
586         wsb = get_block_info(blk)->ws_start;
587
588         /* process all pred blocks */
589         for (i=0, max=get_irn_arity(blk); i<max; ++i) {
590                 ir_node *irnb, *irnp, *pred = get_Block_cfgpred_block(blk, i);
591                 workset_t *wsp = get_block_info(pred)->ws_end;
592
593                 DBG((dbg, DBG_FIX, "  Pred %+F\n", pred));
594
595                 workset_foreach(wsb, irnb, iter) {
596                         /* if irnb is a phi of the current block we reload
597                          * the corresponding argument, else irnb itself */
598                         if(is_Phi(irnb) && blk == get_nodes_block(irnb))
599                                 irnb = get_irn_n(irnb, i);
600
601                         /* Unknowns are available everywhere */
602                         if(get_irn_opcode(irnb) == iro_Unknown)
603                                 continue;
604
605                         /* check if irnb is in a register at end of pred */
606                         workset_foreach(wsp, irnp, iter2) {
607                                 if (irnb == irnp)
608                                         goto next_value;
609                         }
610
611                         /* irnb is in memory at the end of pred, so we have to reload it */
612                         DBG((dbg, DBG_FIX, "    reload %+F\n", irnb));
613                         be_add_reload_on_edge(bel->senv, irnb, blk, i);
614
615 next_value:
616                         /*epsilon statement :)*/;
617                 }
618         }
619 }
620
621 /**
622  * Removes all copies introduced for phi-spills
623  */
624 static void remove_copies(belady_env_t *env) {
625         int i;
626
627         for(i = 0; i < ARR_LEN(env->copies); ++i) {
628                 ir_node *node = env->copies[i];
629                 ir_node *src;
630                 const ir_edge_t *edge, *ne;
631
632                 assert(be_is_Copy(node));
633
634                 src = be_get_Copy_op(node);
635                 foreach_out_edge_safe(node, edge, ne) {
636                         ir_node *user = get_edge_src_irn(edge);
637                         int user_pos = get_edge_src_pos(edge);
638
639                         set_irn_n(user, user_pos, src);
640                 }
641         }
642 }
643
644 void be_spill_belady(const be_chordal_env_t *chordal_env) {
645         be_spill_belady_spill_env(chordal_env, NULL);
646 }
647
648 void be_spill_belady_spill_env(const be_chordal_env_t *chordal_env, spill_env_t *spill_env) {
649         belady_env_t bel;
650
651         FIRM_DBG_REGISTER(dbg, "firm.be.spill.belady");
652
653         /* init belady env */
654         obstack_init(&bel.ob);
655         bel.arch      = chordal_env->birg->main_env->arch_env;
656         bel.cls       = chordal_env->cls;
657         bel.n_regs    = arch_register_class_n_regs(bel.cls);
658         bel.ws        = new_workset(&bel.ob, &bel);
659         bel.uses      = be_begin_uses(chordal_env->irg, chordal_env->birg->main_env->arch_env, bel.cls);
660         if(spill_env == NULL) {
661                 bel.senv = be_new_spill_env(chordal_env, is_mem_phi, NULL);
662         } else {
663                 bel.senv = spill_env;
664                 be_set_is_spilled_phi(bel.senv, is_mem_phi, NULL);
665         }
666         DEBUG_ONLY(be_set_spill_env_dbg_module(bel.senv, dbg);)
667         bel.copies    = NEW_ARR_F(ir_node*, 0);
668
669         DBG((dbg, LEVEL_1, "running on register class: %s\n", bel.cls->name));
670
671         /* do the work */
672         be_clear_links(chordal_env->irg);
673         irg_block_walk_graph(chordal_env->irg, NULL, belady, &bel);
674         irg_block_walk_graph(chordal_env->irg, fix_block_borders, NULL, &bel);
675         be_insert_spills_reloads(bel.senv);
676         remove_copies(&bel);
677         DEL_ARR_F(bel.copies);
678
679         be_remove_dead_nodes_from_schedule(chordal_env->irg);
680
681         /* clean up */
682         if(spill_env == NULL)
683                 be_delete_spill_env(bel.senv);
684         be_end_uses(bel.uses);
685         obstack_free(&bel.ob, NULL);
686 }