2 * Base routines for register allocation.
3 * @author Sebastian Hack
21 #include "besched_t.h"
25 be_ra_timer_t *global_ra_timer = NULL;
27 static sched_timestep_t get_time_step(const ir_node *irn)
32 return sched_get_time_step(irn);
35 int value_dominates(const ir_node *a, const ir_node *b)
38 const ir_node *ba = get_block(a);
39 const ir_node *bb = get_block(b);
42 * a and b are not in the same block,
43 * so dominance is determined by the dominance of the blocks.
46 res = block_dominates(ba, bb);
49 * Dominance is determined by the time steps of the schedule.
52 sched_timestep_t as = get_time_step(a);
53 sched_timestep_t bs = get_time_step(b);
61 * Check, if two values interfere.
62 * @param a The first value.
63 * @param b The second value.
64 * @return 1, if a and b interfere, 0 if not.
66 int values_interfere(const be_lv_t *lv, const ir_node *a, const ir_node *b)
68 int a2b = value_dominates(a, b);
69 int b2a = value_dominates(b, a);
71 /* If there is no dominance relation, they do not interfere. */
73 const ir_edge_t *edge;
77 * Adjust a and b so, that a dominates b if
78 * a dominates b or vice versa.
86 bb = get_nodes_block(b);
89 * If a is live end in b's block it is
90 * live at b's definition (a dominates b)
92 if(be_is_live_end(lv, bb, a))
96 * Look at all usages of a.
97 * If there's one usage of a in the block of b, then
98 * we check, if this use is dominated by b, if that's true
99 * a and b interfere. Note that b must strictly dominate the user,
100 * since if b is the last user of in the block, b and a do not
102 * Uses of a not in b's block can be disobeyed, because the
103 * check for a being live at the end of b's block is already
106 foreach_out_edge(a, edge) {
107 const ir_node *user = get_edge_src_irn(edge);
108 if(get_nodes_block(user) == bb && !is_Phi(user) && b != user && value_dominates(b, user))
116 /** The list of register allocators */
117 static be_module_list_entry_t *register_allocators = NULL;
118 static be_ra_t *selected_allocator = NULL;
120 void be_register_allocator(const char *name, be_ra_t *allocator)
122 if(selected_allocator == NULL)
123 selected_allocator = allocator;
124 be_add_module_to_list(®ister_allocators, name, allocator);
127 void be_allocate_registers(be_irg_t *birg)
129 assert(selected_allocator != NULL);
130 if(selected_allocator != NULL) {
131 selected_allocator->allocate(birg);
135 void be_init_ra(void)
137 lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
139 be_add_module_list_opt(be_grp, "regalloc", "register allocator",
140 ®ister_allocators, (void**) &selected_allocator);
142 BE_REGISTER_MODULE_CONSTRUCTOR(init_be_ra);