fix bad input register requirements
[libfirm] / ir / be / bespillslots.c
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Spillslot coalescer.
23  * @author      Matthias Braun
24  * @date        26.07.2006
25  */
26 #include "config.h"
27
28 #include <stdlib.h>
29
30 #include "set.h"
31 #include "array.h"
32 #include "irgwalk.h"
33 #include "ircons.h"
34 #include "irprintf.h"
35 #include "execfreq.h"
36 #include "unionfind.h"
37 #include "irdump_t.h"
38
39 #include "benode.h"
40 #include "besched.h"
41 #include "bespill.h"
42 #include "bespillslots.h"
43 #include "bechordal_t.h"
44 #include "statev_t.h"
45 #include "bemodule.h"
46 #include "beintlive_t.h"
47 #include "beirg.h"
48 #include "bearch.h"
49
50 #define DBG_COALESCING      1
51 #define DBG_INTERFERENCES   2
52
53 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
54
55 typedef struct spill_t {
56         ir_node       *spill;
57         const ir_mode *mode;      /**< mode of the spilled value */
58         int            alignment; /**< alignment for the spilled value */
59         int            spillslot;
60 } spill_t;
61
62 typedef struct affinity_edge_t {
63         double affinity;
64         int    slot1;
65         int    slot2;
66 } affinity_edge_t;
67
68 struct be_fec_env_t {
69         struct obstack         obst;
70         ir_graph              *irg;
71         spill_t              **spills;
72         unsigned              *spills_set;
73         ir_node              **reloads;
74         affinity_edge_t      **affinity_edges;
75         set                   *memperms;
76         set_frame_entity_func  set_frame_entity;
77         bool                   at_begin;  /**< frame entities should be allocate at
78                                                the beginning of the stackframe */
79 };
80
81 /** Compare 2 affinity edges (used in quicksort) */
82 static int cmp_affinity(const void *d1, const void *d2)
83 {
84         const affinity_edge_t * const *e1   = (const affinity_edge_t**)d1;
85         const affinity_edge_t * const *e2   = (const affinity_edge_t**)d2;
86         double                         aff1 = (*e1)->affinity;
87         double                         aff2 = (*e2)->affinity;
88
89         /* sort in descending order */
90         if (aff1 < aff2) {
91                 return 1;
92         } else if (aff1 > aff2) {
93                 return -1;
94         } else {
95                 int slot11 = (*e1)->slot1;
96                 int slot21 = (*e2)->slot1;
97                 if (slot11 < slot21) {
98                         return 1;
99                 } else if (slot11 > slot21) {
100                         return -1;
101                 } else {
102                         int slot12 = (*e1)->slot2;
103                         int slot22 = (*e2)->slot2;
104                         return (slot12<slot22) - (slot12<slot22);
105                 }
106         }
107 }
108
109 static spill_t *get_spill(be_fec_env_t *env, ir_node *node)
110 {
111         assert(rbitset_is_set(env->spills_set, get_irn_idx(node)));
112         return (spill_t*)get_irn_link(node);
113 }
114
115 static inline ir_node *get_memory_edge(const ir_node *node)
116 {
117         int i, arity;
118
119         arity = get_irn_arity(node);
120         for (i = arity - 1; i >= 0; --i) {
121                 ir_node *arg = get_irn_n(node, i);
122                 if (get_irn_mode(arg) == mode_M)
123                         return arg;
124         }
125
126         return NULL;
127 }
128
129 static spill_t *collect_spill(be_fec_env_t *env, ir_node *node,
130                                       const ir_mode *mode, int align)
131 {
132         spill_t *spill;
133
134         /* already in spill set? */
135         unsigned idx = get_irn_idx(node);
136         if (rbitset_is_set(env->spills_set, idx)) {
137                 spill_t *spill = get_spill(env, node);
138                 assert(spill->mode == mode);
139                 assert(spill->alignment == align);
140                 return spill;
141         }
142         rbitset_set(env->spills_set, idx);
143
144         spill = OALLOC(&env->obst, spill_t);
145         /* insert into set of spills if not already there */
146         spill->spill     = node;
147         spill->mode      = mode;
148         spill->alignment = align;
149         spill->spillslot = (int)ARR_LEN(env->spills);
150         ARR_APP1(spill_t*, env->spills, spill);
151         set_irn_link(node, spill);
152         DB((dbg, DBG_COALESCING, "Slot %d: %+F\n", spill->spillslot, node));
153
154         if (is_Phi(node)) {
155                 int                 arity     = get_irn_arity(node);
156                 int                 i;
157                 for (i = 0; i < arity; ++i) {
158                         affinity_edge_t *affinty_edge;
159                         ir_node         *arg       = get_irn_n(node, i);
160                         spill_t         *arg_spill = collect_spill(env, arg, mode, align);
161                         ir_node         *block     = get_nodes_block(arg);
162
163                         /* add an affinity edge */
164                         affinty_edge           = OALLOC(&env->obst, affinity_edge_t);
165                         affinty_edge->affinity = get_block_execfreq(block);
166                         affinty_edge->slot1    = spill->spillslot;
167                         affinty_edge->slot2    = arg_spill->spillslot;
168                         ARR_APP1(affinity_edge_t*, env->affinity_edges, affinty_edge);
169                 }
170         }
171
172         return spill;
173 }
174
175 void be_node_needs_frame_entity(be_fec_env_t *env, ir_node *node,
176                                 const ir_mode *mode, int align)
177 {
178         ir_node *spillnode = get_memory_edge(node);
179         assert(spillnode != NULL);
180
181         /* walk upwards and collect all phis and spills on this way */
182         collect_spill(env, spillnode, mode, align);
183
184         ARR_APP1(ir_node *, env->reloads, node);
185 }
186
187 static int merge_interferences(be_fec_env_t *env, bitset_t** interferences,
188                                int* spillslot_unionfind, int s1, int s2)
189 {
190         int res;
191         size_t spillcount;
192         size_t i;
193
194         /* merge spillslots and interferences */
195         res = uf_union(spillslot_unionfind, s1, s2);
196         /* we assume that we always merge s2 to s1 so swap s1, s2 if necessary */
197         if (res != s1) {
198                 int t = s1;
199                 s1 = s2;
200                 s2 = t;
201         }
202
203         bitset_or(interferences[s1], interferences[s2]);
204
205         /* update other interferences */
206         spillcount = ARR_LEN(env->spills);
207         for (i = 0; i < spillcount; ++i) {
208                 bitset_t *intfs = interferences[i];
209                 if (bitset_is_set(intfs, s2))
210                         bitset_set(intfs, s1);
211         }
212
213         return res;
214 }
215
216 static int my_values_interfere2(ir_graph *irg, const ir_node *a,
217                                 const ir_node *b)
218 {
219         be_lv_t *lv = be_get_irg_liveness(irg);
220
221         int a2b = _value_dominates(a, b);
222         int b2a = _value_dominates(b, a);
223
224         /* If there is no dominance relation, they do not interfere. */
225         if ((a2b | b2a) > 0) {
226                 ir_node *bb;
227
228                 /*
229                  * Adjust a and b so, that a dominates b if
230                  * a dominates b or vice versa.
231                  */
232                 if (b2a) {
233                         const ir_node *t = a;
234                         a = b;
235                         b = t;
236                 }
237
238                 bb = get_nodes_block(b);
239
240                 /*
241                  * If a is live end in b's block it is
242                  * live at b's definition (a dominates b)
243                  */
244                 if (be_is_live_end(lv, bb, a))
245                         return 1;
246
247                 /*
248                  * Look at all usages of a.
249                  * If there's one usage of a in the block of b, then
250                  * we check, if this use is dominated by b, if that's true
251                  * a and b interfere. Note that b must strictly dominate the user,
252                  * since if b is the last user of in the block, b and a do not
253                  * interfere.
254                  * Uses of a not in b's block can be disobeyed, because the
255                  * check for a being live at the end of b's block is already
256                  * performed.
257                  */
258                 foreach_out_edge(a, edge) {
259                         const ir_node *user = get_edge_src_irn(edge);
260                         if (is_Sync(user)) {
261                                 foreach_out_edge(user, edge2) {
262                                         const ir_node *user2 = get_edge_src_irn(edge2);
263                                         assert(!is_Sync(user2));
264                                         if (get_nodes_block(user2) == bb && !is_Phi(user2) &&
265                                            _value_strictly_dominates(b, user2))
266                                                 return 1;
267                                 }
268                         } else {
269                                 if (get_nodes_block(user) == bb && !is_Phi(user) &&
270                                                 _value_strictly_dominates(b, user))
271                                         return 1;
272                         }
273                 }
274         }
275
276         return 0;
277 }
278
279 /**
280  * same as values_interfere but with special handling for Syncs
281  */
282 static int my_values_interfere(ir_graph *irg, ir_node *a, ir_node *b)
283 {
284         if (is_Sync(a)) {
285                 int i, arity = get_irn_arity(a);
286                 for (i = 0; i < arity; ++i) {
287                         ir_node *in = get_irn_n(a, i);
288                         if (my_values_interfere(irg, in, b))
289                                 return 1;
290                 }
291                 return 0;
292         } else if (is_Sync(b)) {
293                 int i, arity = get_irn_arity(b);
294                 for (i = 0; i < arity; ++i) {
295                         ir_node *in = get_irn_n(b, i);
296                         /* a is not a sync, so no need for my_values_interfere */
297                         if (my_values_interfere2(irg, a, in))
298                                 return 1;
299                 }
300                 return 0;
301         }
302
303         return my_values_interfere2(irg, a, b);
304 }
305
306 /**
307  * A greedy coalescing algorithm for spillslots:
308  *  1. Sort the list of affinity edges
309  *  2. Try to merge slots with affinity edges (most expensive slots first)
310  *  3. Try to merge everything else that is possible
311  */
312 static void do_greedy_coalescing(be_fec_env_t *env)
313 {
314         spill_t **spills     = env->spills;
315         size_t    spillcount = ARR_LEN(spills);
316         size_t    i;
317         size_t    affinity_edge_count;
318         bitset_t **interferences;
319         int* spillslot_unionfind;
320         struct obstack data;
321
322         if (spillcount == 0)
323                 return;
324
325         obstack_init(&data);
326
327         DB((dbg, DBG_COALESCING, "Coalescing %d spillslots\n", spillcount));
328
329         interferences       = OALLOCN(&data, bitset_t*, spillcount);
330         spillslot_unionfind = OALLOCN(&data, int,       spillcount);
331
332         uf_init(spillslot_unionfind, spillcount);
333
334         for (i = 0; i < spillcount; ++i) {
335                 interferences[i] = bitset_obstack_alloc(&data, spillcount);
336         }
337
338         /* construct interferences */
339         for (i = 0; i < spillcount; ++i) {
340                 size_t   i2;
341                 ir_node *spill1 = spills[i]->spill;
342                 if (is_NoMem(spill1))
343                         continue;
344
345                 for (i2 = i+1; i2 < spillcount; ++i2) {
346                         ir_node *spill2 = spills[i2]->spill;
347                         if (is_NoMem(spill2))
348                                 continue;
349
350                         if (my_values_interfere(env->irg, spill1, spill2)) {
351                                 DB((dbg, DBG_INTERFERENCES,
352                                      "Slot %d and %d interfere\n", i, i2));
353
354                                 bitset_set(interferences[i], i2);
355                                 bitset_set(interferences[i2], i);
356                         }
357                 }
358         }
359
360         /* sort affinity edges */
361         affinity_edge_count = ARR_LEN(env->affinity_edges);
362         qsort(env->affinity_edges, affinity_edge_count,
363               sizeof(env->affinity_edges[0]), cmp_affinity);
364
365         /* try to merge affine nodes */
366         for (i = 0; i < affinity_edge_count; ++i) {
367                 const affinity_edge_t *edge = env->affinity_edges[i];
368                 int s1 = uf_find(spillslot_unionfind, edge->slot1);
369                 int s2 = uf_find(spillslot_unionfind, edge->slot2);
370
371                 /* test if values interfere */
372                 if (bitset_is_set(interferences[s1], s2)) {
373                         assert(bitset_is_set(interferences[s2], s1));
374                         continue;
375                 }
376
377                 DB((dbg, DBG_COALESCING,
378                     "Merging %d and %d because of affinity edge\n", s1, s2));
379
380                 merge_interferences(env, interferences, spillslot_unionfind, s1, s2);
381         }
382
383         /* try to merge as much remaining spillslots as possible */
384         for (i = 0; i < spillcount; ++i) {
385                 size_t i2;
386                 int    s1 = uf_find(spillslot_unionfind, i);
387                 if (s1 != (int)i)
388                         continue;
389
390                 for (i2 = i+1; i2 < spillcount; ++i2) {
391                         int s2 = uf_find(spillslot_unionfind, i2);
392                         if (s2 != (int)i2)
393                                 continue;
394
395                         /* test if values interfere
396                          * we have to test n1-n2 and n2-n1, because only 1 side gets updated
397                          * when node merging occurs
398                          */
399                         if (bitset_is_set(interferences[s1], s2)) {
400                                 assert(bitset_is_set(interferences[s2], s1));
401                                 continue;
402                         }
403
404                         DB((dbg, DBG_COALESCING,
405                              "Merging %d and %d because it is possible\n", s1, s2));
406
407                         if (merge_interferences(env, interferences, spillslot_unionfind, s1, s2) != 0) {
408                                 /* we can break the loop here, because s2 is the new supernode
409                                  * now and we'll test s2 again later anyway */
410                                 break;
411                         }
412                 }
413         }
414
415         /* assign spillslots to spills */
416         for (i = 0; i < spillcount; ++i) {
417                 spills[i]->spillslot = uf_find(spillslot_unionfind, i);
418         }
419
420         obstack_free(&data, 0);
421 }
422
423 typedef struct spill_slot_t {
424         int size;
425         int align;
426         ir_entity *entity;
427 } spill_slot_t;
428
429 typedef struct memperm_entry_t {
430         ir_node* node;
431         int pos;
432         ir_entity *in;
433         ir_entity *out;
434         struct memperm_entry_t *next;
435 } memperm_entry_t;
436
437 typedef struct memperm_t {
438         ir_node *block;
439         int entrycount;
440         memperm_entry_t *entries;
441 } memperm_t;
442
443 static int cmp_memperm(const void* d1, const void* d2, size_t size)
444 {
445         const memperm_t* e1 = (const memperm_t*)d1;
446         const memperm_t* e2 = (const memperm_t*)d2;
447         (void) size;
448
449         return e1->block != e2->block;
450 }
451
452 static memperm_t *get_memperm(be_fec_env_t *env, ir_node *block)
453 {
454         memperm_t entry, *res;
455         int hash;
456
457         entry.block = block;
458         hash        = hash_irn(block);
459
460         res = set_find(memperm_t, env->memperms, &entry, sizeof(entry), hash);
461
462         if (res == NULL) {
463                 entry.entrycount = 0;
464                 entry.entries = NULL;
465                 res = set_insert(memperm_t, env->memperms, &entry, sizeof(entry), hash);
466         }
467
468         return res;
469 }
470
471 static ir_entity* create_stack_entity(be_fec_env_t *env, spill_slot_t *slot)
472 {
473         ir_graph  *irg   = env->irg;
474         ir_type   *frame = get_irg_frame_type(irg);
475         ir_entity *res   = frame_alloc_area(frame, slot->size, slot->align,
476                                             env->at_begin);
477         slot->entity = res;
478
479         return res;
480 }
481
482 /**
483  * Enlarges a spillslot (if necessary) so that it can carry a value of size
484  * @p othersize and alignment @p otheralign.
485  */
486 static void enlarge_spillslot(spill_slot_t *slot, int otheralign, int othersize)
487 {
488         if (othersize > slot->size) {
489                 slot->size = othersize;
490         }
491         if (otheralign > slot->align) {
492                 if (otheralign % slot->align != 0)
493                         slot->align *= otheralign;
494                 else
495                         slot->align = otheralign;
496         } else if (slot->align % otheralign != 0) {
497                 slot->align *= otheralign;
498         }
499 }
500
501 static void assign_spill_entity(be_fec_env_t *env,
502                                 ir_node *node, ir_entity *entity)
503 {
504         if (is_NoMem(node))
505                 return;
506         if (is_Sync(node)) {
507                 int i, arity;
508
509                 arity = get_irn_arity(node);
510                 for (i = 0; i < arity; ++i) {
511                         ir_node *in = get_irn_n(node, i);
512                         assert(!is_Phi(in));
513
514                         assign_spill_entity(env, in, entity);
515                 }
516                 return;
517         }
518
519         /* beware: we might have Stores with Memory Proj's, ia32 fisttp for
520            instance */
521         node = skip_Proj(node);
522         assert(arch_get_frame_entity(node) == NULL);
523         env->set_frame_entity(node, entity);
524 }
525
526 /**
527  * Create stack entities for the spillslots and assign them to the spill and
528  * reload nodes.
529  */
530 static void assign_spillslots(be_fec_env_t *env)
531 {
532         spill_t      **spills     = env->spills;
533         size_t         spillcount = ARR_LEN(spills);
534         spill_slot_t  *spillslots = ALLOCANZ(spill_slot_t, spillcount);
535         size_t         s;
536
537         /* construct spillslots */
538         for (s = 0; s < spillcount; ++s) {
539                 const spill_t *spill  = spills[s];
540                 int            slotid = spill->spillslot;
541                 const ir_mode *mode   = spill->mode;
542                 spill_slot_t  *slot   = & (spillslots[slotid]);
543                 int            size   = get_mode_size_bytes(mode);
544                 int            align  = spill->alignment;
545
546                 if (slot->align == 0 && slot->size == 0) {
547                         slot->align = align;
548                         slot->size = size;
549                 } else {
550                         enlarge_spillslot(slot, align, size);
551                 }
552         }
553
554         for (s = 0; s < spillcount; ++s) {
555                 const spill_t *spill  = spills[s];
556                 ir_node       *node   = spill->spill;
557                 int            slotid = spill->spillslot;
558                 spill_slot_t  *slot   = &spillslots[slotid];
559
560                 if (slot->entity == NULL) {
561                         create_stack_entity(env, slot);
562                 }
563
564                 if (is_Phi(node)) {
565                         int arity = get_irn_arity(node);
566                         int i;
567                         ir_node *block = get_nodes_block(node);
568
569                         /* should be a PhiM */
570                         assert(get_irn_mode(node) == mode_M);
571
572                         for (i = 0; i < arity; ++i) {
573                                 ir_node *arg       = get_irn_n(node, i);
574                                 ir_node *predblock = get_Block_cfgpred_block(block, i);
575                                 spill_t *argspill  = get_spill(env, arg);
576                                 int      argslotid = argspill->spillslot;
577
578                                 if (slotid != argslotid) {
579                                         memperm_t       *memperm;
580                                         memperm_entry_t *entry;
581                                         spill_slot_t    *argslot = &spillslots[argslotid];
582                                         if (argslot->entity == NULL) {
583                                                 create_stack_entity(env, argslot);
584                                         }
585
586                                         memperm = get_memperm(env, predblock);
587
588                                         entry = OALLOC(&env->obst, memperm_entry_t);
589                                         entry->node = node;
590                                         entry->pos = i;
591                                         entry->in = argslot->entity;
592                                         entry->out = slot->entity;
593                                         entry->next = memperm->entries;
594                                         memperm->entrycount++;
595                                         memperm->entries = entry;
596                                 }
597                         }
598                 } else {
599                         assign_spill_entity(env, node, slot->entity);
600                 }
601         }
602
603         for (s = 0; s < ARR_LEN(env->reloads); ++s) {
604                 ir_node            *reload    = env->reloads[s];
605                 ir_node            *spillnode = get_memory_edge(reload);
606                 const spill_t      *spill     = get_spill(env, spillnode);
607                 const spill_slot_t *slot      = &spillslots[spill->spillslot];
608
609                 assert(slot->entity != NULL);
610
611                 env->set_frame_entity(reload, slot->entity);
612         }
613 }
614
615 /**
616  * Returns the last node in a block which is no control flow changing node
617  */
618 static ir_node *get_end_of_block_insertion_point(ir_node* block)
619 {
620         ir_node* ins = sched_last(block);
621         while (is_Proj(ins) && get_irn_mode(ins) == mode_X) {
622                 ins = sched_prev(ins);
623                 assert(ins != NULL);
624         }
625
626         if (is_cfop(ins)) {
627                 for (;;) {
628                         ir_node *prev = sched_prev(ins);
629                         if (!is_cfop(prev))
630                                 break;
631                         ins = prev;
632                 }
633         }
634
635         return ins;
636 }
637
638 static void create_memperms(be_fec_env_t *env)
639 {
640         foreach_set(env->memperms, memperm_t, memperm) {
641                 ir_node         **nodes = ALLOCAN(ir_node*, memperm->entrycount);
642                 memperm_entry_t  *entry;
643                 ir_node          *blockend;
644                 ir_node          *mempermnode;
645                 int               i;
646
647                 assert(memperm->entrycount > 0);
648
649                 for (entry = memperm->entries, i = 0; entry != NULL; entry = entry->next, ++i) {
650                         ir_node* arg = get_irn_n(entry->node, entry->pos);
651                         nodes[i] = arg;
652                 }
653
654                 mempermnode = be_new_MemPerm(memperm->block, memperm->entrycount,
655                                              nodes);
656
657                 /* insert node into schedule */
658                 blockend = get_end_of_block_insertion_point(memperm->block);
659                 sched_add_before(blockend, mempermnode);
660                 stat_ev_dbl("mem_perm", memperm->entrycount);
661
662                 i = 0;
663                 for (entry = memperm->entries; entry != NULL; entry = entry->next, ++i) {
664                         ir_node *proj;
665                         ir_node* arg = get_irn_n(entry->node, entry->pos);
666
667                         be_set_MemPerm_in_entity(mempermnode, i, entry->in);
668                         be_set_MemPerm_out_entity(mempermnode, i, entry->out);
669                         proj = new_r_Proj(mempermnode, get_irn_mode(arg), i);
670
671                         set_irn_n(entry->node, entry->pos, proj);
672                 }
673         }
674 }
675
676 static unsigned count_spillslots(const be_fec_env_t *env)
677 {
678         size_t         spillcount = ARR_LEN(env->spills);
679         unsigned       slotcount  = 0;
680         unsigned      *counted;
681         size_t         s;
682
683         rbitset_alloca(counted, spillcount);
684
685         for (s = 0; s < spillcount; ++s) {
686                 spill_t *spill     = env->spills[s];
687                 int      spillslot = spill->spillslot;
688                 if (!rbitset_is_set(counted, spillslot)) {
689                         ++slotcount;
690                         rbitset_set(counted, spillslot);
691                 }
692         }
693
694         return slotcount;
695 }
696
697 be_fec_env_t *be_new_frame_entity_coalescer(ir_graph *irg)
698 {
699         be_fec_env_t *env = XMALLOCZ(be_fec_env_t);
700
701         be_assure_live_chk(irg);
702
703         obstack_init(&env->obst);
704         env->irg            = irg;
705         env->spills         = NEW_ARR_F(spill_t*, 0);
706         env->spills_set     = rbitset_malloc(get_irg_last_idx(irg));
707         env->reloads        = NEW_ARR_F(ir_node*, 0);
708         env->affinity_edges = NEW_ARR_F(affinity_edge_t*, 0);
709         env->memperms       = new_set(cmp_memperm, 10);
710
711         ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
712
713         return env;
714 }
715
716 void be_free_frame_entity_coalescer(be_fec_env_t *env)
717 {
718         ir_free_resources(env->irg, IR_RESOURCE_IRN_LINK);
719
720         del_set(env->memperms);
721         DEL_ARR_F(env->reloads);
722         DEL_ARR_F(env->affinity_edges);
723         DEL_ARR_F(env->spills);
724         xfree(env->spills_set);
725         obstack_free(&env->obst, NULL);
726
727         free(env);
728 }
729
730 void be_assign_entities(be_fec_env_t *env,
731                         set_frame_entity_func set_frame_entity,
732                         bool alloc_entities_at_begin)
733 {
734         env->set_frame_entity = set_frame_entity;
735         env->at_begin         = alloc_entities_at_begin;
736
737         if (stat_ev_enabled) {
738                 stat_ev_dbl("spillslots", ARR_LEN(env->spills));
739         }
740
741         if (be_coalesce_spill_slots) {
742                 do_greedy_coalescing(env);
743         }
744
745         if (stat_ev_enabled) {
746                 stat_ev_dbl("spillslots_after_coalescing", count_spillslots(env));
747         }
748
749         assign_spillslots(env);
750
751         create_memperms(env);
752 }
753
754 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillslots)
755 void be_init_spillslots(void)
756 {
757         FIRM_DBG_REGISTER(dbg, "firm.be.spillslots");
758 }