removed defines which are in irtools.h now
[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  * Performs chordal register allocation for each register class on given irg.
324  *
325  * @param bi  Backend irg object
326  * @return Structure containing timer for the single phases or NULL if no timing requested.
327  */
328 static be_ra_timer_t *be_ra_chordal_main(const be_irg_t *bi)
329 {
330         const be_main_env_t *main_env  = bi->main_env;
331         const arch_isa_t    *isa       = arch_env_get_isa(main_env->arch_env);
332         ir_graph            *irg       = bi->irg;
333         be_options_t        *main_opts = main_env->options;
334
335         int j, m;
336         be_chordal_env_t chordal_env;
337
338         if (main_opts->timing == BE_TIME_ON) {
339                 ra_timer.t_prolog  = lc_timer_register("ra_prolog",   "regalloc prolog");
340                 ra_timer.t_epilog  = lc_timer_register("ra_epilog",   "regalloc epilog");
341                 ra_timer.t_live    = lc_timer_register("ra_liveness", "be liveness");
342                 ra_timer.t_spill   = lc_timer_register("ra_spill",    "spiller");
343                 ra_timer.t_color   = lc_timer_register("ra_color",    "graph coloring");
344                 ra_timer.t_ifg     = lc_timer_register("ra_ifg",      "interference graph");
345                 ra_timer.t_copymin = lc_timer_register("ra_copymin",  "copy minimization");
346                 ra_timer.t_ssa     = lc_timer_register("ra_ssadestr", "ssa destruction");
347                 ra_timer.t_verify  = lc_timer_register("ra_verify",   "graph verification");
348                 ra_timer.t_other   = lc_timer_register("ra_other",    "other time");
349
350                 LC_STOP_AND_RESET_TIMER(ra_timer.t_prolog);
351                 LC_STOP_AND_RESET_TIMER(ra_timer.t_epilog);
352                 LC_STOP_AND_RESET_TIMER(ra_timer.t_live);
353                 LC_STOP_AND_RESET_TIMER(ra_timer.t_spill);
354                 LC_STOP_AND_RESET_TIMER(ra_timer.t_color);
355                 LC_STOP_AND_RESET_TIMER(ra_timer.t_ifg);
356                 LC_STOP_AND_RESET_TIMER(ra_timer.t_copymin);
357                 LC_STOP_AND_RESET_TIMER(ra_timer.t_ssa);
358                 LC_STOP_AND_RESET_TIMER(ra_timer.t_verify);
359                 LC_STOP_AND_RESET_TIMER(ra_timer.t_other);
360         }
361
362 #define BE_TIMER_PUSH(timer)                                                        \
363         if (main_opts->timing == BE_TIME_ON) {                                          \
364                 int res = lc_timer_push(timer);                                             \
365                 if (options.vrfy_option == BE_CH_VRFY_ASSERT)                               \
366                         assert(res && "Timer already on stack, cannot be pushed twice.");       \
367                 else if (options.vrfy_option == BE_CH_VRFY_WARN && ! res)                   \
368                         fprintf(stderr, "Timer %s already on stack, cannot be pushed twice.\n", \
369                                 lc_timer_get_name(timer));                                          \
370         }
371 #define BE_TIMER_POP(timer)                                                                    \
372         if (main_opts->timing == BE_TIME_ON) {                                                     \
373                 lc_timer_t *tmp = lc_timer_pop();                                                      \
374                 if (options.vrfy_option == BE_CH_VRFY_ASSERT)                                          \
375                         assert(tmp == timer && "Attempt to pop wrong timer.");                             \
376                 else if (options.vrfy_option == BE_CH_VRFY_WARN && tmp != timer)                       \
377                         fprintf(stderr, "Attempt to pop wrong timer. %s is on stack, trying to pop %s.\n", \
378                                 lc_timer_get_name(tmp), lc_timer_get_name(timer));                             \
379                 timer = tmp;                                                                           \
380         }
381
382         BE_TIMER_PUSH(ra_timer.t_other);
383         BE_TIMER_PUSH(ra_timer.t_prolog);
384
385         compute_doms(irg);
386
387         chordal_env.opts      = &options;
388         chordal_env.irg       = irg;
389         chordal_env.birg      = bi;
390         chordal_env.dom_front = be_compute_dominance_frontiers(irg);
391         chordal_env.exec_freq = compute_execfreq(irg, be_loop_weight);
392         FIRM_DBG_REGISTER(chordal_env.dbg, "firm.be.chordal");
393
394         obstack_init(&chordal_env.obst);
395
396         BE_TIMER_POP(ra_timer.t_prolog);
397
398         /* Perform the following for each register class. */
399         for (j = 0, m = arch_isa_get_n_reg_class(isa); j < m; ++j) {
400                 FILE *f;
401                 copy_opt_t *co = NULL;
402
403                 chordal_env.cls           = arch_isa_get_reg_class(isa, j);
404                 chordal_env.border_heads  = pmap_create();
405                 chordal_env.ignore_colors = bitset_malloc(chordal_env.cls->n_regs);
406
407                 BE_TIMER_PUSH(ra_timer.t_live);
408
409                 /* put all ignore registers into the ignore register set. */
410                 put_ignore_colors(&chordal_env);
411
412                 be_liveness(irg);
413
414                 BE_TIMER_POP(ra_timer.t_live);
415
416                 dump(BE_CH_DUMP_LIVE, irg, chordal_env.cls, "-live", dump_ir_block_graph_sched);
417
418                 BE_TIMER_PUSH(ra_timer.t_spill);
419
420                 /* spilling */
421                 switch(options.spill_method) {
422                 case BE_CH_SPILL_MORGAN:
423                         be_spill_morgan(&chordal_env);
424                         break;
425                 case BE_CH_SPILL_BELADY:
426                         be_spill_belady(&chordal_env);
427                         break;
428 #ifdef WITH_ILP
429                 case BE_CH_SPILL_REMAT:
430                         be_spill_remat(&chordal_env);
431                         break;
432 #endif /* WITH_ILP */
433                 default:
434                         fprintf(stderr, "no valid spiller selected. falling back to belady\n");
435                         be_spill_belady(&chordal_env);
436                 }
437
438                 BE_TIMER_POP(ra_timer.t_spill);
439
440                 dump(BE_CH_DUMP_SPILL, irg, chordal_env.cls, "-spill", dump_ir_block_graph_sched);
441                 be_abi_fix_stack_nodes(bi->abi);
442
443                 BE_TIMER_PUSH(ra_timer.t_verify);
444
445                 /* verify schedule and register pressure */
446                 if (options.vrfy_option == BE_CH_VRFY_WARN) {
447                         be_verify_schedule(irg);
448                         be_verify_register_pressure(chordal_env.birg->main_env->arch_env, chordal_env.cls, irg);
449                 }
450                 else if (options.vrfy_option == BE_CH_VRFY_ASSERT) {
451                         assert(be_verify_schedule(irg) && "Schedule verification failed");
452                         assert(be_verify_register_pressure(chordal_env.birg->main_env->arch_env, chordal_env.cls, irg)
453                                 && "Register pressure verification failed");
454                 }
455
456                 BE_TIMER_POP(ra_timer.t_verify);
457                 BE_TIMER_PUSH(ra_timer.t_live);
458                 be_liveness(irg);
459                 BE_TIMER_POP(ra_timer.t_live);
460                 BE_TIMER_PUSH(ra_timer.t_color);
461
462                 /* Color the graph. */
463                 be_ra_chordal_color(&chordal_env);
464
465                 BE_TIMER_POP(ra_timer.t_color);
466
467                 dump(BE_CH_DUMP_CONSTR, irg, chordal_env.cls, "-color", dump_ir_block_graph_sched);
468
469                 BE_TIMER_PUSH(ra_timer.t_ifg);
470
471                 /* Create the ifg with the selected flavor */
472                 switch (options.ifg_flavor) {
473                         default:
474                                 fprintf(stderr, "no valid ifg flavour selected. falling back to std\n");
475                         case BE_CH_IFG_STD:
476                         case BE_CH_IFG_FAST:
477                                 chordal_env.ifg = be_ifg_std_new(&chordal_env);
478                                 break;
479                         case BE_CH_IFG_CLIQUE:
480                                 chordal_env.ifg = be_ifg_clique_new(&chordal_env);
481                                 break;
482                         case BE_CH_IFG_POINTER:
483                                 chordal_env.ifg = be_ifg_pointer_new(&chordal_env);
484                                 break;
485                         case BE_CH_IFG_LIST:
486                                 chordal_env.ifg = be_ifg_list_new(&chordal_env);
487                                 break;
488                         case BE_CH_IFG_CHECK:
489                                 check_ifg_implementations(&chordal_env);
490                                 /* Build the interference graph. */
491                                 chordal_env.ifg = be_ifg_std_new(&chordal_env);
492                                 break;
493                 }
494
495
496 #if 0
497                 {
498                         be_ifg_t *std = be_ifg_std_new(&chordal_env);
499                         f = be_chordal_open(&chordal_env, "std", "csv");
500                         be_ifg_check_sorted_to_file(std, f);
501                         be_ifg_free(std);
502                         fclose(f);
503                 }
504
505                 f = be_chordal_open(&chordal_env, "clique", "csv");
506                 be_ifg_check_sorted_to_file(chordal_env.ifg, f);
507                 fclose(f);
508 #endif
509                 BE_TIMER_POP(ra_timer.t_ifg);
510
511                 BE_TIMER_PUSH(ra_timer.t_verify);
512
513                 if (options.vrfy_option != BE_CH_VRFY_OFF)
514                         be_ra_chordal_check(&chordal_env);
515
516 //              be_ifg_check_sorted(chordal_env.ifg);
517                 BE_TIMER_POP(ra_timer.t_verify);
518                 BE_TIMER_PUSH(ra_timer.t_copymin);
519
520                 /* copy minimization */
521                 if (options.copymin_method != BE_CH_COPYMIN_NONE && options.copymin_method != BE_CH_COPYMIN_STAT) {
522                         FILE *f;
523                         co = new_copy_opt(&chordal_env, co_get_costs_loop_depth);
524                         co_build_ou_structure(co);
525                         co_build_graph_structure(co);
526                         if(be_copymin_stats) {
527                                 ir_printf("%40F %20s\n", current_ir_graph, chordal_env.cls->name);
528                                 printf("max copy costs:         %d\n", co_get_max_copy_costs(co));
529                                 printf("init copy costs:        %d\n", co_get_copy_costs(co));
530                                 printf("inevit copy costs:      %d\n", co_get_inevit_copy_costs(co));
531                                 printf("copy costs lower bound: %d\n", co_get_lower_bound(co));
532                         }
533
534 #if 0
535                         f = be_chordal_open(&chordal_env, "appel-", "apl");
536                         co_dump_appel_graph(co, f);
537                         fclose(f);
538                         f = be_chordal_open(&chordal_env, "appel-clique-", "p");
539                         co_dump_appel_graph_cliques(co, f);
540                         fclose(f);
541 #endif
542                 }
543
544                 switch(options.copymin_method) {
545                         case BE_CH_COPYMIN_HEUR1:
546                                 co_solve_heuristic(co);
547                                 break;
548                         case BE_CH_COPYMIN_HEUR2:
549                                 co_solve_heuristic_new(co);
550                                 break;
551                         case BE_CH_COPYMIN_PARK_MOON:
552                                 co_solve_park_moon(co);
553                                 break;
554                         case BE_CH_COPYMIN_STAT:
555                                 co_compare_solvers(&chordal_env);
556                                 break;
557 #ifdef WITH_ILP
558                         case BE_CH_COPYMIN_ILP1:
559                                 printf("FIXME: %s:%d ILP1 not yet implemented!\n", __FILE__, __LINE__);
560                                 co_solve_ilp1(co, 60.0);
561                                 break;
562                         case BE_CH_COPYMIN_ILP2:
563                                 co_solve_ilp2(co, 60.0);
564                                 break;
565 #endif /* WITH_ILP */
566                         case BE_CH_COPYMIN_NONE:
567                         default:
568                                 break;
569                 }
570
571                 if (co) {
572                         if(be_copymin_stats) {
573                                 printf("final copy costs      : %d\n", co_get_copy_costs(co));
574                         }
575                         co_free_graph_structure(co);
576                         co_free_ou_structure(co);
577                         free_copy_opt(co);
578                 }
579
580                 BE_TIMER_POP(ra_timer.t_copymin);
581
582                 dump(BE_CH_DUMP_COPYMIN, irg, chordal_env.cls, "-copymin", dump_ir_block_graph_sched);
583
584                 BE_TIMER_PUSH(ra_timer.t_verify);
585
586                 if (options.vrfy_option != BE_CH_VRFY_OFF)
587                         be_ra_chordal_check(&chordal_env);
588
589                 BE_TIMER_POP(ra_timer.t_verify);
590                 BE_TIMER_PUSH(ra_timer.t_ssa);
591
592                 /* ssa destruction */
593                 be_ssa_destruction(&chordal_env);
594
595                 BE_TIMER_POP(ra_timer.t_ssa);
596
597                 dump(BE_CH_DUMP_SSADESTR, irg, chordal_env.cls, "-ssadestr", dump_ir_block_graph_sched);
598
599                 BE_TIMER_PUSH(ra_timer.t_verify);
600                 if (options.vrfy_option != BE_CH_VRFY_OFF) {
601                         be_ssa_destruction_check(&chordal_env);
602                         be_ra_chordal_check(&chordal_env);
603                 }
604                 BE_TIMER_POP(ra_timer.t_verify);
605
606                 if (options.copymin_method == BE_CH_COPYMIN_STAT)
607                         copystat_dump(irg);
608
609                 be_ifg_free(chordal_env.ifg);
610                 pmap_destroy(chordal_env.border_heads);
611                 bitset_free(chordal_env.ignore_colors);
612         }
613
614         BE_TIMER_PUSH(ra_timer.t_epilog);
615
616         be_compute_spill_offsets(&chordal_env);
617
618         dump(BE_CH_DUMP_LOWER, irg, NULL, "-spilloff", dump_ir_block_graph_sched);
619
620         lower_nodes_after_ra(&chordal_env, options.lower_perm_opt & BE_CH_LOWER_PERM_COPY ? 1 : 0);
621         dump(BE_CH_DUMP_LOWER, irg, NULL, "-belower-after-ra", dump_ir_block_graph_sched);
622
623         obstack_free(&chordal_env.obst, NULL);
624         be_free_dominance_frontiers(chordal_env.dom_front);
625         free_execfreq(chordal_env.exec_freq);
626
627         BE_TIMER_POP(ra_timer.t_epilog);
628         BE_TIMER_POP(ra_timer.t_other);
629
630 #undef BE_TIMER_PUSH
631 #undef BE_TIMER_POP
632
633         return main_opts->timing == BE_TIME_ON ? &ra_timer : NULL;
634 }
635
636 const be_ra_t be_ra_chordal_allocator = {
637 #ifdef WITH_LIBCORE
638         be_ra_chordal_register_options,
639 #endif
640         be_ra_chordal_main
641 };