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