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