2 * Base routines for register allocation.
3 * @author Sebastian Hack
21 #include "besched_t.h"
25 be_ra_timer_t *global_ra_timer = NULL;
28 sched_timestep_t get_time_step(const ir_node *irn)
33 return sched_get_time_step(irn);
36 int value_dominates_intrablock(const ir_node *a, const ir_node *b)
38 sched_timestep_t as = get_time_step(a);
39 sched_timestep_t bs = get_time_step(b);
44 int value_dominates(const ir_node *a, const ir_node *b)
46 const ir_node *block_a = get_block(a);
47 const ir_node *block_b = get_block(b);
50 * a and b are not in the same block,
51 * so dominance is determined by the dominance of the blocks.
53 if(block_a != block_b) {
54 return block_dominates(block_a, block_b);
58 * Dominance is determined by the time steps of the schedule.
60 return value_dominates_intrablock(a, b);
64 * Check, if two values interfere.
65 * @param a The first value.
66 * @param b The second value.
67 * @return 1, if a and b interfere, 0 if not.
69 int values_interfere(const be_lv_t *lv, const ir_node *a, const ir_node *b)
71 int a2b = value_dominates(a, b);
72 int b2a = value_dominates(b, a);
74 /* If there is no dominance relation, they do not interfere. */
76 const ir_edge_t *edge;
80 * Adjust a and b so, that a dominates b if
81 * a dominates b or vice versa.
89 bb = get_nodes_block(b);
92 * If a is live end in b's block it is
93 * live at b's definition (a dominates b)
95 if(be_is_live_end(lv, bb, a))
99 * Look at all usages of a.
100 * If there's one usage of a in the block of b, then
101 * we check, if this use is dominated by b, if that's true
102 * a and b interfere. Note that b must strictly dominate the user,
103 * since if b is the last user of in the block, b and a do not
105 * Uses of a not in b's block can be disobeyed, because the
106 * check for a being live at the end of b's block is already
109 foreach_out_edge(a, edge) {
110 const ir_node *user = get_edge_src_irn(edge);
111 if(get_nodes_block(user) == bb && !is_Phi(user) && b != user && value_dominates(b, user))
119 /** The list of register allocators */
120 static be_module_list_entry_t *register_allocators = NULL;
121 static be_ra_t *selected_allocator = NULL;
123 void be_register_allocator(const char *name, be_ra_t *allocator)
125 if(selected_allocator == NULL)
126 selected_allocator = allocator;
127 be_add_module_to_list(®ister_allocators, name, allocator);
130 void be_allocate_registers(be_irg_t *birg)
132 assert(selected_allocator != NULL);
133 if(selected_allocator != NULL) {
134 selected_allocator->allocate(birg);
138 void be_init_ra(void)
140 lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
142 be_add_module_list_opt(be_grp, "regalloc", "register allocator",
143 ®ister_allocators, (void**) &selected_allocator);
145 BE_REGISTER_MODULE_CONSTRUCTOR(init_be_ra);