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