X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbeschedregpress.c;h=111fa7e40e13d7875716e350dd46bce82298190b;hb=5bb8cd35a8074112fa2da8b8f68d7c77918119e5;hp=b939c8774b7fafe0a7cdcc37e98e1ecee2c27716;hpb=39f3a8dbd0f00f90b7b12a849d1bf7b9c1329479;p=libfirm diff --git a/ir/be/beschedregpress.c b/ir/be/beschedregpress.c index b939c8774..111fa7e40 100644 --- a/ir/be/beschedregpress.c +++ b/ir/be/beschedregpress.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -19,23 +19,22 @@ /** * @file - * @brief Regpressure node selector. + * @brief Register pressure node selector. * @author Sebastian Hack * @date 29.08.2006 * @version $Id$ */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include #include "iredges_t.h" #include "irgwalk.h" +#include "irtools.h" -#include "besched_t.h" +#include "besched.h" #include "belistsched.h" -#include "benode_t.h" +#include "benode.h" typedef struct _usage_stats_t { @@ -49,7 +48,6 @@ typedef struct _usage_stats_t { typedef struct { const list_sched_selector_t *vtab; - const arch_env_t *arch_env; } reg_pressure_main_env_t; typedef struct { @@ -80,7 +78,7 @@ static int cmp_usage(const void *a, const void *b) * One of them is live at the end of the block. * Then, that one shall be scheduled at after the other */ - if(res != 0) + if (res != 0) return res; @@ -88,12 +86,12 @@ static int cmp_usage(const void *a, const void *b) } #endif -static INLINE usage_stats_t *get_or_set_usage_stats(reg_pressure_selector_env_t *env, ir_node *irn) +static inline usage_stats_t *get_or_set_usage_stats(reg_pressure_selector_env_t *env, ir_node *irn) { usage_stats_t *us = get_irn_link(irn); - if(!us) { - us = obstack_alloc(&env->obst, sizeof(us[0])); + if (!us) { + us = OALLOC(&env->obst, usage_stats_t); us->irn = irn; us->already_consumed = 0; us->max_hops = INT_MAX; @@ -105,7 +103,7 @@ static INLINE usage_stats_t *get_or_set_usage_stats(reg_pressure_selector_env_t return us; } -static INLINE usage_stats_t *get_usage_stats(ir_node *irn) +static inline usage_stats_t *get_usage_stats(ir_node *irn) { usage_stats_t *us = get_irn_link(irn); assert(us && "This node must have usage stats"); @@ -119,20 +117,20 @@ static int max_hops_walker(reg_pressure_selector_env_t *env, ir_node *irn, ir_no * If the reached node is not in the block desired, * return the value passed for this situation. */ - if(get_nodes_block(irn) != bl) + if (get_nodes_block(irn) != bl) return block_dominates(bl, curr_bl) ? 0 : INT_MAX; /* * If the node is in the current block but not * yet scheduled, we keep on searching from that node. */ - if(!ir_nodeset_contains(&env->already_scheduled, irn)) { + if (!ir_nodeset_contains(&env->already_scheduled, irn)) { int i, n; int res = 0; - for(i = 0, n = get_irn_ins_or_deps(irn); i < n; ++i) { + for (i = 0, n = get_irn_ins_or_deps(irn); i < n; ++i) { ir_node *operand = get_irn_in_or_dep(irn, i); - if(get_irn_visited(operand) < visited_nr) { + if (get_irn_visited(operand) < visited_nr) { int tmp; set_irn_visited(operand, visited_nr); @@ -173,31 +171,30 @@ static int compute_max_hops(reg_pressure_selector_env_t *env, ir_node *irn) return res; } -static void *reg_pressure_graph_init(const list_sched_selector_t *vtab, const arch_env_t *arch_env, ir_graph *irg) +static void *reg_pressure_graph_init(const list_sched_selector_t *vtab, const be_irg_t *birg) { - reg_pressure_main_env_t *main_env = xmalloc(sizeof(main_env[0])); + reg_pressure_main_env_t *main_env = XMALLOC(reg_pressure_main_env_t); - main_env->arch_env = arch_env; - main_env->vtab = vtab; - irg_walk_graph(irg, firm_clear_link, NULL, NULL); + main_env->vtab = vtab; + irg_walk_graph(be_get_birg_irg(birg), firm_clear_link, NULL, NULL); return main_env; } -static INLINE int must_appear_in_schedule(const list_sched_selector_t *sel, void *block_env, const ir_node *irn) +static inline int must_appear_in_schedule(const list_sched_selector_t *sel, void *block_env, const ir_node *irn) { int res = -1; - if(sel->to_appear_in_schedule) + if (sel->to_appear_in_schedule) res = sel->to_appear_in_schedule(block_env, irn); - return res >= 0 ? res : (to_appear_in_schedule(irn) || be_is_Keep(irn) || be_is_CopyKeep(irn) || be_is_RegParams(irn)); + return res >= 0 ? res : (to_appear_in_schedule(irn) || be_is_Keep(irn) || be_is_CopyKeep(irn) || be_is_Start(irn)); } static void *reg_pressure_block_init(void *graph_env, ir_node *bl) { ir_node *irn; - reg_pressure_selector_env_t *env = xmalloc(sizeof(env[0])); + reg_pressure_selector_env_t *env = XMALLOC(reg_pressure_selector_env_t); obstack_init(&env->obst); ir_nodeset_init(&env->already_scheduled); @@ -208,15 +205,15 @@ static void *reg_pressure_block_init(void *graph_env, ir_node *bl) * Collect usage statistics. */ sched_foreach(bl, irn) { - if(must_appear_in_schedule(env->main_env->vtab, env, irn)) { + if (must_appear_in_schedule(env->main_env->vtab, env, irn)) { int i, n; - for(i = 0, n = get_irn_arity(irn); i < n; ++i) { + for (i = 0, n = get_irn_arity(irn); i < n; ++i) { //ir_node *op = get_irn_n(irn, i); - if(must_appear_in_schedule(env->main_env->vtab, env, irn)) { + if (must_appear_in_schedule(env->main_env->vtab, env, irn)) { usage_stats_t *us = get_or_set_usage_stats(env, irn); #if 0 /* Liveness is not computed here! */ - if(is_live_end(bl, op)) + if (is_live_end(bl, op)) us->uses_in_block = 99999; else #endif @@ -234,7 +231,7 @@ static void reg_pressure_block_free(void *block_env) reg_pressure_selector_env_t *env = block_env; usage_stats_t *us; - for(us = env->root; us; us = us->next) + for (us = env->root; us; us = us->next) set_irn_link(us->irn, NULL); obstack_free(&env->obst, NULL); @@ -245,29 +242,29 @@ static void reg_pressure_block_free(void *block_env) static int get_result_hops_sum(reg_pressure_selector_env_t *env, ir_node *irn) { int res = 0; - if(get_irn_mode(irn) == mode_T) { + if (get_irn_mode(irn) == mode_T) { const ir_edge_t *edge; foreach_out_edge(irn, edge) res += get_result_hops_sum(env, get_edge_src_irn(edge)); } - else if(mode_is_data(get_irn_mode(irn))) + else if (mode_is_data(get_irn_mode(irn))) res = compute_max_hops(env, irn); return res; } -static INLINE int reg_pr_costs(reg_pressure_selector_env_t *env, ir_node *irn) +static inline int reg_pr_costs(reg_pressure_selector_env_t *env, ir_node *irn) { int i, n; int sum = 0; - for(i = 0, n = get_irn_arity(irn); i < n; ++i) { + for (i = 0, n = get_irn_arity(irn); i < n; ++i) { ir_node *op = get_irn_n(irn, i); - if(must_appear_in_schedule(env->main_env->vtab, env, op)) + if (must_appear_in_schedule(env->main_env->vtab, env, op)) sum += compute_max_hops(env, op); } @@ -283,16 +280,17 @@ static ir_node *reg_pressure_select(void *block_env, ir_nodeset_t *ready_set, reg_pressure_selector_env_t *env = block_env; ir_node *irn, *res = NULL; int curr_cost = INT_MAX; + (void) live_set; assert(ir_nodeset_size(ready_set) > 0); ir_nodeset_iterator_init(&iter, ready_set); - while( (irn = ir_nodeset_iterator_next(&iter)) != NULL) { + while ( (irn = ir_nodeset_iterator_next(&iter)) != NULL) { /* Ignore branch instructions for the time being. They should only be scheduled if there is nothing else. */ - if (! arch_irn_class_is(env->main_env->arch_env, irn, branch)) { + if (!is_cfop(irn)) { int costs = reg_pr_costs(env, irn); if (costs <= curr_cost) { res = irn; @@ -306,7 +304,7 @@ static ir_node *reg_pressure_select(void *block_env, ir_nodeset_t *ready_set, Take it and finish. */ - if(!res) { + if (!res) { ir_nodeset_iterator_init(&iter, ready_set); res = ir_nodeset_iterator_next(&iter); @@ -317,7 +315,7 @@ static ir_node *reg_pressure_select(void *block_env, ir_nodeset_t *ready_set, return res; } -static const list_sched_selector_t reg_pressure_selector_struct = { +const list_sched_selector_t reg_pressure_selector = { reg_pressure_graph_init, reg_pressure_block_init, reg_pressure_select, @@ -329,5 +327,3 @@ static const list_sched_selector_t reg_pressure_selector_struct = { reg_pressure_block_free, free }; - -const list_sched_selector_t *reg_pressure_selector = ®_pressure_selector_struct;