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