X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbeschednormal.c;h=dacc5a6750a40aaabd493df161cfa11e81791659;hb=4d808298b72e72bd06c7466e837dd9dda4eb1070;hp=00f2a9e9e52577b8dbc7fa5f5e86dbd3db5351ca;hpb=7bde85a69092a96255c5608d45adf1b0ccfeb054;p=libfirm diff --git a/ir/be/beschednormal.c b/ir/be/beschednormal.c index 00f2a9e9e..dacc5a675 100644 --- a/ir/be/beschednormal.c +++ b/ir/be/beschednormal.c @@ -32,13 +32,15 @@ #include "belistsched.h" #include "belive_t.h" #include "beutil.h" +#include "height.h" #include "irtools.h" #include "irgwalk.h" #include "benode_t.h" // XXX there is no one time init for schedulers -#define NORMAL_DBG +//#define NORMAL_DBG +#include "irprintf.h" static int must_be_scheduled(const ir_node* const irn) @@ -92,15 +94,7 @@ static int cost_cmp(const void* a, const void* b) { const irn_cost_pair* const a1 = a; const irn_cost_pair* const b1 = b; - int ret; - if (is_irn_forking(a1->irn)) { - ret = 1; - } else if (is_irn_forking(b1->irn)) { - ret = -1; - } else { - ret = b1->cost - a1->cost; - //ret = a1->cost - b1->cost; - } + int ret = b1->cost - a1->cost; #if defined NORMAL_DBG ir_fprintf(stderr, "%+F %s %+F\n", a1->irn, ret < 0 ? "<" : ret > 0 ? ">" : "=", b1->irn); #endif @@ -138,6 +132,9 @@ static int normal_tree_cost(ir_node* irn) int n_op_res = 0; int i; + if (be_is_Keep(irn)) + return 0; + if (is_Proj(irn)) { return normal_tree_cost(get_Proj_pred(irn)); } @@ -164,12 +161,14 @@ static int normal_tree_cost(ir_node* irn) cost = normal_tree_cost(pred); if (be_is_Barrier(pred)) cost = 1; // XXX hack: the barrier causes all users to have a reguse of #regs - real_pred = (is_Proj(pred) ? get_Proj_pred(pred) : pred); - pred_fc = get_irn_link(real_pred); - pred_fc->no_root = 1; + if (!arch_irn_is(cur_arch_env, pred, ignore)) { + real_pred = (is_Proj(pred) ? get_Proj_pred(pred) : pred); + pred_fc = get_irn_link(real_pred); + pred_fc->no_root = 1; #if defined NORMAL_DBG - ir_fprintf(stderr, "%+F says that %+F is no root\n", irn, real_pred); + ir_fprintf(stderr, "%+F says that %+F is no root\n", irn, real_pred); #endif + } } costs[i].irn = pred; @@ -213,20 +212,20 @@ static void normal_cost_walker(ir_node* irn, void* env) static void collect_roots(ir_node* irn, void* env) { - flag_and_cost* fc; + int is_root; (void)env; if (is_Block(irn)) return; if (!must_be_scheduled(irn)) return; - fc = get_irn_link(irn); + is_root = be_is_Keep(irn) || !((flag_and_cost*)get_irn_link(irn))->no_root; #if defined NORMAL_DBG - ir_fprintf(stderr, "%+F is %sroot\n", irn, fc->no_root ? "no " : ""); + ir_fprintf(stderr, "%+F is %sroot\n", irn, is_root ? "" : "no "); #endif - if (!fc->no_root) { + if (is_root) { ir_node* block = get_nodes_block(irn); ir_node** roots = get_irn_link(block); if (roots == NULL) { @@ -249,7 +248,7 @@ static ir_node** sched_node(ir_node** sched, ir_node* irn) if (irn_visited(irn)) return sched; if (is_End(irn)) return sched; - if (!is_Phi(irn)) { + if (!is_Phi(irn) && !be_is_Keep(irn)) { for (i = 0; i < arity; ++i) { ir_node* pred = irns[i].irn; if (get_nodes_block(pred) != block) continue; @@ -265,16 +264,38 @@ static ir_node** sched_node(ir_node** sched, ir_node* irn) } +static int root_cmp(const void* a, const void* b) +{ + const irn_cost_pair* const a1 = a; + const irn_cost_pair* const b1 = b; + int ret; + if (is_irn_forking(a1->irn)) { + ret = 1; + } else if (is_irn_forking(b1->irn)) { + ret = -1; + } else { + ret = b1->cost - a1->cost; + if (ret == 0) { + /* place live-out nodes later */ + ret = (count_result(a1->irn) != 0) - (count_result(b1->irn) != 0); + } + } +#if defined NORMAL_DBG + ir_fprintf(stderr, "%+F %s %+F\n", a1->irn, ret < 0 ? "<" : ret > 0 ? ">" : "=", b1->irn); +#endif + return ret; +} + + static void normal_sched_block(ir_node* block, void* env) { - ir_node** roots = get_irn_link(block); + heights_t* heights = env; + ir_node** roots = get_irn_link(block); int root_count; irn_cost_pair* root_costs; int i; ir_node** sched; - (void)env; - #if defined NORMAL_DBG ir_fprintf(stderr, "sched walking block %+F\n", block); #endif @@ -290,9 +311,12 @@ static void normal_sched_block(ir_node* block, void* env) NEW_ARR_A(irn_cost_pair, root_costs, root_count); for (i = 0; i < root_count; ++i) { root_costs[i].irn = roots[i]; - root_costs[i].cost = normal_tree_cost(roots[i]); + root_costs[i].cost = get_irn_height(heights, roots[i]); +#if defined NORMAL_DBG + ir_fprintf(stderr, "height of %+F is %u\n", roots[i], root_costs[i].cost); +#endif } - qsort(root_costs, root_count, sizeof(*root_costs), cost_cmp); + qsort(root_costs, root_count, sizeof(*root_costs), root_cmp); #if defined NORMAL_DBG { int n = root_count; @@ -333,7 +357,8 @@ static void normal_sched_block(ir_node* block, void* env) static void *normal_init_graph(const list_sched_selector_t *vtab, const be_irg_t *birg) { - ir_graph* irg = be_get_birg_irg(birg); + ir_graph *irg = be_get_birg_irg(birg); + heights_t *heights; (void)vtab; @@ -341,10 +366,14 @@ static void *normal_init_graph(const list_sched_selector_t *vtab, be_clear_links(irg); + heights = heights_new(irg); + irg_walk_graph(irg, normal_cost_walker, NULL, NULL); irg_walk_graph(irg, collect_roots, NULL, NULL); inc_irg_visited(irg); - irg_block_walk_graph(irg, normal_sched_block, NULL, NULL); + irg_block_walk_graph(irg, normal_sched_block, NULL, heights); + + heights_free(heights); return NULL; }