X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbeschednormal.c;h=22bc29aa7e1cb811bdc56626e6dbaff56210ced1;hb=b4647d67ab7885d5da32c2a30242fbc4ed93d81b;hp=e642435cf492e492662af3a9d741fcdd796cdd32;hpb=661e8c55444874a4b35d9802b02728576b98fb91;p=libfirm diff --git a/ir/be/beschednormal.c b/ir/be/beschednormal.c index e642435cf..22bc29aa7 100644 --- a/ir/be/beschednormal.c +++ b/ir/be/beschednormal.c @@ -26,14 +26,14 @@ #include -#include "besched_t.h" +#include "besched.h" #include "belistsched.h" #include "belive_t.h" #include "beutil.h" -#include "height.h" +#include "heights.h" #include "irtools.h" #include "irgwalk.h" -#include "benode_t.h" +#include "benode.h" #include "array_t.h" // XXX there is no one time init for schedulers @@ -42,8 +42,9 @@ /** An instance of the normal scheduler. */ typedef struct instance_t { - ir_graph* irg; /**< the IR graph of this instance */ - struct obstack obst; /**< obstack for temporary data */ + ir_graph* irg; /**< the IR graph of this instance */ + struct obstack obst; /**< obstack for temporary data */ + ir_node* curr_list; /**< current block schedule list */ } instance_t; static int must_be_scheduled(const ir_node* const irn) @@ -55,31 +56,30 @@ static int must_be_scheduled(const ir_node* const irn) static ir_node *normal_select(void *block_env, ir_nodeset_t *ready_set, ir_nodeset_t *live_set) { + instance_t* inst = block_env; + ir_node* irn; + ir_node* next; + ir_node* last = NULL; ir_nodeset_iterator_t iter; - ir_node* block; - ir_node* irn; - ir_node** sched; - int sched_count; - (void)block_env; (void)live_set; - ir_nodeset_iterator_init(&iter, ready_set); - irn = ir_nodeset_iterator_next(&iter); - block = get_nodes_block(irn); - sched = get_irn_link(block); - sched_count = ARR_LEN(sched); - for (; sched_count-- != 0; ++sched) { - ir_node* irn = *sched; - if (ir_nodeset_contains(ready_set, irn) && - !arch_irn_class_is(irn, branch)) { + for (irn = inst->curr_list; irn != NULL; last = irn, irn = next) { + next = get_irn_link(irn); + if (ir_nodeset_contains(ready_set, irn)) { #if defined NORMAL_DBG ir_fprintf(stderr, "scheduling %+F\n", irn); #endif + if (last == NULL) + inst->curr_list = next; + else + set_irn_link(last, next); return irn; } } + ir_nodeset_iterator_init(&iter, ready_set); + irn = ir_nodeset_iterator_next(&iter); return irn; } @@ -119,6 +119,9 @@ static int count_result(const ir_node* irn) if (mode == mode_M || mode == mode_X) return 0; + if (mode == mode_T) + return 1; + if (arch_get_register_req_out(irn)->type & arch_register_req_type_ignore) return 0; @@ -154,7 +157,7 @@ static int normal_tree_cost(ir_node* irn, instance_t *inst) 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; @@ -194,9 +197,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 (mode != mode_T && arch_irn_is_ignore(op)) + continue; cost = MAX(fc->costs[i].cost + n_op_res, cost); last = op; ++n_op_res; @@ -303,8 +311,8 @@ static int root_cmp(const void* a, const void* b) static void normal_sched_block(ir_node* block, void* env) { - heights_t* heights = env; - ir_node** roots = get_irn_link(block); + ir_node** roots = get_irn_link(block); + ir_heights_t* heights = env; int root_count; irn_cost_pair* root_costs; int i; @@ -369,19 +377,18 @@ 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) { - instance_t *inst = XMALLOC(instance_t); - ir_graph *irg = be_get_birg_irg(birg); - heights_t *heights; + instance_t *inst = XMALLOC(instance_t); + ir_heights_t *heights; (void)vtab; - inst->irg = irg; - obstack_init(&inst->obst); - be_clear_links(irg); + obstack_init(&inst->obst); + inst->irg = irg; + heights = heights_new(irg); ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK); @@ -397,16 +404,31 @@ static void *normal_init_graph(const list_sched_selector_t *vtab, return inst; } - static void *normal_init_block(void *graph_env, ir_node *block) { - (void)graph_env; - (void)block; - - return NULL; + instance_t* inst = graph_env; + ir_node** sched = get_irn_link(block); + ir_node* first = NULL; + int i; + + /* turn into a list, so we can easily remove nodes. + The link field is used anyway. */ + for (i = ARR_LEN(sched) - 1; i >= 0; --i) { + ir_node* irn = sched[i]; + if (!is_cfop(irn)) { + set_irn_link(irn, first); + first = irn; + } + } + /* note: we can free sched here, there should be no attempt to schedule + a block twice */ + DEL_ARR_F(sched); + set_irn_link(block, sched); + inst->curr_list = first; + return inst; } -void normal_finish_graph(void *env) +static void normal_finish_graph(void *env) { instance_t *inst = env; @@ -420,7 +442,6 @@ 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 */