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
25 * @version $Id: bechordal.c 26750 2009-11-27 09:37:43Z bersch $
28 /* miscellaneous includes */
36 #include "iredges_t.h"
42 /* libfirm/ir/adt includes */
43 #include "bipartite.h"
45 /* libfirm/ir/be includes */
50 #include "bechordal_common.h"
51 #include "bechordal.h"
52 #include "bechordal_t.h"
60 #include "becopyopt.h"
67 #include "heuristical_co.h"
68 #include "heuristical_co_ld.h"
70 #include "html_dumper.h"
71 #include "pbqp_node_t.h"
72 #include "pbqp_node.h"
73 #include "pbqp_edge_t.h"
77 #define USE_BIPARTIT_MATCHING 0
78 #define DO_USEFUL_OPT 1
81 static int use_exec_freq = true;
82 static int use_late_decision = false;
84 typedef struct be_pbqp_alloc_env_t {
85 pbqp_t *pbqp_inst; /**< PBQP instance for register allocation */
86 ir_graph *irg; /**< The graph under examination. */
87 const arch_register_class_t *cls; /**< Current processed register class */
89 bitset_t *allocatable_regs;
90 pbqp_matrix_t *ife_matrix_template;
91 pbqp_matrix_t *aff_matrix_template;
93 unsigned *restr_nodes;
94 unsigned *ife_edge_num;
95 be_chordal_env_t *env;
96 } be_pbqp_alloc_env_t;
99 #define is_Reg_Phi(irn) (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
100 #define get_Perm_src(irn) (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
101 #define is_Perm_Proj(irn) (is_Proj(irn) && be_is_Perm(get_Proj_pred(irn)))
102 #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)))
103 #define get_free_regs(restr_nodes, cls, irn) (arch_register_class_n_regs(cls) - restr_nodes[get_irn_idx(irn)])
105 static inline int is_2addr_code(const arch_register_req_t *req)
107 return (req->type & arch_register_req_type_should_be_same) != 0;
110 static const lc_opt_table_entry_t options[] = {
111 LC_OPT_ENT_BOOL("exec_freq", "use exec_freq", &use_exec_freq),
112 LC_OPT_ENT_BOOL("late_decision", "use late decision for register allocation", &use_late_decision),
117 static FILE *my_open(const be_chordal_env_t *env, const char *prefix, const char *suffix)
124 const char *cup_name = be_get_irg_main_env(env->irg)->cup_name;
126 n = strlen(cup_name);
127 tu_name = XMALLOCN(char, n + 1);
128 strcpy(tu_name, cup_name);
129 for (i = 0; i < n; ++i)
130 if (tu_name[i] == '.')
133 ir_snprintf(buf, sizeof(buf), "%s%s_%F_%s%s", prefix, tu_name, env->irg, env->cls->name, suffix);
135 result = fopen(buf, "wt");
136 if (result == NULL) {
137 panic("Couldn't open '%s' for writing.", buf);
145 static void create_pbqp_node(be_pbqp_alloc_env_t *pbqp_alloc_env, ir_node *irn)
147 const arch_register_class_t *cls = pbqp_alloc_env->cls;
148 pbqp_t *pbqp_inst = pbqp_alloc_env->pbqp_inst;
149 bitset_t *allocatable_regs = pbqp_alloc_env->allocatable_regs;
150 unsigned colors_n = arch_register_class_n_regs(cls);
151 unsigned cntConstrains = 0;
153 /* create costs vector depending on register constrains */
154 vector_t *costs_vector = vector_alloc(pbqp_inst, colors_n);
156 /* set costs depending on register constrains */
158 for (idx = 0; idx < colors_n; idx++) {
159 const arch_register_req_t *req = arch_get_irn_register_req(irn);
160 const arch_register_t *reg = arch_register_for_index(cls, idx);
161 if (!bitset_is_set(allocatable_regs, idx)
162 || !arch_reg_is_allocatable(req, reg)) {
164 vector_set(costs_vector, idx, INF_COSTS);
169 /* add vector to pbqp node */
170 add_node_costs(pbqp_inst, get_irn_idx(irn), costs_vector);
171 pbqp_alloc_env->restr_nodes[get_irn_idx(irn)] = cntConstrains;
174 static void insert_ife_edge(be_pbqp_alloc_env_t *pbqp_alloc_env, ir_node *src_node, ir_node *trg_node)
176 pbqp_t *pbqp = pbqp_alloc_env->pbqp_inst;
177 const arch_register_class_t *cls = pbqp_alloc_env->cls;
178 pbqp_matrix_t *ife_matrix_template = pbqp_alloc_env->ife_matrix_template;
179 unsigned *restr_nodes = pbqp_alloc_env->restr_nodes;
181 if (get_edge(pbqp, get_irn_idx(src_node), get_irn_idx(trg_node)) == NULL) {
183 /* increase ife edge counter */
184 pbqp_alloc_env->ife_edge_num[get_irn_idx(src_node)]++;
185 pbqp_alloc_env->ife_edge_num[get_irn_idx(trg_node)]++;
187 #if DO_USEFUL_OPT || USE_BIPARTIT_MATCHING
188 /* do useful optimization to speed up pbqp solving (we can do this because we know our matrix) */
189 if (get_free_regs(restr_nodes, cls, src_node) == 1 && get_free_regs(restr_nodes, cls, trg_node) == 1) {
190 assert(vector_get_min_index(get_node(pbqp, get_irn_idx(src_node))->costs) !=
191 vector_get_min_index(get_node(pbqp, get_irn_idx(trg_node))->costs) &&
192 "Interfering nodes must not have the same register!");
195 if (get_free_regs(restr_nodes, cls, src_node) == 1 || get_free_regs(restr_nodes, cls, trg_node) == 1) {
196 if (get_free_regs(restr_nodes, cls, src_node) == 1) {
197 unsigned idx = vector_get_min_index(get_node(pbqp, get_irn_idx(src_node))->costs);
198 vector_set(get_node(pbqp, get_irn_idx(trg_node))->costs, idx, INF_COSTS);
201 unsigned idx = vector_get_min_index(get_node(pbqp, get_irn_idx(trg_node))->costs);
202 vector_set(get_node(pbqp, get_irn_idx(src_node))->costs, idx, INF_COSTS);
207 /* insert interference edge */
208 insert_edge(pbqp, src_node, trg_node, ife_matrix_template);
212 static void insert_afe_edge(be_pbqp_alloc_env_t *pbqp_alloc_env, ir_node *src_node, ir_node *trg_node, int pos)
214 pbqp_t *pbqp = pbqp_alloc_env->pbqp_inst;
215 const arch_register_class_t *cls = pbqp_alloc_env->cls;
216 unsigned *restr_nodes = pbqp_alloc_env->restr_nodes;
217 pbqp_matrix_t *afe_matrix = pbqp_matrix_alloc(pbqp, arch_register_class_n_regs(cls), arch_register_class_n_regs(cls));
218 unsigned colors_n = arch_register_class_n_regs(cls);
220 if (get_edge(pbqp, get_irn_idx(src_node), get_irn_idx(trg_node)) == NULL) {
222 /* get exec_freq for copy_block */
223 ir_node *root_bl = get_nodes_block(src_node);
224 ir_node *copy_bl = is_Phi(src_node) ? get_Block_cfgpred_block(root_bl, pos) : root_bl;
225 ir_exec_freq *exec_freq = be_get_irg_exec_freq(pbqp_alloc_env->irg);
226 unsigned long res = get_block_execfreq_ulong(exec_freq, copy_bl);
228 /* create afe-matrix */
230 for (row = 0; row < colors_n; row++) {
231 for (col = 0; col < colors_n; col++) {
233 pbqp_matrix_set(afe_matrix, row, col, (num)res);
238 afe_matrix = pbqp_alloc_env->aff_matrix_template;
240 #if DO_USEFUL_OPT || USE_BIPARTIT_MATCHING
241 /* do useful optimization to speed up pbqp solving */
242 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 || get_free_regs(restr_nodes, cls, trg_node) == 1) {
246 if (get_free_regs(restr_nodes, cls, src_node) == 1) {
247 unsigned regIdx = vector_get_min_index(get_node(pbqp, get_irn_idx(src_node))->costs);
248 vector_add_matrix_col(get_node(pbqp, get_irn_idx(trg_node))->costs, afe_matrix, regIdx);
251 unsigned regIdx = vector_get_min_index(get_node(pbqp, get_irn_idx(trg_node))->costs);
252 vector_add_matrix_col(get_node(pbqp, get_irn_idx(src_node))->costs, afe_matrix, regIdx);
257 /* insert interference edge */
258 insert_edge(pbqp, src_node, trg_node, afe_matrix);
262 static void create_affinity_edges(ir_node *irn, void *env)
264 be_pbqp_alloc_env_t *pbqp_alloc_env = (be_pbqp_alloc_env_t*)env;
265 const arch_register_class_t *cls = pbqp_alloc_env->cls;
266 const arch_register_req_t *req = arch_get_irn_register_req(irn);
270 if (is_Reg_Phi(irn)) { /* Phis */
271 for (pos = 0, max = get_irn_arity(irn); pos < max; ++pos) {
272 ir_node *arg = get_irn_n(irn, pos);
274 if (!arch_irn_consider_in_reg_alloc(cls, arg))
277 /* no edges to itself */
282 insert_afe_edge(pbqp_alloc_env, irn, arg, pos);
285 else if (is_Perm_Proj(irn)) { /* Perms */
286 ir_node *arg = get_Perm_src(irn);
287 if (!arch_irn_consider_in_reg_alloc(cls, arg))
290 insert_afe_edge(pbqp_alloc_env, irn, arg, -1);
292 else { /* 2-address code */
293 if (is_2addr_code(req)) {
294 const unsigned other = req->other_same;
297 for (i = 0; 1U << i <= other; ++i) {
298 if (other & (1U << i)) {
299 ir_node *other = get_irn_n(skip_Proj(irn), i);
300 if (!arch_irn_consider_in_reg_alloc(cls, other))
303 /* no edges to itself */
308 insert_afe_edge(pbqp_alloc_env, irn, other, i);
315 static void create_pbqp_coloring_instance(ir_node *block, void *data)
317 be_pbqp_alloc_env_t *pbqp_alloc_env = (be_pbqp_alloc_env_t*)data;
318 be_lv_t *lv = pbqp_alloc_env->lv;
319 const arch_register_class_t *cls = pbqp_alloc_env->cls;
320 plist_t *rpeo = pbqp_alloc_env->rpeo;
321 pbqp_t *pbqp_inst = pbqp_alloc_env->pbqp_inst;
322 plist_t *temp_list = plist_new();
325 ir_nodeset_t live_nodes;
326 #if USE_BIPARTIT_MATCHING
327 int *assignment = ALLOCAN(int, cls->n_regs);
329 unsigned *restr_nodes = pbqp_alloc_env->restr_nodes;
330 pqueue_t *restr_nodes_queue = new_pqueue();
331 pqueue_t *queue = new_pqueue();
332 plist_t *sorted_list = plist_new();
333 ir_node *last_element = NULL;
336 /* first, determine the pressure */
337 /* (this is only for compatibility with copymin optimization, it's not needed for pbqp coloring) */
338 create_borders(block, pbqp_alloc_env->env);
340 /* calculate living nodes for the first step */
341 ir_nodeset_init(&live_nodes);
342 be_liveness_end_of_block(lv, cls, block, &live_nodes);
344 /* create pbqp nodes, interference edges and reverse perfect elimination order */
345 sched_foreach_reverse(block, irn) {
347 ir_nodeset_iterator_t iter;
349 if (get_irn_mode(irn) == mode_T) {
350 const ir_edge_t *edge;
351 foreach_out_edge(irn, edge) {
352 ir_node *proj = get_edge_src_irn(edge);
353 if (!arch_irn_consider_in_reg_alloc(cls, proj))
356 /* create pbqp source node if it dosn't exist */
357 if (get_node(pbqp_inst, get_irn_idx(proj)) == NULL) {
358 create_pbqp_node(pbqp_alloc_env, proj);
361 /* create nodes and interference edges */
362 foreach_ir_nodeset(&live_nodes, live, iter) {
363 /* create pbqp source node if it dosn't exist */
364 if (get_node(pbqp_inst, get_irn_idx(live)) == NULL) {
365 create_pbqp_node(pbqp_alloc_env, live);
368 /* no edges to itself */
373 insert_ife_edge(pbqp_alloc_env, proj, live);
378 if (arch_irn_consider_in_reg_alloc(cls, irn)) {
379 /* create pbqp source node if it dosn't exist */
380 if (get_node(pbqp_inst, get_irn_idx(irn)) == NULL) {
381 create_pbqp_node(pbqp_alloc_env, irn);
384 /* create nodes and interference edges */
385 foreach_ir_nodeset(&live_nodes, live, iter) {
386 /* create pbqp source node if it dosn't exist */
387 if (get_node(pbqp_inst, get_irn_idx(live)) == NULL) {
388 create_pbqp_node(pbqp_alloc_env, live);
391 /* no edges to itself */
396 /* insert interference edge */
397 insert_ife_edge(pbqp_alloc_env, irn, live);
402 /* get living nodes for next step */
404 be_liveness_transfer(cls, irn, &live_nodes);
407 #if USE_BIPARTIT_MATCHING
408 if (get_irn_mode(irn) == mode_T) {
409 unsigned clique_size = 0;
410 unsigned n_alloc = 0;
411 pbqp_node *clique[cls->n_regs];
412 bipartite_t *bp = bipartite_new(cls->n_regs, cls->n_regs);
414 /* add all proj after a perm to clique */
415 const ir_edge_t *edge;
416 foreach_out_edge(irn, edge) {
417 ir_node *proj = get_edge_src_irn(edge);
419 /* ignore node if it is not necessary for register allocation */
420 if (!arch_irn_consider_in_reg_alloc(cls, proj))
423 /* insert pbqp node into temp rpeo list of this block */
424 plist_insert_front(temp_list, get_node(pbqp_inst, get_irn_idx(proj)));
426 if(is_Perm_Proj(proj)) {
427 /* add proj to clique */
428 pbqp_node *clique_member = get_node(pbqp_inst,proj->node_idx);
429 vector *costs = clique_member->costs;
432 clique[clique_size] = clique_member;
434 for(idx = 0; idx < costs->len; idx++) {
435 if(costs->entries[idx].data != INF_COSTS) {
436 bipartite_add(bp, clique_size, idx);
440 /* increase node counter */
446 if(clique_size > 0) {
447 plist_element_t *listElement;
448 foreach_plist(temp_list, listElement) {
449 pbqp_node *clique_candidate = listElement->data;
451 bool isMember = true;
453 /* clique size not bigger then register class size */
454 if(clique_size >= cls->n_regs) break;
456 for(idx = 0; idx < clique_size; idx++) {
457 pbqp_node *member = clique[idx];
459 if(member == clique_candidate) {
464 if(get_edge(pbqp_inst, member->index, clique_candidate->index) == NULL && get_edge(pbqp_inst, clique_candidate->index, member->index) == NULL) {
470 /* goto next list element if current node is not a member of the clique */
471 if(!isMember) { continue; }
473 /* add candidate to clique */
474 clique[clique_size] = clique_candidate;
476 vector *costs = clique_candidate->costs;
477 for(idx = 0; idx < costs->len; idx++) {
478 if(costs->entries[idx].data != INF_COSTS) {
479 bipartite_add(bp, clique_size, idx);
483 /* increase node counter */
488 /* solve bipartite matching */
489 bipartite_matching(bp, assignment);
492 unsigned nodeIdx = 0;
493 for(nodeIdx = 0; nodeIdx < clique_size; nodeIdx++) {
494 vector *costs = clique[nodeIdx]->costs;
496 for(idx = 0; idx < (int)costs->len; idx++) {
497 if(assignment[nodeIdx] != idx) {
498 costs->entries[idx].data = INF_COSTS;
501 assert(assignment[nodeIdx] >= 0 && "there must have been a register assigned (node not register pressure faithful?)");
508 if (arch_irn_consider_in_reg_alloc(cls, irn)) {
509 plist_insert_front(temp_list, get_node(pbqp_inst, get_irn_idx(irn)));
513 /* order nodes for perfect elimination order */
514 if (get_irn_mode(irn) == mode_T) {
515 bool allHaveIFEdges = true;
516 const ir_edge_t *edge;
518 foreach_out_edge(irn, edge) {
519 ir_node *proj = get_edge_src_irn(edge);
520 if (!arch_irn_consider_in_reg_alloc(cls, proj))
523 /* insert proj node into priority queue (descending by the number of interference edges) */
524 if (get_free_regs(restr_nodes, cls, proj) <= 4) {
525 pqueue_put(restr_nodes_queue, proj, pbqp_alloc_env->ife_edge_num[get_irn_idx(proj)]);
528 pqueue_put(queue, proj, pbqp_alloc_env->ife_edge_num[get_irn_idx(proj)]);
531 /* skip last step if there is no last_element */
532 if(last_element == NULL)
535 /* check if proj has an if edge to last_element (at this time pbqp contains only if edges) */
536 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) {
537 allHaveIFEdges = false; /* there is no if edge between proj and last_element */
541 if(last_element != NULL && allHaveIFEdges) {
542 if (get_free_regs(restr_nodes, cls, last_element) <= 4) {
543 pqueue_put(restr_nodes_queue, last_element, pbqp_alloc_env->ife_edge_num[get_irn_idx(last_element)]);
546 pqueue_put(queue, last_element, pbqp_alloc_env->ife_edge_num[get_irn_idx(last_element)]);
548 plist_erase(temp_list, plist_find_value(temp_list, get_node(pbqp_inst, last_element->node_idx)));
552 /* first insert all restricted proj nodes */
553 while (!pqueue_empty(restr_nodes_queue)) {
554 ir_node *node = (ir_node*)pqueue_pop_front(restr_nodes_queue);
555 plist_insert_front(sorted_list, get_node(pbqp_inst, get_irn_idx(node)));
558 /* insert proj nodes descending by their number of interference edges */
559 while (!pqueue_empty(queue)) {
560 ir_node *node = (ir_node*)pqueue_pop_front(queue);
561 plist_insert_front(sorted_list, get_node(pbqp_inst, get_irn_idx(node)));
564 /* invert sorted list */
565 foreach_plist(sorted_list, el) {
566 plist_insert_front(temp_list, el->data);
569 plist_clear(sorted_list);
573 if (arch_irn_consider_in_reg_alloc(cls, irn)) {
574 // remember last colorable node
576 plist_insert_front(temp_list, get_node(pbqp_inst, get_irn_idx(irn)));
579 // node not colorable, so ignore it
586 /* add the temp rpeo list of this block to the global reverse perfect elimination order list*/
587 foreach_plist(temp_list, el) {
588 plist_insert_back(rpeo, el->data);
591 /* free reserved memory */
592 ir_nodeset_destroy(&live_nodes);
593 plist_free(temp_list);
594 #if USE_BIPARTIT_MATCHING
596 plist_free(sorted_list);
598 del_pqueue(restr_nodes_queue);
602 static void insert_perms(ir_node *block, void *data)
604 be_chordal_env_t *env = (be_chordal_env_t*)data;
607 for (irn = sched_first(block); !sched_is_end(irn);) {
608 be_insn_t *insn = chordal_scan_insn(env, irn);
609 irn = insn->next_insn;
611 if (!insn->has_constraints)
614 pre_process_constraints(env, &insn);
618 static void be_pbqp_coloring(be_chordal_env_t *env)
620 ir_graph *irg = env->irg;
621 const arch_register_class_t *cls = env->cls;
623 plist_element_t *element = NULL;
624 unsigned colors_n = arch_register_class_n_regs(cls);
625 be_pbqp_alloc_env_t pbqp_alloc_env;
628 pbqp_matrix_t *ife_matrix;
634 ir_timer_t *t_ra_pbqp_alloc_create = ir_timer_new();
635 ir_timer_t *t_ra_pbqp_alloc_solve = ir_timer_new();
636 ir_timer_t *t_ra_pbqp_alloc_create_aff = ir_timer_new();
638 printf("#### ----- === Allocating registers of %s (%s) ===\n", cls->name, get_entity_name(get_irg_entity(irg)));
640 lv = be_assure_liveness(irg);
641 be_liveness_assure_sets(lv);
642 be_liveness_assure_chk(lv);
646 dom_tree_walk_irg(irg, insert_perms, NULL, env);
648 /* dump graph after inserting perms */
649 if (env->opts->dump_flags & BE_CH_DUMP_CONSTR) {
651 snprintf(buf, sizeof(buf), "-%s-constr", cls->name);
652 dump_ir_graph(irg, buf);
656 /* initialize pbqp allocation data structure */
657 pbqp_alloc_env.pbqp_inst = alloc_pbqp(get_irg_last_idx(irg)); /* initialize pbqp instance */
658 pbqp_alloc_env.cls = cls;
659 pbqp_alloc_env.irg = irg;
660 pbqp_alloc_env.lv = lv;
661 pbqp_alloc_env.allocatable_regs = bitset_malloc(colors_n);
662 pbqp_alloc_env.rpeo = plist_new();
663 pbqp_alloc_env.restr_nodes = XMALLOCNZ(unsigned, get_irg_last_idx(irg));
664 pbqp_alloc_env.ife_edge_num = XMALLOCNZ(unsigned, get_irg_last_idx(irg));
665 pbqp_alloc_env.env = env;
666 be_put_allocatable_regs(irg, cls, pbqp_alloc_env.allocatable_regs);
669 /* create costs matrix template for interference edges */
670 ife_matrix = pbqp_matrix_alloc(pbqp_alloc_env.pbqp_inst, colors_n, colors_n);
672 for (row = 0, col = 0; row < colors_n; row++, col++)
673 pbqp_matrix_set(ife_matrix, row, col, INF_COSTS);
675 pbqp_alloc_env.ife_matrix_template = ife_matrix;
678 if (!use_exec_freq) {
679 /* create costs matrix template for affinity edges */
680 pbqp_matrix_t *afe_matrix = pbqp_matrix_alloc(pbqp_alloc_env.pbqp_inst, colors_n, colors_n);
682 for (row = 0; row < colors_n; row++) {
683 for (col = 0; col < colors_n; col++) {
685 pbqp_matrix_set(afe_matrix, row, col, 2);
688 pbqp_alloc_env.aff_matrix_template = afe_matrix;
692 /* create pbqp instance */
694 ir_timer_reset_and_start(t_ra_pbqp_alloc_create);
697 dom_tree_walk_irg(irg, create_pbqp_coloring_instance , NULL, &pbqp_alloc_env);
699 ir_timer_stop(t_ra_pbqp_alloc_create);
703 /* set up affinity edges */
705 ir_timer_reset_and_start(t_ra_pbqp_alloc_create_aff);
707 foreach_plist(pbqp_alloc_env.rpeo, element) {
708 pbqp_node_t *node = (pbqp_node_t*)element->data;
709 ir_node *irn = get_idx_irn(irg, node->index);
711 create_affinity_edges(irn, &pbqp_alloc_env);
714 ir_timer_stop(t_ra_pbqp_alloc_create_aff);
719 // dump graph before solving pbqp
720 file_before = my_open(env, "", "-pbqp_coloring.html");
721 set_dumpfile(pbqp_alloc_env.pbqp_inst, file_before);
724 /* print out reverse perfect elimination order */
727 plist_element_t *elements;
728 foreach_plist(pbqp_alloc_env.rpeo, elements) {
729 pbqp_node_t *node = elements->data;
730 printf(" %d(%ld);", node->index, get_idx_irn(irg, node->index)->node_nr);
736 /* solve pbqp instance */
738 ir_timer_reset_and_start(t_ra_pbqp_alloc_solve);
740 if(use_late_decision) {
741 solve_pbqp_heuristical_co_ld(pbqp_alloc_env.pbqp_inst,pbqp_alloc_env.rpeo);
744 solve_pbqp_heuristical_co(pbqp_alloc_env.pbqp_inst,pbqp_alloc_env.rpeo);
747 ir_timer_stop(t_ra_pbqp_alloc_solve);
751 solution = get_solution(pbqp_alloc_env.pbqp_inst);
752 if (solution == INF_COSTS)
753 panic("No PBQP solution found");
757 foreach_plist(pbqp_alloc_env.rpeo, element) {
758 pbqp_node_t *node = (pbqp_node_t*)element->data;
759 ir_node *irn = get_idx_irn(irg, node->index);
760 num color = get_node_solution(pbqp_alloc_env.pbqp_inst, node->index);
761 const arch_register_t *reg = arch_register_for_index(cls, color);
763 arch_set_irn_register(irn, reg);
768 printf("PBQP alloc create: %10.3lf msec\n",
769 (double)ir_timer_elapsed_usec(t_ra_pbqp_alloc_create) / 1000.0);
770 printf("PBQP alloc solve: %10.3lf msec\n",
771 (double)ir_timer_elapsed_usec(t_ra_pbqp_alloc_solve) / 1000.0);
772 printf("PBQP alloc create aff: %10.3lf msec\n",
773 (double)ir_timer_elapsed_usec(t_ra_pbqp_alloc_create_aff) / 1000.0);
777 /* free reserved memory */
781 bitset_free(pbqp_alloc_env.allocatable_regs);
782 free_pbqp(pbqp_alloc_env.pbqp_inst);
783 plist_free(pbqp_alloc_env.rpeo);
784 xfree(pbqp_alloc_env.restr_nodes);
785 xfree(pbqp_alloc_env.ife_edge_num);
790 * Initializes this module.
792 BE_REGISTER_MODULE_CONSTRUCTOR(be_init_pbqp_coloring)
793 void be_init_pbqp_coloring(void)
795 lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be");
796 lc_opt_entry_t *ra_grp = lc_opt_get_grp(be_grp, "ra");
797 lc_opt_entry_t *chordal_grp = lc_opt_get_grp(ra_grp, "chordal");
798 lc_opt_entry_t *coloring_grp = lc_opt_get_grp(chordal_grp, "coloring");
799 lc_opt_entry_t *pbqp_grp = lc_opt_get_grp(coloring_grp, "pbqp");
801 static be_ra_chordal_coloring_t coloring = {
805 lc_opt_add_table(pbqp_grp, options);
806 be_register_chordal_coloring("pbqp", &coloring);