adapted to new callback
[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 "obst.h"
17 #include "pset.h"
18 #include "list.h"
19 #include "bitset.h"
20 #include "iterator.h"
21 #include "firm_config.h"
22
23 #ifdef WITH_LIBCORE
24 #include <libcore/lc_opts.h>
25 #include <libcore/lc_opts_enum.h>
26 #include <libcore/lc_timing.h>
27 #endif /* WITH_LIBCORE */
28
29 #include "ircons_t.h"
30 #include "irmode_t.h"
31 #include "irgraph_t.h"
32 #include "irprintf_t.h"
33 #include "irgwalk.h"
34 #include "ircons.h"
35 #include "irdump.h"
36 #include "irdom.h"
37 #include "ircons.h"
38 #include "irbitset.h"
39 #include "irnode.h"
40 #include "ircons.h"
41 #include "debug.h"
42 #include "xmalloc.h"
43 #include "execfreq.h"
44
45 #include "bechordal_t.h"
46 #include "beabi.h"
47 #include "bejavacoal.h"
48 #include "beutil.h"
49 #include "besched.h"
50 #include "benumb_t.h"
51 #include "besched_t.h"
52 #include "belive_t.h"
53 #include "bearch.h"
54 #include "beifg_t.h"
55 #include "beifg_impl.h"
56 #include "benode_t.h"
57
58 #include "bespillbelady.h"
59 #include "bespillmorgan.h"
60 #include "bespillslots.h"
61 #include "belower.h"
62
63 #ifdef WITH_ILP
64 #include "bespillremat.h"
65 #endif /* WITH_ILP */
66
67 #include "bejavacoal.h"
68 #include "becopystat.h"
69 #include "becopyopt.h"
70 #include "bessadestr.h"
71 #include "beverify.h"
72 #include "bespillcost.h"
73 #include "benode_t.h"
74
75 void be_ra_chordal_check(be_chordal_env_t *chordal_env) {
76         const arch_env_t *arch_env = chordal_env->birg->main_env->arch_env;
77         struct obstack ob;
78         pmap_entry *pme;
79         ir_node **nodes, *n1, *n2;
80         int i, o;
81         DEBUG_ONLY(firm_dbg_module_t *dbg = chordal_env->dbg;)
82
83         /* Collect all irns */
84         obstack_init(&ob);
85         pmap_foreach(chordal_env->border_heads, pme) {
86                 border_t *curr;
87                 struct list_head *head = pme->value;
88                 list_for_each_entry(border_t, curr, head, list)
89                         if (curr->is_def && curr->is_real)
90                                 if (arch_get_irn_reg_class(arch_env, curr->irn, -1) == chordal_env->cls)
91                                         obstack_ptr_grow(&ob, curr->irn);
92         }
93         obstack_ptr_grow(&ob, NULL);
94         nodes = (ir_node **) obstack_finish(&ob);
95
96         /* Check them */
97         for (i = 0, n1 = nodes[i]; n1; n1 = nodes[++i]) {
98                 const arch_register_t *n1_reg, *n2_reg;
99
100                 n1_reg = arch_get_irn_register(arch_env, n1);
101                 if (!arch_reg_is_allocatable(arch_env, n1, -1, n1_reg)) {
102                         DBG((dbg, 0, "Register %s assigned to %+F is not allowed\n", n1_reg->name, n1));
103                         assert(0 && "Register constraint does not hold");
104                 }
105                 for (o = i+1, n2 = nodes[o]; n2; n2 = nodes[++o]) {
106                         n2_reg = arch_get_irn_register(arch_env, n2);
107                         if (values_interfere(chordal_env->lv, n1, n2) && n1_reg == n2_reg) {
108                                 DBG((dbg, 0, "Values %+F and %+F interfere and have the same register assigned: %s\n", n1, n2, n1_reg->name));
109                                 assert(0 && "Interfering values have the same color!");
110                         }
111                 }
112         }
113         obstack_free(&ob, NULL);
114 }
115
116 int nodes_interfere(const be_chordal_env_t *env, const ir_node *a, const ir_node *b)
117 {
118         if(env->ifg)
119                 return be_ifg_connected(env->ifg, a, b);
120         else
121                 return values_interfere(env->lv, a, b);
122 }
123
124
125 static be_ra_chordal_opts_t options = {
126         BE_CH_DUMP_NONE,
127         BE_CH_SPILL_BELADY,
128         BE_CH_IFG_STD,
129         BE_CH_LOWER_PERM_SWAP,
130         BE_CH_VRFY_WARN,
131 };
132
133 /** Enable extreme live range splitting. */
134 static int be_elr_split = 0;
135
136 /** Assumed loop iteration count for execution frequency estimation. */
137 static int be_loop_weight = 9;
138
139 #ifdef WITH_LIBCORE
140 static be_ra_timer_t ra_timer = {
141         NULL,
142         NULL,
143         NULL,
144         NULL,
145         NULL,
146         NULL,
147         NULL,
148         NULL,
149         NULL,
150         NULL,
151         NULL,
152 };
153
154 static const lc_opt_enum_int_items_t spill_items[] = {
155         { "morgan", BE_CH_SPILL_MORGAN },
156         { "belady", BE_CH_SPILL_BELADY },
157 #ifdef WITH_ILP
158         { "remat",  BE_CH_SPILL_REMAT },
159 #endif /* WITH_ILP */
160         { NULL, 0 }
161 };
162
163 static const lc_opt_enum_int_items_t ifg_flavor_items[] = {
164         { "std",     BE_CH_IFG_STD     },
165         { "fast",    BE_CH_IFG_FAST    },
166         { "clique",  BE_CH_IFG_CLIQUE  },
167         { "pointer", BE_CH_IFG_POINTER },
168         { "list",    BE_CH_IFG_LIST    },
169         { "check",   BE_CH_IFG_CHECK   },
170         { NULL,      0                 }
171 };
172
173 static const lc_opt_enum_int_items_t lower_perm_items[] = {
174         { "copy", BE_CH_LOWER_PERM_COPY },
175         { "swap", BE_CH_LOWER_PERM_SWAP },
176         { NULL, 0 }
177 };
178
179 static const lc_opt_enum_int_items_t lower_perm_stat_items[] = {
180         { NULL, 0 }
181 };
182
183 static const lc_opt_enum_int_items_t dump_items[] = {
184         { "spill",      BE_CH_DUMP_SPILL      },
185         { "live",       BE_CH_DUMP_LIVE       },
186         { "color",      BE_CH_DUMP_COLOR      },
187         { "copymin",    BE_CH_DUMP_COPYMIN    },
188         { "ssadestr",   BE_CH_DUMP_SSADESTR   },
189         { "tree",       BE_CH_DUMP_TREE_INTV  },
190         { "constr",     BE_CH_DUMP_CONSTR     },
191         { "lower",      BE_CH_DUMP_LOWER      },
192         { "spillslots", BE_CH_DUMP_SPILLSLOTS },
193         { "appel",      BE_CH_DUMP_APPEL      },
194         { "all",        BE_CH_DUMP_ALL        },
195         { NULL, 0 }
196 };
197
198 static const lc_opt_enum_int_items_t be_ch_vrfy_items[] = {
199         { "off",    BE_CH_VRFY_OFF    },
200         { "warn",   BE_CH_VRFY_WARN   },
201         { "assert", BE_CH_VRFY_ASSERT },
202         { NULL, 0 }
203 };
204
205 static lc_opt_enum_int_var_t spill_var = {
206         &options.spill_method, spill_items
207 };
208
209 static lc_opt_enum_int_var_t ifg_flavor_var = {
210         &options.ifg_flavor, ifg_flavor_items
211 };
212
213 static lc_opt_enum_int_var_t lower_perm_var = {
214         &options.lower_perm_opt, lower_perm_items
215 };
216
217 static lc_opt_enum_int_var_t dump_var = {
218         &options.dump_flags, dump_items
219 };
220
221 static lc_opt_enum_int_var_t be_ch_vrfy_var = {
222         &options.vrfy_option, be_ch_vrfy_items
223 };
224
225 static const lc_opt_table_entry_t be_chordal_options[] = {
226         LC_OPT_ENT_ENUM_INT ("spill",         "spill method (belady, morgan or remat)", &spill_var),
227         LC_OPT_ENT_ENUM_PTR ("ifg",           "interference graph flavour (std, fast, clique, pointer, list, check)", &ifg_flavor_var),
228         LC_OPT_ENT_ENUM_PTR ("perm",          "perm lowering options (copy or swap)", &lower_perm_var),
229         LC_OPT_ENT_ENUM_MASK("dump",          "select dump phases", &dump_var),
230         LC_OPT_ENT_ENUM_PTR ("vrfy",          "verify options (off, warn, assert)", &be_ch_vrfy_var),
231         LC_OPT_ENT_BOOL     ("elrsplit",      "enable extreme live range splitting", &be_elr_split),
232         LC_OPT_ENT_INT      ("loop_weight",   "assumed amount of loop iterations for guessing the execution frequency", &be_loop_weight),
233         { NULL }
234 };
235
236 extern void be_spill_remat_register_options(lc_opt_entry_t *ent);
237
238
239 static void be_ra_chordal_register_options(lc_opt_entry_t *grp)
240 {
241         static int run_once = 0;
242         lc_opt_entry_t *chordal_grp;
243
244         if (! run_once) {
245                 run_once    = 1;
246                 chordal_grp = lc_opt_get_grp(grp, "chordal");
247
248                 lc_opt_add_table(chordal_grp, be_chordal_options);
249
250                 co_register_options(chordal_grp);
251                 be_java_coal_register_options(chordal_grp);
252 #ifdef WITH_ILP
253                 be_spill_remat_register_options(chordal_grp);
254 #endif
255         }
256 }
257 #endif /* WITH_LIBCORE */
258
259 static void dump(unsigned mask, ir_graph *irg,
260                                  const arch_register_class_t *cls,
261                                  const char *suffix,
262                                  void (*dump_func)(ir_graph *, const char *))
263 {
264         if((options.dump_flags & mask) == mask) {
265                 if (cls) {
266                         char buf[256];
267                         snprintf(buf, sizeof(buf), "-%s%s", cls->name, suffix);
268                         be_dump(irg, buf, dump_func);
269                 }
270                 else
271                         be_dump(irg, suffix, dump_func);
272         }
273 }
274
275 static void put_ignore_colors(be_chordal_env_t *chordal_env)
276 {
277         int n_colors = chordal_env->cls->n_regs;
278         int i;
279
280         bitset_clear_all(chordal_env->ignore_colors);
281         be_abi_put_ignore_regs(chordal_env->birg->abi, chordal_env->cls, chordal_env->ignore_colors);
282         for(i = 0; i < n_colors; ++i)
283                 if(arch_register_type_is(&chordal_env->cls->regs[i], ignore))
284                         bitset_set(chordal_env->ignore_colors, i);
285 }
286
287 FILE *be_chordal_open(const be_chordal_env_t *env, const char *prefix, const char *suffix)
288 {
289         char buf[1024];
290
291         ir_snprintf(buf, sizeof(buf), "%s%F_%s%s", prefix, env->irg, env->cls->name, suffix);
292         return fopen(buf, "wt");
293 }
294
295 void check_ifg_implementations(be_chordal_env_t *chordal_env)
296 {
297         FILE *f;
298
299         f = be_chordal_open(chordal_env, "std", ".log");
300         chordal_env->ifg = be_ifg_std_new(chordal_env);
301         be_ifg_check_sorted_to_file(chordal_env->ifg, f);
302         fclose(f);
303
304         f = be_chordal_open(chordal_env, "list", ".log");
305         be_ifg_free(chordal_env->ifg);
306         chordal_env->ifg = be_ifg_list_new(chordal_env);
307         be_ifg_check_sorted_to_file(chordal_env->ifg, f);
308         fclose(f);
309
310         f = be_chordal_open(chordal_env, "clique", ".log");
311         be_ifg_free(chordal_env->ifg);
312         chordal_env->ifg = be_ifg_clique_new(chordal_env);
313         be_ifg_check_sorted_to_file(chordal_env->ifg, f);
314         fclose(f);
315
316         f = be_chordal_open(chordal_env, "pointer", ".log");
317         be_ifg_free(chordal_env->ifg);
318         chordal_env->ifg = be_ifg_pointer_new(chordal_env);
319         be_ifg_check_sorted_to_file(chordal_env->ifg, f);
320         fclose(f);
321
322         chordal_env->ifg = NULL;
323 };
324
325 /**
326  * Checks for every reload if it's user can perform the load on itself.
327  */
328 static void memory_operand_walker(ir_node *irn, void *env) {
329         be_chordal_env_t *cenv = env;
330         const arch_env_t *aenv = cenv->birg->main_env->arch_env;
331         const ir_edge_t  *edge, *ne;
332         ir_node          *block;
333         ir_node          *spill;
334
335         if (! be_is_Reload(irn))
336                 return;
337
338         // only use memory operands, if the reload is only used by 1 node
339         if(get_irn_n_edges(irn) > 1)
340                 return;
341
342         spill = be_get_Reload_mem(irn);
343         block = get_nodes_block(irn);
344
345         foreach_out_edge_safe(irn, edge, ne) {
346                 ir_node *src = get_edge_src_irn(edge);
347                 int     pos  = get_edge_src_pos(edge);
348
349                 if (! src)
350                         continue;
351
352                 if (get_nodes_block(src) == block && arch_possible_memory_operand(aenv, src, pos)) {
353                         DBG((cenv->dbg, LEVEL_3, "performing memory operand %+F at %+F\n", irn, src));
354                         arch_perform_memory_operand(aenv, src, spill, pos);
355                 }
356         }
357
358         /* kill the Reload */
359         if (get_irn_n_edges(irn) == 0) {
360                 sched_remove(irn);
361                 set_irn_n(irn, 0, new_Bad());
362                 set_irn_n(irn, 1, new_Bad());
363         }
364 }
365
366 /**
367  * Starts a walk for memory operands if supported by the backend.
368  */
369 static INLINE void check_for_memory_operands(be_chordal_env_t *chordal_env) {
370         irg_walk_graph(chordal_env->irg, NULL, memory_operand_walker, chordal_env);
371 }
372
373 #ifdef WITH_LIBCORE
374 /**
375  * Initialize all timers.
376  */
377 static void be_init_timer(be_options_t *main_opts)
378 {
379         if (main_opts->timing == BE_TIME_ON) {
380                 ra_timer.t_prolog  = lc_timer_register("ra_prolog",   "regalloc prolog");
381                 ra_timer.t_epilog  = lc_timer_register("ra_epilog",   "regalloc epilog");
382                 ra_timer.t_live    = lc_timer_register("ra_liveness", "be liveness");
383                 ra_timer.t_spill   = lc_timer_register("ra_spill",    "spiller");
384                 ra_timer.t_spillslots = lc_timer_register("ra_spillslots",    "spillslots");
385                 ra_timer.t_color   = lc_timer_register("ra_color",    "graph coloring");
386                 ra_timer.t_ifg     = lc_timer_register("ra_ifg",      "interference graph");
387                 ra_timer.t_copymin = lc_timer_register("ra_copymin",  "copy minimization");
388                 ra_timer.t_ssa     = lc_timer_register("ra_ssadestr", "ssa destruction");
389                 ra_timer.t_verify  = lc_timer_register("ra_verify",   "graph verification");
390                 ra_timer.t_other   = lc_timer_register("ra_other",    "other time");
391
392                 LC_STOP_AND_RESET_TIMER(ra_timer.t_prolog);
393                 LC_STOP_AND_RESET_TIMER(ra_timer.t_epilog);
394                 LC_STOP_AND_RESET_TIMER(ra_timer.t_live);
395                 LC_STOP_AND_RESET_TIMER(ra_timer.t_spill);
396                 LC_STOP_AND_RESET_TIMER(ra_timer.t_spillslots);
397                 LC_STOP_AND_RESET_TIMER(ra_timer.t_color);
398                 LC_STOP_AND_RESET_TIMER(ra_timer.t_ifg);
399                 LC_STOP_AND_RESET_TIMER(ra_timer.t_copymin);
400                 LC_STOP_AND_RESET_TIMER(ra_timer.t_ssa);
401                 LC_STOP_AND_RESET_TIMER(ra_timer.t_verify);
402                 LC_STOP_AND_RESET_TIMER(ra_timer.t_other);
403         }
404 }
405
406 #define BE_TIMER_INIT(main_opts)        be_init_timer(main_opts)
407
408 #define BE_TIMER_PUSH(timer)                                                            \
409         if (main_opts->timing == BE_TIME_ON) {                                              \
410                 if (! lc_timer_push(timer)) {                                                   \
411                         if (options.vrfy_option == BE_CH_VRFY_ASSERT)                               \
412                                 assert(!"Timer already on stack, cannot be pushed twice.");             \
413                         else if (options.vrfy_option == BE_CH_VRFY_WARN)                            \
414                                 fprintf(stderr, "Timer %s already on stack, cannot be pushed twice.\n", \
415                                         lc_timer_get_name(timer));                                          \
416                 }                                                                               \
417         }
418 #define BE_TIMER_POP(timer)                                                                    \
419         if (main_opts->timing == BE_TIME_ON) {                                                     \
420                 lc_timer_t *tmp = lc_timer_pop();                                                      \
421                 if (options.vrfy_option == BE_CH_VRFY_ASSERT)                                          \
422                         assert(tmp == timer && "Attempt to pop wrong timer.");                             \
423                 else if (options.vrfy_option == BE_CH_VRFY_WARN && tmp != timer)                       \
424                         fprintf(stderr, "Attempt to pop wrong timer. %s is on stack, trying to pop %s.\n", \
425                                 lc_timer_get_name(tmp), lc_timer_get_name(timer));                             \
426                 timer = tmp;                                                                           \
427         }
428 #else
429
430 #define BE_TIMER_INIT(main_opts)
431 #define BE_TIMER_PUSH(timer)
432 #define BE_TIMER_POP(timer)
433
434 #endif /* WITH_LIBCORE */
435
436 /**
437  * Performs chordal register allocation for each register class on given irg.
438  *
439  * @param bi  Backend irg object
440  * @return Structure containing timer for the single phases or NULL if no timing requested.
441  */
442 static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi)
443 {
444         const be_main_env_t *main_env  = bi->main_env;
445         const arch_isa_t    *isa       = arch_env_get_isa(main_env->arch_env);
446         ir_graph            *irg       = bi->irg;
447         be_options_t        *main_opts = main_env->options;
448         int                  splitted  = 0;
449
450         int j, m;
451         be_chordal_env_t chordal_env;
452
453         BE_TIMER_INIT(main_opts);
454         BE_TIMER_PUSH(ra_timer.t_other);
455         BE_TIMER_PUSH(ra_timer.t_prolog);
456
457         compute_doms(irg);
458
459         chordal_env.opts      = &options;
460         chordal_env.irg       = irg;
461         chordal_env.birg      = bi;
462         chordal_env.dom_front = be_compute_dominance_frontiers(irg);
463         chordal_env.exec_freq = compute_execfreq(irg, be_loop_weight);
464         chordal_env.lv        = be_liveness(irg);
465         FIRM_DBG_REGISTER(chordal_env.dbg, "firm.be.chordal");
466
467         obstack_init(&chordal_env.obst);
468
469         BE_TIMER_POP(ra_timer.t_prolog);
470
471         /* Perform the following for each register class. */
472         for (j = 0, m = arch_isa_get_n_reg_class(isa); j < m; ++j) {
473                 chordal_env.cls           = arch_isa_get_reg_class(isa, j);
474                 chordal_env.border_heads  = pmap_create();
475                 chordal_env.ignore_colors = bitset_malloc(chordal_env.cls->n_regs);
476
477                 /* put all ignore registers into the ignore register set. */
478                 put_ignore_colors(&chordal_env);
479
480                 BE_TIMER_PUSH(ra_timer.t_live);
481                 be_liveness_recompute(chordal_env.lv);
482                 BE_TIMER_POP(ra_timer.t_live);
483                 dump(BE_CH_DUMP_LIVE, irg, chordal_env.cls, "-live", dump_ir_block_graph_sched);
484
485                 be_pre_spill_prepare_constr(&chordal_env);
486                 dump(BE_CH_DUMP_CONSTR, irg, chordal_env.cls, "-constr-pre", dump_ir_block_graph_sched);
487
488                 BE_TIMER_PUSH(ra_timer.t_spill);
489
490                 /* spilling */
491                 switch(options.spill_method) {
492                 case BE_CH_SPILL_MORGAN:
493                         be_spill_morgan(&chordal_env);
494                         break;
495                 case BE_CH_SPILL_BELADY:
496                         be_spill_belady(&chordal_env);
497                         break;
498 #ifdef WITH_ILP
499                 case BE_CH_SPILL_REMAT:
500                         be_spill_remat(&chordal_env);
501                         break;
502 #endif /* WITH_ILP */
503                 default:
504                         fprintf(stderr, "no valid spiller selected. falling back to belady\n");
505                         be_spill_belady(&chordal_env);
506                 }
507
508                 BE_TIMER_POP(ra_timer.t_spill);
509
510                 DBG((chordal_env.dbg, LEVEL_1, "spill costs for %+F in regclass %s: %g\n",
511                       irg,
512                       chordal_env.cls->name,
513                       get_irg_spill_cost(&chordal_env))
514                     );
515
516                 dump(BE_CH_DUMP_SPILL, irg, chordal_env.cls, "-spill", dump_ir_block_graph_sched);
517
518                 check_for_memory_operands(&chordal_env);
519
520                 be_abi_fix_stack_nodes(bi->abi, chordal_env.lv);
521
522                 BE_TIMER_PUSH(ra_timer.t_verify);
523
524                 /* verify schedule and register pressure */
525                 if (options.vrfy_option == BE_CH_VRFY_WARN) {
526                         be_verify_schedule(irg);
527                         be_verify_register_pressure(chordal_env.birg, chordal_env.cls, irg);
528                 }
529                 else if (options.vrfy_option == BE_CH_VRFY_ASSERT) {
530                         assert(be_verify_schedule(irg) && "Schedule verification failed");
531                         assert(be_verify_register_pressure(chordal_env.birg, chordal_env.cls, irg)
532                                 && "Register pressure verification failed");
533                 }
534                 BE_TIMER_POP(ra_timer.t_verify);
535
536                 if (be_elr_split && ! splitted) {
537                         extreme_liverange_splitting(&chordal_env);
538                         splitted = 1;
539                 }
540
541
542                 /* Color the graph. */
543                 BE_TIMER_PUSH(ra_timer.t_color);
544                 be_ra_chordal_color(&chordal_env);
545                 BE_TIMER_POP(ra_timer.t_color);
546
547                 dump(BE_CH_DUMP_CONSTR, irg, chordal_env.cls, "-color", dump_ir_block_graph_sched);
548
549                 /* Create the ifg with the selected flavor */
550                 BE_TIMER_PUSH(ra_timer.t_ifg);
551                 switch (options.ifg_flavor) {
552                         default:
553                                 fprintf(stderr, "no valid ifg flavour selected. falling back to std\n");
554                         case BE_CH_IFG_STD:
555                         case BE_CH_IFG_FAST:
556                                 chordal_env.ifg = be_ifg_std_new(&chordal_env);
557                                 break;
558                         case BE_CH_IFG_CLIQUE:
559                                 chordal_env.ifg = be_ifg_clique_new(&chordal_env);
560                                 break;
561                         case BE_CH_IFG_POINTER:
562                                 chordal_env.ifg = be_ifg_pointer_new(&chordal_env);
563                                 break;
564                         case BE_CH_IFG_LIST:
565                                 chordal_env.ifg = be_ifg_list_new(&chordal_env);
566                                 break;
567                         case BE_CH_IFG_CHECK:
568                                 check_ifg_implementations(&chordal_env);
569                                 /* Build the interference graph. */
570                                 chordal_env.ifg = be_ifg_std_new(&chordal_env);
571                                 break;
572                 }
573                 BE_TIMER_POP(ra_timer.t_ifg);
574
575                 BE_TIMER_PUSH(ra_timer.t_verify);
576                 if (options.vrfy_option != BE_CH_VRFY_OFF)
577                         be_ra_chordal_check(&chordal_env);
578
579                 BE_TIMER_POP(ra_timer.t_verify);
580
581                 /* copy minimization */
582                 BE_TIMER_PUSH(ra_timer.t_copymin);
583                 co_driver(&chordal_env);
584                 BE_TIMER_POP(ra_timer.t_copymin);
585                 dump(BE_CH_DUMP_COPYMIN, irg, chordal_env.cls, "-copymin", dump_ir_block_graph_sched);
586
587                 BE_TIMER_PUSH(ra_timer.t_verify);
588
589                 if (options.vrfy_option != BE_CH_VRFY_OFF)
590                         be_ra_chordal_check(&chordal_env);
591
592                 BE_TIMER_POP(ra_timer.t_verify);
593                 BE_TIMER_PUSH(ra_timer.t_ssa);
594
595                 /* ssa destruction */
596                 be_ssa_destruction(&chordal_env);
597
598                 BE_TIMER_POP(ra_timer.t_ssa);
599
600                 dump(BE_CH_DUMP_SSADESTR, irg, chordal_env.cls, "-ssadestr", dump_ir_block_graph_sched);
601
602                 BE_TIMER_PUSH(ra_timer.t_verify);
603                 if (options.vrfy_option != BE_CH_VRFY_OFF) {
604                         be_ssa_destruction_check(&chordal_env);
605                         be_ra_chordal_check(&chordal_env);
606                 }
607                 BE_TIMER_POP(ra_timer.t_verify);
608
609                 be_ifg_free(chordal_env.ifg);
610                 pmap_destroy(chordal_env.border_heads);
611                 bitset_free(chordal_env.ignore_colors);
612         }
613
614         BE_TIMER_PUSH(ra_timer.t_spillslots);
615
616         be_coalesce_spillslots(&chordal_env);
617         dump(BE_CH_DUMP_SPILLSLOTS, irg, NULL, "-spillslots", dump_ir_block_graph_sched);
618
619         BE_TIMER_POP(ra_timer.t_spillslots);
620
621         BE_TIMER_PUSH(ra_timer.t_verify);
622
623         /* verify spillslots */
624         if (options.vrfy_option == BE_CH_VRFY_WARN) {
625                 be_verify_spillslots(main_env->arch_env, irg);
626         }
627         else if (options.vrfy_option == BE_CH_VRFY_ASSERT) {
628                 assert(be_verify_spillslots(main_env->arch_env, irg) && "Spillslot verification failed");
629         }
630         BE_TIMER_POP(ra_timer.t_verify);
631
632         BE_TIMER_PUSH(ra_timer.t_epilog);
633
634         dump(BE_CH_DUMP_LOWER, irg, NULL, "-spilloff", dump_ir_block_graph_sched);
635
636         lower_nodes_after_ra(&chordal_env, options.lower_perm_opt & BE_CH_LOWER_PERM_COPY ? 1 : 0);
637         dump(BE_CH_DUMP_LOWER, irg, NULL, "-belower-after-ra", dump_ir_block_graph_sched);
638
639         obstack_free(&chordal_env.obst, NULL);
640         be_free_dominance_frontiers(chordal_env.dom_front);
641         be_liveness_free(chordal_env.lv);
642         free_execfreq(chordal_env.exec_freq);
643
644         BE_TIMER_POP(ra_timer.t_epilog);
645         BE_TIMER_POP(ra_timer.t_other);
646
647 #ifdef WITH_LIBCORE
648         return main_opts->timing == BE_TIME_ON ? &ra_timer : NULL;
649 #endif /* WITH_LIBCORE */
650         return NULL;
651 }
652
653 const be_ra_t be_ra_chordal_allocator = {
654 #ifdef WITH_LIBCORE
655         be_ra_chordal_register_options,
656         be_ra_chordal_main
657 #else
658         0
659 #endif
660 };