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 PBQP based register allocation.
23 * @author Thomas Bersch
27 /* miscellaneous includes */
35 #include "iredges_t.h"
40 #include "execfreq_t.h"
41 #include "bipartite.h"
43 /* libfirm/ir/be includes */
48 #include "bechordal_common.h"
49 #include "bechordal.h"
50 #include "bechordal_t.h"
58 #include "becopyopt.h"
65 #include "heuristical_co.h"
66 #include "heuristical_co_ld.h"
68 #include "html_dumper.h"
69 #include "pbqp_node_t.h"
70 #include "pbqp_node.h"
71 #include "pbqp_edge_t.h"
75 #define USE_BIPARTIT_MATCHING 0
76 #define DO_USEFUL_OPT 1
79 static int use_exec_freq = true;
80 static int use_late_decision = false;
82 typedef struct be_pbqp_alloc_env_t {
83 pbqp_t *pbqp_inst; /**< PBQP instance for register allocation */
84 ir_graph *irg; /**< The graph under examination. */
85 const arch_register_class_t *cls; /**< Current processed register class */
87 bitset_t *allocatable_regs;
88 pbqp_matrix_t *ife_matrix_template;
89 pbqp_matrix_t *aff_matrix_template;
91 unsigned *restr_nodes;
92 unsigned *ife_edge_num;
93 ir_execfreq_int_factors execfreq_factors;
94 be_chordal_env_t *env;
95 } be_pbqp_alloc_env_t;
98 #define is_Reg_Phi(irn) (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
99 #define get_Perm_src(irn) (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
100 #define is_Perm_Proj(irn) (is_Proj(irn) && be_is_Perm(get_Proj_pred(irn)))
101 #define insert_edge(pbqp, src_node, trg_node, template_matrix) (add_edge_costs(pbqp, get_irn_idx(src_node), get_irn_idx(trg_node), pbqp_matrix_copy(pbqp, template_matrix)))
102 #define get_free_regs(restr_nodes, cls, irn) (arch_register_class_n_regs(cls) - restr_nodes[get_irn_idx(irn)])
104 static inline int is_2addr_code(const arch_register_req_t *req)
106 return (req->type & arch_register_req_type_should_be_same) != 0;
109 static const lc_opt_table_entry_t options[] = {
110 LC_OPT_ENT_BOOL("exec_freq", "use exec_freq", &use_exec_freq),
111 LC_OPT_ENT_BOOL("late_decision", "use late decision for register allocation", &use_late_decision),
116 static FILE *my_open(const be_chordal_env_t *env, const char *prefix, const char *suffix)
123 const char *cup_name = be_get_irg_main_env(env->irg)->cup_name;
125 n = strlen(cup_name);
126 tu_name = XMALLOCN(char, n + 1);
127 strcpy(tu_name, cup_name);
128 for (i = 0; i < n; ++i)
129 if (tu_name[i] == '.')
132 ir_snprintf(buf, sizeof(buf), "%s%s_%F_%s%s", prefix, tu_name, env->irg, env->cls->name, suffix);
134 result = fopen(buf, "wt");
135 if (result == NULL) {
136 panic("Couldn't open '%s' for writing.", buf);
144 static void create_pbqp_node(be_pbqp_alloc_env_t *pbqp_alloc_env, ir_node *irn)
146 const arch_register_class_t *cls = pbqp_alloc_env->cls;
147 pbqp_t *pbqp_inst = pbqp_alloc_env->pbqp_inst;
148 bitset_t *allocatable_regs = pbqp_alloc_env->allocatable_regs;
149 unsigned colors_n = arch_register_class_n_regs(cls);
150 unsigned cntConstrains = 0;
152 /* create costs vector depending on register constrains */
153 vector_t *costs_vector = vector_alloc(pbqp_inst, colors_n);
155 /* set costs depending on register constrains */
157 for (idx = 0; idx < colors_n; idx++) {
158 const arch_register_req_t *req = arch_get_irn_register_req(irn);
159 const arch_register_t *reg = arch_register_for_index(cls, idx);
160 if (!bitset_is_set(allocatable_regs, idx)
161 || !arch_reg_is_allocatable(req, reg)) {
163 vector_set(costs_vector, idx, INF_COSTS);
168 /* add vector to pbqp node */
169 add_node_costs(pbqp_inst, get_irn_idx(irn), costs_vector);
170 pbqp_alloc_env->restr_nodes[get_irn_idx(irn)] = cntConstrains;
173 static void insert_ife_edge(be_pbqp_alloc_env_t *pbqp_alloc_env, ir_node *src_node, ir_node *trg_node)
175 pbqp_t *pbqp = pbqp_alloc_env->pbqp_inst;
176 const arch_register_class_t *cls = pbqp_alloc_env->cls;
177 pbqp_matrix_t *ife_matrix_template = pbqp_alloc_env->ife_matrix_template;
178 unsigned *restr_nodes = pbqp_alloc_env->restr_nodes;
180 if (get_edge(pbqp, get_irn_idx(src_node), get_irn_idx(trg_node)) == NULL) {
182 /* increase ife edge counter */
183 pbqp_alloc_env->ife_edge_num[get_irn_idx(src_node)]++;
184 pbqp_alloc_env->ife_edge_num[get_irn_idx(trg_node)]++;
186 #if DO_USEFUL_OPT || USE_BIPARTIT_MATCHING
187 /* do useful optimization to speed up pbqp solving (we can do this because we know our matrix) */
188 if (get_free_regs(restr_nodes, cls, src_node) == 1 && get_free_regs(restr_nodes, cls, trg_node) == 1) {
189 assert(vector_get_min_index(get_node(pbqp, get_irn_idx(src_node))->costs) !=
190 vector_get_min_index(get_node(pbqp, get_irn_idx(trg_node))->costs) &&
191 "Interfering nodes must not have the same register!");
194 if (get_free_regs(restr_nodes, cls, src_node) == 1 || get_free_regs(restr_nodes, cls, trg_node) == 1) {
195 if (get_free_regs(restr_nodes, cls, src_node) == 1) {
196 unsigned idx = vector_get_min_index(get_node(pbqp, get_irn_idx(src_node))->costs);
197 vector_set(get_node(pbqp, get_irn_idx(trg_node))->costs, idx, INF_COSTS);
200 unsigned idx = vector_get_min_index(get_node(pbqp, get_irn_idx(trg_node))->costs);
201 vector_set(get_node(pbqp, get_irn_idx(src_node))->costs, idx, INF_COSTS);
206 /* insert interference edge */
207 insert_edge(pbqp, src_node, trg_node, ife_matrix_template);
211 static void insert_afe_edge(be_pbqp_alloc_env_t *pbqp_alloc_env, ir_node *src_node, ir_node *trg_node, int pos)
213 pbqp_t *pbqp = pbqp_alloc_env->pbqp_inst;
214 const arch_register_class_t *cls = pbqp_alloc_env->cls;
215 unsigned *restr_nodes = pbqp_alloc_env->restr_nodes;
216 pbqp_matrix_t *afe_matrix = pbqp_matrix_alloc(pbqp, arch_register_class_n_regs(cls), arch_register_class_n_regs(cls));
217 unsigned colors_n = arch_register_class_n_regs(cls);
219 if (get_edge(pbqp, get_irn_idx(src_node), get_irn_idx(trg_node)) == NULL) {
221 /* get exec_freq for copy_block */
222 ir_node *root_bl = get_nodes_block(src_node);
223 ir_node *copy_bl = is_Phi(src_node) ? get_Block_cfgpred_block(root_bl, pos) : root_bl;
224 int res = get_block_execfreq_int(&pbqp_alloc_env->execfreq_factors, copy_bl);
226 /* create afe-matrix */
228 for (row = 0; row < colors_n; row++) {
229 for (col = 0; col < colors_n; col++) {
231 pbqp_matrix_set(afe_matrix, row, col, (num)res);
236 afe_matrix = pbqp_alloc_env->aff_matrix_template;
238 #if DO_USEFUL_OPT || USE_BIPARTIT_MATCHING
239 /* do useful optimization to speed up pbqp solving */
240 if (get_free_regs(restr_nodes, cls, src_node) == 1 && get_free_regs(restr_nodes, cls, trg_node) == 1) {
243 if (get_free_regs(restr_nodes, cls, src_node) == 1 || get_free_regs(restr_nodes, cls, trg_node) == 1) {
244 if (get_free_regs(restr_nodes, cls, src_node) == 1) {
245 unsigned regIdx = vector_get_min_index(get_node(pbqp, get_irn_idx(src_node))->costs);
246 vector_add_matrix_col(get_node(pbqp, get_irn_idx(trg_node))->costs, afe_matrix, regIdx);
249 unsigned regIdx = vector_get_min_index(get_node(pbqp, get_irn_idx(trg_node))->costs);
250 vector_add_matrix_col(get_node(pbqp, get_irn_idx(src_node))->costs, afe_matrix, regIdx);
255 /* insert interference edge */
256 insert_edge(pbqp, src_node, trg_node, afe_matrix);
260 static void create_affinity_edges(ir_node *irn, void *env)
262 be_pbqp_alloc_env_t *pbqp_alloc_env = (be_pbqp_alloc_env_t*)env;
263 const arch_register_class_t *cls = pbqp_alloc_env->cls;
264 const arch_register_req_t *req = arch_get_irn_register_req(irn);
268 if (is_Reg_Phi(irn)) { /* Phis */
269 for (pos = 0, max = get_irn_arity(irn); pos < max; ++pos) {
270 ir_node *arg = get_irn_n(irn, pos);
272 if (!arch_irn_consider_in_reg_alloc(cls, arg))
275 /* no edges to itself */
280 insert_afe_edge(pbqp_alloc_env, irn, arg, pos);
283 else if (is_Perm_Proj(irn)) { /* Perms */
284 ir_node *arg = get_Perm_src(irn);
285 if (!arch_irn_consider_in_reg_alloc(cls, arg))
288 insert_afe_edge(pbqp_alloc_env, irn, arg, -1);
290 else { /* 2-address code */
291 if (is_2addr_code(req)) {
292 const unsigned other = req->other_same;
295 for (i = 0; 1U << i <= other; ++i) {
296 if (other & (1U << i)) {
297 ir_node *other = get_irn_n(skip_Proj(irn), i);
298 if (!arch_irn_consider_in_reg_alloc(cls, other))
301 /* no edges to itself */
306 insert_afe_edge(pbqp_alloc_env, irn, other, i);
313 static void create_pbqp_coloring_instance(ir_node *block, void *data)
315 be_pbqp_alloc_env_t *pbqp_alloc_env = (be_pbqp_alloc_env_t*)data;
316 be_lv_t *lv = pbqp_alloc_env->lv;
317 const arch_register_class_t *cls = pbqp_alloc_env->cls;
318 plist_t *rpeo = pbqp_alloc_env->rpeo;
319 pbqp_t *pbqp_inst = pbqp_alloc_env->pbqp_inst;
320 plist_t *temp_list = plist_new();
322 ir_nodeset_t live_nodes;
323 #if USE_BIPARTIT_MATCHING
324 int *assignment = ALLOCAN(int, cls->n_regs);
326 unsigned *restr_nodes = pbqp_alloc_env->restr_nodes;
327 pqueue_t *restr_nodes_queue = new_pqueue();
328 pqueue_t *queue = new_pqueue();
329 plist_t *sorted_list = plist_new();
330 ir_node *last_element = NULL;
333 /* first, determine the pressure */
334 /* (this is only for compatibility with copymin optimization, it's not needed for pbqp coloring) */
335 create_borders(block, pbqp_alloc_env->env);
337 /* calculate living nodes for the first step */
338 ir_nodeset_init(&live_nodes);
339 be_liveness_end_of_block(lv, cls, block, &live_nodes);
341 /* create pbqp nodes, interference edges and reverse perfect elimination order */
342 sched_foreach_reverse(block, irn) {
343 if (get_irn_mode(irn) == mode_T) {
344 foreach_out_edge(irn, edge) {
345 ir_node *proj = get_edge_src_irn(edge);
346 if (!arch_irn_consider_in_reg_alloc(cls, proj))
349 /* create pbqp source node if it dosn't exist */
350 if (get_node(pbqp_inst, get_irn_idx(proj)) == NULL) {
351 create_pbqp_node(pbqp_alloc_env, proj);
354 /* create nodes and interference edges */
355 foreach_ir_nodeset(&live_nodes, live, iter) {
356 /* create pbqp source node if it dosn't exist */
357 if (get_node(pbqp_inst, get_irn_idx(live)) == NULL) {
358 create_pbqp_node(pbqp_alloc_env, live);
361 /* no edges to itself */
366 insert_ife_edge(pbqp_alloc_env, proj, live);
371 if (arch_irn_consider_in_reg_alloc(cls, irn)) {
372 /* create pbqp source node if it dosn't exist */
373 if (get_node(pbqp_inst, get_irn_idx(irn)) == NULL) {
374 create_pbqp_node(pbqp_alloc_env, irn);
377 /* create nodes and interference edges */
378 foreach_ir_nodeset(&live_nodes, live, iter) {
379 /* create pbqp source node if it dosn't exist */
380 if (get_node(pbqp_inst, get_irn_idx(live)) == NULL) {
381 create_pbqp_node(pbqp_alloc_env, live);
384 /* no edges to itself */
389 /* insert interference edge */
390 insert_ife_edge(pbqp_alloc_env, irn, live);
395 /* get living nodes for next step */
397 be_liveness_transfer(cls, irn, &live_nodes);
400 #if USE_BIPARTIT_MATCHING
401 if (get_irn_mode(irn) == mode_T) {
402 unsigned clique_size = 0;
403 unsigned n_alloc = 0;
404 pbqp_node *clique[cls->n_regs];
405 bipartite_t *bp = bipartite_new(cls->n_regs, cls->n_regs);
407 /* add all proj after a perm to clique */
408 foreach_out_edge(irn, edge) {
409 ir_node *proj = get_edge_src_irn(edge);
411 /* ignore node if it is not necessary for register allocation */
412 if (!arch_irn_consider_in_reg_alloc(cls, proj))
415 /* insert pbqp node into temp rpeo list of this block */
416 plist_insert_front(temp_list, get_node(pbqp_inst, get_irn_idx(proj)));
418 if(is_Perm_Proj(proj)) {
419 /* add proj to clique */
420 pbqp_node *clique_member = get_node(pbqp_inst,proj->node_idx);
421 vector *costs = clique_member->costs;
424 clique[clique_size] = clique_member;
426 for(idx = 0; idx < costs->len; idx++) {
427 if(costs->entries[idx].data != INF_COSTS) {
428 bipartite_add(bp, clique_size, idx);
432 /* increase node counter */
438 if(clique_size > 0) {
439 plist_element_t *listElement;
440 foreach_plist(temp_list, listElement) {
441 pbqp_node *clique_candidate = listElement->data;
443 bool isMember = true;
445 /* clique size not bigger then register class size */
446 if(clique_size >= cls->n_regs) break;
448 for(idx = 0; idx < clique_size; idx++) {
449 pbqp_node *member = clique[idx];
451 if(member == clique_candidate) {
456 if(get_edge(pbqp_inst, member->index, clique_candidate->index) == NULL && get_edge(pbqp_inst, clique_candidate->index, member->index) == NULL) {
462 /* goto next list element if current node is not a member of the clique */
463 if(!isMember) { continue; }
465 /* add candidate to clique */
466 clique[clique_size] = clique_candidate;
468 vector *costs = clique_candidate->costs;
469 for(idx = 0; idx < costs->len; idx++) {
470 if(costs->entries[idx].data != INF_COSTS) {
471 bipartite_add(bp, clique_size, idx);
475 /* increase node counter */
480 /* solve bipartite matching */
481 bipartite_matching(bp, assignment);
484 unsigned nodeIdx = 0;
485 for(nodeIdx = 0; nodeIdx < clique_size; nodeIdx++) {
486 vector *costs = clique[nodeIdx]->costs;
488 for(idx = 0; idx < (int)costs->len; idx++) {
489 if(assignment[nodeIdx] != idx) {
490 costs->entries[idx].data = INF_COSTS;
493 assert(assignment[nodeIdx] >= 0 && "there must have been a register assigned (node not register pressure faithful?)");
500 if (arch_irn_consider_in_reg_alloc(cls, irn)) {
501 plist_insert_front(temp_list, get_node(pbqp_inst, get_irn_idx(irn)));
505 /* order nodes for perfect elimination order */
506 if (get_irn_mode(irn) == mode_T) {
507 bool allHaveIFEdges = true;
508 foreach_out_edge(irn, edge) {
509 ir_node *proj = get_edge_src_irn(edge);
510 if (!arch_irn_consider_in_reg_alloc(cls, proj))
513 /* insert proj node into priority queue (descending by the number of interference edges) */
514 if (get_free_regs(restr_nodes, cls, proj) <= 4) {
515 pqueue_put(restr_nodes_queue, proj, pbqp_alloc_env->ife_edge_num[get_irn_idx(proj)]);
518 pqueue_put(queue, proj, pbqp_alloc_env->ife_edge_num[get_irn_idx(proj)]);
521 /* skip last step if there is no last_element */
522 if(last_element == NULL)
525 /* check if proj has an if edge to last_element (at this time pbqp contains only if edges) */
526 if(get_edge(pbqp_inst, proj->node_idx, last_element->node_idx) == NULL && get_edge(pbqp_inst, last_element->node_idx, proj->node_idx) == NULL) {
527 allHaveIFEdges = false; /* there is no if edge between proj and last_element */
531 if(last_element != NULL && allHaveIFEdges) {
532 if (get_free_regs(restr_nodes, cls, last_element) <= 4) {
533 pqueue_put(restr_nodes_queue, last_element, pbqp_alloc_env->ife_edge_num[get_irn_idx(last_element)]);
536 pqueue_put(queue, last_element, pbqp_alloc_env->ife_edge_num[get_irn_idx(last_element)]);
538 plist_erase(temp_list, plist_find_value(temp_list, get_node(pbqp_inst, last_element->node_idx)));
542 /* first insert all restricted proj nodes */
543 while (!pqueue_empty(restr_nodes_queue)) {
544 ir_node *node = (ir_node*)pqueue_pop_front(restr_nodes_queue);
545 plist_insert_front(sorted_list, get_node(pbqp_inst, get_irn_idx(node)));
548 /* insert proj nodes descending by their number of interference edges */
549 while (!pqueue_empty(queue)) {
550 ir_node *node = (ir_node*)pqueue_pop_front(queue);
551 plist_insert_front(sorted_list, get_node(pbqp_inst, get_irn_idx(node)));
554 /* invert sorted list */
555 foreach_plist(sorted_list, el) {
556 plist_insert_front(temp_list, el->data);
559 plist_clear(sorted_list);
563 if (arch_irn_consider_in_reg_alloc(cls, irn)) {
564 // remember last colorable node
566 plist_insert_front(temp_list, get_node(pbqp_inst, get_irn_idx(irn)));
569 // node not colorable, so ignore it
576 /* add the temp rpeo list of this block to the global reverse perfect elimination order list*/
577 foreach_plist(temp_list, el) {
578 plist_insert_back(rpeo, el->data);
581 /* free reserved memory */
582 ir_nodeset_destroy(&live_nodes);
583 plist_free(temp_list);
584 #if USE_BIPARTIT_MATCHING
586 plist_free(sorted_list);
588 del_pqueue(restr_nodes_queue);
592 static void insert_perms(ir_node *block, void *data)
594 be_chordal_env_t *env = (be_chordal_env_t*)data;
597 for (irn = sched_first(block); !sched_is_end(irn);) {
598 be_insn_t *insn = chordal_scan_insn(env, irn);
599 irn = insn->next_insn;
601 if (!insn->has_constraints)
604 pre_process_constraints(env, &insn);
608 static void be_pbqp_coloring(be_chordal_env_t *env)
610 ir_graph *irg = env->irg;
611 const arch_register_class_t *cls = env->cls;
613 plist_element_t *element = NULL;
614 unsigned colors_n = arch_register_class_n_regs(cls);
615 be_pbqp_alloc_env_t pbqp_alloc_env;
618 pbqp_matrix_t *ife_matrix;
624 ir_timer_t *t_ra_pbqp_alloc_create = ir_timer_new();
625 ir_timer_t *t_ra_pbqp_alloc_solve = ir_timer_new();
626 ir_timer_t *t_ra_pbqp_alloc_create_aff = ir_timer_new();
628 printf("#### ----- === Allocating registers of %s (%s) ===\n", cls->name, get_entity_name(get_irg_entity(irg)));
630 be_assure_live_sets(irg);
631 lv = be_get_irg_liveness(irg);
635 dom_tree_walk_irg(irg, insert_perms, NULL, env);
637 /* dump graph after inserting perms */
638 if (env->opts->dump_flags & BE_CH_DUMP_CONSTR) {
640 snprintf(buf, sizeof(buf), "-%s-constr", cls->name);
641 dump_ir_graph(irg, buf);
644 ir_calculate_execfreq_int_factors(&pbqp_alloc_env.execfreq_factors, irg);
646 /* initialize pbqp allocation data structure */
647 pbqp_alloc_env.pbqp_inst = alloc_pbqp(get_irg_last_idx(irg)); /* initialize pbqp instance */
648 pbqp_alloc_env.cls = cls;
649 pbqp_alloc_env.irg = irg;
650 pbqp_alloc_env.lv = lv;
651 pbqp_alloc_env.allocatable_regs = bitset_malloc(colors_n);
652 pbqp_alloc_env.rpeo = plist_new();
653 pbqp_alloc_env.restr_nodes = XMALLOCNZ(unsigned, get_irg_last_idx(irg));
654 pbqp_alloc_env.ife_edge_num = XMALLOCNZ(unsigned, get_irg_last_idx(irg));
655 pbqp_alloc_env.env = env;
656 be_put_allocatable_regs(irg, cls, pbqp_alloc_env.allocatable_regs);
659 /* create costs matrix template for interference edges */
660 ife_matrix = pbqp_matrix_alloc(pbqp_alloc_env.pbqp_inst, colors_n, colors_n);
662 for (row = 0, col = 0; row < colors_n; row++, col++)
663 pbqp_matrix_set(ife_matrix, row, col, INF_COSTS);
665 pbqp_alloc_env.ife_matrix_template = ife_matrix;
668 if (!use_exec_freq) {
669 /* create costs matrix template for affinity edges */
670 pbqp_matrix_t *afe_matrix = pbqp_matrix_alloc(pbqp_alloc_env.pbqp_inst, colors_n, colors_n);
672 for (row = 0; row < colors_n; row++) {
673 for (col = 0; col < colors_n; col++) {
675 pbqp_matrix_set(afe_matrix, row, col, 2);
678 pbqp_alloc_env.aff_matrix_template = afe_matrix;
682 /* create pbqp instance */
684 ir_timer_reset_and_start(t_ra_pbqp_alloc_create);
687 dom_tree_walk_irg(irg, create_pbqp_coloring_instance , NULL, &pbqp_alloc_env);
689 ir_timer_stop(t_ra_pbqp_alloc_create);
693 /* set up affinity edges */
695 ir_timer_reset_and_start(t_ra_pbqp_alloc_create_aff);
697 foreach_plist(pbqp_alloc_env.rpeo, element) {
698 pbqp_node_t *node = (pbqp_node_t*)element->data;
699 ir_node *irn = get_idx_irn(irg, node->index);
701 create_affinity_edges(irn, &pbqp_alloc_env);
704 ir_timer_stop(t_ra_pbqp_alloc_create_aff);
709 // dump graph before solving pbqp
710 file_before = my_open(env, "", "-pbqp_coloring.html");
711 set_dumpfile(pbqp_alloc_env.pbqp_inst, file_before);
714 /* print out reverse perfect elimination order */
717 plist_element_t *elements;
718 foreach_plist(pbqp_alloc_env.rpeo, elements) {
719 pbqp_node_t *node = elements->data;
720 printf(" %d(%ld);", node->index, get_idx_irn(irg, node->index)->node_nr);
726 /* solve pbqp instance */
728 ir_timer_reset_and_start(t_ra_pbqp_alloc_solve);
730 if(use_late_decision) {
731 solve_pbqp_heuristical_co_ld(pbqp_alloc_env.pbqp_inst,pbqp_alloc_env.rpeo);
734 solve_pbqp_heuristical_co(pbqp_alloc_env.pbqp_inst,pbqp_alloc_env.rpeo);
737 ir_timer_stop(t_ra_pbqp_alloc_solve);
741 solution = get_solution(pbqp_alloc_env.pbqp_inst);
742 if (solution == INF_COSTS)
743 panic("No PBQP solution found");
747 foreach_plist(pbqp_alloc_env.rpeo, element) {
748 pbqp_node_t *node = (pbqp_node_t*)element->data;
749 ir_node *irn = get_idx_irn(irg, node->index);
750 num color = get_node_solution(pbqp_alloc_env.pbqp_inst, node->index);
751 const arch_register_t *reg = arch_register_for_index(cls, color);
753 arch_set_irn_register(irn, reg);
758 printf("PBQP alloc create: %10.3lf msec\n",
759 (double)ir_timer_elapsed_usec(t_ra_pbqp_alloc_create) / 1000.0);
760 printf("PBQP alloc solve: %10.3lf msec\n",
761 (double)ir_timer_elapsed_usec(t_ra_pbqp_alloc_solve) / 1000.0);
762 printf("PBQP alloc create aff: %10.3lf msec\n",
763 (double)ir_timer_elapsed_usec(t_ra_pbqp_alloc_create_aff) / 1000.0);
767 /* free reserved memory */
771 bitset_free(pbqp_alloc_env.allocatable_regs);
772 free_pbqp(pbqp_alloc_env.pbqp_inst);
773 plist_free(pbqp_alloc_env.rpeo);
774 xfree(pbqp_alloc_env.restr_nodes);
775 xfree(pbqp_alloc_env.ife_edge_num);
780 * Initializes this module.
782 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_pbqp_coloring)
783 void be_init_pbqp_coloring(void)
785 lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
786 lc_opt_entry_t *ra_grp = lc_opt_get_grp(be_grp, "ra");
787 lc_opt_entry_t *chordal_grp = lc_opt_get_grp(ra_grp, "chordal");
788 lc_opt_entry_t *coloring_grp = lc_opt_get_grp(chordal_grp, "coloring");
789 lc_opt_entry_t *pbqp_grp = lc_opt_get_grp(coloring_grp, "pbqp");
791 static be_ra_chordal_coloring_t coloring = {
795 lc_opt_add_table(pbqp_grp, options);
796 be_register_chordal_coloring("pbqp", &coloring);