2 * @file bechordal_main.c
4 * @author Sebastian Hack
7 * Copyright (C) 2005-2006 Universitaet Karlsruhe
8 * Released under the GPL
10 * Driver for the chordal register allocator.
23 #include "firm_config.h"
26 #include <libcore/lc_opts.h>
27 #include <libcore/lc_opts_enum.h>
28 #include <libcore/lc_timing.h>
29 #endif /* WITH_LIBCORE */
33 #include "irgraph_t.h"
34 #include "irprintf_t.h"
47 #include "bechordal_t.h"
49 #include "bejavacoal.h"
52 #include "besched_t.h"
56 #include "beifg_impl.h"
58 #include "bestatevent.h"
61 #include "bespillbelady.h"
62 #include "bespillmorgan.h"
63 #include "bespillslots.h"
64 #include "bespilloptions.h"
68 #include "bespillremat.h"
71 #include "bejavacoal.h"
72 #include "becopystat.h"
73 #include "becopyopt.h"
74 #include "bessadestr.h"
78 static be_ra_chordal_opts_t options = {
82 BE_CH_LOWER_PERM_SWAP,
86 /** Enable extreme live range splitting. */
87 static int be_elr_split = 0;
89 /** Assumed loop iteration count for execution frequency estimation. */
90 static int be_loop_weight = 9;
92 typedef struct _post_spill_env_t {
93 be_chordal_env_t cenv;
94 double pre_spill_cost;
98 static be_ra_timer_t ra_timer = {
112 static const lc_opt_enum_int_items_t spill_items[] = {
113 { "morgan", BE_CH_SPILL_MORGAN },
114 { "belady", BE_CH_SPILL_BELADY },
116 { "remat", BE_CH_SPILL_REMAT },
117 #endif /* WITH_ILP */
121 static const lc_opt_enum_int_items_t ifg_flavor_items[] = {
122 { "std", BE_CH_IFG_STD },
123 { "fast", BE_CH_IFG_FAST },
124 { "clique", BE_CH_IFG_CLIQUE },
125 { "pointer", BE_CH_IFG_POINTER },
126 { "list", BE_CH_IFG_LIST },
127 { "check", BE_CH_IFG_CHECK },
131 static const lc_opt_enum_int_items_t lower_perm_items[] = {
132 { "copy", BE_CH_LOWER_PERM_COPY },
133 { "swap", BE_CH_LOWER_PERM_SWAP },
137 static const lc_opt_enum_int_items_t lower_perm_stat_items[] = {
141 static const lc_opt_enum_int_items_t dump_items[] = {
142 { "spill", BE_CH_DUMP_SPILL },
143 { "live", BE_CH_DUMP_LIVE },
144 { "color", BE_CH_DUMP_COLOR },
145 { "copymin", BE_CH_DUMP_COPYMIN },
146 { "ssadestr", BE_CH_DUMP_SSADESTR },
147 { "tree", BE_CH_DUMP_TREE_INTV },
148 { "constr", BE_CH_DUMP_CONSTR },
149 { "lower", BE_CH_DUMP_LOWER },
150 { "spillslots", BE_CH_DUMP_SPILLSLOTS },
151 { "appel", BE_CH_DUMP_APPEL },
152 { "all", BE_CH_DUMP_ALL },
156 static const lc_opt_enum_int_items_t be_ch_vrfy_items[] = {
157 { "off", BE_CH_VRFY_OFF },
158 { "warn", BE_CH_VRFY_WARN },
159 { "assert", BE_CH_VRFY_ASSERT },
163 static lc_opt_enum_int_var_t spill_var = {
164 &options.spill_method, spill_items
167 static lc_opt_enum_int_var_t ifg_flavor_var = {
168 &options.ifg_flavor, ifg_flavor_items
171 static lc_opt_enum_int_var_t lower_perm_var = {
172 &options.lower_perm_opt, lower_perm_items
175 static lc_opt_enum_int_var_t dump_var = {
176 &options.dump_flags, dump_items
179 static lc_opt_enum_int_var_t be_ch_vrfy_var = {
180 &options.vrfy_option, be_ch_vrfy_items
183 static const lc_opt_table_entry_t be_chordal_options[] = {
184 LC_OPT_ENT_ENUM_INT ("spill", "spill method", &spill_var),
185 LC_OPT_ENT_ENUM_PTR ("ifg", "interference graph flavour", &ifg_flavor_var),
186 LC_OPT_ENT_ENUM_PTR ("perm", "perm lowering options", &lower_perm_var),
187 LC_OPT_ENT_ENUM_MASK("dump", "select dump phases", &dump_var),
188 LC_OPT_ENT_ENUM_PTR ("vrfy", "verify options", &be_ch_vrfy_var),
189 LC_OPT_ENT_BOOL ("elrsplit", "enable extreme live range splitting", &be_elr_split),
190 LC_OPT_ENT_INT ("loop_weight", "assumed amount of loop iterations for guessing the execution frequency", &be_loop_weight),
194 extern void be_spill_remat_register_options(lc_opt_entry_t *ent);
196 void be_ra_chordal_check(be_chordal_env_t *chordal_env) {
197 const arch_env_t *arch_env = chordal_env->birg->main_env->arch_env;
200 ir_node **nodes, *n1, *n2;
202 be_lv_t *lv = chordal_env->birg->lv;
203 DEBUG_ONLY(firm_dbg_module_t *dbg = chordal_env->dbg;)
205 /* Collect all irns */
207 pmap_foreach(chordal_env->border_heads, pme) {
209 struct list_head *head = pme->value;
210 list_for_each_entry(border_t, curr, head, list)
211 if (curr->is_def && curr->is_real)
212 if (arch_get_irn_reg_class(arch_env, curr->irn, -1) == chordal_env->cls)
213 obstack_ptr_grow(&ob, curr->irn);
215 obstack_ptr_grow(&ob, NULL);
216 nodes = (ir_node **) obstack_finish(&ob);
219 for (i = 0, n1 = nodes[i]; n1; n1 = nodes[++i]) {
220 const arch_register_t *n1_reg, *n2_reg;
222 n1_reg = arch_get_irn_register(arch_env, n1);
223 if (!arch_reg_is_allocatable(arch_env, n1, -1, n1_reg)) {
224 DBG((dbg, 0, "Register %s assigned to %+F is not allowed\n", n1_reg->name, n1));
225 assert(0 && "Register constraint does not hold");
227 for (o = i+1, n2 = nodes[o]; n2; n2 = nodes[++o]) {
228 n2_reg = arch_get_irn_register(arch_env, n2);
229 if (values_interfere(lv, n1, n2) && n1_reg == n2_reg) {
230 DBG((dbg, 0, "Values %+F and %+F interfere and have the same register assigned: %s\n", n1, n2, n1_reg->name));
231 assert(0 && "Interfering values have the same color!");
235 obstack_free(&ob, NULL);
238 int nodes_interfere(const be_chordal_env_t *env, const ir_node *a, const ir_node *b)
241 return be_ifg_connected(env->ifg, a, b);
243 return values_interfere(env->birg->lv, a, b);
246 static void be_ra_chordal_register_options(lc_opt_entry_t *grp)
248 static int run_once = 0;
249 lc_opt_entry_t *chordal_grp;
253 chordal_grp = lc_opt_get_grp(grp, "chordal");
255 lc_opt_add_table(chordal_grp, be_chordal_options);
257 co_register_options(chordal_grp);
259 be_java_coal_register_options(chordal_grp);
262 be_spill_remat_register_options(chordal_grp);
264 be_spill_register_options(chordal_grp);
267 #endif /* WITH_LIBCORE */
269 static void dump(unsigned mask, ir_graph *irg,
270 const arch_register_class_t *cls,
272 void (*dump_func)(ir_graph *, const char *))
274 if((options.dump_flags & mask) == mask) {
277 snprintf(buf, sizeof(buf), "-%s%s", cls->name, suffix);
278 be_dump(irg, buf, dump_func);
281 be_dump(irg, suffix, dump_func);
285 static void put_ignore_colors(be_chordal_env_t *chordal_env)
287 int n_colors = chordal_env->cls->n_regs;
290 bitset_clear_all(chordal_env->ignore_colors);
291 be_abi_put_ignore_regs(chordal_env->birg->abi, chordal_env->cls, chordal_env->ignore_colors);
292 for(i = 0; i < n_colors; ++i)
293 if(arch_register_type_is(&chordal_env->cls->regs[i], ignore))
294 bitset_set(chordal_env->ignore_colors, i);
297 FILE *be_chordal_open(const be_chordal_env_t *env, const char *prefix, const char *suffix)
301 ir_snprintf(buf, sizeof(buf), "%s%F_%s%s", prefix, env->irg, env->cls->name, suffix);
302 return fopen(buf, "wt");
305 void check_ifg_implementations(be_chordal_env_t *chordal_env)
309 f = be_chordal_open(chordal_env, "std", ".log");
310 chordal_env->ifg = be_ifg_std_new(chordal_env);
311 be_ifg_check_sorted_to_file(chordal_env->ifg, f);
314 f = be_chordal_open(chordal_env, "list", ".log");
315 be_ifg_free(chordal_env->ifg);
316 chordal_env->ifg = be_ifg_list_new(chordal_env);
317 be_ifg_check_sorted_to_file(chordal_env->ifg, f);
320 f = be_chordal_open(chordal_env, "clique", ".log");
321 be_ifg_free(chordal_env->ifg);
322 chordal_env->ifg = be_ifg_clique_new(chordal_env);
323 be_ifg_check_sorted_to_file(chordal_env->ifg, f);
326 f = be_chordal_open(chordal_env, "pointer", ".log");
327 be_ifg_free(chordal_env->ifg);
328 chordal_env->ifg = be_ifg_pointer_new(chordal_env);
329 be_ifg_check_sorted_to_file(chordal_env->ifg, f);
332 chordal_env->ifg = NULL;
336 * Checks for every reload if it's user can perform the load on itself.
338 static void memory_operand_walker(ir_node *irn, void *env) {
339 be_chordal_env_t *cenv = env;
340 const arch_env_t *aenv = cenv->birg->main_env->arch_env;
341 const ir_edge_t *edge, *ne;
345 if (! be_is_Reload(irn))
348 /* always use addressmode, it's good for x86 */
350 /* only use memory operands, if the reload is only used by 1 node */
351 if(get_irn_n_edges(irn) > 1)
355 spill = be_get_Reload_mem(irn);
356 block = get_nodes_block(irn);
358 foreach_out_edge_safe(irn, edge, ne) {
359 ir_node *src = get_edge_src_irn(edge);
360 int pos = get_edge_src_pos(edge);
362 assert(src && "outedges broken!");
364 if (get_nodes_block(src) == block && arch_possible_memory_operand(aenv, src, pos)) {
365 DBG((cenv->dbg, LEVEL_3, "performing memory operand %+F at %+F\n", irn, src));
366 //arch_perform_memory_operand(aenv, src, spill, pos);
370 /* kill the Reload */
371 if (get_irn_n_edges(irn) == 0) {
373 set_irn_n(irn, 0, new_Bad());
374 set_irn_n(irn, 1, new_Bad());
379 * Starts a walk for memory operands if supported by the backend.
381 static INLINE void check_for_memory_operands(be_chordal_env_t *chordal_env) {
382 irg_walk_graph(chordal_env->irg, NULL, memory_operand_walker, chordal_env);
386 * Sorry for doing stats again...
388 typedef struct _node_stat_t {
389 unsigned int n_phis; /**< Phis of the current register class. */
390 unsigned int n_mem_phis; /**< Memory Phis (Phis with spill operands). */
391 unsigned int n_copies; /**< Copies */
392 unsigned int n_perms; /**< Perms */
393 unsigned int n_spills; /**< Spill nodes */
394 unsigned int n_reloads; /**< Reloads */
397 struct node_stat_walker {
399 const be_chordal_env_t *cenv;
403 static void node_stat_walker(ir_node *irn, void *data)
405 struct node_stat_walker *env = data;
406 const arch_env_t *aenv = env->cenv->birg->main_env->arch_env;
408 if(arch_irn_consider_in_reg_alloc(aenv, env->cenv->cls, irn)) {
410 /* if the node is a normal phi */
414 else if(arch_irn_classify(aenv, irn) & arch_irn_class_spill)
415 ++env->stat->n_spills;
417 else if(arch_irn_classify(aenv, irn) & arch_irn_class_reload)
418 ++env->stat->n_reloads;
420 else if(arch_irn_classify(aenv, irn) & arch_irn_class_copy)
421 ++env->stat->n_copies;
423 else if(arch_irn_classify(aenv, irn) & arch_irn_class_perm)
424 ++env->stat->n_perms;
427 /* a mem phi is a PhiM with a mem phi operand or a Spill operand */
428 else if(is_Phi(irn) && get_irn_mode(irn) == mode_M) {
431 for(i = get_irn_arity(irn) - 1; i >= 0; --i) {
432 ir_node *op = get_irn_n(irn, i);
434 if((is_Phi(op) && bitset_contains_irn(env->mem_phis, op)) || (arch_irn_classify(aenv, op) & arch_irn_class_spill)) {
435 bitset_add_irn(env->mem_phis, irn);
436 env->stat->n_mem_phis++;
443 static void node_stats(const be_chordal_env_t *cenv, node_stat_t *stat)
445 struct node_stat_walker env;
447 memset(stat, 0, sizeof(stat[0]));
449 env.mem_phis = bitset_irg_malloc(cenv->irg);
451 irg_walk_graph(cenv->irg, NULL, node_stat_walker, &env);
452 bitset_free(env.mem_phis);
455 static void insn_count_walker(ir_node *irn, void *data)
459 switch(get_irn_opcode(irn)) {
470 static unsigned int count_insns(ir_graph *irg)
473 irg_walk_graph(irg, insn_count_walker, NULL, &cnt);
479 * Initialize all timers.
481 static void be_init_timer(be_options_t *main_opts)
483 if (main_opts->timing == BE_TIME_ON) {
484 ra_timer.t_prolog = lc_timer_register("ra_prolog", "regalloc prolog");
485 ra_timer.t_epilog = lc_timer_register("ra_epilog", "regalloc epilog");
486 ra_timer.t_live = lc_timer_register("ra_liveness", "be liveness");
487 ra_timer.t_spill = lc_timer_register("ra_spill", "spiller");
488 ra_timer.t_spillslots = lc_timer_register("ra_spillslots", "spillslots");
489 ra_timer.t_color = lc_timer_register("ra_color", "graph coloring");
490 ra_timer.t_ifg = lc_timer_register("ra_ifg", "interference graph");
491 ra_timer.t_copymin = lc_timer_register("ra_copymin", "copy minimization");
492 ra_timer.t_ssa = lc_timer_register("ra_ssadestr", "ssa destruction");
493 ra_timer.t_verify = lc_timer_register("ra_verify", "graph verification");
494 ra_timer.t_other = lc_timer_register("ra_other", "other time");
496 LC_STOP_AND_RESET_TIMER(ra_timer.t_prolog);
497 LC_STOP_AND_RESET_TIMER(ra_timer.t_epilog);
498 LC_STOP_AND_RESET_TIMER(ra_timer.t_live);
499 LC_STOP_AND_RESET_TIMER(ra_timer.t_spill);
500 LC_STOP_AND_RESET_TIMER(ra_timer.t_spillslots);
501 LC_STOP_AND_RESET_TIMER(ra_timer.t_color);
502 LC_STOP_AND_RESET_TIMER(ra_timer.t_ifg);
503 LC_STOP_AND_RESET_TIMER(ra_timer.t_copymin);
504 LC_STOP_AND_RESET_TIMER(ra_timer.t_ssa);
505 LC_STOP_AND_RESET_TIMER(ra_timer.t_verify);
506 LC_STOP_AND_RESET_TIMER(ra_timer.t_other);
510 #define BE_TIMER_INIT(main_opts) be_init_timer(main_opts)
512 #define BE_TIMER_PUSH(timer) \
513 if (main_opts->timing == BE_TIME_ON) { \
514 if (! lc_timer_push(timer)) { \
515 if (options.vrfy_option == BE_CH_VRFY_ASSERT) \
516 assert(!"Timer already on stack, cannot be pushed twice."); \
517 else if (options.vrfy_option == BE_CH_VRFY_WARN) \
518 fprintf(stderr, "Timer %s already on stack, cannot be pushed twice.\n", \
519 lc_timer_get_name(timer)); \
522 #define BE_TIMER_POP(timer) \
523 if (main_opts->timing == BE_TIME_ON) { \
524 lc_timer_t *tmp = lc_timer_pop(); \
525 if (options.vrfy_option == BE_CH_VRFY_ASSERT) \
526 assert(tmp == timer && "Attempt to pop wrong timer."); \
527 else if (options.vrfy_option == BE_CH_VRFY_WARN && tmp != timer) \
528 fprintf(stderr, "Attempt to pop wrong timer. %s is on stack, trying to pop %s.\n", \
529 lc_timer_get_name(tmp), lc_timer_get_name(timer)); \
534 #define BE_TIMER_INIT(main_opts)
535 #define BE_TIMER_PUSH(timer)
536 #define BE_TIMER_POP(timer)
538 #endif /* WITH_LIBCORE */
541 * Perform things which need to be done per register class before spilling.
543 static void pre_spill(const arch_isa_t *isa, int cls_idx, post_spill_env_t *pse) {
544 be_chordal_env_t *chordal_env = &pse->cenv;
545 node_stat_t node_stat;
547 chordal_env->cls = arch_isa_get_reg_class(isa, cls_idx);
548 chordal_env->border_heads = pmap_create();
549 chordal_env->ignore_colors = bitset_malloc(chordal_env->cls->n_regs);
551 #ifdef FIRM_STATISTICS
552 if (be_stat_ev_is_active()) {
553 be_stat_tags[STAT_TAG_CLS] = chordal_env->cls->name;
554 be_stat_ev_push(be_stat_tags, STAT_TAG_LAST, be_stat_file);
556 /* perform some node statistics. */
557 node_stats(chordal_env, &node_stat);
558 be_stat_ev("phis_before_spill", node_stat.n_phis);
560 #endif /* FIRM_STATISTICS */
562 /* put all ignore registers into the ignore register set. */
563 put_ignore_colors(chordal_env);
565 be_pre_spill_prepare_constr(chordal_env);
566 dump(BE_CH_DUMP_CONSTR, chordal_env->irg, chordal_env->cls, "-constr-pre", dump_ir_block_graph_sched);
568 #ifdef FIRM_STATISTICS
569 if (be_stat_ev_is_active()) {
570 pse->pre_spill_cost = be_estimate_irg_costs(chordal_env->irg,
571 chordal_env->birg->main_env->arch_env, chordal_env->birg->exec_freq);
573 #endif /* FIRM_STATISTICS */
577 * Perform things which need to be done per register class after spilling.
579 static void post_spill(post_spill_env_t *pse) {
580 be_chordal_env_t *chordal_env = &pse->cenv;
581 ir_graph *irg = chordal_env->irg;
582 be_irg_t *birg = chordal_env->birg;
583 const be_main_env_t *main_env = birg->main_env;
584 be_options_t *main_opts = main_env->options;
585 static int splitted = 0;
586 node_stat_t node_stat;
588 #ifdef FIRM_STATISTICS
589 if (be_stat_ev_is_active()) {
590 double spillcosts = be_estimate_irg_costs(irg, main_env->arch_env, birg->exec_freq) - pse->pre_spill_cost;
592 be_stat_ev_l("spillcosts", (long) spillcosts);
594 node_stats(chordal_env, &node_stat);
595 be_stat_ev("phis_after_spill", node_stat.n_phis);
596 be_stat_ev("mem_phis", node_stat.n_mem_phis);
597 be_stat_ev("reloads", node_stat.n_reloads);
598 be_stat_ev("spills", node_stat.n_spills);
600 #endif /* FIRM_STATISTICS */
602 check_for_memory_operands(chordal_env);
604 be_abi_fix_stack_nodes(birg->abi, birg->lv);
606 BE_TIMER_PUSH(ra_timer.t_verify);
608 /* verify schedule and register pressure */
609 if (chordal_env->opts->vrfy_option == BE_CH_VRFY_WARN) {
610 be_verify_schedule(irg);
611 be_verify_register_pressure(chordal_env->birg, chordal_env->cls, irg);
613 else if (chordal_env->opts->vrfy_option == BE_CH_VRFY_ASSERT) {
614 assert(be_verify_schedule(irg) && "Schedule verification failed");
615 assert(be_verify_register_pressure(chordal_env->birg, chordal_env->cls, irg)
616 && "Register pressure verification failed");
618 BE_TIMER_POP(ra_timer.t_verify);
620 if (be_elr_split && ! splitted) {
621 extreme_liverange_splitting(chordal_env);
625 /* Color the graph. */
626 BE_TIMER_PUSH(ra_timer.t_color);
627 be_ra_chordal_color(chordal_env);
628 BE_TIMER_POP(ra_timer.t_color);
630 dump(BE_CH_DUMP_CONSTR, irg, chordal_env->cls, "-color", dump_ir_block_graph_sched);
632 /* Create the ifg with the selected flavor */
633 BE_TIMER_PUSH(ra_timer.t_ifg);
634 switch (chordal_env->opts->ifg_flavor) {
636 fprintf(stderr, "no valid ifg flavour selected. falling back to std\n");
639 chordal_env->ifg = be_ifg_std_new(chordal_env);
641 case BE_CH_IFG_CLIQUE:
642 chordal_env->ifg = be_ifg_clique_new(chordal_env);
644 case BE_CH_IFG_POINTER:
645 chordal_env->ifg = be_ifg_pointer_new(chordal_env);
648 chordal_env->ifg = be_ifg_list_new(chordal_env);
650 case BE_CH_IFG_CHECK:
651 check_ifg_implementations(chordal_env);
652 /* Build the interference graph. */
653 chordal_env->ifg = be_ifg_std_new(chordal_env);
656 BE_TIMER_POP(ra_timer.t_ifg);
658 #ifdef FIRM_STATISTICS
659 if (be_stat_ev_is_active()) {
661 be_ifg_stat(chordal_env, &stat);
662 be_stat_ev("ifg_nodes", stat.n_nodes);
663 be_stat_ev("ifg_edges", stat.n_edges);
664 be_stat_ev("ifg_comps", stat.n_comps);
666 node_stats(chordal_env, &node_stat);
667 be_stat_ev("perms_before_coal", node_stat.n_perms);
668 be_stat_ev("copies_before_coal", node_stat.n_copies);
670 #endif /* FIRM_STATISTICS */
672 /* copy minimization */
673 BE_TIMER_PUSH(ra_timer.t_copymin);
674 co_driver(chordal_env);
675 BE_TIMER_POP(ra_timer.t_copymin);
677 dump(BE_CH_DUMP_COPYMIN, irg, chordal_env->cls, "-copymin", dump_ir_block_graph_sched);
679 BE_TIMER_PUSH(ra_timer.t_ssa);
681 /* ssa destruction */
682 be_ssa_destruction(chordal_env);
684 BE_TIMER_POP(ra_timer.t_ssa);
686 dump(BE_CH_DUMP_SSADESTR, irg, chordal_env->cls, "-ssadestr", dump_ir_block_graph_sched);
688 BE_TIMER_PUSH(ra_timer.t_verify);
689 if (chordal_env->opts->vrfy_option != BE_CH_VRFY_OFF) {
690 be_ssa_destruction_check(chordal_env);
692 BE_TIMER_POP(ra_timer.t_verify);
694 be_ifg_free(chordal_env->ifg);
695 pmap_destroy(chordal_env->border_heads);
696 bitset_free(chordal_env->ignore_colors);
698 #ifdef FIRM_STATISTICS
699 if (be_stat_ev_is_active()) {
700 node_stats(chordal_env, &node_stat);
701 be_stat_ev("perms_after_coal", node_stat.n_perms);
702 be_stat_ev("copies_after_coal", node_stat.n_copies);
705 #endif /* FIRM_STATISTICS */
709 * Performs chordal register allocation for each register class on given irg.
711 * @param birg Backend irg object
712 * @return Structure containing timer for the single phases or NULL if no timing requested.
714 static be_ra_timer_t *be_ra_chordal_main(be_irg_t *birg)
716 const be_main_env_t *main_env = birg->main_env;
717 const arch_isa_t *isa = arch_env_get_isa(main_env->arch_env);
718 ir_graph *irg = birg->irg;
719 be_options_t *main_opts = main_env->options;
721 be_chordal_env_t chordal_env;
723 BE_TIMER_INIT(main_opts);
724 BE_TIMER_PUSH(ra_timer.t_other);
725 BE_TIMER_PUSH(ra_timer.t_prolog);
727 be_assure_dom_front(birg);
728 be_assure_liveness(birg);
730 chordal_env.opts = &options;
731 chordal_env.irg = irg;
732 chordal_env.birg = birg;
733 FIRM_DBG_REGISTER(chordal_env.dbg, "firm.be.chordal");
735 obstack_init(&chordal_env.obst);
737 BE_TIMER_POP(ra_timer.t_prolog);
739 be_stat_ev("insns_before", count_insns(irg));
741 if (! arch_code_generator_has_spiller(birg->cg)) {
742 /* use one of the generic spiller */
744 /* Perform the following for each register class. */
745 for (j = 0, m = arch_isa_get_n_reg_class(isa); j < m; ++j) {
746 post_spill_env_t pse;
748 memcpy(&pse.cenv, &chordal_env, sizeof(chordal_env));
749 pre_spill(isa, j, &pse);
751 BE_TIMER_PUSH(ra_timer.t_spill);
753 switch(options.spill_method) {
754 case BE_CH_SPILL_MORGAN:
755 be_spill_morgan(&pse.cenv);
757 case BE_CH_SPILL_BELADY:
758 be_spill_belady(&pse.cenv);
761 case BE_CH_SPILL_REMAT:
762 be_spill_remat(&pse.cenv);
764 #endif /* WITH_ILP */
766 fprintf(stderr, "no valid spiller selected. falling back to belady\n");
767 be_spill_belady(&pse.cenv);
769 BE_TIMER_POP(ra_timer.t_spill);
771 dump(BE_CH_DUMP_SPILL, irg, pse.cenv.cls, "-spill", dump_ir_block_graph_sched);
777 post_spill_env_t *pse;
779 /* the backend has it's own spiller */
780 m = arch_isa_get_n_reg_class(isa);
782 pse = alloca(m * sizeof(pse[0]));
784 for (j = 0; j < m; ++j) {
785 memcpy(&pse[j].cenv, &chordal_env, sizeof(chordal_env));
786 pre_spill(isa, j, &pse[j]);
789 BE_TIMER_PUSH(ra_timer.t_spill);
790 arch_code_generator_spill(birg->cg, &chordal_env);
791 BE_TIMER_POP(ra_timer.t_spill);
792 dump(BE_CH_DUMP_SPILL, irg, NULL, "-spill", dump_ir_block_graph_sched);
794 for (j = 0; j < m; ++j) {
799 BE_TIMER_PUSH(ra_timer.t_spillslots);
801 be_coalesce_spillslots(&chordal_env);
802 dump(BE_CH_DUMP_SPILLSLOTS, irg, NULL, "-spillslots", dump_ir_block_graph_sched);
804 BE_TIMER_POP(ra_timer.t_spillslots);
806 BE_TIMER_PUSH(ra_timer.t_verify);
807 /* verify spillslots */
808 if (options.vrfy_option == BE_CH_VRFY_WARN) {
809 be_verify_spillslots(main_env->arch_env, irg);
811 else if (options.vrfy_option == BE_CH_VRFY_ASSERT) {
812 assert(be_verify_spillslots(main_env->arch_env, irg) && "Spillslot verification failed");
814 BE_TIMER_POP(ra_timer.t_verify);
816 BE_TIMER_PUSH(ra_timer.t_epilog);
817 dump(BE_CH_DUMP_LOWER, irg, NULL, "-spilloff", dump_ir_block_graph_sched);
819 lower_nodes_after_ra(&chordal_env, options.lower_perm_opt & BE_CH_LOWER_PERM_COPY ? 1 : 0);
820 dump(BE_CH_DUMP_LOWER, irg, NULL, "-belower-after-ra", dump_ir_block_graph_sched);
822 obstack_free(&chordal_env.obst, NULL);
823 BE_TIMER_POP(ra_timer.t_epilog);
825 BE_TIMER_POP(ra_timer.t_other);
827 be_stat_ev("insns_after", count_insns(irg));
830 return main_opts->timing == BE_TIME_ON ? &ra_timer : NULL;
831 #endif /* WITH_LIBCORE */
835 const be_ra_t be_ra_chordal_allocator = {
837 be_ra_chordal_register_options,