- Schedule memperm node
[libfirm] / ir / be / bespillslots.c
1 /*
2  * Author:      Matthias Braun
3  * Date:                26.7.06
4  * Copyright:   (c) Universitaet Karlsruhe
5  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6  */
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10
11 #include <stdlib.h>
12
13 #include "set.h"
14
15 #include "irgwalk.h"
16 #include "ircons.h"
17 #include "irprintf.h"
18 #include "execfreq.h"
19 #include "unionfind.h"
20 #include "type.h"
21 #include "irdump_t.h"
22
23 #include "benode_t.h"
24 #include "besched.h"
25 #include "bespillslots.h"
26 #include "bechordal_t.h"
27 #include "bejavacoal.h"
28
29
30 #define DBG_COALESCING          1
31 #define DBG_INTERFERENCES       2
32
33 DEBUG_ONLY(
34 static firm_dbg_module_t *dbg = NULL;
35 )
36
37 typedef struct _spill_t {
38         ir_node *spill;
39         /** regclass of the spilled value */
40         const arch_register_class_t *cls;
41         /** index into spillslot_unionfind unionfind structure */
42         int spillslot;
43 } spill_t;
44
45 typedef struct _affinity_edge_t {
46         double affinity;
47         int slot1, slot2;
48 } affinity_edge_t;
49
50 typedef struct _ss_env_t {
51         struct obstack obst;
52         const be_chordal_env_t *chordal_env;
53         set *spills;
54         ir_node **reloads;
55         affinity_edge_t **affinity_edges;
56         set *memperms;
57 } ss_env_t;
58
59 /** Compare 2 affinity edges (used in quicksort) */
60 static int cmp_affinity(const void *d1, const void *d2) {
61         const affinity_edge_t *e1 = d1;
62         const affinity_edge_t *e2 = d2;
63
64         return e1->affinity < e2->affinity ? -1 : 1;
65 }
66
67 static int cmp_spill(const void* d1, const void* d2, size_t size) {
68         const spill_t* s1 = d1;
69         const spill_t* s2 = d2;
70         return s1->spill != s2->spill;
71 }
72
73 static spill_t *get_spill(ss_env_t *env, ir_node *node) {
74         spill_t spill, *res;
75         int hash = HASH_PTR(node);
76
77         spill.spill = node;
78         res = set_find(env->spills, &spill, sizeof(spill), hash);
79
80         return res;
81 }
82
83 /*
84  *   ____      _ _           _     ____        _ _ _
85  *  / ___|___ | | | ___  ___| |_  / ___| _ __ (_) | |___
86  * | |   / _ \| | |/ _ \/ __| __| \___ \| '_ \| | | / __|
87  * | |__| (_) | | |  __/ (__| |_   ___) | |_) | | | \__ \
88  *  \____\___/|_|_|\___|\___|\__| |____/| .__/|_|_|_|___/
89  *                                      |_|
90  */
91
92 static spill_t *collect_spill(ss_env_t *env, ir_node *node, const arch_register_class_t *cls) {
93         spill_t spill, *res;
94         int hash = HASH_PTR(node);
95
96         assert(be_is_Spill(node));
97
98         spill.spill = node;
99         res = set_find(env->spills, &spill, sizeof(spill), hash);
100
101         if(res == NULL) {
102                 spill.spillslot = set_count(env->spills);
103                 spill.cls = cls;
104                 res = set_insert(env->spills, &spill, sizeof(spill), hash);
105         } else {
106                 assert(cls == res->cls);
107         }
108
109         return res;
110 }
111
112 static spill_t *collect_memphi(ss_env_t *env, ir_node *node, const arch_register_class_t *cls) {
113         int i, arity;
114         spill_t spill, *res;
115         int hash = HASH_PTR(node);
116
117         assert(is_Phi(node));
118
119         spill.spill = node;
120         res = set_find(env->spills, &spill, sizeof(spill), hash);
121         if(res != NULL) {
122                 return res;
123         }
124
125         spill.spillslot = set_count(env->spills);
126         spill.cls = cls;
127         res = set_insert(env->spills, &spill, sizeof(spill), hash);
128
129         // is 1 of the arguments a spill?
130         for(i = 0, arity = get_irn_arity(node); i < arity; ++i) {
131                 affinity_edge_t *affinty_edge;
132                 ir_node* arg = get_irn_n(node, i);
133                 spill_t* arg_spill;
134
135                 if(be_is_Spill(arg)) {
136                         arg_spill = collect_spill(env, arg, cls);
137                 } else {
138                         // if it wasn't a spill then it must be a Mem-Phi
139                         assert(is_Phi(arg));
140                         arg_spill = collect_memphi(env, arg, cls);
141                 }
142
143                 // add an affinity edge
144                 affinty_edge = obstack_alloc(&env->obst, sizeof(affinty_edge[0]));
145                 affinty_edge->affinity = get_block_execfreq(env->chordal_env->exec_freq, get_nodes_block(arg));
146                 affinty_edge->slot1 = res->spillslot;
147                 affinty_edge->slot2 = arg_spill->spillslot;
148                 ARR_APP1(affinity_edge_t*, env->affinity_edges, affinty_edge);
149         }
150
151         return res;
152 }
153
154 /**
155  * This walker function searches for reloads and collects all the spills
156  * and memphis attached to them.
157  */
158 static void collect_spills_walker(ir_node *node, void *data) {
159         ss_env_t *env = data;
160
161         if(be_is_Reload(node)) {
162                 ir_node *spill = get_irn_n(node, be_pos_Reload_mem);
163                 const arch_env_t *arch_env = env->chordal_env->birg->main_env->arch_env;
164                 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, node, -1);
165
166                 if(is_Phi(spill)) {
167                         collect_memphi(env, spill, cls);
168                 } else {
169                         collect_spill(env, spill, cls);
170                 }
171                 ARR_APP1(ir_node*, env->reloads, node);
172         }
173 }
174
175 /*
176  *   ____            _                      ____  _       _
177  *  / ___|___   __ _| | ___  ___  ___ ___  / ___|| | ___ | |_ ___
178  * | |   / _ \ / _` | |/ _ \/ __|/ __/ _ \ \___ \| |/ _ \| __/ __|
179  * | |__| (_) | (_| | |  __/\__ \ (_|  __/  ___) | | (_) | |_\__ \
180  *  \____\___/ \__,_|_|\___||___/\___\___| |____/|_|\___/ \__|___/
181  */
182
183 static int merge_interferences(ss_env_t *env, bitset_t** interferences, int* spillslot_unionfind, int s1, int s2)
184 {
185         int res;
186         int i;
187         int spillcount;
188
189         // merge spillslots and interferences
190         res = uf_union(spillslot_unionfind, s1, s2);
191         // we assume that we always merge s2 to s1 so swap s1, s2 if necessary
192         if(res != 0) {
193                 int t = s1;
194                 s1 = s2;
195                 s2 = t;
196         }
197
198         bitset_or(interferences[s1], interferences[s2]);
199
200         // update other interferences
201         spillcount = set_count(env->spills);
202         for(i = 0; i < spillcount; ++i) {
203                 bitset_t *intfs = interferences[i];
204                 if(bitset_is_set(intfs, s2))
205                         bitset_set(intfs, s1);
206         }
207
208         return res;
209 }
210
211 #if 0
212
213 static void dump_interference_graph(ss_env_t *env, bitset_t **interferences, const char* suffix) {
214         char name[256];
215         int i;
216         int spillcount;
217         spill_t *spill;
218         FILE *f;
219         static int cnt = 0;
220
221         snprintf(name, sizeof(name), "%d-%s-spillslots-%s.vcg", cnt++, get_irg_dump_name(env->chordal_env->birg->irg), suffix);
222
223         f = fopen(name, "w");
224         assert(f != NULL);
225
226         fprintf(f, "graph: {\n");
227
228         spillcount = set_count(env->spills);
229         for(spill = set_first(env->spills), i = 0; spill != NULL; spill = set_next(env->spills), ++i) {
230                 int slotid = spill->spillslot;
231                 fprintf(f, "\tnode: { title: \"n%d\" label: \"%d\" }\n", i, slotid);
232         }
233
234         for(i = 0; i < ARR_LEN(env->affinity_edges); ++i) {
235                 affinity_edge_t *edge = env->affinity_edges[i];
236                 fprintf(f, "\tedge: { sourcename: \"n%d\" targetname: \"n%d\" color: green }\n", edge->slot1, edge->slot2);
237         }
238
239         for(i = 0; i < spillcount; ++i) {
240                 int i2;
241                 for(i2 = 0; i2 < spillcount; ++i2) {
242                         if(bitset_is_set(interferences[i], i2)) {
243                                 fprintf(f, "\tedge: { sourcename: \"n%d\" targetname: \"n%d\" color: red }\n", i, i2);
244                         }
245                 }
246         }
247
248         fprintf(f, "}\n");
249         fclose(f);
250 }
251
252 static void show_stats(ss_env_t *env) {
253         int spillcount;
254         int slotcount;
255         int *slotused;
256         spill_t *spill;
257
258         spillcount = set_count(env->spills);
259         fprintf(stderr, "%s: Collected %d spills\n", get_irg_dump_name(env->chordal_env->birg->irg), spillcount);
260
261         slotused = alloca(spillcount * sizeof(slotused[0]));
262         memset(slotused, 0, spillcount * sizeof(slotused[0]));
263
264         slotcount = 0;
265         for(spill = set_first(env->spills); spill != NULL; spill = set_next(env->spills)) {
266                 int slot = spill->spillslot;
267                 if(slotused[slot] == 0) {
268                         slotused[slot] = 1;
269                         slotcount++;
270                 }
271         }
272
273         fprintf(stderr, "%s: Coalesced to %d spillslots\n", get_irg_dump_name(env->chordal_env->birg->irg), slotcount);
274 }
275
276 #endif
277
278 static void assign_spillslots(ss_env_t *env);
279
280 /**
281  * A greedy coalescing algorithm for spillslots:
282  *  1. Sort the list of affinity edges
283  *  2. Try to merge slots with affinity edges (most expensive slots first)
284  *  3. Try to merge everything else that is possible
285  */
286 static void do_greedy_coalescing(ss_env_t *env)
287 {
288         int spillcount;
289         spill_t **spilllist;
290         spill_t *spill;
291         int i, i2;
292         int affinity_edge_count;
293         bitset_t **interferences;
294         int* spillslot_unionfind;
295
296         spillcount = set_count(env->spills);
297         if(spillcount == 0)
298                 return;
299
300         DBG((dbg, DBG_COALESCING, "Coalescing %d spillslots\n", spillcount));
301
302         interferences = alloca(spillcount * sizeof(interferences[0]));
303         spillslot_unionfind = alloca(spillcount * sizeof(spillslot_unionfind[0]));
304         spilllist = alloca(spillcount * sizeof(spilllist[0]));
305
306         uf_init(spillslot_unionfind, 0, spillcount);
307
308         DEBUG_ONLY(
309                 memset(spilllist, 0, spillcount * sizeof(spilllist[0]));
310         );
311
312         for(spill = set_first(env->spills), i = 0; spill != NULL; spill = set_next(env->spills), ++i) {
313                 assert(spill->spillslot < spillcount);
314                 spilllist[spill->spillslot] = spill;
315         }
316
317         for(i = 0; i < spillcount; ++i) {
318                 interferences[i] = bitset_alloca(spillcount);
319         }
320
321         // construct interferences
322         for(i = 0; i < spillcount; ++i) {
323                 for(i2 = i+1; i2 < spillcount; ++i2) {
324                         if(values_interfere(env->chordal_env->lv, spilllist[i]->spill, spilllist[i2]->spill)) {
325                                 DBG((dbg, DBG_INTERFERENCES, "Slot %d and %d interfere\n", i, i2));
326                                 bitset_set(interferences[i], i2);
327                                 bitset_set(interferences[i2], i);
328                         }
329                 }
330         }
331
332         // sort affinity edges
333         affinity_edge_count = ARR_LEN(env->affinity_edges);
334         qsort(env->affinity_edges, affinity_edge_count, sizeof(env->affinity_edges[0]), cmp_affinity);
335
336         //dump_interference_graph(env, interferences, "before");
337
338         // try to merge affine nodes
339         for(i = 0; i < affinity_edge_count; ++i) {
340                 const affinity_edge_t *edge = env->affinity_edges[i];
341                 int s1 = uf_find(spillslot_unionfind, edge->slot1);
342                 int s2 = uf_find(spillslot_unionfind, edge->slot2);
343
344                 /* test if values interfere */
345                 if(bitset_is_set(interferences[s1], s2)) {
346                         assert(bitset_is_set(interferences[s2], s1));
347                         continue;
348                 }
349
350                 DBG((dbg, DBG_COALESCING, "Merging %d and %d because of affinity edge\n", s1, s2));
351
352                 merge_interferences(env, interferences, spillslot_unionfind, s1, s2);
353         }
354
355         // try to merge as much remaining spillslots as possible
356         for(i = 0; i < spillcount; ++i) {
357                 int s1 = uf_find(spillslot_unionfind, i);
358                 if(s1 != i)
359                         continue;
360
361                 for(i2 = i+1; i2 < spillcount; ++i2) {
362                         int s2 = uf_find(spillslot_unionfind, i2);
363                         if(s2 != i2)
364                                 continue;
365
366                         /* test if values interfere
367                          * we have to test n1-n2 and n2-n1, because only 1 side gets updated
368                          * when node merging occurs
369                          */
370                         if(bitset_is_set(interferences[s1], s2)) {
371                                 assert(bitset_is_set(interferences[s2], s1));
372                                 continue;
373                         }
374
375                         DBG((dbg, DBG_COALESCING, "Merging %d and %d because it is possible\n", s1, s2));
376
377                         if(merge_interferences(env, interferences, spillslot_unionfind, s1, s2) != 0) {
378                                 // we can break the loop here, because s2 is the new supernode now
379                                 // and we'll test s2 again later anyway
380                                 break;
381                         }
382                 }
383         }
384
385         // assign spillslots
386         for(i = 0; i < spillcount; ++i) {
387                 spill_t *spill = spilllist[i];
388
389                 spill->spillslot = uf_find(spillslot_unionfind, i);
390         }
391
392         //dump_interference_graph(env, interferences, "after");
393 }
394
395 #if 0
396 static void do_java_coalescing(ss_env_t *env)
397 {
398         int spillcount;
399         spill_t **spilllist;
400         spill_t *spill;
401         int i, i2;
402         be_java_coal_t *coal;
403
404         spillcount = set_count(env->spills);
405         if(spillcount == 0)
406                 return;
407
408         spilllist = alloca(spillcount * sizeof(spilllist[0]));
409
410         DEBUG_ONLY(
411                 memset(spilllist, 0, spillcount * sizeof(spilllist[0]));
412         );
413
414         coal = be_java_coal_init("spillslot coalescing", spillcount, spillcount, 1);
415
416         for(spill = set_first(env->spills), i = 0; spill != NULL; spill = set_next(env->spills), ++i) {
417                 assert(spill->spillslot < spillcount);
418                 DEBUG_ONLY(assert(spilllist[spill->spillslot] == NULL));
419                 spilllist[spill->spillslot] = spill;
420
421                 be_java_coal_set_color(coal, spill->spillslot, spill->spillslot);
422         }
423
424         // construct interferences
425         for(i = 0; i < spillcount; ++i) {
426                 for(i2 = i+1; i2 < spillcount; ++i2) {
427                         if(values_interfere(env->chordal_env->lv, spilllist[i]->spill, spilllist[i2]->spill)) {
428                                 be_java_coal_add_int_edge(coal, i, i2);
429                         }
430                 }
431         }
432
433         for(i = 0; i < ARR_LEN(env->affinity_edges); ++i) {
434                 const affinity_edge_t *edge = env->affinity_edges[i];
435                 int n = edge->slot1;
436                 int m = edge->slot2;
437                 int costs = (int) (edge->affinity * 10000);
438                 be_java_coal_add_aff_edge(coal, n, m, costs);
439         }
440
441         be_java_coal_coalesce(coal);
442
443         // construct spillslots
444         for(i = 0; i < spillcount; ++i) {
445                 spill_t *spill = spilllist[i];
446                 spill->spillslot = be_java_coal_get_color(coal, i);
447         }
448         be_java_coal_destroy(coal);
449 }
450 #endif
451
452 /*
453  *     _            _               _____       _   _ _   _
454  *    / \   ___ ___(_) __ _ _ __   | ____|_ __ | |_(_) |_(_) ___  ___
455  *   / _ \ / __/ __| |/ _` | '_ \  |  _| | '_ \| __| | __| |/ _ \/ __|
456  *  / ___ \\__ \__ \ | (_| | | | | | |___| | | | |_| | |_| |  __/\__ \
457  * /_/   \_\___/___/_|\__, |_| |_| |_____|_| |_|\__|_|\__|_|\___||___/
458  *                    |___/
459  */
460
461 typedef struct _spill_slot_t {
462         int size;
463         int align;
464         entity   *entity;
465 } spill_slot_t;
466
467 typedef struct _memperm_entry_t {
468         ir_node* node;
469         int pos;
470         entity *in;
471         entity *out;
472         struct _memperm_entry_t *next;
473 } memperm_entry_t;
474
475 typedef struct _memperm_t {
476         ir_node *block;
477         int entrycount;
478         memperm_entry_t *entries;
479 } memperm_t;
480
481 static int cmp_memperm(const void* d1, const void* d2, size_t size) {
482         const memperm_t* e1 = d1;
483         const memperm_t* e2 = d2;
484         return e1->block != e2->block;
485 }
486
487 static memperm_t *get_memperm(ss_env_t *env, ir_node *block) {
488         memperm_t entry, *res;
489         int hash;
490
491         entry.block = block;
492         hash = HASH_PTR(block);
493
494         res = set_find(env->memperms, &entry, sizeof(entry), hash);
495
496         if(res == NULL) {
497                 entry.entrycount = 0;
498                 entry.entries = NULL;
499                 res = set_insert(env->memperms, &entry, sizeof(entry), hash);
500         }
501
502         return res;
503 }
504
505 static entity* create_stack_entity(ss_env_t *env, spill_slot_t *slot) {
506         ir_type* frame = get_irg_frame_type(env->chordal_env->irg);
507         entity* res = frame_alloc_area(frame, slot->size, slot->align, 0);
508
509         slot->entity = res;
510
511         return res;
512 }
513
514 static int get_spillslotsize_for_spill(ss_env_t *env, spill_t *spill) {
515         const ir_mode *mode = arch_register_class_mode(spill->cls);
516
517         return get_mode_size_bytes(mode);
518 }
519
520 static int get_spillslotalign_for_spill(ss_env_t *env, spill_t *spill) {
521         const arch_isa_t *isa = env->chordal_env->birg->main_env->arch_env->isa;
522
523         return arch_isa_get_reg_class_alignment(isa, spill->cls);
524 }
525
526 /**
527  * Enlarges a spillslot (if necessary) so that it can carry a value of size
528  * @p othersize and alignment @p otheralign.
529  */
530 static void enlarge_spillslot(spill_slot_t *slot, int otheralign, int othersize) {
531         if(othersize > slot->size) {
532                 slot->size = othersize;
533         }
534         if(otheralign > slot->align) {
535                 if(otheralign % slot->align != 0)
536                         slot->align *= otheralign;
537                 else
538                         slot->align = otheralign;
539         } else if(slot->align % otheralign != 0) {
540                 slot->align *= otheralign;
541         }
542 }
543
544 /**
545  * Create stack entities for the spillslots and assign them to the spill and
546  * reload nodes.
547  */
548 static void assign_spillslots(ss_env_t *env) {
549         int i;
550         int spillcount;
551         spill_t *spill;
552         spill_slot_t* spillslots;
553
554         spillcount = set_count(env->spills);
555         spillslots = alloca(spillcount * sizeof(spillslots[0]));
556
557         memset(spillslots, 0, spillcount * sizeof(spillslots[0]));
558
559         // construct spillslots
560         for(spill = set_first(env->spills); spill != NULL; spill = set_next(env->spills)) {
561                 int slotid = spill->spillslot;
562                 spill_slot_t *slot = & (spillslots[slotid]);
563                 int align = get_spillslotalign_for_spill(env, spill);
564                 int size = get_spillslotsize_for_spill(env, spill);
565
566                 if(slot->align == 0 && slot->size == 0) {
567                         slot->align = align;
568                         slot->size = size;
569                 } else {
570                         enlarge_spillslot(slot, align, size);
571                 }
572         }
573
574         for(spill = set_first(env->spills); spill != NULL; spill = set_next(env->spills)) {
575                 spill_slot_t *slot;
576                 ir_node *node = spill->spill;
577                 int slotid = spill->spillslot;
578
579                 slot = &spillslots[slotid];
580                 if(slot->entity == NULL) {
581                         create_stack_entity(env, slot);
582                 }
583
584                 if(be_is_Spill(node)) {
585                         be_set_frame_entity(node, slot->entity);
586                 } else {
587                         int i, arity;
588
589                         // should be a PhiM
590                         assert(is_Phi(node));
591
592                         for(i = 0, arity = get_irn_arity(node); i < arity; ++i) {
593                                 ir_node *arg = get_irn_n(node, i);
594                                 spill_t *argspill;
595                                 int argslotid;
596
597                                 argspill = get_spill(env, arg);
598                                 assert(argspill != NULL);
599
600                                 argslotid = argspill->spillslot;
601                                 if(slotid != argslotid) {
602                                         memperm_t *memperm;
603                                         memperm_entry_t *entry;
604                                         spill_slot_t *argslot = &spillslots[argslotid];
605                                         if(argslot->entity == NULL) {
606                                                 create_stack_entity(env, argslot);
607                                         }
608
609                                         memperm = get_memperm(env, get_nodes_block(arg));
610
611                                         entry = obstack_alloc(&env->obst, sizeof(entry[0]));
612                                         entry->node = node;
613                                         entry->pos = i;
614                                         entry->in = argslot->entity;
615                                         entry->out = slot->entity;
616                                         entry->next = memperm->entries;
617                                         memperm->entrycount++;
618                                         memperm->entries = entry;
619                                 }
620                         }
621                 }
622         }
623
624         for(i = 0; i < ARR_LEN(env->reloads); ++i) {
625                 const ir_node* reload = env->reloads[i];
626                 ir_node* spillnode = get_irn_n(reload, be_pos_Reload_mem);
627                 spill_t *spill = get_spill(env, spillnode);
628                 const spill_slot_t *slot = & spillslots[spill->spillslot];
629
630                 assert(slot->entity != NULL);
631
632                 be_set_frame_entity(reload, slot->entity);
633         }
634 }
635
636 static void create_memperms(ss_env_t *env) {
637         memperm_t *memperm;
638
639         for(memperm = set_first(env->memperms); memperm != NULL; memperm = set_next(env->memperms)) {
640                 int i;
641                 memperm_entry_t *entry;
642                 ir_node** nodes = alloca(memperm->entrycount * sizeof(nodes[0]));
643                 ir_node* mempermnode;
644
645                 assert(memperm->entrycount > 0);
646
647                 for(entry = memperm->entries, i = 0; entry != NULL; entry = entry->next, ++i) {
648                         ir_node* arg = get_irn_n(entry->node, entry->pos);
649                         nodes[i] = arg;
650                 }
651
652                 mempermnode = be_new_MemPerm(env->chordal_env->birg->main_env->arch_env, env->chordal_env->irg, memperm->block,
653                         memperm->entrycount, nodes);
654
655                 for(entry = memperm->entries, i = 0; entry != NULL; entry = entry->next, ++i) {
656                         ir_node *proj;
657                         ir_node* arg = get_irn_n(entry->node, entry->pos);
658
659                         be_set_MemPerm_in_entity(mempermnode, i, entry->in);
660                         be_set_MemPerm_out_entity(mempermnode, i, entry->out);
661                         proj = new_Proj(mempermnode, get_irn_mode(arg), i);
662                         set_irn_n(entry->node, entry->pos, proj);
663                 }
664
665                 // insert node into schedule
666                 sched_add_before(sched_last(memperm->block), mempermnode);
667         }
668 }
669
670 void be_coalesce_spillslots(const be_chordal_env_t *chordal_env) {
671         ss_env_t env;
672
673         obstack_init(&env.obst);
674         env.chordal_env = chordal_env;
675         env.spills = new_set(cmp_spill, 10);
676         env.reloads = NEW_ARR_F(ir_node*, 0);
677         env.affinity_edges = NEW_ARR_F(affinity_edge_t*, 0);
678         env.memperms = new_set(cmp_memperm, 10);
679         FIRM_DBG_REGISTER(dbg, "firm.be.spillslots");
680         //firm_dbg_set_mask(dbg, DBG_COALESCING);
681
682         /* Get initial spill slots */
683         irg_walk_graph(chordal_env->irg, NULL, collect_spills_walker, &env);
684
685         do_greedy_coalescing(&env);
686
687         assign_spillslots(&env);
688
689         create_memperms(&env);
690
691         //show_stats(&env);
692
693         del_set(env.memperms);
694         DEL_ARR_F(env.reloads);
695         DEL_ARR_F(env.affinity_edges);
696         del_set(env.spills);
697         obstack_free(&env.obst, NULL);
698 }