Bugfixes
[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 "irgraph.h"
24 #include "irnode.h"
25 #include "irmode.h"
26 #include "irgwalk.h"
27 #include "iredges_t.h"
28 #include "ircons_t.h"
29
30 #include "beutil.h"
31 #include "bearch.h"
32 #include "bespillbelady.h"
33 #include "beuses_t.h"
34 #include "besched_t.h"
35 #include "beirgmod.h"
36 #include "belive_t.h"
37 #include "benode_t.h"
38 #include "bechordal_t.h"
39
40 #define DBG_SPILL   1
41 #define DBG_WSETS   2
42 #define DBG_FIX     4
43 #define DBG_DECIDE  8
44 #define DBG_START  16
45 #define DBG_SLOTS  32
46 #define DBG_TRACE  64
47 #define DEBUG_LVL 0 //(DBG_START | DBG_DECIDE | DBG_WSETS | DBG_FIX | DBG_SPILL)
48 static firm_dbg_module_t *dbg = NULL;
49
50 #define MIN(a,b) (((a)<(b))?(a):(b))
51
52 typedef struct _workset_t workset_t;
53
54 typedef struct _belady_env_t {
55         struct obstack ob;
56         const arch_env_t *arch;
57         const arch_register_class_t *cls;
58         int n_regs;                     /** number of regs in this reg-class */
59
60         workset_t *ws;          /**< the main workset used while processing a block. ob-allocated */
61         be_uses_t *uses;        /**< env for the next-use magic */
62         ir_node *instr;         /**< current instruction */
63         unsigned instr_nr;      /**< current instruction number (relative to block start) */
64         pset *used;                     /**< holds the values used (so far) in the current BB */
65         pset *copies;           /**< holds all copies placed due to phi-spilling */
66
67         spill_env_t *senv;      /* see bespill.h */
68         pset *reloads;          /**< all reload nodes placed */
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_DECIDE, "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         if((fl & (arch_irn_flags_ignore | arch_irn_flags_dont_spill)) != 0)
259                 return 0;
260         else
261                 return be_get_next_use(bel->uses, from, from_step, def, skip_from_uses);
262 }
263
264 /**
265  * Performs the actions necessary to grant the request that:
266  * - new_vals can be held in registers
267  * - as few as possible other values are disposed
268  * - the worst values get disposed
269  *
270  * @p is_usage indicates that the values in new_vals are used (not defined)
271  * In this case reloads must be performed
272  */
273 static void displace(belady_env_t *bel, workset_t *new_vals, int is_usage) {
274         ir_node *val;
275         int i, len, max_allowed, demand, iter;
276         workset_t *ws = bel->ws;
277         ir_node **to_insert = alloca(bel->n_regs * sizeof(*to_insert));
278
279         /*
280          * 1. Identify the number of needed slots and the values to reload
281          */
282         demand = 0;
283         workset_foreach(new_vals, val, iter) {
284                 /* mark value as used */
285                 if (is_usage)
286                         pset_insert_ptr(bel->used, val);
287
288                 if (!workset_contains(ws, val)) {
289                         DBG((dbg, DBG_DECIDE, "    insert %+F\n", val));
290                         to_insert[demand++] = val;
291                         if (is_usage)
292                                 be_add_reload(bel->senv, val, bel->instr);
293                 } else
294                         DBG((dbg, DBG_DECIDE, "    skip %+F\n", val));
295         }
296         DBG((dbg, DBG_DECIDE, "    demand = %d\n", demand));
297
298
299         /*
300          * 2. Make room for at least 'demand' slots
301          */
302         len = workset_get_length(ws);
303         max_allowed = bel->n_regs - demand;
304
305         /* Only make more free room if we do not have enough */
306         if (len > max_allowed) {
307                 /* get current next-use distance */
308                 for (i=0; i<ws->len; ++i)
309                         workset_set_time(ws, i, get_distance(bel, bel->instr, bel->instr_nr, workset_get_val(ws, i), !is_usage));
310
311                 /* sort entries by increasing nextuse-distance*/
312                 workset_sort(ws);
313
314                 /* Logic for not needed live-ins: If a value is disposed
315                    before its first usage, remove it from start workset */
316                 for (i=max_allowed; i<ws->len; ++i) {
317                         ir_node *irn = ws->vals[i].irn;
318                         if (!pset_find_ptr(bel->used, irn)) {
319                                 ir_node *curr_bb = get_nodes_block(bel->instr);
320                                 workset_t *ws_start = get_block_info(curr_bb)->ws_start;
321                                 workset_remove(ws_start, irn);
322
323                                 DBG((dbg, DBG_DECIDE, "    dispose %+F dumb\n", irn));
324                         } else
325                                 DBG((dbg, DBG_DECIDE, "    dispose %+F\n", irn));
326                 }
327
328                 /* kill the last 'demand' entries in the array */
329                 workset_set_length(ws, max_allowed);
330         }
331
332         /*
333          * 3. Insert the new values into the workset
334          */
335         workset_bulk_insert(bel->ws, demand, to_insert);
336 }
337
338 static void belady(ir_node *blk, void *env);
339
340 /**
341  * Collects all values live-in at block @p blk and all phi results in this block.
342  * Then it adds the best values (at most n_regs) to the blocks start_workset.
343  * The phis among the remaining values get spilled: Introduce psudo-copies of
344  *  their args to break interference and make it possible to spill them to the
345  *  same spill slot.
346  */
347 static block_info_t *compute_block_start_info(ir_node *blk, void *env) {
348         belady_env_t *bel = env;
349         ir_node *irn, *first;
350         irn_live_t *li;
351         int i, count, ws_count;
352         loc_t loc, *starters;
353         ir_graph *irg = get_irn_irg(blk);
354         struct obstack ob;
355         block_info_t *res = get_block_info(blk);
356
357         /* Have we seen this block before? */
358         if (res)
359                 return res;
360
361         /* Create the block info for this block. */
362         res = new_block_info(&bel->ob);
363         set_block_info(blk, res);
364
365
366         /* Get all values living at the block start sorted by next use*/
367         obstack_init(&ob);
368
369         DBG((dbg, DBG_START, "Living at start of %+F:\n", blk));
370         first = sched_first(blk);
371         count = 0;
372         sched_foreach(blk, irn)
373                 if (is_Phi(irn) && arch_get_irn_reg_class(bel->arch, irn, -1) == bel->cls) {
374                         loc.irn = irn;
375                         loc.time = get_distance(bel, first, 0, irn, 0);
376                         obstack_grow(&ob, &loc, sizeof(loc));
377                         DBG((dbg, DBG_START, "    %+F:\n", irn));
378                         count++;
379                 } else
380                         break;
381
382         live_foreach(blk, li)
383                 if (live_is_in(li) && arch_get_irn_reg_class(bel->arch, li->irn, -1) == bel->cls) {
384                         loc.irn = (ir_node *)li->irn;
385                         loc.time = get_distance(bel, first, 0, li->irn, 0);
386                         obstack_grow(&ob, &loc, sizeof(loc));
387                         DBG((dbg, DBG_START, "    %+F:\n", irn));
388                         count++;
389                 }
390
391         starters = obstack_finish(&ob);
392         qsort(starters, count, sizeof(starters[0]), loc_compare);
393
394
395         /* If we have only one predecessor, we want the start_set of blk to be the end_set of pred */
396         if (get_Block_n_cfgpreds(blk) == 1 && blk != get_irg_start_block(get_irn_irg(blk))) {
397                 ir_node *pred_blk       = get_Block_cfgpred_block(blk, 0);
398                 block_info_t *pred_info = get_block_info(pred_blk);
399
400                 /* if pred block has not been processed yet, do it now */
401                 if (! pred_info) {
402                         belady(pred_blk, bel);
403                         pred_info = get_block_info(pred_blk);
404                 }
405
406                 /* now we have an end_set of pred */
407                 assert(pred_info->ws_end && "The recursive call (above) is supposed to compute an end_set");
408                 res->ws_start = workset_clone(&bel->ob, pred_info->ws_end);
409
410         } else
411
412         /* Else we want the start_set to be the values used 'the closest' */
413         {
414                 /* Copy the best ones from starters to start workset */
415                 ws_count = MIN(count, bel->n_regs);
416                 res->ws_start = new_workset(&bel->ob, bel);
417                 workset_bulk_fill(res->ws_start, ws_count, starters);
418         }
419
420
421         /* The phis of this block which are not in the start set have to be spilled later.
422          * Therefore we add temporary copies in the pred_blocks so the spills can spill
423          * into the same spill slot.
424          * After spilling these copies get deleted. */
425         for (i=workset_get_length(res->ws_start); i<count; ++i) {
426                 int o, max;
427
428                 irn = starters[i].irn;
429                 if (!is_Phi(irn) || get_nodes_block(irn) != blk)
430                         continue;
431
432                 DBG((dbg, DBG_START, "For %+F:\n", irn));
433
434                 for (max=get_irn_arity(irn), o=0; o<max; ++o) {
435                         ir_node *arg = get_irn_n(irn, o);
436                         ir_node *pred_block = get_Block_cfgpred_block(get_nodes_block(irn), o);
437                         ir_node *cpy = be_new_Copy(bel->cls, irg, pred_block, arg);
438                         pset_insert_ptr(bel->copies, cpy);
439                         DBG((dbg, DBG_START, "    place a %+F of %+F in %+F\n", cpy, arg, pred_block));
440                         sched_add_before(pred_block, cpy);
441                         set_irn_n(irn, o, cpy);
442                 }
443         }
444
445         obstack_free(&ob, NULL);
446         return res;
447 }
448
449
450 /**
451  * For the given block @p blk, decide for each values
452  * whether it is used from a register or is reloaded
453  * before the use.
454  */
455 static void belady(ir_node *blk, void *env) {
456         belady_env_t *bel = env;
457         workset_t *new_vals;
458         ir_node *irn;
459         int iter;
460         block_info_t *blk_info;
461
462         /* Don't do a block twice */
463         if (get_block_info(blk))
464                 return;
465
466         /* get the starting workset for this block */
467         blk_info = compute_block_start_info(blk, bel);
468
469         DBG((dbg, DBG_DECIDE, "\n"));
470         DBG((dbg, DBG_DECIDE, "Decide for %+F\n", blk));
471
472         workset_copy(bel->ws, blk_info->ws_start);
473         DBG((dbg, DBG_WSETS, "Start workset for %+F:\n", blk));
474         workset_foreach(bel->ws, irn, iter)
475                 DBG((dbg, DBG_WSETS, "  %+F\n", irn));
476
477         /* process the block from start to end */
478         DBG((dbg, DBG_WSETS, "Processing...\n"));
479         bel->used = pset_new_ptr(32);
480         bel->instr_nr = 0;
481         new_vals = new_workset(&bel->ob, bel);
482         sched_foreach(blk, irn) {
483                 assert(workset_get_length(bel->ws) <= bel->n_regs && "Too much values in workset!");
484
485
486                 /* projs are handled with the tuple value.
487                  * Phis are no real instr (see insert_starters())
488                  * instr_nr does not increase */
489                 if (is_Proj(irn) || is_Phi(irn)) {
490                         DBG((dbg, DBG_DECIDE, "  ...%+F skipped\n", irn));
491                         continue;
492                 }
493                 DBG((dbg, DBG_DECIDE, "  ...%+F\n", irn));
494
495                 /* set instruction in the workset */
496                 bel->instr = irn;
497
498                 /* allocate all values _used_ by this instruction */
499                 workset_clear(new_vals);
500                 workset_bulk_insert(new_vals, get_irn_arity(irn)+1, get_irn_in(irn));
501                 displace(bel, new_vals, 1);
502
503                 /* allocate all values _defined_ by this instruction */
504                 workset_clear(new_vals);
505                 if (get_irn_mode(irn) == mode_T) { /* special handling for tuples and projs */
506                         ir_node *proj;
507                         for(proj=sched_next(irn); is_Proj(proj); proj=sched_next(proj))
508                                 workset_insert(new_vals, proj);
509                 } else {
510                         workset_insert(new_vals, irn);
511                 }
512                 displace(bel, new_vals, 0);
513
514                 bel->instr_nr++;
515         }
516         del_pset(bel->used);
517
518         /* Remember end-workset for this block */
519         blk_info->ws_end = workset_clone(&bel->ob, bel->ws);
520         DBG((dbg, DBG_WSETS, "End workset for %+F:\n", blk));
521         workset_foreach(blk_info->ws_end, irn, iter)
522                 DBG((dbg, DBG_WSETS, "  %+F\n", irn));
523 }
524
525 /**
526  * 'decide' is block-local and makes assumptions
527  * about the set of live-ins. Thus we must adapt the
528  * live-outs to the live-ins at each block-border.
529  */
530 static void fix_block_borders(ir_node *blk, void *env) {
531         workset_t *wsb;
532         belady_env_t *bel = env;
533         int i, max, iter, iter2;
534
535         DBG((dbg, DBG_FIX, "\n"));
536         DBG((dbg, DBG_FIX, "Fixing %+F\n", blk));
537
538         wsb = get_block_info(blk)->ws_start;
539
540         /* process all pred blocks */
541         for (i=0, max=get_irn_arity(blk); i<max; ++i) {
542                 ir_node *irnb, *irnp, *pred = get_Block_cfgpred_block(blk, i);
543                 workset_t *wsp = get_block_info(pred)->ws_end;
544
545                 DBG((dbg, DBG_FIX, "  Pred %+F\n", pred));
546
547                 workset_foreach(wsb, irnb, iter) {
548                         /* if irnb is a phi of the current block we reload
549                          * the corresponding argument, else irnb itself */
550                         if(is_Phi(irnb) && blk == get_nodes_block(irnb))
551                                 irnb = get_irn_n(irnb, i);
552
553                         /* Unknowns are available everywhere */
554                         if(get_irn_opcode(irnb) == iro_Unknown)
555                                 continue;
556
557                         /* check if irnb is in a register at end of pred */
558                         workset_foreach(wsp, irnp, iter2)
559                                 if (irnb == irnp)
560                                         goto next_value;
561
562                         /* irnb is in memory at the end of pred, so we have to reload it */
563                         DBG((dbg, DBG_FIX, "    reload %+F\n", irnb));
564                         be_add_reload_on_edge(bel->senv, irnb, blk, i);
565
566 next_value:
567                         /*epsilon statement :)*/;
568                 }
569         }
570 }
571
572 /**
573  * Removes all used reloads from bel->reloads.
574  * The remaining nodes in bel->reloads will be removed from the graph.
575  */
576 static void rescue_used_reloads(ir_node *irn, void *env) {
577         pset *rlds = (pset *)env;
578         if (pset_find_ptr(rlds, irn))
579                 pset_remove_ptr(rlds, irn);
580 }
581
582 /**
583  * Removes all copies introduced for phi-spills
584  */
585 static void remove_copies(belady_env_t *bel) {
586         ir_node *irn;
587
588         for (irn = pset_first(bel->copies); irn; irn = pset_next(bel->copies)) {
589                 ir_node *src, *spill;
590
591                 assert(be_is_Copy(irn));
592                 assert(get_irn_n_edges(irn) == 1 && "This is not a copy introduced in 'compute_block_start_info()'. Who created it?");
593
594                 spill = get_irn_edge(get_irn_irg(irn), irn, 0)->src;
595                 assert(be_is_Spill(spill) && "This is not a copy introduced in 'compute_block_start_info()'. Who created it?");
596
597                 src = get_irn_n(irn, 0);
598                 set_irn_n(spill, 0, src);
599         }
600 }
601
602 /**
603  * Finds all unused reloads and remove them from the schedule
604  * Also removes spills if they are not used anymore after removing reloads
605  */
606 static void remove_unused_reloads(ir_graph *irg, belady_env_t *bel) {
607         ir_node *irn;
608
609         irg_walk_graph(irg, rescue_used_reloads, NULL, bel->reloads);
610         for(irn = pset_first(bel->reloads); irn; irn = pset_next(bel->reloads)) {
611                 ir_node *spill;
612                 DBG((dbg, DBG_SPILL, "Removing %+F before %+F in %+F\n", irn, sched_next(irn), get_nodes_block(irn)));
613
614                 spill = get_irn_n(irn, 0);
615
616                 /* remove reload */
617                 set_irn_n(irn, 0, new_Bad());
618                 sched_remove(irn);
619
620                 /* if spill not used anymore, remove it too
621                  * test of regclass is necessary since spill may be a phi-M */
622                 if (get_irn_n_edges(spill) == 0 && bel->cls == arch_get_irn_reg_class(bel->arch, spill, -1)) {
623                         set_irn_n(spill, 0, new_Bad());
624                         sched_remove(spill);
625                 }
626         }
627 }
628
629 void be_spill_belady(const be_chordal_env_t *chordal_env) {
630         belady_env_t bel;
631
632         dbg = firm_dbg_register("ir.be.spillbelady");
633
634         /* init belady env */
635         obstack_init(&bel.ob);
636         bel.arch    = chordal_env->birg->main_env->arch_env;
637         bel.cls     = chordal_env->cls;
638         bel.n_regs  = arch_register_class_n_regs(bel.cls);
639         bel.ws      = new_workset(&bel.ob, &bel);
640         bel.uses    = be_begin_uses(chordal_env->irg, chordal_env->birg->main_env->arch_env, bel.cls);
641         bel.senv    = be_new_spill_env(dbg, chordal_env, is_mem_phi, NULL);
642         bel.reloads = pset_new_ptr_default();
643         bel.copies  = pset_new_ptr_default();
644
645         DBG((dbg, LEVEL_1, "running on register class: %s\n", bel.cls->name));
646
647         /* do the work */
648         be_clear_links(chordal_env->irg);
649         irg_block_walk_graph(chordal_env->irg, NULL, belady, &bel);
650         irg_block_walk_graph(chordal_env->irg, fix_block_borders, NULL, &bel);
651         be_insert_spills_reloads(bel.senv, bel.reloads);
652         remove_unused_reloads(chordal_env->irg, &bel);
653         remove_copies(&bel);
654
655         /* clean up */
656         del_pset(bel.reloads);
657         be_delete_spill_env(bel.senv);
658         be_end_uses(bel.uses);
659         obstack_free(&bel.ob, NULL);
660 }