2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief New approach to allocation and copy coalescing
23 * @author Matthias Braun
27 * ... WE NEED A NAME FOR THIS ...
29 * Only a proof of concept at this moment...
31 * The idea is to allocate registers in 2 passes:
32 * 1. A first pass to determine "preferred" registers for live-ranges. This
33 * calculates for each register and each live-range a value indicating
34 * the usefulness. (You can roughly think of the value as the negative
35 * costs needed for copies when the value is in the specific registers...)
37 * 2. Walk blocks and assigns registers in a greedy fashion. Preferring registers
38 * with high preferences. When register constraints are not met, add copies
39 * and split live-ranges.
42 * - output constraints are not ensured. The algorithm fails to copy values
43 * away, so the registers for constrained outputs are free.
44 * - must_be_different constraint is not respected
45 * - No parallel copies at basic block borders are created, no additional phis
46 * created after copies have been inserted.
47 * - Phi color assignment should give bonus points towards registers already
48 * assigned at predecessors.
49 * - think about a smarter sequence of visiting the blocks. Sorted by
50 * execfreq might be good, or looptree from inner to outermost loops going
51 * over blocks in a reverse postorder
59 #include "irgraph_t.h"
60 #include "iredges_t.h"
69 #include "bechordal_t.h"
70 #include "besched_t.h"
73 #include "bespilloptions.h"
76 #include "bipartite.h"
77 #include "hungarian.h"
79 #define USE_FACTOR 1.0f
80 #define DEF_FACTOR 1.0f
81 #define NEIGHBOR_FACTOR 0.2f
82 #define SHOULD_BE_SAME 1.0f
84 DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
86 static struct obstack obst;
87 static be_irg_t *birg;
89 static const arch_register_class_t *cls;
91 static const ir_exec_freq *execfreqs;
92 static unsigned n_regs;
93 static bitset_t *ignore_regs;
95 typedef struct assignment_t assignment_t;
97 ir_node *value; /**< currently assigned value */
100 static assignment_t *assignments;
102 typedef struct allocation_info_t allocation_info_t;
103 struct allocation_info_t {
104 unsigned last_uses; /**< bitset indicating last uses (input pos) */
105 assignment_t *current_assignment;
106 float prefs[0]; /**< register preferences */
109 typedef struct reg_pref_t reg_pref_t;
116 * Get the allocation info for a node.
117 * The info is allocated on the first visit of a node.
119 static allocation_info_t *get_allocation_info(ir_node *node)
121 allocation_info_t *info;
122 if (!irn_visited(node)) {
123 size_t size = sizeof(info[0]) + n_regs * sizeof(float);
124 info = obstack_alloc(&obst, size);
125 memset(info, 0, size);
126 set_irn_link(node, info);
127 mark_irn_visited(node);
129 info = get_irn_link(node);
136 * Link the allocation info of a node to a copy.
137 * Afterwards, both nodes uses the same allocation info.
138 * Copy must not have an allocation info assigned yet.
140 * @param copy the node that gets the allocation info assigned
141 * @param value the original node
143 static void link_to(ir_node *copy, ir_node *value)
145 allocation_info_t *info = get_allocation_info(value);
146 assert(!irn_visited(copy));
147 set_irn_link(copy, info);
148 mark_irn_visited(copy);
152 * Calculate the penalties for every register on a node and its live neighbors.
154 * @param live_nodes the set of live nodes at the current position, may be NULL
155 * @param penalty the penalty to subtract from
156 * @param limited a raw bitset containing the limited set for the node
157 * @param node the node
159 static void give_penalties_for_limits(const ir_nodeset_t *live_nodes,
160 float penalty, const unsigned* limited,
163 ir_nodeset_iterator_t iter;
165 allocation_info_t *info = get_allocation_info(node);
168 /* give penalty for all forbidden regs */
169 for (r = 0; r < n_regs; ++r) {
170 if (rbitset_is_set(limited, r))
173 info->prefs[r] -= penalty;
176 /* all other live values should get a penalty for allowed regs */
177 if (live_nodes == NULL)
180 /* TODO: reduce penalty if there are multiple allowed registers... */
181 penalty *= NEIGHBOR_FACTOR;
182 foreach_ir_nodeset(live_nodes, neighbor, iter) {
183 allocation_info_t *neighbor_info;
185 /* TODO: if op is used on multiple inputs we might not do a
187 if (neighbor == node)
190 neighbor_info = get_allocation_info(neighbor);
191 for (r = 0; r < n_regs; ++r) {
192 if (!rbitset_is_set(limited, r))
195 neighbor_info->prefs[r] -= penalty;
201 * Calculate the preferences of a definition for the current register class.
202 * If the definition uses a limited set of registers, reduce the preferences
203 * for the limited register on the node and its neighbors.
205 * @param live_nodes the set of live nodes at the current node
206 * @param weight the weight
207 * @param node the current node
209 static void check_defs(const ir_nodeset_t *live_nodes, float weight,
212 const arch_register_req_t *req;
214 if (get_irn_mode(node) == mode_T) {
215 const ir_edge_t *edge;
216 foreach_out_edge(node, edge) {
217 ir_node *proj = get_edge_src_irn(edge);
218 check_defs(live_nodes, weight, proj);
223 if (!arch_irn_consider_in_reg_alloc(cls, node))
226 req = arch_get_register_req_out(node);
227 if (req->type & arch_register_req_type_limited) {
228 const unsigned *limited = req->limited;
229 float penalty = weight * DEF_FACTOR;
230 give_penalties_for_limits(live_nodes, penalty, limited, node);
233 if (req->type & arch_register_req_type_should_be_same) {
234 ir_node *insn = skip_Proj(node);
235 allocation_info_t *info = get_allocation_info(node);
236 int arity = get_irn_arity(insn);
239 float factor = 1.0f / rbitset_popcnt(&req->other_same, arity);
240 for (i = 0; i < arity; ++i) {
243 allocation_info_t *op_info;
245 if (!rbitset_is_set(&req->other_same, i))
248 op = get_irn_n(insn, i);
249 op_info = get_allocation_info(op);
250 for (r = 0; r < n_regs; ++r) {
251 if (bitset_is_set(ignore_regs, r))
253 op_info->prefs[r] += info->prefs[r] * factor;
260 * Walker: Runs an a block calculates the preferences for any
261 * node and every register from the considered register class.
263 static void analyze_block(ir_node *block, void *data)
265 float weight = get_block_execfreq(execfreqs, block);
266 ir_nodeset_t live_nodes;
270 ir_nodeset_init(&live_nodes);
271 be_liveness_end_of_block(lv, cls, block, &live_nodes);
273 sched_foreach_reverse(block, node) {
274 allocation_info_t *info;
278 /* TODO: handle constrained phi-nodes */
282 /* TODO give/take penalties for should_be_same/different) */
283 check_defs(&live_nodes, weight, node);
286 arity = get_irn_arity(node);
287 /* I was lazy, and only allocated 1 unsigned
288 => maximum of 32 uses per node (rewrite if necessary) */
289 assert(arity <= (int) sizeof(unsigned) * 8);
291 info = get_allocation_info(node);
292 for (i = 0; i < arity; ++i) {
293 ir_node *op = get_irn_n(node, i);
294 if (!arch_irn_consider_in_reg_alloc(cls, op))
297 /* last usage of a value? */
298 if (!ir_nodeset_contains(&live_nodes, op)) {
299 rbitset_set(&info->last_uses, i);
303 be_liveness_transfer(cls, node, &live_nodes);
305 /* update weights based on usage constraints */
306 for (i = 0; i < arity; ++i) {
307 const arch_register_req_t *req;
308 const unsigned *limited;
309 ir_node *op = get_irn_n(node, i);
311 if (!arch_irn_consider_in_reg_alloc(cls, op))
314 req = arch_get_register_req(node, i);
315 if ((req->type & arch_register_req_type_limited) == 0)
318 /* TODO: give penalties to neighbors for precolored nodes! */
320 limited = req->limited;
321 give_penalties_for_limits(&live_nodes, weight * USE_FACTOR, limited,
326 ir_nodeset_destroy(&live_nodes);
330 * Assign register reg to the given node.
332 * @param node the node
333 * @param reg the register
335 static void use_reg(ir_node *node, const arch_register_t *reg)
337 unsigned r = arch_register_get_index(reg);
338 assignment_t *assignment = &assignments[r];
339 allocation_info_t *info;
341 assert(assignment->value == NULL);
342 assignment->value = node;
344 info = get_allocation_info(node);
345 info->current_assignment = assignment;
347 arch_set_irn_register(node, reg);
351 * Compare two register preferences in decreasing order.
353 static int compare_reg_pref(const void *e1, const void *e2)
355 const reg_pref_t *rp1 = (const reg_pref_t*) e1;
356 const reg_pref_t *rp2 = (const reg_pref_t*) e2;
357 if (rp1->pref < rp2->pref)
359 if (rp1->pref > rp2->pref)
364 static void fill_sort_candidates(reg_pref_t *regprefs,
365 const allocation_info_t *info)
369 for (r = 0; r < n_regs; ++r) {
370 float pref = info->prefs[r];
371 if (bitset_is_set(ignore_regs, r)) {
375 regprefs[r].pref = pref;
377 /* TODO: use a stable sort here to avoid unnecessary register jumping */
378 qsort(regprefs, n_regs, sizeof(regprefs[0]), compare_reg_pref);
381 static void assign_reg(const ir_node *block, ir_node *node)
383 const arch_register_t *reg;
384 allocation_info_t *info;
385 const arch_register_req_t *req;
386 reg_pref_t *reg_prefs;
390 assert(arch_irn_consider_in_reg_alloc(cls, node));
392 /* preassigned register? */
393 reg = arch_get_irn_register(node);
395 DB((dbg, LEVEL_2, "Preassignment %+F -> %s\n", node, reg->name));
400 /* give should_be_same boni */
401 info = get_allocation_info(node);
402 req = arch_get_register_req_out(node);
404 in_node = skip_Proj(node);
405 if (req->type & arch_register_req_type_should_be_same) {
406 float weight = get_block_execfreq(execfreqs, block);
407 int arity = get_irn_arity(in_node);
410 assert(arity <= (int) sizeof(req->other_same) * 8);
411 for (i = 0; i < arity; ++i) {
413 const arch_register_t *reg;
415 if (!rbitset_is_set(&req->other_same, i))
418 in = get_irn_n(in_node, i);
419 reg = arch_get_irn_register(in);
421 r = arch_register_get_index(reg);
422 if (bitset_is_set(ignore_regs, r))
424 info->prefs[r] += weight * SHOULD_BE_SAME;
428 /* TODO: handle must_be_different */
431 DB((dbg, LEVEL_2, "Candidates for %+F:", node));
432 reg_prefs = alloca(n_regs * sizeof(reg_prefs[0]));
433 fill_sort_candidates(reg_prefs, info);
434 for (i = 0; i < n_regs; ++i) {
435 unsigned num = reg_prefs[i].num;
436 const arch_register_t *reg = arch_register_for_index(cls, num);
437 DB((dbg, LEVEL_2, " %s(%f)", reg->name, reg_prefs[i].pref));
439 DB((dbg, LEVEL_2, "\n"));
441 for (i = 0; i < n_regs; ++i) {
442 unsigned r = reg_prefs[i].num;
443 /* ignores should be last and we should have a non-ignore left */
444 assert(!bitset_is_set(ignore_regs, r));
445 /* already used? TODO: It might be better to copy the value occupying the register around here, find out when... */
446 if (assignments[r].value != NULL)
448 reg = arch_register_for_index(cls, r);
449 DB((dbg, LEVEL_2, "Assign %+F -> %s\n", node, reg->name));
455 static void free_reg_of_value(ir_node *node)
457 allocation_info_t *info;
458 assignment_t *assignment;
461 if (!arch_irn_consider_in_reg_alloc(cls, node))
464 info = get_allocation_info(node);
465 assignment = info->current_assignment;
467 assert(assignment != NULL);
469 r = assignment - assignments;
470 DB((dbg, LEVEL_2, "Value %+F ended, freeing %s\n",
471 node, arch_register_for_index(cls, r)->name));
472 assignment->value = NULL;
473 info->current_assignment = NULL;
477 * Return the index of the currently assigned register of a node.
479 static unsigned get_current_reg(ir_node *node)
481 allocation_info_t *info = get_allocation_info(node);
482 assignment_t *assignment = info->current_assignment;
483 return assignment - assignments;
487 * Return the currently assigned assignment of a node.
489 static assignment_t *get_current_assignment(ir_node *node)
491 allocation_info_t *info = get_allocation_info(node);
492 return info->current_assignment;
496 * Add an permutation in front of a node and change the assignments
497 * due to this permutation.
499 * To understand this imagine a permutation like this:
509 * First we count how many destinations a single value has. At the same time
510 * we can be sure that each destination register has at most 1 source register
511 * (it can have 0 which means we don't care what value is in it).
512 * We ignore all fullfilled permuations (like 7->7)
513 * In a first pass we create as much copy instructions as possible as they
514 * are generally cheaper than exchanges. We do this by counting into how many
515 * destinations a register has to be copied (in the example it's 2 for register
516 * 3, or 1 for the registers 1,2,4 and 7).
517 * We can then create a copy into every destination register when the usecount
518 * of that register is 0 (= noone else needs the value in the register).
520 * After this step we should have cycles left. We implement a cyclic permutation
521 * of n registers with n-1 transpositions.
523 * @param live_nodes the set of live nodes, updated due to live range split
524 * @param before the node before we add the permutation
525 * @param permutation the permutation array indices are the destination
526 * registers, the values in the array are the source
529 static void permutate_values(ir_nodeset_t *live_nodes, ir_node *before,
530 unsigned *permutation)
533 ir_node **ins = ALLOCANZ(ir_node*, n_regs);
534 unsigned *n_used = ALLOCANZ(unsigned, n_regs);
537 /* create a list of permutations. Leave out fix points. */
538 for (r = 0; r < n_regs; ++r) {
539 unsigned old_reg = permutation[r];
540 assignment_t *assignment;
543 /* no need to do anything for a fixpoint */
547 assignment = &assignments[old_reg];
548 value = assignment->value;
550 /* nothing to do here, reg is not live. Mark it as fixpoint
551 * so we ignore it in the next steps */
556 ins[old_reg] = value;
559 /* free occupation infos, we'll add the values back later */
560 free_reg_of_value(value);
561 ir_nodeset_remove(live_nodes, value);
564 block = get_nodes_block(before);
566 /* step1: create copies where immediately possible */
567 for (r = 0; r < n_regs; /* empty */) {
570 const arch_register_t *reg;
571 unsigned old_r = permutation[r];
573 /* - no need to do anything for fixed points.
574 - we can't copy if the value in the dest reg is still needed */
575 if (old_r == r || n_used[r] > 0) {
582 copy = be_new_Copy(cls, block, src);
583 reg = arch_register_for_index(cls, r);
584 DB((dbg, LEVEL_2, "Copy %+F (from %+F) -> %s\n", copy, src, reg->name));
587 sched_add_before(before, copy);
589 /* old register has 1 user less, permutation is resolved */
590 assert(arch_register_get_index(arch_get_irn_register(src)) == old_r);
591 assert(n_used[old_r] > 0);
595 /* advance or jump back (this copy could have enabled another copy) */
596 if (old_r < r && n_used[old_r] == 0) {
603 /* at this point we only have "cycles" left which we have to resolve with
605 * TODO: if we have free registers left, then we should really use copy
606 * instructions for any cycle longer than 2 registers...
607 * (this is probably architecture dependent, there might be archs where
608 * copies are preferable even for 2 cycles)
611 /* create perms with the rest */
612 for (r = 0; r < n_regs; /* empty */) {
613 const arch_register_t *reg;
614 unsigned old_r = permutation[r];
626 /* we shouldn't have copies from 1 value to multiple destinations left*/
627 assert(n_used[old_r] == 1);
629 /* exchange old_r and r2; after that old_r is a fixed point */
630 r2 = permutation[old_r];
634 perm = be_new_Perm(cls, block, 2, in);
636 proj0 = new_r_Proj(block, perm, get_irn_mode(in[0]), 0);
637 link_to(proj0, in[0]);
638 reg = arch_register_for_index(cls, old_r);
641 proj1 = new_r_Proj(block, perm, get_irn_mode(in[1]), 1);
643 /* 1 value is now in the correct register */
644 permutation[old_r] = old_r;
645 /* the source of r changed to r2 */
648 reg = arch_register_for_index(cls, r2);
650 /* if we have reached a fixpoint update data structures */
651 link_to(proj1, in[1]);
654 arch_set_irn_register(proj1, reg);
659 /* now we should only have fixpoints left */
660 for (r = 0; r < n_regs; ++r) {
661 assert(permutation[r] == r);
667 * Free regs for values last used.
669 * @param live_nodes set of live nodes, will be updated
670 * @param node the node to consider
672 static void free_last_uses(ir_nodeset_t *live_nodes, ir_node *node)
674 allocation_info_t *info = get_allocation_info(node);
675 int arity = get_irn_arity(node);
677 for (i = 0; i < arity; ++i) {
680 /* check if one operand is the last use */
681 if (!rbitset_is_set(&info->last_uses, i))
684 op = get_irn_n(node, i);
685 free_reg_of_value(op);
686 ir_nodeset_remove(live_nodes, op);
691 * Enforce constraints at a node by live range splits.
693 * @param live_nodes the set of live nodes, might be changed
694 * @param node the current node
696 static void enforce_constraints(ir_nodeset_t *live_nodes, ir_node *node)
698 int arity = get_irn_arity(node);
700 hungarian_problem_t *bp;
702 unsigned *assignment;
704 /* see if any use constraints are not met */
706 for (i = 0; i < arity; ++i) {
707 ir_node *op = get_irn_n(node, i);
708 const arch_register_req_t *req;
709 const unsigned *limited;
712 if (!arch_irn_consider_in_reg_alloc(cls, op))
715 /* are there any limitations for the i'th operand? */
716 req = arch_get_register_req(node, i);
717 if ((req->type & arch_register_req_type_limited) == 0)
720 limited = req->limited;
721 r = get_current_reg(op);
722 if (!rbitset_is_set(limited, r)) {
723 /* found an assignement outside the limited set */
732 /* swap values around */
733 bp = hungarian_new(n_regs, n_regs, HUNGARIAN_MATCH_PERFECT);
735 /* add all combinations, then remove not allowed ones */
736 for (l = 0; l < n_regs; ++l) {
737 if (bitset_is_set(ignore_regs, l)) {
738 hungarian_add(bp, l, l, 90);
742 for (r = 0; r < n_regs; ++r) {
743 if (bitset_is_set(ignore_regs, r))
746 hungarian_add(bp, l, r, l == r ? 90 : 89);
750 for (i = 0; i < arity; ++i) {
751 ir_node *op = get_irn_n(node, i);
752 const arch_register_req_t *req;
753 const unsigned *limited;
754 unsigned current_reg;
756 if (!arch_irn_consider_in_reg_alloc(cls, op))
759 req = arch_get_register_req(node, i);
760 if ((req->type & arch_register_req_type_limited) == 0)
763 limited = req->limited;
764 current_reg = get_current_reg(op);
765 for (r = 0; r < n_regs; ++r) {
766 if (rbitset_is_set(limited, r))
768 hungarian_remv(bp, current_reg, r);
772 hungarian_print_costmatrix(bp, 1);
773 hungarian_prepare_cost_matrix(bp, HUNGARIAN_MODE_MAXIMIZE_UTIL);
775 assignment = ALLOCAN(unsigned, n_regs);
776 res = hungarian_solve(bp, (int*) assignment, &dummy, 0);
779 printf("Swap result:");
780 for (p = 0; p < n_regs; ++p) {
781 printf(" %d", assignment[p]);
787 permutate_values(live_nodes, node, assignment);
791 * Walker: assign registers to all nodes of a block that
792 * needs registers from the currently considered register class.
794 static void allocate_coalesce_block(ir_node *block, void *data)
797 ir_nodeset_t live_nodes;
798 ir_nodeset_iterator_t iter;
799 ir_node *node, *start;
801 DB((dbg, LEVEL_2, "Allocating in block %+F\n",
804 /* clear assignments */
805 memset(assignments, 0, n_regs * sizeof(assignments[0]));
806 ir_nodeset_init(&live_nodes);
810 /* collect live-in nodes and preassigned values */
811 be_lv_foreach(lv, block, be_lv_state_in, i) {
812 const arch_register_t *reg;
814 node = be_lv_get_irn(lv, block, i);
815 if (!arch_irn_consider_in_reg_alloc(cls, node))
818 /* remember that this node is live at the beginning of the block */
819 ir_nodeset_insert(&live_nodes, node);
821 /* if the node already has a register assigned use it */
822 /* TODO: the value could already be copied away at this point and be in
824 reg = arch_get_irn_register(node);
831 node = sched_first(block);
832 for ( ; is_Phi(node); node = sched_next(node)) {
833 const arch_register_t *reg;
835 if (!arch_irn_consider_in_reg_alloc(cls, node))
838 /* fill in regs already assigned */
839 reg = arch_get_irn_register(node);
843 /* TODO: give boni for registers already assigned at the
849 /* assign regs for live-in values */
850 foreach_ir_nodeset(&live_nodes, node, iter) {
851 const arch_register_t *reg;
852 reg = arch_get_irn_register(node);
856 assign_reg(block, node);
859 /* assign instructions in the block */
860 for (node = start; !sched_is_end(node); node = sched_next(node)) {
861 int arity = get_irn_arity(node);
864 /* enforce use constraints */
865 enforce_constraints(&live_nodes, node);
867 /* exchange values to copied values where needed */
868 for (i = 0; i < arity; ++i) {
869 ir_node *op = get_irn_n(node, i);
870 assignment_t *assignment;
872 if (!arch_irn_consider_in_reg_alloc(cls, op))
874 assignment = get_current_assignment(op);
875 assert(assignment != NULL);
876 if (op != assignment->value) {
877 set_irn_n(node, i, assignment->value);
881 free_last_uses(&live_nodes, node);
883 /* assign output registers */
884 /* TODO: 2 phases: first: pre-assigned ones, 2nd real regs */
885 if (get_irn_mode(node) == mode_T) {
886 const ir_edge_t *edge;
887 foreach_out_edge(node, edge) {
888 ir_node *proj = get_edge_src_irn(edge);
889 if (!arch_irn_consider_in_reg_alloc(cls, proj))
891 assign_reg(block, proj);
893 } else if (arch_irn_consider_in_reg_alloc(cls, node)) {
894 assign_reg(block, node);
898 foreach_ir_nodeset(&live_nodes, node, iter) {
899 free_reg_of_value(node);
902 ir_nodeset_destroy(&live_nodes);
906 * Run the register allocator for the current register class.
908 static void be_straight_alloc_cls(void)
910 n_regs = arch_register_class_n_regs(cls);
911 lv = be_assure_liveness(birg);
912 be_liveness_assure_sets(lv);
913 be_liveness_assure_chk(lv);
915 assignments = obstack_alloc(&obst, n_regs * sizeof(assignments[0]));
917 ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_IRN_VISITED);
918 inc_irg_visited(irg);
920 DB((dbg, LEVEL_2, "=== Registers in %s ===\n", cls->name));
922 irg_block_walk_graph(irg, NULL, analyze_block, NULL);
923 irg_block_walk_graph(irg, NULL, allocate_coalesce_block, NULL);
925 ir_free_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_IRN_VISITED);
929 * Run the spiller on the current graph.
931 static void spill(void)
933 /* make sure all nodes show their real register pressure */
934 BE_TIMER_PUSH(t_ra_constr);
935 be_pre_spill_prepare_constr(birg, cls);
936 BE_TIMER_POP(t_ra_constr);
939 BE_TIMER_PUSH(t_ra_spill);
940 be_do_spill(birg, cls);
941 BE_TIMER_POP(t_ra_spill);
943 BE_TIMER_PUSH(t_ra_spill_apply);
944 check_for_memory_operands(irg);
945 BE_TIMER_POP(t_ra_spill_apply);
949 * The straight register allocator for a whole procedure.
951 static void be_straight_alloc(be_irg_t *new_birg)
953 const arch_env_t *arch_env = new_birg->main_env->arch_env;
954 int n_cls = arch_env_get_n_reg_class(arch_env);
960 irg = be_get_birg_irg(birg);
961 execfreqs = birg->exec_freq;
963 /* TODO: extract some of the stuff from bechordal allocator, like
964 * statistics, time measurements, etc. and use them here too */
966 for (c = 0; c < n_cls; ++c) {
967 cls = arch_env_get_reg_class(arch_env, c);
968 if (arch_register_class_flags(cls) & arch_register_class_flag_manual_ra)
971 stat_ev_ctx_push_str("bestraight_cls", cls->name);
973 n_regs = cls->n_regs;
974 ignore_regs = bitset_malloc(n_regs);
975 be_put_ignore_regs(birg, cls, ignore_regs);
979 /* verify schedule and register pressure */
980 BE_TIMER_PUSH(t_verify);
981 if (birg->main_env->options->vrfy_option == BE_CH_VRFY_WARN) {
982 be_verify_schedule(birg);
983 be_verify_register_pressure(birg, cls, irg);
984 } else if (birg->main_env->options->vrfy_option == BE_CH_VRFY_ASSERT) {
985 assert(be_verify_schedule(birg) && "Schedule verification failed");
986 assert(be_verify_register_pressure(birg, cls, irg)
987 && "Register pressure verification failed");
989 BE_TIMER_POP(t_verify);
991 BE_TIMER_PUSH(t_ra_color);
992 be_straight_alloc_cls();
993 BE_TIMER_POP(t_ra_color);
995 bitset_free(ignore_regs);
997 /* TODO: dump intermediate results */
999 stat_ev_ctx_pop("bestraight_cls");
1002 obstack_free(&obst, NULL);
1005 static be_ra_t be_ra_straight = {
1010 * Initializes this module.
1012 void be_init_straight_alloc(void)
1014 FIRM_DBG_REGISTER(dbg, "firm.be.straightalloc");
1016 be_register_allocator("straight", &be_ra_straight);
1019 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_straight_alloc);