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