2 * Base routines for register allocation.
3 * @author Sebastian Hack
21 #include "besched_t.h"
25 static sched_timestep_t get_time_step(const ir_node *irn)
30 return sched_get_time_step(irn);
33 int value_dominates(const ir_node *a, const ir_node *b)
36 const ir_node *ba = get_block(a);
37 const ir_node *bb = get_block(b);
40 * a and b are not in the same block,
41 * so dominance is determined by the dominance of the blocks.
44 res = block_dominates(ba, bb);
47 * Dominance is determined by the time steps of the schedule.
50 sched_timestep_t as = get_time_step(a);
51 sched_timestep_t bs = get_time_step(b);
59 * Check, if two values interfere.
60 * @param a The first value.
61 * @param b The second value.
62 * @return 1, if a and b interfere, 0 if not.
64 int values_interfere(const be_lv_t *lv, const ir_node *a, const ir_node *b)
66 int a2b = value_dominates(a, b);
67 int b2a = value_dominates(b, a);
69 /* If there is no dominance relation, they do not interfere. */
71 const ir_edge_t *edge;
75 * Adjust a and b so, that a dominates b if
76 * a dominates b or vice versa.
84 bb = get_nodes_block(b);
87 * If a is live end in b's block it is
88 * live at b's definition (a dominates b)
90 if(be_is_live_end(lv, bb, a))
94 * Look at all usages of a.
95 * If there's one usage of a in the block of b, then
96 * we check, if this use is dominated by b, if that's true
97 * a and b interfere. Note that b must strictly dominate the user,
98 * since if b is the last user of in the block, b and a do not
100 * Uses of a not in b's block can be disobeyed, because the
101 * check for a being live at the end of b's block is already
104 foreach_out_edge(a, edge) {
105 const ir_node *user = get_edge_src_irn(edge);
106 if(get_nodes_block(user) == bb && !is_Phi(user) && b != user && value_dominates(b, user))
114 /** The list of register allocators */
115 static be_module_list_entry_t *register_allocators = NULL;
116 static be_ra_t *selected_allocator = NULL;
118 void be_register_allocator(const char *name, be_ra_t *allocator)
120 if(selected_allocator == NULL)
121 selected_allocator = allocator;
122 be_add_module_to_list(®ister_allocators, name, allocator);
125 void be_allocate_registers(be_irg_t *birg)
127 assert(selected_allocator != NULL);
128 if(selected_allocator != NULL) {
129 selected_allocator->allocate(birg);
133 void be_init_ra(void)
135 lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
137 be_add_module_list_opt(be_grp, "regalloc", "register allocator",
138 ®ister_allocators, (void**) &selected_allocator);
140 BE_REGISTER_MODULE_CONSTRUCTOR(init_be_ra);