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