unified header
[libfirm] / ir / be / bechordal_main.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       Driver for the chordal register allocator.
23  * @author      Sebastian Hack
24  * @date        29.11.2005
25  * @version     $Id$
26  */
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <stdlib.h>
32 #include <time.h>
33
34 #include "obst.h"
35 #include "pset.h"
36 #include "list.h"
37 #include "bitset.h"
38 #include "iterator.h"
39 #include "firm_config.h"
40
41 #include <libcore/lc_opts.h>
42 #include <libcore/lc_opts_enum.h>
43 #include <libcore/lc_timing.h>
44
45 #include "ircons_t.h"
46 #include "irmode_t.h"
47 #include "irgraph_t.h"
48 #include "irprintf_t.h"
49 #include "irgwalk.h"
50 #include "ircons.h"
51 #include "irdump.h"
52 #include "irdom.h"
53 #include "ircons.h"
54 #include "irbitset.h"
55 #include "irnode.h"
56 #include "ircons.h"
57 #include "debug.h"
58 #include "xmalloc.h"
59 #include "execfreq.h"
60
61 #include "bechordal_t.h"
62 #include "beabi.h"
63 #include "bejavacoal.h"
64 #include "beutil.h"
65 #include "besched.h"
66 #include "besched_t.h"
67 #include "belive_t.h"
68 #include "bearch_t.h"
69 #include "beifg_t.h"
70 #include "beifg_impl.h"
71 #include "benode_t.h"
72 #include "bestatevent.h"
73 #include "bestat.h"
74 #include "bemodule.h"
75 #include "be_t.h"
76 #include "bera.h"
77 #include "beirg_t.h"
78
79 #include "bespillbelady.h"
80 #include "bespillmorgan.h"
81 #include "bespillslots.h"
82 #include "bespilloptions.h"
83 #include "belower.h"
84
85 #ifdef WITH_ILP
86 #include "bespillremat.h"
87 #endif /* WITH_ILP */
88
89 #include "bejavacoal.h"
90 #include "becopystat.h"
91 #include "becopyopt.h"
92 #include "bessadestr.h"
93 #include "beverify.h"
94 #include "benode_t.h"
95
96 static be_ra_chordal_opts_t options = {
97         BE_CH_DUMP_NONE,
98         BE_CH_LOWER_PERM_SWAP,
99         BE_CH_VRFY_WARN,
100 };
101
102 typedef struct _post_spill_env_t {
103         be_chordal_env_t            cenv;
104         be_irg_t                    *birg;
105         const arch_register_class_t *cls;
106         double                      pre_spill_cost;
107 } post_spill_env_t;
108
109 static be_ra_timer_t ra_timer = {
110         NULL,
111         NULL,
112         NULL,
113         NULL,
114         NULL,
115         NULL,
116         NULL,
117         NULL,
118         NULL,
119         NULL,
120         NULL,
121 };
122
123 static const lc_opt_enum_int_items_t lower_perm_items[] = {
124         { "copy", BE_CH_LOWER_PERM_COPY },
125         { "swap", BE_CH_LOWER_PERM_SWAP },
126         { NULL, 0 }
127 };
128
129 static const lc_opt_enum_int_items_t lower_perm_stat_items[] = {
130         { NULL, 0 }
131 };
132
133 static const lc_opt_enum_int_items_t dump_items[] = {
134         { "none",       BE_CH_DUMP_NONE       },
135         { "spill",      BE_CH_DUMP_SPILL      },
136         { "live",       BE_CH_DUMP_LIVE       },
137         { "color",      BE_CH_DUMP_COLOR      },
138         { "copymin",    BE_CH_DUMP_COPYMIN    },
139         { "ssadestr",   BE_CH_DUMP_SSADESTR   },
140         { "tree",       BE_CH_DUMP_TREE_INTV  },
141         { "constr",     BE_CH_DUMP_CONSTR     },
142         { "lower",      BE_CH_DUMP_LOWER      },
143         { "spillslots", BE_CH_DUMP_SPILLSLOTS },
144         { "appel",      BE_CH_DUMP_APPEL      },
145         { "all",        BE_CH_DUMP_ALL        },
146         { NULL, 0 }
147 };
148
149 static const lc_opt_enum_int_items_t be_ch_vrfy_items[] = {
150         { "off",    BE_CH_VRFY_OFF    },
151         { "warn",   BE_CH_VRFY_WARN   },
152         { "assert", BE_CH_VRFY_ASSERT },
153         { NULL, 0 }
154 };
155
156 static lc_opt_enum_int_var_t lower_perm_var = {
157         &options.lower_perm_opt, lower_perm_items
158 };
159
160 static lc_opt_enum_int_var_t dump_var = {
161         &options.dump_flags, dump_items
162 };
163
164 static lc_opt_enum_int_var_t be_ch_vrfy_var = {
165         &options.vrfy_option, be_ch_vrfy_items
166 };
167
168 static const lc_opt_table_entry_t be_chordal_options[] = {
169         LC_OPT_ENT_ENUM_PTR ("perm",          "perm lowering options", &lower_perm_var),
170         LC_OPT_ENT_ENUM_MASK("dump",          "select dump phases", &dump_var),
171         LC_OPT_ENT_ENUM_PTR ("vrfy",          "verify options", &be_ch_vrfy_var),
172         { NULL }
173 };
174
175 static void dump(unsigned mask, ir_graph *irg,
176                                  const arch_register_class_t *cls,
177                                  const char *suffix,
178                                  void (*dump_func)(ir_graph *, const char *))
179 {
180         if((options.dump_flags & mask) == mask) {
181                 if (cls) {
182                         char buf[256];
183                         snprintf(buf, sizeof(buf), "-%s%s", cls->name, suffix);
184                         be_dump(irg, buf, dump_func);
185                 }
186                 else
187                         be_dump(irg, suffix, dump_func);
188         }
189 }
190
191 /**
192  * Checks for every reload if it's user can perform the load on itself.
193  */
194 static void memory_operand_walker(ir_node *irn, void *env) {
195         be_chordal_env_t *cenv = env;
196         const arch_env_t *aenv = cenv->birg->main_env->arch_env;
197         const ir_edge_t  *edge, *ne;
198         ir_node          *block;
199         ir_node          *spill;
200
201         if (! be_is_Reload(irn))
202                 return;
203
204         /* only use memory operands, if the reload is only used by 1 node */
205         if(get_irn_n_edges(irn) > 1)
206                 return;
207
208         spill = be_get_Reload_mem(irn);
209         block = get_nodes_block(irn);
210
211         foreach_out_edge_safe(irn, edge, ne) {
212                 ir_node *src = get_edge_src_irn(edge);
213                 int     pos  = get_edge_src_pos(edge);
214
215                 assert(src && "outedges broken!");
216
217                 if (get_nodes_block(src) == block && arch_possible_memory_operand(aenv, src, pos)) {
218                         arch_perform_memory_operand(aenv, src, spill, pos);
219                 }
220         }
221
222         /* kill the Reload */
223         if (get_irn_n_edges(irn) == 0) {
224                 sched_remove(irn);
225                 set_irn_n(irn, be_pos_Reload_mem, new_Bad());
226                 set_irn_n(irn, be_pos_Reload_frame, new_Bad());
227         }
228 }
229
230 /**
231  * Starts a walk for memory operands if supported by the backend.
232  */
233 static INLINE void check_for_memory_operands(be_chordal_env_t *chordal_env) {
234         irg_walk_graph(chordal_env->irg, NULL, memory_operand_walker, chordal_env);
235 }
236
237 /**
238  * Sorry for doing stats again...
239  */
240 typedef struct _node_stat_t {
241         unsigned int n_phis;      /**< Phis of the current register class. */
242         unsigned int n_mem_phis;  /**< Memory Phis (Phis with spill operands). */
243         unsigned int n_copies;    /**< Copies */
244         unsigned int n_perms;     /**< Perms */
245         unsigned int n_spills;    /**< Spill nodes */
246         unsigned int n_reloads;   /**< Reloads */
247 } node_stat_t;
248
249 struct node_stat_walker {
250         node_stat_t      *stat;
251         const arch_env_t *arch_env;
252         bitset_t         *mem_phis;
253         const arch_register_class_t *cls;
254 };
255
256 static void node_stat_walker(ir_node *irn, void *data)
257 {
258         struct node_stat_walker *env  = data;
259         const arch_env_t        *aenv = env->arch_env;
260
261         if (arch_irn_consider_in_reg_alloc(aenv, env->cls, irn)) {
262
263                 /* if the node is a normal phi */
264                 if(is_Phi(irn))
265                         env->stat->n_phis++;
266
267                 else if(arch_irn_classify(aenv, irn) & arch_irn_class_spill)
268                         ++env->stat->n_spills;
269
270                 else if(arch_irn_classify(aenv, irn) & arch_irn_class_reload)
271                         ++env->stat->n_reloads;
272
273                 else if(arch_irn_classify(aenv, irn) & arch_irn_class_copy)
274                         ++env->stat->n_copies;
275
276                 else if(arch_irn_classify(aenv, irn) & arch_irn_class_perm)
277                         ++env->stat->n_perms;
278         }
279
280         /* a mem phi is a PhiM with a mem phi operand or a Spill operand */
281         else if(is_Phi(irn) && get_irn_mode(irn) == mode_M) {
282                 int i;
283
284                 for(i = get_irn_arity(irn) - 1; i >= 0; --i) {
285                         ir_node *op = get_irn_n(irn, i);
286
287                         if((is_Phi(op) && bitset_contains_irn(env->mem_phis, op)) || (arch_irn_classify(aenv, op) & arch_irn_class_spill)) {
288                                 bitset_add_irn(env->mem_phis, irn);
289                                 env->stat->n_mem_phis++;
290                                 break;
291                         }
292                 }
293         }
294 }
295
296 static void node_stats(be_irg_t *birg, const arch_register_class_t *cls, node_stat_t *stat)
297 {
298         struct node_stat_walker env;
299
300         memset(stat, 0, sizeof(stat[0]));
301         env.arch_env = birg->main_env->arch_env;
302         env.mem_phis = bitset_irg_malloc(birg->irg);
303         env.stat     = stat;
304         env.cls      = cls;
305         irg_walk_graph(birg->irg, NULL, node_stat_walker, &env);
306         bitset_free(env.mem_phis);
307 }
308
309 static void insn_count_walker(ir_node *irn, void *data)
310 {
311         int *cnt = data;
312
313         switch(get_irn_opcode(irn)) {
314         case iro_Proj:
315         case iro_Phi:
316         case iro_Start:
317         case iro_End:
318                 break;
319         default:
320                 (*cnt)++;
321         }
322 }
323
324 static unsigned int count_insns(ir_graph *irg)
325 {
326         int cnt = 0;
327         irg_walk_graph(irg, insn_count_walker, NULL, &cnt);
328         return cnt;
329 }
330
331 /**
332  * Initialize all timers.
333  */
334 static void be_init_timer(be_options_t *main_opts)
335 {
336         if (main_opts->timing == BE_TIME_ON) {
337                 ra_timer.t_prolog     = lc_timer_register("ra_prolog",     "regalloc prolog");
338                 ra_timer.t_epilog     = lc_timer_register("ra_epilog",     "regalloc epilog");
339                 ra_timer.t_live       = lc_timer_register("ra_liveness",   "be liveness");
340                 ra_timer.t_spill      = lc_timer_register("ra_spill",      "spiller");
341                 ra_timer.t_spillslots = lc_timer_register("ra_spillslots", "spillslots");
342                 ra_timer.t_color      = lc_timer_register("ra_color",      "graph coloring");
343                 ra_timer.t_ifg        = lc_timer_register("ra_ifg",        "interference graph");
344                 ra_timer.t_copymin    = lc_timer_register("ra_copymin",    "copy minimization");
345                 ra_timer.t_ssa        = lc_timer_register("ra_ssadestr",   "ssa destruction");
346                 ra_timer.t_verify     = lc_timer_register("ra_verify",     "graph verification");
347                 ra_timer.t_other      = lc_timer_register("ra_other",      "other time");
348
349                 LC_STOP_AND_RESET_TIMER(ra_timer.t_prolog);
350                 LC_STOP_AND_RESET_TIMER(ra_timer.t_epilog);
351                 LC_STOP_AND_RESET_TIMER(ra_timer.t_live);
352                 LC_STOP_AND_RESET_TIMER(ra_timer.t_spill);
353                 LC_STOP_AND_RESET_TIMER(ra_timer.t_spillslots);
354                 LC_STOP_AND_RESET_TIMER(ra_timer.t_color);
355                 LC_STOP_AND_RESET_TIMER(ra_timer.t_ifg);
356                 LC_STOP_AND_RESET_TIMER(ra_timer.t_copymin);
357                 LC_STOP_AND_RESET_TIMER(ra_timer.t_ssa);
358                 LC_STOP_AND_RESET_TIMER(ra_timer.t_verify);
359                 LC_STOP_AND_RESET_TIMER(ra_timer.t_other);
360
361                 global_ra_timer = &ra_timer;
362         }
363 }
364
365 #define BE_TIMER_INIT(main_opts)        be_init_timer(main_opts)
366
367 #define BE_TIMER_PUSH(timer)                                                            \
368         if (main_opts->timing == BE_TIME_ON) {                                              \
369                 if (! lc_timer_push(timer)) {                                                   \
370                         if (options.vrfy_option == BE_CH_VRFY_ASSERT)                               \
371                                 assert(!"Timer already on stack, cannot be pushed twice.");             \
372                         else if (options.vrfy_option == BE_CH_VRFY_WARN)                            \
373                                 fprintf(stderr, "Timer %s already on stack, cannot be pushed twice.\n", \
374                                         lc_timer_get_name(timer));                                          \
375                 }                                                                               \
376         }
377 #define BE_TIMER_POP(timer)                                                                    \
378         if (main_opts->timing == BE_TIME_ON) {                                                     \
379                 lc_timer_t *tmp = lc_timer_pop();                                                      \
380                 if (options.vrfy_option == BE_CH_VRFY_ASSERT)                                          \
381                         assert(tmp == timer && "Attempt to pop wrong timer.");                             \
382                 else if (options.vrfy_option == BE_CH_VRFY_WARN && tmp != timer)                       \
383                         fprintf(stderr, "Attempt to pop wrong timer. %s is on stack, trying to pop %s.\n", \
384                                 lc_timer_get_name(tmp), lc_timer_get_name(timer));                             \
385                 timer = tmp;                                                                           \
386         }
387
388 /**
389  * Perform things which need to be done per register class before spilling.
390  */
391 static void pre_spill(const arch_isa_t *isa, int cls_idx, post_spill_env_t *pse) {
392         be_chordal_env_t *chordal_env = &pse->cenv;
393         be_irg_t         *birg        = pse->birg;
394         node_stat_t      node_stat;
395
396         pse->cls                   = arch_isa_get_reg_class(isa, cls_idx);
397         chordal_env->cls           = pse->cls;
398         chordal_env->border_heads  = pmap_create();
399         chordal_env->ignore_colors = bitset_malloc(chordal_env->cls->n_regs);
400
401 #ifdef FIRM_STATISTICS
402         if (be_stat_ev_is_active()) {
403                 be_stat_tags[STAT_TAG_CLS] = pse->cls->name;
404                 be_stat_ev_push(be_stat_tags, STAT_TAG_LAST, be_stat_file);
405
406                 /* perform some node statistics. */
407                 node_stats(birg, pse->cls, &node_stat);
408                 be_stat_ev("phis_before_spill", node_stat.n_phis);
409         }
410 #endif /* FIRM_STATISTICS */
411
412         /* put all ignore registers into the ignore register set. */
413         be_put_ignore_regs(birg, pse->cls, chordal_env->ignore_colors);
414
415         be_pre_spill_prepare_constr(chordal_env);
416         dump(BE_CH_DUMP_CONSTR, birg->irg, pse->cls, "-constr-pre", dump_ir_block_graph_sched);
417
418 #ifdef FIRM_STATISTICS
419         if (be_stat_ev_is_active()) {
420                 pse->pre_spill_cost = be_estimate_irg_costs(birg->irg,
421                         birg->main_env->arch_env, birg->exec_freq);
422                 be_stat_ev_pop();
423         }
424 #endif /* FIRM_STATISTICS */
425 }
426
427 /**
428  * Perform things which need to be done per register class after spilling.
429  */
430 static void post_spill(post_spill_env_t *pse, int iteration) {
431         be_chordal_env_t    *chordal_env = &pse->cenv;
432         be_irg_t            *birg        = pse->birg;
433         ir_graph            *irg         = birg->irg;
434         const be_main_env_t *main_env    = birg->main_env;
435         be_options_t        *main_opts   = main_env->options;
436         node_stat_t         node_stat;
437         int                 colors_n     = arch_register_class_n_regs(chordal_env->cls);
438         int             allocatable_regs = colors_n - be_put_ignore_regs(birg, chordal_env->cls, NULL);
439
440         /* some special classes contain only ignore regs, no work to be done */
441         if (allocatable_regs > 0) {
442
443 #ifdef FIRM_STATISTICS
444                 if (be_stat_ev_is_active()) {
445                         double spillcosts = be_estimate_irg_costs(irg, main_env->arch_env, birg->exec_freq) - pse->pre_spill_cost;
446
447                         be_stat_tags[STAT_TAG_CLS] = pse->cls->name;
448                         be_stat_ev_push(be_stat_tags, STAT_TAG_LAST, be_stat_file);
449
450                         be_stat_ev_l("spillcosts", (long) spillcosts);
451
452                         node_stats(birg, pse->cls, &node_stat);
453                         be_stat_ev("phis_after_spill", node_stat.n_phis);
454                         be_stat_ev("mem_phis", node_stat.n_mem_phis);
455                         be_stat_ev("reloads", node_stat.n_reloads);
456                         be_stat_ev("spills", node_stat.n_spills);
457                 }
458 #endif /* FIRM_STATISTICS */
459
460                 /*
461                         If we have a backend provided spiller, post spill is
462                         called in a loop after spilling for each register class.
463                         But we only need to fix stack nodes once in this case.
464                 */
465                 if (iteration == 0) {
466                         check_for_memory_operands(chordal_env);
467                         be_abi_fix_stack_nodes(birg->abi);
468                 }
469
470                 BE_TIMER_PUSH(ra_timer.t_verify);
471
472                 /* verify schedule and register pressure */
473                 if (chordal_env->opts->vrfy_option == BE_CH_VRFY_WARN) {
474                         be_verify_schedule(birg);
475                         be_verify_register_pressure(birg, pse->cls, irg);
476                 }
477                 else if (chordal_env->opts->vrfy_option == BE_CH_VRFY_ASSERT) {
478                         assert(be_verify_schedule(birg) && "Schedule verification failed");
479                         assert(be_verify_register_pressure(birg, pse->cls, irg)
480                                 && "Register pressure verification failed");
481                 }
482                 BE_TIMER_POP(ra_timer.t_verify);
483
484                 /* Color the graph. */
485                 BE_TIMER_PUSH(ra_timer.t_color);
486                 be_ra_chordal_color(chordal_env);
487                 BE_TIMER_POP(ra_timer.t_color);
488
489                 dump(BE_CH_DUMP_CONSTR, irg, pse->cls, "-color", dump_ir_block_graph_sched);
490
491                 /* Create the ifg with the selected flavor */
492                 BE_TIMER_PUSH(ra_timer.t_ifg);
493                 chordal_env->ifg = be_create_ifg(chordal_env);
494                 BE_TIMER_POP(ra_timer.t_ifg);
495
496 #ifdef FIRM_STATISTICS
497                 if (be_stat_ev_is_active()) {
498                         be_ifg_stat_t stat;
499
500                         be_ifg_stat(birg, chordal_env->ifg, &stat);
501                         be_stat_ev("ifg_nodes", stat.n_nodes);
502                         be_stat_ev("ifg_edges", stat.n_edges);
503                         be_stat_ev("ifg_comps", stat.n_comps);
504
505                         node_stats(birg, pse->cls, &node_stat);
506                         be_stat_ev("perms_before_coal", node_stat.n_perms);
507                         be_stat_ev("copies_before_coal", node_stat.n_copies);
508                 }
509 #endif /* FIRM_STATISTICS */
510
511                 /* copy minimization */
512                 BE_TIMER_PUSH(ra_timer.t_copymin);
513                 co_driver(chordal_env);
514                 BE_TIMER_POP(ra_timer.t_copymin);
515
516                 dump(BE_CH_DUMP_COPYMIN, irg, pse->cls, "-copymin", dump_ir_block_graph_sched);
517
518                 BE_TIMER_PUSH(ra_timer.t_ssa);
519
520                 /* ssa destruction */
521                 be_ssa_destruction(chordal_env);
522
523                 BE_TIMER_POP(ra_timer.t_ssa);
524
525                 dump(BE_CH_DUMP_SSADESTR, irg, pse->cls, "-ssadestr", dump_ir_block_graph_sched);
526
527                 BE_TIMER_PUSH(ra_timer.t_verify);
528                 if (chordal_env->opts->vrfy_option != BE_CH_VRFY_OFF) {
529                         be_ssa_destruction_check(chordal_env);
530                 }
531                 BE_TIMER_POP(ra_timer.t_verify);
532
533 #ifdef FIRM_STATISTICS
534                 if (be_stat_ev_is_active()) {
535                         node_stats(birg, pse->cls, &node_stat);
536                         be_stat_ev("perms_after_coal", node_stat.n_perms);
537                         be_stat_ev("copies_after_coal", node_stat.n_copies);
538                         be_stat_ev_pop();
539                 }
540 #endif /* FIRM_STATISTICS */
541
542                 /* the ifg exists only if there are allocatable regs */
543                 be_ifg_free(chordal_env->ifg);
544         }
545
546         /* free some always allocated data structures */
547         pmap_destroy(chordal_env->border_heads);
548         bitset_free(chordal_env->ignore_colors);
549 }
550
551 /**
552  * Performs chordal register allocation for each register class on given irg.
553  *
554  * @param birg  Backend irg object
555  * @return Structure containing timer for the single phases or NULL if no timing requested.
556  */
557 static void be_ra_chordal_main(be_irg_t *birg)
558 {
559         const be_main_env_t *main_env  = birg->main_env;
560         const arch_isa_t    *isa       = arch_env_get_isa(main_env->arch_env);
561         ir_graph            *irg       = birg->irg;
562         be_options_t        *main_opts = main_env->options;
563         int                 j, m;
564         be_chordal_env_t    chordal_env;
565         struct obstack      obst;
566
567         BE_TIMER_INIT(main_opts);
568         BE_TIMER_PUSH(ra_timer.t_other);
569         BE_TIMER_PUSH(ra_timer.t_prolog);
570
571         be_assure_dom_front(birg);
572         be_assure_liveness(birg);
573
574         chordal_env.obst          = &obst;
575         chordal_env.opts          = &options;
576         chordal_env.irg           = irg;
577         chordal_env.birg          = birg;
578         chordal_env.border_heads  = NULL;
579         chordal_env.ifg           = NULL;
580         chordal_env.ignore_colors = NULL;
581
582         obstack_init(&obst);
583
584         BE_TIMER_POP(ra_timer.t_prolog);
585
586         be_stat_ev("insns_before", count_insns(irg));
587
588         if (! arch_code_generator_has_spiller(birg->cg)) {
589                 /* use one of the generic spiller */
590
591                 /* Perform the following for each register class. */
592                 for (j = 0, m = arch_isa_get_n_reg_class(isa); j < m; ++j) {
593                         post_spill_env_t pse;
594
595                         memcpy(&pse.cenv, &chordal_env, sizeof(chordal_env));
596                         pse.birg = birg;
597                         pre_spill(isa, j, &pse);
598
599                         BE_TIMER_PUSH(ra_timer.t_spill);
600                         be_do_spill(birg, pse.cls);
601                         BE_TIMER_POP(ra_timer.t_spill);
602
603                         dump(BE_CH_DUMP_SPILL, irg, pse.cls, "-spill", dump_ir_block_graph_sched);
604
605                         post_spill(&pse, 0);
606                 }
607         } else {
608                 post_spill_env_t *pse;
609
610                 /* the backend has it's own spiller */
611                 m = arch_isa_get_n_reg_class(isa);
612
613                 pse = alloca(m * sizeof(pse[0]));
614
615                 for (j = 0; j < m; ++j) {
616                         memcpy(&pse[j].cenv, &chordal_env, sizeof(chordal_env));
617                         pse[j].birg = birg;
618                         pre_spill(isa, j, &pse[j]);
619                 }
620
621                 BE_TIMER_PUSH(ra_timer.t_spill);
622                 arch_code_generator_spill(birg->cg, birg);
623                 BE_TIMER_POP(ra_timer.t_spill);
624                 dump(BE_CH_DUMP_SPILL, irg, NULL, "-spill", dump_ir_block_graph_sched);
625
626                 for (j = 0; j < m; ++j) {
627                         post_spill(&pse[j], j);
628                 }
629         }
630
631         BE_TIMER_PUSH(ra_timer.t_epilog);
632         lower_nodes_after_ra(birg, options.lower_perm_opt & BE_CH_LOWER_PERM_COPY ? 1 : 0);
633         dump(BE_CH_DUMP_LOWER, irg, NULL, "-belower-after-ra", dump_ir_block_graph_sched);
634
635         obstack_free(&obst, NULL);
636         be_invalidate_liveness(birg);
637         BE_TIMER_POP(ra_timer.t_epilog);
638
639         BE_TIMER_POP(ra_timer.t_other);
640
641         be_stat_ev("insns_after", count_insns(irg));
642
643         return;
644 }
645
646 static be_ra_t be_ra_chordal_allocator = {
647         be_ra_chordal_main,
648 };
649
650 void be_init_chordal_main(void)
651 {
652         lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
653         lc_opt_entry_t *ra_grp = lc_opt_get_grp(be_grp, "ra");
654         lc_opt_entry_t *chordal_grp = lc_opt_get_grp(ra_grp, "chordal");
655
656         lc_opt_add_table(chordal_grp, be_chordal_options);
657
658         be_register_allocator("chordal", &be_ra_chordal_allocator);
659 }
660
661 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_chordal_main);