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