X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbeschednormal.c;h=e32ebef8509625fbe4e61285c81ac5ac1127aa5f;hb=226c238839ce84c2c310c8e7522838160c6f71af;hp=842c332442124603991b10d41e217078545ce46e;hpb=40b21ac11c66e34012ceb0bc04a3a5421e1ee9bf;p=libfirm diff --git a/ir/be/beschednormal.c b/ir/be/beschednormal.c index 842c33244..e32ebef85 100644 --- a/ir/be/beschednormal.c +++ b/ir/be/beschednormal.c @@ -1,39 +1,25 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. - * * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. + * Copyright (C) 2012 University of Karlsruhe. */ /** * @brief Use the strong normal form theorem (though it does not hold) * @author Christoph Mallon - * @version $Id$ */ #include "config.h" #include -#include "besched_t.h" +#include "besched.h" #include "belistsched.h" #include "belive_t.h" #include "beutil.h" -#include "height.h" -#include "irtools.h" +#include "heights.h" #include "irgwalk.h" -#include "benode_t.h" +#include "benode.h" +#include "bemodule.h" +#include "util.h" #include "array_t.h" // XXX there is no one time init for schedulers @@ -49,23 +35,19 @@ typedef struct instance_t { static int must_be_scheduled(const ir_node* const irn) { - return !is_Proj(irn) && !is_Sync(irn); + return !is_Proj(irn) && !arch_irn_is(irn, not_scheduled); } -static ir_node *normal_select(void *block_env, ir_nodeset_t *ready_set, - ir_nodeset_t *live_set) +static ir_node *normal_select(void *block_env, ir_nodeset_t *ready_set) { - instance_t* inst = block_env; + instance_t* inst = (instance_t*)block_env; ir_node* irn; ir_node* next; ir_node* last = NULL; - ir_nodeset_iterator_t iter; - - (void)live_set; for (irn = inst->curr_list; irn != NULL; last = irn, irn = next) { - next = get_irn_link(irn); + next = (ir_node*)get_irn_link(irn); if (ir_nodeset_contains(ready_set, irn)) { #if defined NORMAL_DBG ir_fprintf(stderr, "scheduling %+F\n", irn); @@ -78,9 +60,7 @@ static ir_node *normal_select(void *block_env, ir_nodeset_t *ready_set, } } - ir_nodeset_iterator_init(&iter, ready_set); - irn = ir_nodeset_iterator_next(&iter); - return irn; + return ir_nodeset_first(ready_set); } @@ -91,8 +71,8 @@ typedef struct irn_cost_pair { static int cost_cmp(const void* a, const void* b) { - const irn_cost_pair* const a1 = a; - const irn_cost_pair* const b1 = b; + const irn_cost_pair* const a1 = (const irn_cost_pair*)a; + const irn_cost_pair* const b1 = (const irn_cost_pair*)b; int ret = b1->cost - a1->cost; if (ret == 0) ret = (int)get_irn_idx(a1->irn) - (int)get_irn_idx(b1->irn); @@ -119,7 +99,11 @@ static int count_result(const ir_node* irn) if (mode == mode_M || mode == mode_X) return 0; - if (arch_get_register_req_out(irn)->type & arch_register_req_type_ignore) + if (mode == mode_T) + return 1; + + arch_register_req_t const *const req = arch_get_irn_register_req(irn); + if (arch_register_req_is(req, ignore)) return 0; return 1; @@ -151,18 +135,16 @@ static int normal_tree_cost(ir_node* irn, instance_t *inst) if (fc == NULL) { irn_cost_pair* costs; - int i; ir_node* block = get_nodes_block(irn); - fc = obstack_alloc(&inst->obst, sizeof(*fc) + sizeof(*fc->costs) * arity); + fc = OALLOCF(&inst->obst, flag_and_cost, costs, arity); fc->no_root = 0; costs = fc->costs; for (i = 0; i < arity; ++i) { ir_node* pred = get_irn_n(irn, i); - int cost; - if (is_Phi(irn) || get_irn_mode(pred) == mode_M || is_Block(pred)) { + if (is_Phi(irn) || get_irn_mode(pred) == mode_M) { cost = 0; } else if (get_nodes_block(pred) != block) { cost = 1; @@ -171,7 +153,6 @@ static int normal_tree_cost(ir_node* irn, instance_t *inst) ir_node* real_pred; cost = normal_tree_cost(pred, inst); - if (be_is_Barrier(pred)) cost = 1; // XXX hack: the barrier causes all users to have a reguse of #regs if (!arch_irn_is_ignore(pred)) { real_pred = (is_Proj(pred) ? get_Proj_pred(pred) : pred); pred_fc = get_irn_fc(real_pred); @@ -194,9 +175,14 @@ static int normal_tree_cost(ir_node* irn, instance_t *inst) last = 0; for (i = 0; i < arity; ++i) { ir_node* op = fc->costs[i].irn; - if (op == last) continue; - if (get_irn_mode(op) == mode_M) continue; - if (arch_irn_is_ignore(op)) continue; + ir_mode* mode; + if (op == last) + continue; + mode = get_irn_mode(op); + if (mode == mode_M) + continue; + if (arch_irn_is_ignore(op)) + continue; cost = MAX(fc->costs[i].cost + n_op_res, cost); last = op; ++n_op_res; @@ -214,12 +200,16 @@ static int normal_tree_cost(ir_node* irn, instance_t *inst) static void normal_cost_walker(ir_node* irn, void* env) { - instance_t *inst = env; + instance_t *inst = (instance_t*)env; #if defined NORMAL_DBG ir_fprintf(stderr, "cost walking node %+F\n", irn); #endif - if (is_Block(irn)) return; + if (is_Block(irn)) { + ir_node **const roots = NEW_ARR_F(ir_node*, 0); + set_irn_link(irn, roots); + return; + } if (!must_be_scheduled(irn)) return; normal_tree_cost(irn, inst); } @@ -231,7 +221,6 @@ static void collect_roots(ir_node* irn, void* env) (void)env; - if (is_Block(irn)) return; if (!must_be_scheduled(irn)) return; is_root = be_is_Keep(irn) || !get_irn_fc(irn)->no_root; @@ -242,10 +231,7 @@ static void collect_roots(ir_node* irn, void* env) if (is_root) { ir_node* block = get_nodes_block(irn); - ir_node** roots = get_irn_link(block); - if (roots == NULL) { - roots = NEW_ARR_F(ir_node*, 0); - } + ir_node** roots = (ir_node**)get_irn_link(block); ARR_APP1(ir_node*, roots, irn); set_irn_link(block, roots); } @@ -255,7 +241,6 @@ static void collect_roots(ir_node* irn, void* env) static ir_node** sched_node(ir_node** sched, ir_node* irn) { if (irn_visited_else_mark(irn)) return sched; - if (is_End(irn)) return sched; if (!is_Phi(irn) && !be_is_Keep(irn)) { ir_node* block = get_nodes_block(irn); @@ -280,18 +265,22 @@ 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; + const irn_cost_pair* const a1 = (const irn_cost_pair*)a; + const irn_cost_pair* const b1 = (const irn_cost_pair*)b; int ret; - if (is_irn_forking(a1->irn)) { + if (is_irn_forking(a1->irn) && !is_irn_forking(b1->irn)) { ret = 1; - } else if (is_irn_forking(b1->irn)) { + } else if (is_irn_forking(b1->irn) && !is_irn_forking(a1->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 (ret == 0) { + /* compare node idx */ + ret = get_irn_idx(a1->irn) - get_irn_idx(b1->irn); + } } } #if defined NORMAL_DBG @@ -303,9 +292,8 @@ static int root_cmp(const void* a, const void* b) static void normal_sched_block(ir_node* block, void* env) { - ir_node** roots = get_irn_link(block); - heights_t* heights = env; - int root_count; + ir_node** roots = (ir_node**)get_irn_link(block); + ir_heights_t* heights = (ir_heights_t*)env; irn_cost_pair* root_costs; int i; ir_node** sched; @@ -314,14 +302,14 @@ static void normal_sched_block(ir_node* block, void* env) ir_fprintf(stderr, "sched walking block %+F\n", block); #endif - if (roots == NULL) { + int const root_count = ARR_LEN(roots); + if (root_count == 0) { #if defined NORMAL_DBG fprintf(stderr, "has no roots\n"); #endif return; } - root_count = ARR_LEN(roots); NEW_ARR_A(irn_cost_pair, root_costs, root_count); for (i = 0; i < root_count; ++i) { root_costs[i].irn = roots[i]; @@ -368,14 +356,10 @@ 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) +static void *normal_init_graph(ir_graph *irg) { - instance_t* inst = XMALLOC(instance_t); - ir_graph* irg = be_get_birg_irg(birg); - heights_t* heights; - - (void)vtab; + instance_t *inst = XMALLOC(instance_t); + ir_heights_t *heights; be_clear_links(irg); @@ -399,8 +383,8 @@ static void *normal_init_graph(const list_sched_selector_t *vtab, static void *normal_init_block(void *graph_env, ir_node *block) { - instance_t* inst = graph_env; - ir_node** sched = get_irn_link(block); + instance_t* inst = (instance_t*)graph_env; + ir_node** sched = (ir_node**)get_irn_link(block); ir_node* first = NULL; int i; @@ -408,7 +392,7 @@ static void *normal_init_block(void *graph_env, ir_node *block) The link field is used anyway. */ for (i = ARR_LEN(sched) - 1; i >= 0; --i) { ir_node* irn = sched[i]; - if (!arch_irn_class_is(irn, branch)) { + if (!is_cfop(irn)) { set_irn_link(irn, first); first = irn; } @@ -421,9 +405,9 @@ static void *normal_init_block(void *graph_env, ir_node *block) return inst; } -void normal_finish_graph(void *env) +static void normal_finish_graph(void *env) { - instance_t *inst = env; + instance_t *inst = (instance_t*)env; /* block uses the link field to store the schedule */ ir_free_resources(inst->irg, IR_RESOURCE_IRN_LINK); @@ -431,15 +415,22 @@ void normal_finish_graph(void *env) xfree(inst); } -const list_sched_selector_t normal_selector = { - normal_init_graph, - normal_init_block, - normal_select, - NULL, /* to_appear_in_schedule */ - NULL, /* node_ready */ - NULL, /* node_selected */ - NULL, /* exectime */ - NULL, /* latency */ - NULL, /* finish_block */ - normal_finish_graph -}; +static void sched_normal(ir_graph *irg) +{ + static const list_sched_selector_t normal_selector = { + normal_init_graph, + normal_init_block, + normal_select, + NULL, /* node_ready */ + NULL, /* node_selected */ + NULL, /* finish_block */ + normal_finish_graph + }; + be_list_sched_graph(irg, &normal_selector); +} + +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_sched_normal) +void be_init_sched_normal(void) +{ + be_register_scheduler("normal", sched_normal); +}