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"
41 /* libfirm/ir/adt includes */
42 #include "bipartite.h"
44 /* libfirm/ir/be includes */
49 #include "bechordal_common.h"
50 #include "bechordal.h"
51 #include "bechordal_t.h"
59 #include "becopyopt.h"
66 #include "heuristical_co.h"
67 #include "heuristical_co_ld.h"
69 #include "html_dumper.h"
70 #include "pbqp_node_t.h"
71 #include "pbqp_node.h"
72 #include "pbqp_edge_t.h"
76 #define USE_BIPARTIT_MATCHING 0
77 #define DO_USEFUL_OPT 1
80 static int use_exec_freq = true;
81 static int use_late_decision = false;
83 typedef struct be_pbqp_alloc_env_t {
84 pbqp_t *pbqp_inst; /**< PBQP instance for register allocation */
85 ir_graph *irg; /**< The graph under examination. */
86 const arch_register_class_t *cls; /**< Current processed register class */
88 bitset_t *allocatable_regs;
89 pbqp_matrix_t *ife_matrix_template;
90 pbqp_matrix_t *aff_matrix_template;
92 unsigned *restr_nodes;
93 unsigned *ife_edge_num;
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 ir_exec_freq *exec_freq = be_get_irg_exec_freq(pbqp_alloc_env->irg);
225 unsigned long res = get_block_execfreq_ulong(exec_freq, copy_bl);
227 /* create afe-matrix */
229 for (row = 0; row < colors_n; row++) {
230 for (col = 0; col < colors_n; col++) {
232 pbqp_matrix_set(afe_matrix, row, col, (num)res);
237 afe_matrix = pbqp_alloc_env->aff_matrix_template;
239 #if DO_USEFUL_OPT || USE_BIPARTIT_MATCHING
240 /* do useful optimization to speed up pbqp solving */
241 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 || get_free_regs(restr_nodes, cls, trg_node) == 1) {
245 if (get_free_regs(restr_nodes, cls, src_node) == 1) {
246 unsigned regIdx = vector_get_min_index(get_node(pbqp, get_irn_idx(src_node))->costs);
247 vector_add_matrix_col(get_node(pbqp, get_irn_idx(trg_node))->costs, afe_matrix, regIdx);
250 unsigned regIdx = vector_get_min_index(get_node(pbqp, get_irn_idx(trg_node))->costs);
251 vector_add_matrix_col(get_node(pbqp, get_irn_idx(src_node))->costs, afe_matrix, regIdx);
256 /* insert interference edge */
257 insert_edge(pbqp, src_node, trg_node, afe_matrix);
261 static void create_affinity_edges(ir_node *irn, void *env)
263 be_pbqp_alloc_env_t *pbqp_alloc_env = (be_pbqp_alloc_env_t*)env;
264 const arch_register_class_t *cls = pbqp_alloc_env->cls;
265 const arch_register_req_t *req = arch_get_irn_register_req(irn);
269 if (is_Reg_Phi(irn)) { /* Phis */
270 for (pos = 0, max = get_irn_arity(irn); pos < max; ++pos) {
271 ir_node *arg = get_irn_n(irn, pos);
273 if (!arch_irn_consider_in_reg_alloc(cls, arg))
276 /* no edges to itself */
281 insert_afe_edge(pbqp_alloc_env, irn, arg, pos);
284 else if (is_Perm_Proj(irn)) { /* Perms */
285 ir_node *arg = get_Perm_src(irn);
286 if (!arch_irn_consider_in_reg_alloc(cls, arg))
289 insert_afe_edge(pbqp_alloc_env, irn, arg, -1);
291 else { /* 2-address code */
292 if (is_2addr_code(req)) {
293 const unsigned other = req->other_same;
296 for (i = 0; 1U << i <= other; ++i) {
297 if (other & (1U << i)) {
298 ir_node *other = get_irn_n(skip_Proj(irn), i);
299 if (!arch_irn_consider_in_reg_alloc(cls, other))
302 /* no edges to itself */
307 insert_afe_edge(pbqp_alloc_env, irn, other, i);
314 static void create_pbqp_coloring_instance(ir_node *block, void *data)
316 be_pbqp_alloc_env_t *pbqp_alloc_env = (be_pbqp_alloc_env_t*)data;
317 be_lv_t *lv = pbqp_alloc_env->lv;
318 const arch_register_class_t *cls = pbqp_alloc_env->cls;
319 plist_t *rpeo = pbqp_alloc_env->rpeo;
320 pbqp_t *pbqp_inst = pbqp_alloc_env->pbqp_inst;
321 plist_t *temp_list = plist_new();
324 ir_nodeset_t live_nodes;
325 #if USE_BIPARTIT_MATCHING
326 int *assignment = ALLOCAN(int, cls->n_regs);
328 unsigned *restr_nodes = pbqp_alloc_env->restr_nodes;
329 pqueue_t *restr_nodes_queue = new_pqueue();
330 pqueue_t *queue = new_pqueue();
331 plist_t *sorted_list = plist_new();
332 ir_node *last_element = NULL;
335 /* first, determine the pressure */
336 /* (this is only for compatibility with copymin optimization, it's not needed for pbqp coloring) */
337 create_borders(block, pbqp_alloc_env->env);
339 /* calculate living nodes for the first step */
340 ir_nodeset_init(&live_nodes);
341 be_liveness_end_of_block(lv, cls, block, &live_nodes);
343 /* create pbqp nodes, interference edges and reverse perfect elimination order */
344 sched_foreach_reverse(block, irn) {
346 ir_nodeset_iterator_t iter;
348 if (get_irn_mode(irn) == mode_T) {
349 const ir_edge_t *edge;
350 foreach_out_edge(irn, edge) {
351 ir_node *proj = get_edge_src_irn(edge);
352 if (!arch_irn_consider_in_reg_alloc(cls, proj))
355 /* create pbqp source node if it dosn't exist */
356 if (get_node(pbqp_inst, get_irn_idx(proj)) == NULL) {
357 create_pbqp_node(pbqp_alloc_env, proj);
360 /* create nodes and interference edges */
361 foreach_ir_nodeset(&live_nodes, live, iter) {
362 /* create pbqp source node if it dosn't exist */
363 if (get_node(pbqp_inst, get_irn_idx(live)) == NULL) {
364 create_pbqp_node(pbqp_alloc_env, live);
367 /* no edges to itself */
372 insert_ife_edge(pbqp_alloc_env, proj, live);
377 if (arch_irn_consider_in_reg_alloc(cls, irn)) {
378 /* create pbqp source node if it dosn't exist */
379 if (get_node(pbqp_inst, get_irn_idx(irn)) == NULL) {
380 create_pbqp_node(pbqp_alloc_env, irn);
383 /* create nodes and interference edges */
384 foreach_ir_nodeset(&live_nodes, live, iter) {
385 /* create pbqp source node if it dosn't exist */
386 if (get_node(pbqp_inst, get_irn_idx(live)) == NULL) {
387 create_pbqp_node(pbqp_alloc_env, live);
390 /* no edges to itself */
395 /* insert interference edge */
396 insert_ife_edge(pbqp_alloc_env, irn, live);
401 /* get living nodes for next step */
403 be_liveness_transfer(cls, irn, &live_nodes);
406 #if USE_BIPARTIT_MATCHING
407 if (get_irn_mode(irn) == mode_T) {
408 unsigned clique_size = 0;
409 unsigned n_alloc = 0;
410 pbqp_node *clique[cls->n_regs];
411 bipartite_t *bp = bipartite_new(cls->n_regs, cls->n_regs);
413 /* add all proj after a perm to clique */
414 const ir_edge_t *edge;
415 foreach_out_edge(irn, edge) {
416 ir_node *proj = get_edge_src_irn(edge);
418 /* ignore node if it is not necessary for register allocation */
419 if (!arch_irn_consider_in_reg_alloc(cls, proj))
422 /* insert pbqp node into temp rpeo list of this block */
423 plist_insert_front(temp_list, get_node(pbqp_inst, get_irn_idx(proj)));
425 if(is_Perm_Proj(proj)) {
426 /* add proj to clique */
427 pbqp_node *clique_member = get_node(pbqp_inst,proj->node_idx);
428 vector *costs = clique_member->costs;
431 clique[clique_size] = clique_member;
433 for(idx = 0; idx < costs->len; idx++) {
434 if(costs->entries[idx].data != INF_COSTS) {
435 bipartite_add(bp, clique_size, idx);
439 /* increase node counter */
445 if(clique_size > 0) {
446 plist_element_t *listElement;
447 foreach_plist(temp_list, listElement) {
448 pbqp_node *clique_candidate = listElement->data;
450 bool isMember = true;
452 /* clique size not bigger then register class size */
453 if(clique_size >= cls->n_regs) break;
455 for(idx = 0; idx < clique_size; idx++) {
456 pbqp_node *member = clique[idx];
458 if(member == clique_candidate) {
463 if(get_edge(pbqp_inst, member->index, clique_candidate->index) == NULL && get_edge(pbqp_inst, clique_candidate->index, member->index) == NULL) {
469 /* goto next list element if current node is not a member of the clique */
470 if(!isMember) { continue; }
472 /* add candidate to clique */
473 clique[clique_size] = clique_candidate;
475 vector *costs = clique_candidate->costs;
476 for(idx = 0; idx < costs->len; idx++) {
477 if(costs->entries[idx].data != INF_COSTS) {
478 bipartite_add(bp, clique_size, idx);
482 /* increase node counter */
487 /* solve bipartite matching */
488 bipartite_matching(bp, assignment);
491 unsigned nodeIdx = 0;
492 for(nodeIdx = 0; nodeIdx < clique_size; nodeIdx++) {
493 vector *costs = clique[nodeIdx]->costs;
495 for(idx = 0; idx < (int)costs->len; idx++) {
496 if(assignment[nodeIdx] != idx) {
497 costs->entries[idx].data = INF_COSTS;
500 assert(assignment[nodeIdx] >= 0 && "there must have been a register assigned (node not register pressure faithful?)");
507 if (arch_irn_consider_in_reg_alloc(cls, irn)) {
508 plist_insert_front(temp_list, get_node(pbqp_inst, get_irn_idx(irn)));
512 /* order nodes for perfect elimination order */
513 if (get_irn_mode(irn) == mode_T) {
514 bool allHaveIFEdges = true;
515 const ir_edge_t *edge;
517 foreach_out_edge(irn, edge) {
518 ir_node *proj = get_edge_src_irn(edge);
519 if (!arch_irn_consider_in_reg_alloc(cls, proj))
522 /* insert proj node into priority queue (descending by the number of interference edges) */
523 if (get_free_regs(restr_nodes, cls, proj) <= 4) {
524 pqueue_put(restr_nodes_queue, proj, pbqp_alloc_env->ife_edge_num[get_irn_idx(proj)]);
527 pqueue_put(queue, proj, pbqp_alloc_env->ife_edge_num[get_irn_idx(proj)]);
530 /* skip last step if there is no last_element */
531 if(last_element == NULL)
534 /* check if proj has an if edge to last_element (at this time pbqp contains only if edges) */
535 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) {
536 allHaveIFEdges = false; /* there is no if edge between proj and last_element */
540 if(last_element != NULL && allHaveIFEdges) {
541 if (get_free_regs(restr_nodes, cls, last_element) <= 4) {
542 pqueue_put(restr_nodes_queue, last_element, pbqp_alloc_env->ife_edge_num[get_irn_idx(last_element)]);
545 pqueue_put(queue, last_element, pbqp_alloc_env->ife_edge_num[get_irn_idx(last_element)]);
547 plist_erase(temp_list, plist_find_value(temp_list, get_node(pbqp_inst, last_element->node_idx)));
551 /* first insert all restricted proj nodes */
552 while (!pqueue_empty(restr_nodes_queue)) {
553 ir_node *node = (ir_node*)pqueue_pop_front(restr_nodes_queue);
554 plist_insert_front(sorted_list, get_node(pbqp_inst, get_irn_idx(node)));
557 /* insert proj nodes descending by their number of interference edges */
558 while (!pqueue_empty(queue)) {
559 ir_node *node = (ir_node*)pqueue_pop_front(queue);
560 plist_insert_front(sorted_list, get_node(pbqp_inst, get_irn_idx(node)));
563 /* invert sorted list */
564 foreach_plist(sorted_list, el) {
565 plist_insert_front(temp_list, el->data);
568 plist_clear(sorted_list);
572 if (arch_irn_consider_in_reg_alloc(cls, irn)) {
573 // remember last colorable node
575 plist_insert_front(temp_list, get_node(pbqp_inst, get_irn_idx(irn)));
578 // node not colorable, so ignore it
585 /* add the temp rpeo list of this block to the global reverse perfect elimination order list*/
586 foreach_plist(temp_list, el) {
587 plist_insert_back(rpeo, el->data);
590 /* free reserved memory */
591 ir_nodeset_destroy(&live_nodes);
592 plist_free(temp_list);
593 #if USE_BIPARTIT_MATCHING
595 plist_free(sorted_list);
597 del_pqueue(restr_nodes_queue);
601 static void insert_perms(ir_node *block, void *data)
603 be_chordal_env_t *env = (be_chordal_env_t*)data;
606 for (irn = sched_first(block); !sched_is_end(irn);) {
607 be_insn_t *insn = chordal_scan_insn(env, irn);
608 irn = insn->next_insn;
610 if (!insn->has_constraints)
613 pre_process_constraints(env, &insn);
617 static void be_pbqp_coloring(be_chordal_env_t *env)
619 ir_graph *irg = env->irg;
620 const arch_register_class_t *cls = env->cls;
622 plist_element_t *element = NULL;
623 unsigned colors_n = arch_register_class_n_regs(cls);
624 be_pbqp_alloc_env_t pbqp_alloc_env;
627 pbqp_matrix_t *ife_matrix;
633 ir_timer_t *t_ra_pbqp_alloc_create = ir_timer_new();
634 ir_timer_t *t_ra_pbqp_alloc_solve = ir_timer_new();
635 ir_timer_t *t_ra_pbqp_alloc_create_aff = ir_timer_new();
637 printf("#### ----- === Allocating registers of %s (%s) ===\n", cls->name, get_entity_name(get_irg_entity(irg)));
639 be_assure_live_sets(irg);
640 lv = be_get_irg_liveness(irg);
644 dom_tree_walk_irg(irg, insert_perms, NULL, env);
646 /* dump graph after inserting perms */
647 if (env->opts->dump_flags & BE_CH_DUMP_CONSTR) {
649 snprintf(buf, sizeof(buf), "-%s-constr", cls->name);
650 dump_ir_graph(irg, buf);
654 /* initialize pbqp allocation data structure */
655 pbqp_alloc_env.pbqp_inst = alloc_pbqp(get_irg_last_idx(irg)); /* initialize pbqp instance */
656 pbqp_alloc_env.cls = cls;
657 pbqp_alloc_env.irg = irg;
658 pbqp_alloc_env.lv = lv;
659 pbqp_alloc_env.allocatable_regs = bitset_malloc(colors_n);
660 pbqp_alloc_env.rpeo = plist_new();
661 pbqp_alloc_env.restr_nodes = XMALLOCNZ(unsigned, get_irg_last_idx(irg));
662 pbqp_alloc_env.ife_edge_num = XMALLOCNZ(unsigned, get_irg_last_idx(irg));
663 pbqp_alloc_env.env = env;
664 be_put_allocatable_regs(irg, cls, pbqp_alloc_env.allocatable_regs);
667 /* create costs matrix template for interference edges */
668 ife_matrix = pbqp_matrix_alloc(pbqp_alloc_env.pbqp_inst, colors_n, colors_n);
670 for (row = 0, col = 0; row < colors_n; row++, col++)
671 pbqp_matrix_set(ife_matrix, row, col, INF_COSTS);
673 pbqp_alloc_env.ife_matrix_template = ife_matrix;
676 if (!use_exec_freq) {
677 /* create costs matrix template for affinity edges */
678 pbqp_matrix_t *afe_matrix = pbqp_matrix_alloc(pbqp_alloc_env.pbqp_inst, colors_n, colors_n);
680 for (row = 0; row < colors_n; row++) {
681 for (col = 0; col < colors_n; col++) {
683 pbqp_matrix_set(afe_matrix, row, col, 2);
686 pbqp_alloc_env.aff_matrix_template = afe_matrix;
690 /* create pbqp instance */
692 ir_timer_reset_and_start(t_ra_pbqp_alloc_create);
695 dom_tree_walk_irg(irg, create_pbqp_coloring_instance , NULL, &pbqp_alloc_env);
697 ir_timer_stop(t_ra_pbqp_alloc_create);
701 /* set up affinity edges */
703 ir_timer_reset_and_start(t_ra_pbqp_alloc_create_aff);
705 foreach_plist(pbqp_alloc_env.rpeo, element) {
706 pbqp_node_t *node = (pbqp_node_t*)element->data;
707 ir_node *irn = get_idx_irn(irg, node->index);
709 create_affinity_edges(irn, &pbqp_alloc_env);
712 ir_timer_stop(t_ra_pbqp_alloc_create_aff);
717 // dump graph before solving pbqp
718 file_before = my_open(env, "", "-pbqp_coloring.html");
719 set_dumpfile(pbqp_alloc_env.pbqp_inst, file_before);
722 /* print out reverse perfect elimination order */
725 plist_element_t *elements;
726 foreach_plist(pbqp_alloc_env.rpeo, elements) {
727 pbqp_node_t *node = elements->data;
728 printf(" %d(%ld);", node->index, get_idx_irn(irg, node->index)->node_nr);
734 /* solve pbqp instance */
736 ir_timer_reset_and_start(t_ra_pbqp_alloc_solve);
738 if(use_late_decision) {
739 solve_pbqp_heuristical_co_ld(pbqp_alloc_env.pbqp_inst,pbqp_alloc_env.rpeo);
742 solve_pbqp_heuristical_co(pbqp_alloc_env.pbqp_inst,pbqp_alloc_env.rpeo);
745 ir_timer_stop(t_ra_pbqp_alloc_solve);
749 solution = get_solution(pbqp_alloc_env.pbqp_inst);
750 if (solution == INF_COSTS)
751 panic("No PBQP solution found");
755 foreach_plist(pbqp_alloc_env.rpeo, element) {
756 pbqp_node_t *node = (pbqp_node_t*)element->data;
757 ir_node *irn = get_idx_irn(irg, node->index);
758 num color = get_node_solution(pbqp_alloc_env.pbqp_inst, node->index);
759 const arch_register_t *reg = arch_register_for_index(cls, color);
761 arch_set_irn_register(irn, reg);
766 printf("PBQP alloc create: %10.3lf msec\n",
767 (double)ir_timer_elapsed_usec(t_ra_pbqp_alloc_create) / 1000.0);
768 printf("PBQP alloc solve: %10.3lf msec\n",
769 (double)ir_timer_elapsed_usec(t_ra_pbqp_alloc_solve) / 1000.0);
770 printf("PBQP alloc create aff: %10.3lf msec\n",
771 (double)ir_timer_elapsed_usec(t_ra_pbqp_alloc_create_aff) / 1000.0);
775 /* free reserved memory */
779 bitset_free(pbqp_alloc_env.allocatable_regs);
780 free_pbqp(pbqp_alloc_env.pbqp_inst);
781 plist_free(pbqp_alloc_env.rpeo);
782 xfree(pbqp_alloc_env.restr_nodes);
783 xfree(pbqp_alloc_env.ife_edge_num);
788 * Initializes this module.
790 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_pbqp_coloring)
791 void be_init_pbqp_coloring(void)
793 lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
794 lc_opt_entry_t *ra_grp = lc_opt_get_grp(be_grp, "ra");
795 lc_opt_entry_t *chordal_grp = lc_opt_get_grp(ra_grp, "chordal");
796 lc_opt_entry_t *coloring_grp = lc_opt_get_grp(chordal_grp, "coloring");
797 lc_opt_entry_t *pbqp_grp = lc_opt_get_grp(coloring_grp, "pbqp");
799 static be_ra_chordal_coloring_t coloring = {
803 lc_opt_add_table(pbqp_grp, options);
804 be_register_chordal_coloring("pbqp", &coloring);