X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbespillmorgan.c;h=183ef81c92d2f41eb457a31be139d2be95f4fd26;hb=e1bfe8d072410f6ca115452bf9c1e3131fa27f4d;hp=1ed67c08382fc5463d89ac894cf1b51a4fc948ad;hpb=4d5c3365a58cba59993045a9e08e686d8ae079a7;p=libfirm diff --git a/ir/be/bespillmorgan.c b/ir/be/bespillmorgan.c index 1ed67c083..183ef81c9 100644 --- a/ir/be/bespillmorgan.c +++ b/ir/be/bespillmorgan.c @@ -17,35 +17,37 @@ * PURPOSE. */ -/* - * Author: Matthias Braun - * Date: 05.05.2006 - * Copyright: (c) Universitaet Karlsruhe - * License: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE. - * +/** + * @file + * @brief Morgans spill algorithm. + * @author Matthias Braun + * @date 05.05.2006 + * @version $Id$ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "bespillmorgan.h" - -#include "bechordal_t.h" -#include "bespill.h" -#include "belive_t.h" -#include "beabi.h" #include "irgwalk.h" -#include "besched.h" -#include "beutil.h" #include "irloop_t.h" #include "irgraph_t.h" #include "irprintf.h" #include "obst.h" +#include "error.h" +#include "bespillmorgan.h" +#include "bechordal_t.h" +#include "bespill.h" +#include "belive_t.h" +#include "beabi.h" #include "bespillbelady.h" #include "beverify.h" #include "benodesets.h" #include "bespilloptions.h" +#include "besched.h" +#include "beutil.h" +#include "bemodule.h" +#include "beirg_t.h" #define DBG_LIVE 1 #define DBG_LOOPANA 2 @@ -58,7 +60,7 @@ typedef struct morgan_env { const arch_env_t *arch; const arch_register_class_t *cls; ir_graph *irg; - const be_lv_t *lv; + be_lv_t *lv; struct obstack obst; /** maximum safe register pressure */ int registers_available; @@ -90,23 +92,26 @@ typedef struct morgan_block_attr { //--------------------------------------------------------------------------- -static int loop_edge_cmp(const void* p1, const void* p2, size_t s) { +static int loop_edge_cmp(const void* p1, const void* p2, size_t size) { loop_edge_t *e1 = (loop_edge_t*) p1; loop_edge_t *e2 = (loop_edge_t*) p2; + (void) size; return e1->block != e2->block || e1->pos != e2->pos; } -static int loop_attr_cmp(const void *e1, const void *e2, size_t s) { +static int loop_attr_cmp(const void *e1, const void *e2, size_t size) { loop_attr_t *la1 = (loop_attr_t*) e1; loop_attr_t *la2 = (loop_attr_t*) e2; + (void) size; return la1->loop != la2->loop; } -static int block_attr_cmp(const void *e1, const void *e2, size_t s) { +static int block_attr_cmp(const void *e1, const void *e2, size_t size) { block_attr_t *b1 = (block_attr_t*) e1; block_attr_t *b2 = (block_attr_t*) e2; + (void) size; return b1->block != b2->block; } @@ -310,7 +315,10 @@ static void construct_block_livethrough_unused(ir_node *block, void *data) { /* * All values that are used within the block are not unused (and therefore not * livethrough_unused) + * + * TODO FIXME use block out edges and not schedule to find uses */ + panic("needs fixing"); sched_foreach(block, node) { int i, arity; @@ -419,6 +427,7 @@ static void spill_values(morgan_env_t *env, const loop_attr_t *loop_attr, int sp const bitset_t *cand_bitset = loop_attr->livethrough_unused; int candidatecount = bitset_popcnt(cand_bitset); spillcandidate_t *candidates; + bitset_pos_t idx; int i, c; loop_edge_t *edge; @@ -429,8 +438,8 @@ static void spill_values(morgan_env_t *env, const loop_attr_t *loop_attr, int sp DBG((dbg, DBG_CHOOSE, "Candidates for loop %d\n", get_loop_loop_nr(loop_attr->loop))); // build candidiatelist c = 0; - bitset_foreach(cand_bitset, i) { - ir_node *node = get_idx_irn(env->irg, i); + bitset_foreach(cand_bitset, idx) { + ir_node *node = get_idx_irn(env->irg, idx); candidates[c].node = node; candidates[c].cost = 0; @@ -461,11 +470,13 @@ static int reduce_register_pressure_in_block(morgan_env_t *env, const ir_node* b ir_node *node; int max_pressure; int loop_unused_spills_needed; - pset *live_nodes = pset_new_ptr_default(); + ir_nodeset_t live_nodes; const be_lv_t *lv = env->lv; - be_liveness_end_of_block(lv, env->arch, env->cls, block, live_nodes); - max_pressure = pset_count(live_nodes); + ir_nodeset_init(&live_nodes); + + be_liveness_end_of_block(lv, env->arch, env->cls, block, &live_nodes); + max_pressure = ir_nodeset_size(&live_nodes); DBG((dbg, DBG_LIVE, "Reduce pressure to %d In Block %+F:\n", env->registers_available, block)); @@ -478,12 +489,12 @@ static int reduce_register_pressure_in_block(morgan_env_t *env, const ir_node* b if(is_Phi(node)) break; - be_liveness_transfer(env->arch, env->cls, node, live_nodes); - pressure = pset_count(live_nodes); + be_liveness_transfer(env->arch, env->cls, node, &live_nodes); + pressure = ir_nodeset_size(&live_nodes); if(pressure > max_pressure) max_pressure = pressure; } - del_pset(live_nodes); + ir_nodeset_destroy(&live_nodes); loop_unused_spills_needed = max_pressure - env->registers_available; @@ -560,29 +571,28 @@ static int reduce_register_pressure_in_loop(morgan_env_t *env, const ir_loop *lo } void be_spill_morgan(be_irg_t *birg, const arch_register_class_t *cls) { - ir_graph *irg = be_get_birg_irg(birg); + ir_graph *irg = be_get_birg_irg(birg); morgan_env_t env; - be_assure_liveness(birg); + be_liveness_assure_sets(be_assure_liveness(birg)); env.arch = birg->main_env->arch_env; - env.irg = irg; - env.cls = cls; - env.lv = be_get_birg_liveness(birg); + env.irg = irg; + env.cls = cls; + env.lv = be_get_birg_liveness(birg); env.senv = be_new_spill_env(birg); - DEBUG_ONLY(be_set_spill_env_dbg_module(env.senv, dbg);) obstack_init(&env.obst); env.registers_available = env.cls->n_regs - be_put_ignore_regs(birg, env.cls, NULL); - env.loop_attr_set = new_set(loop_attr_cmp, 5); + env.loop_attr_set = new_set(loop_attr_cmp, 5); env.block_attr_set = new_set(block_attr_cmp, 20); - /*-- Part1: Analysis --*/ + /* -- Part1: Analysis -- */ /* construct control flow loop tree */ - if(! (get_irg_loopinfo_state(irg) & loopinfo_cf_consistent)) { + if (! (get_irg_loopinfo_state(irg) & loopinfo_cf_consistent)) { construct_cf_backedges(irg); } @@ -590,7 +600,7 @@ void be_spill_morgan(be_irg_t *birg, const arch_register_class_t *cls) { irg_block_walk_graph(irg, construct_block_livethrough_unused, construct_loop_edges, &env); construct_loop_livethrough_unused(&env, get_irg_loop(irg)); - /*-- Part2: Transformation --*/ + /* -- Part2: Transformation -- */ /* spill unused livethrough values around loops and blocks where * the pressure is too high @@ -601,7 +611,7 @@ void be_spill_morgan(be_irg_t *birg, const arch_register_class_t *cls) { be_insert_spills_reloads(env.senv); /* Verify the result */ - if(birg->main_env->options->vrfy_option == BE_VRFY_WARN) { + if (birg->main_env->options->vrfy_option == BE_VRFY_WARN) { be_verify_schedule(birg); } else if (birg->main_env->options->vrfy_option == BE_VRFY_ASSERT) { assert(be_verify_schedule(birg));