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