X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbepbqpcoloring.c;h=b5ddcaeccaf7c1742caba4e020d1a2d254a69448;hb=01c4c27c4b7824dd0020f6fd2218edbe9ab40548;hp=8fae9e20fe17e6f47ba42795a25280849dc175a0;hpb=ce6161a7e42a48f7422b7babcc64d8ace18e2687;p=libfirm diff --git a/ir/be/bepbqpcoloring.c b/ir/be/bepbqpcoloring.c index 8fae9e20f..b5ddcaecc 100644 --- a/ir/be/bepbqpcoloring.c +++ b/ir/be/bepbqpcoloring.c @@ -22,14 +22,11 @@ * @brief PBQP based register allocation. * @author Thomas Bersch * @date 27.11.2009 - * @version $Id: bechordal.c 26750 2009-11-27 09:37:43Z bersch $ */ /* miscellaneous includes */ #include "config.h" -#ifdef FIRM_KAPS - #include "debug.h" #include "error.h" @@ -38,9 +35,9 @@ #include "iredges_t.h" #include "irprintf.h" #include "irgwalk.h" +#include "irtools.h" #include "time.h" - -/* libfirm/ir/adt includes */ +#include "execfreq_t.h" #include "bipartite.h" /* libfirm/ir/be includes */ @@ -93,6 +90,7 @@ typedef struct be_pbqp_alloc_env_t { plist_t *rpeo; unsigned *restr_nodes; unsigned *ife_edge_num; + ir_execfreq_int_factors execfreq_factors; be_chordal_env_t *env; } be_pbqp_alloc_env_t; @@ -157,7 +155,10 @@ static void create_pbqp_node(be_pbqp_alloc_env_t *pbqp_alloc_env, ir_node *irn) /* set costs depending on register constrains */ unsigned idx; for (idx = 0; idx < colors_n; idx++) { - if (!bitset_is_set(allocatable_regs, idx) || !arch_reg_out_is_allocatable(irn, arch_register_for_index(cls, idx))) { + const arch_register_req_t *req = arch_get_irn_register_req(irn); + const arch_register_t *reg = arch_register_for_index(cls, idx); + if (!bitset_is_set(allocatable_regs, idx) + || !arch_reg_is_allocatable(req, reg)) { /* constrained */ vector_set(costs_vector, idx, INF_COSTS); cntConstrains++; @@ -218,10 +219,9 @@ static void insert_afe_edge(be_pbqp_alloc_env_t *pbqp_alloc_env, ir_node *src_no if (get_edge(pbqp, get_irn_idx(src_node), get_irn_idx(trg_node)) == NULL) { if (use_exec_freq) { /* get exec_freq for copy_block */ - ir_node *root_bl = get_nodes_block(src_node); - ir_node *copy_bl = is_Phi(src_node) ? get_Block_cfgpred_block(root_bl, pos) : root_bl; - ir_exec_freq *exec_freq = be_get_irg_exec_freq(pbqp_alloc_env->irg); - unsigned long res = get_block_execfreq_ulong(exec_freq, copy_bl); + ir_node *root_bl = get_nodes_block(src_node); + ir_node *copy_bl = is_Phi(src_node) ? get_Block_cfgpred_block(root_bl, pos) : root_bl; + int res = get_block_execfreq_int(&pbqp_alloc_env->execfreq_factors, copy_bl); /* create afe-matrix */ unsigned row, col; @@ -261,7 +261,7 @@ static void create_affinity_edges(ir_node *irn, void *env) { be_pbqp_alloc_env_t *pbqp_alloc_env = (be_pbqp_alloc_env_t*)env; const arch_register_class_t *cls = pbqp_alloc_env->cls; - const arch_register_req_t *req = arch_get_register_req_out(irn); + const arch_register_req_t *req = arch_get_irn_register_req(irn); unsigned pos; unsigned max; @@ -319,7 +319,6 @@ static void create_pbqp_coloring_instance(ir_node *block, void *data) pbqp_t *pbqp_inst = pbqp_alloc_env->pbqp_inst; plist_t *temp_list = plist_new(); plist_element_t *el; - ir_node *irn; ir_nodeset_t live_nodes; #if USE_BIPARTIT_MATCHING int *assignment = ALLOCAN(int, cls->n_regs); @@ -341,11 +340,7 @@ static void create_pbqp_coloring_instance(ir_node *block, void *data) /* create pbqp nodes, interference edges and reverse perfect elimination order */ sched_foreach_reverse(block, irn) { - ir_node *live; - ir_nodeset_iterator_t iter; - if (get_irn_mode(irn) == mode_T) { - const ir_edge_t *edge; foreach_out_edge(irn, edge) { ir_node *proj = get_edge_src_irn(edge); if (!arch_irn_consider_in_reg_alloc(cls, proj)) @@ -410,7 +405,6 @@ static void create_pbqp_coloring_instance(ir_node *block, void *data) bipartite_t *bp = bipartite_new(cls->n_regs, cls->n_regs); /* add all proj after a perm to clique */ - const ir_edge_t *edge; foreach_out_edge(irn, edge) { ir_node *proj = get_edge_src_irn(edge); @@ -510,9 +504,7 @@ static void create_pbqp_coloring_instance(ir_node *block, void *data) #else /* order nodes for perfect elimination order */ if (get_irn_mode(irn) == mode_T) { - bool allHaveIFEdges = true; - const ir_edge_t *edge; - + bool allHaveIFEdges = true; foreach_out_edge(irn, edge) { ir_node *proj = get_edge_src_irn(edge); if (!arch_irn_consider_in_reg_alloc(cls, proj)) @@ -599,34 +591,16 @@ static void create_pbqp_coloring_instance(ir_node *block, void *data) static void insert_perms(ir_node *block, void *data) { - /* - * Start silent in the start block. - * The silence remains until the first barrier is seen. - * Each other block is begun loud. - */ be_chordal_env_t *env = (be_chordal_env_t*)data; - int silent = block == get_irg_start_block(get_irn_irg(block)); ir_node *irn; - /* - * If the block is the start block search the barrier and - * start handling constraints from there. - */ for (irn = sched_first(block); !sched_is_end(irn);) { - int silent_old = silent; /* store old silent value */ - if (be_is_Barrier(irn)) - silent = !silent; /* toggle silent flag */ - - be_insn_t *insn = chordal_scan_insn(env, irn); - irn = insn->next_insn; - - if (silent_old) - continue; - - if (!insn->has_constraints) - continue; + ir_node *const next = sched_next(irn); + be_insn_t * insn = be_scan_insn(env, irn); + if (insn->has_constraints) + pre_process_constraints(env, &insn); - pre_process_constraints(env, &insn); + irn = next; } } @@ -640,7 +614,11 @@ static void be_pbqp_coloring(be_chordal_env_t *env) be_pbqp_alloc_env_t pbqp_alloc_env; unsigned col; unsigned row; - + pbqp_matrix_t *ife_matrix; + num solution; +#if KAPS_DUMP + FILE *file_before; +#endif #if TIMER ir_timer_t *t_ra_pbqp_alloc_create = ir_timer_new(); ir_timer_t *t_ra_pbqp_alloc_solve = ir_timer_new(); @@ -648,9 +626,8 @@ static void be_pbqp_coloring(be_chordal_env_t *env) printf("#### ----- === Allocating registers of %s (%s) ===\n", cls->name, get_entity_name(get_irg_entity(irg))); #endif - lv = be_assure_liveness(irg); - be_liveness_assure_sets(lv); - be_liveness_assure_chk(lv); + be_assure_live_sets(irg); + lv = be_get_irg_liveness(irg); /* insert perms */ assure_doms(irg); @@ -663,6 +640,7 @@ static void be_pbqp_coloring(be_chordal_env_t *env) dump_ir_graph(irg, buf); } + ir_calculate_execfreq_int_factors(&pbqp_alloc_env.execfreq_factors, irg); /* initialize pbqp allocation data structure */ pbqp_alloc_env.pbqp_inst = alloc_pbqp(get_irg_last_idx(irg)); /* initialize pbqp instance */ @@ -678,7 +656,7 @@ static void be_pbqp_coloring(be_chordal_env_t *env) /* create costs matrix template for interference edges */ - pbqp_matrix_t *ife_matrix = pbqp_matrix_alloc(pbqp_alloc_env.pbqp_inst, colors_n, colors_n); + ife_matrix = pbqp_matrix_alloc(pbqp_alloc_env.pbqp_inst, colors_n, colors_n); /* set costs */ for (row = 0, col = 0; row < colors_n; row++, col++) pbqp_matrix_set(ife_matrix, row, col, INF_COSTS); @@ -728,18 +706,20 @@ static void be_pbqp_coloring(be_chordal_env_t *env) #if KAPS_DUMP // dump graph before solving pbqp - FILE *file_before = my_open(env, "", "-pbqp_coloring.html"); + file_before = my_open(env, "", "-pbqp_coloring.html"); set_dumpfile(pbqp_alloc_env.pbqp_inst, file_before); #endif - /* print out reverse perfect eleminiation order */ + /* print out reverse perfect elimination order */ #if PRINT_RPEO - plist_element_t *elements; - foreach_plist(pbqp_alloc_env.rpeo, elements) { - pbqp_node *node = elements->data; - printf(" %d(%lu);", node->index, get_idx_irn(irg, node->index)->node_nr); + { + plist_element_t *elements; + foreach_plist(pbqp_alloc_env.rpeo, elements) { + pbqp_node_t *node = elements->data; + printf(" %d(%ld);", node->index, get_idx_irn(irg, node->index)->node_nr); + } + printf("\n"); } - printf("\n"); #endif /* solve pbqp instance */ @@ -757,7 +737,7 @@ static void be_pbqp_coloring(be_chordal_env_t *env) #endif - num solution = get_solution(pbqp_alloc_env.pbqp_inst); + solution = get_solution(pbqp_alloc_env.pbqp_inst); if (solution == INF_COSTS) panic("No PBQP solution found"); @@ -798,7 +778,7 @@ static void be_pbqp_coloring(be_chordal_env_t *env) /** * Initializes this module. */ -BE_REGISTER_MODULE_CONSTRUCTOR(be_init_pbqp_coloring); +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_pbqp_coloring) void be_init_pbqp_coloring(void) { lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be"); @@ -814,5 +794,3 @@ void be_init_pbqp_coloring(void) lc_opt_add_table(pbqp_grp, options); be_register_chordal_coloring("pbqp", &coloring); } - -#endif