X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbespillmorgan.c;h=1ebce396b9f9bc0caae5f2ae9e5c23b78c78031c;hb=8cb8fe7d9d69a9bd06365823d5d5f68d051f6db0;hp=f889bccdcfa3599e79b2d7c0cb4b37695729a657;hpb=8624e724f0873fe99349c327f9bb0a618910106e;p=libfirm diff --git a/ir/be/bespillmorgan.c b/ir/be/bespillmorgan.c index f889bccdc..1ebce396b 100644 --- a/ir/be/bespillmorgan.c +++ b/ir/be/bespillmorgan.c @@ -1,32 +1,52 @@ /* - * Author: Matthias Braun - * Date: 05.05.2006 - * Copyright: (c) Universitaet Karlsruhe - * License: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE. + * Copyright (C) 1995-2007 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. + */ + +/** + * @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 "obstack.h" +#include "obst.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 @@ -36,10 +56,10 @@ DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;) typedef struct morgan_env { - const be_chordal_env_t *cenv; const arch_env_t *arch; const arch_register_class_t *cls; ir_graph *irg; + const be_lv_t *lv; struct obstack obst; /** maximum safe register pressure */ int registers_available; @@ -63,7 +83,7 @@ typedef struct loop_attr { bitset_t *livethrough_unused; } loop_attr_t; -typedef struct block_attr { +typedef struct morgan_block_attr { const ir_node *block; /** set of all values that are live in the block but not used in the block */ bitset_t *livethrough_unused; @@ -241,7 +261,7 @@ static void show_nodebitset(ir_graph* irg, const bitset_t* bitset) { static INLINE void init_livethrough_unuseds(block_attr_t *attr, morgan_env_t *env) { const ir_node *block; int i; - be_lv_t *lv = env->cenv->birg->lv; + const be_lv_t *lv = env->lv; if(attr->livethrough_unused != NULL) return; @@ -433,7 +453,7 @@ static void spill_values(morgan_env_t *env, const loop_attr_t *loop_attr, int sp DBG((dbg, DBG_CHOOSE, "Spilling %+F ", to_spill)); for(edge = set_first(loop_attr->out_edges); edge != NULL; edge = set_next(loop_attr->out_edges)) { - be_add_reload_on_edge(env->senv, to_spill, edge->block, edge->pos, env->cls); + be_add_reload_on_edge(env->senv, to_spill, edge->block, edge->pos, env->cls, 1); } } } @@ -443,7 +463,7 @@ static int reduce_register_pressure_in_block(morgan_env_t *env, const ir_node* b int max_pressure; int loop_unused_spills_needed; pset *live_nodes = pset_new_ptr_default(); - be_lv_t *lv = env->cenv->birg->lv; + 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); @@ -540,33 +560,30 @@ static int reduce_register_pressure_in_loop(morgan_env_t *env, const ir_loop *lo return outer_spills_needed; } -void be_spill_morgan(const be_chordal_env_t *chordal_env) { - ir_graph *irg = chordal_env->irg; +void be_spill_morgan(be_irg_t *birg, const arch_register_class_t *cls) { + ir_graph *irg = be_get_birg_irg(birg); morgan_env_t env; - FIRM_DBG_REGISTER(dbg, "ir.be.spillmorgan"); - //firm_dbg_set_mask(dbg, DBG_SPILLS | DBG_LOOPANA); + be_assure_liveness(birg); - env.cenv = chordal_env; - env.arch = chordal_env->birg->main_env->arch_env; - env.irg = chordal_env->irg; - env.cls = chordal_env->cls; - env.senv = be_new_spill_env(chordal_env); + env.arch = birg->main_env->arch_env; + 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(chordal_env->birg, env.cls, NULL); + 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 --*/ - //Matze: I hope liveness information is up to date at this point... - //be_liveness_recompute(chordal_env->lv); + /* -- 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); } @@ -574,7 +591,7 @@ void be_spill_morgan(const be_chordal_env_t *chordal_env) { 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 @@ -585,22 +602,19 @@ void be_spill_morgan(const be_chordal_env_t *chordal_env) { be_insert_spills_reloads(env.senv); /* Verify the result */ - if (chordal_env->opts->vrfy_option == BE_CH_VRFY_WARN) { - be_verify_schedule(irg); - } else if (chordal_env->opts->vrfy_option == BE_CH_VRFY_ASSERT) { - assert(be_verify_schedule(irg)); + 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)); } - if (chordal_env->opts->dump_flags & BE_CH_DUMP_SPILL) - be_dump(irg, "-spillmorgan", dump_ir_block_graph_sched); - /* cleanup */ free_loop_edges(&env); del_set(env.loop_attr_set); del_set(env.block_attr_set); /* fix the remaining places with too high register pressure with beladies algorithm */ - be_spill_belady_spill_env(chordal_env, env.senv); + be_spill_belady_spill_env(birg, cls, env.senv); be_delete_spill_env(env.senv); obstack_free(&env.obst, NULL); @@ -613,6 +627,7 @@ void be_init_spillmorgan(void) }; be_register_spiller("morgan", &morgan_spiller); + FIRM_DBG_REGISTER(dbg, "ir.be.spillmorgan"); } BE_REGISTER_MODULE_CONSTRUCTOR(be_init_spillmorgan);