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