X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbespillremat.c;h=b0e1e3696c1e86950635d79ca1c3de5be82569b2;hb=b519dd6a1e6d85e843eff533be787d1f138a07ff;hp=882e951fbf927fa33c97037214339dcb1a67d407;hpb=863d31d7a5c8210432fef88b30fc3e8353131538;p=libfirm diff --git a/ir/be/bespillremat.c b/ir/be/bespillremat.c index 882e951fb..b0e1e3696 100644 --- a/ir/be/bespillremat.c +++ b/ir/be/bespillremat.c @@ -1,12 +1,28 @@ -/** vim: set sw=4 ts=4: - * @file bespillremat.c - * @date 2006-04-06 - * @author Adam M. Szalkowski & Sebastian Hack +/* + * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. * - * ILP based spilling & rematerialization + * This file is part of libFirm. * - * Copyright (C) 2006 Universitaet Karlsruhe - * Released under the GPL + * 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 ILP based spilling & rematerialization + * @author Adam M. Szalkowski + * @date 06.04.2006 + * @version $Id$ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -29,8 +45,9 @@ #include "irnode_t.h" #include "ircons_t.h" #include "irloop_t.h" +#include "irnodeset.h" #include "phiclass.h" -#include "iredges.h" +#include "iredges_t.h" #include "execfreq.h" #include "irvrfy.h" #include "irbackedge_t.h" @@ -41,10 +58,12 @@ #include #include "be_t.h" +#include "beirg_t.h" #include "belive_t.h" #include "besched_t.h" -#include "beirgmod.h" -#include "bearch.h" +#include "bessaconstr.h" +#include "bearch_t.h" +#include "beintlive_t.h" #include "beabi.h" #include "benode_t.h" #include "beutil.h" @@ -53,8 +72,8 @@ #include "bepressurestat.h" #include "beprofile.h" #include "bespilloptions.h" - #include "bechordal_t.h" +#include "bemodule.h" #include #include @@ -150,7 +169,7 @@ static const lc_opt_table_entry_t options[] = { LC_OPT_ENT_DBL ("cost_memoperand", "cost of a memory operand", &opt_cost_memoperand), LC_OPT_ENT_DBL ("cost_spill", "cost of a spill instruction", &opt_cost_spill), LC_OPT_ENT_DBL ("cost_remat", "cost of a rematerialization", &opt_cost_remat), - { NULL } + LC_OPT_LAST }; //#define EXECFREQ_LOOPDEPH /* compute execution frequency from loop depth only */ @@ -285,7 +304,7 @@ static int cmp_remat(const void *a, const void *b) { const remat_t *r = a; - const remat_t *s = a; + const remat_t *s = b; return !(r == s || r->op == s->op); } @@ -295,6 +314,7 @@ cmp_spill(const void *a, const void *b, size_t size) { const spill_t *p = a; const spill_t *q = b; + (void) size; // return !(p->irn == q->irn && p->bb == q->bb); return !(p->irn == q->irn); @@ -305,6 +325,7 @@ cmp_memoperands(const void *a, const void *b, size_t size) { const memoperand_t *p = a; const memoperand_t *q = b; + (void) size; return !(p->irn == q->irn && p->pos == q->pos); } @@ -390,6 +411,7 @@ cmp_remat_info(const void *a, const void *b, size_t size) { const remat_info_t *p = a; const remat_info_t *q = b; + (void) size; return !(p->irn == q->irn); } @@ -399,6 +421,7 @@ cmp_defs(const void *a, const void *b, size_t size) { const defs_t *p = a; const defs_t *q = b; + (void) size; return !(p->value == q->value); } @@ -408,6 +431,7 @@ cmp_keyval(const void *a, const void *b, size_t size) { const keyval_t *p = a; const keyval_t *q = b; + (void) size; return !(p->key == q->key); } @@ -658,6 +682,7 @@ value_is_defined_before(const spill_ilp_t * si, const ir_node * pos, const ir_no ir_node *block; ir_node *def_block = get_nodes_block(val); int ret; + (void) si; if(val == pos) return 0; @@ -702,6 +727,7 @@ sched_block_first_nonphi(const ir_node * bb) static int sched_skip_proj_predicator(const ir_node * irn, void * data) { + (void) data; return (is_Proj(irn)); } @@ -2851,6 +2877,7 @@ cmp_interference(const void *a, const void *b, size_t size) { const interference_t *p = a; const interference_t *q = b; + (void) size; return !(p->a == q->a && p->b == q->b); } @@ -2893,19 +2920,19 @@ set_insert_interference(spill_ilp_t * si, set * set, ir_node * a, ir_node * b, i return result; } -static int -values_interfere_in_block(const spill_ilp_t * si, const ir_node * bb, const ir_node * a, const ir_node * b) +static +int values_interfere_in_block(const spill_ilp_t *si, const ir_node *bb, const ir_node *a, const ir_node *b) { const ir_edge_t *edge; - if(get_nodes_block(a) != bb && get_nodes_block(b) != bb) { + if (get_nodes_block(a) != bb && get_nodes_block(b) != bb) { /* both values are live in, so they interfere */ return 1; } /* ensure a dominates b */ - if(value_dominates(b,a)) { - const ir_node * t; + if (value_dominates(b, a)) { + const ir_node *t; t = b; b = a; a = t; @@ -2914,15 +2941,15 @@ values_interfere_in_block(const spill_ilp_t * si, const ir_node * bb, const ir_n /* the following code is stolen from bera.c */ - if(be_is_live_end(si->lv, bb, a)) + if (be_is_live_end(si->lv, bb, a)) return 1; foreach_out_edge(a, edge) { const ir_node *user = edge->src; - if(get_nodes_block(user) == bb - && !is_Phi(user) + if (get_nodes_block(user) == bb + && ! is_Phi(user) && b != user - && !pset_find_ptr(si->inverse_ops, user) + && ! pset_find_ptr(si->inverse_ops, user) && value_dominates(b, user)) return 1; } @@ -3223,6 +3250,7 @@ is_zero(double x) static int mark_remat_nodes_hook(FILE *F, ir_node *n, ir_node *l) { spill_ilp_t *si = get_irg_link(current_ir_graph); + (void) l; if(pset_find_ptr(si->all_possible_remats, n)) { op_t *op = (op_t*)get_irn_link(n); @@ -3438,6 +3466,7 @@ delete_remat(spill_ilp_t * si, ir_node * remat) { } } +/* FIXME: is this still correct:? Proj's are neither scheduled anymore nor they have a block ... */ static void clean_remat_info(spill_ilp_t * si) { @@ -4130,10 +4159,10 @@ static void rewire_uses(spill_ilp_t * si) { defs_t *defs; - pset *ignore = pset_new_ptr(1); - be_dom_front_info_t *dom_front = si->birg->dom_front; + ir_nodeset_t ignore; - pset_insert_ptr(ignore, get_irg_end(si->birg->irg)); + ir_nodeset_init(&ignore); + ir_nodeset_insert(&ignore, get_irg_end(si->birg->irg)); /* then fix uses of spills */ set_foreach(si->values, defs) { @@ -4156,11 +4185,25 @@ rewire_uses(spill_ilp_t * si) spills = get_spills_for_value(si, defs->value); DBG((si->dbg, LEVEL_2, "\t %d remats, %d reloads, and %d spills for value %+F\n", remats, pset_count(reloads), pset_count(spills), defs->value)); if(pset_count(spills) > 1) { + be_ssa_construction_env_t senv; + ir_node *node; //assert(pset_count(reloads) > 0); // print_irn_pset(spills); // print_irn_pset(reloads); - be_ssa_constr_set_ignore(dom_front, si->lv, spills, ignore); + be_ssa_construction_init(&senv, si->birg); + be_ssa_construction_set_ignore_uses(&senv, &ignore); + pset_foreach(spills, node) { + be_ssa_construction_add_copy(&senv, node); + } + pset_foreach(spills, node) { + be_ssa_construction_fix_users(&senv, node); + } + be_ssa_construction_update_liveness_phis(&senv, si->lv); + pset_foreach(spills, node) { + be_liveness_update(si->lv, node); + } + be_ssa_construction_destroy(&senv); } del_pset(reloads); @@ -4169,29 +4212,51 @@ rewire_uses(spill_ilp_t * si) /* first fix uses of remats and reloads */ set_foreach(si->values, defs) { - pset *nodes; const ir_node *next = defs->remats; int orig_kept = 0; if(next) { - nodes = pset_new_ptr_default(); + be_ssa_construction_env_t senv; + + be_ssa_construction_init(&senv, si->birg); + if(sched_is_scheduled(defs->value)) { - pset_insert_ptr(nodes, defs->value); + be_ssa_construction_add_copy(&senv, (ir_node*) defs->value); orig_kept = 1; } + next = defs->remats; while(next) { - pset_insert_ptr(nodes, next); + be_ssa_construction_add_copy(&senv, (ir_node*) next); next = get_irn_link(next); } - DBG((si->dbg, LEVEL_4, "\t %d new definitions for value %+F\n", pset_count(nodes)-orig_kept, defs->value)); - be_ssa_constr_set_ignore(dom_front, si->lv, nodes, NULL); + if(sched_is_scheduled(defs->value)) { + be_ssa_construction_fix_users(&senv, (ir_node*) defs->value); + } + + next = defs->remats; + while(next) { + be_ssa_construction_fix_users(&senv, (ir_node*) next); + next = get_irn_link(next); + } + + be_ssa_construction_update_liveness_phis(&senv, si->lv); + if(sched_is_scheduled(defs->value)) { + be_liveness_update(si->lv, (ir_node*) defs->value); + } + + next = defs->remats; + while(next) { + be_liveness_update(si->lv, (ir_node*) next); + next = get_irn_link(next); + } - del_pset(nodes); + be_ssa_construction_destroy(&senv); } } + ir_nodeset_destroy(&ignore); // remove_unused_defs(si); }