X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=ir%2Fbe%2Fbeilpsched.c;h=f1b372b1608c96352e94b8442a3ba7705770d4f3;hb=2bc25d820b8f3f04feb5693e73bf5d446cdbcb50;hp=fab9262bcb21dd122d866aca641baee6c08517e1;hpb=a39875e8317d248b8d75669b3e19d2ce356b0f90;p=libfirm diff --git a/ir/be/beilpsched.c b/ir/be/beilpsched.c index fab9262bc..f1b372b16 100644 --- a/ir/be/beilpsched.c +++ b/ir/be/beilpsched.c @@ -1,12 +1,33 @@ +/* + * 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. + */ + /** - * Scheduling algorithms. + * @file + * @brief ILP based instruction scheduling. + * @author Christian Wuerdig + * @date 22.10.2006 + * @version $Id$ + * * An ILP scheduler based on * "ILP-based Instruction Scheduling for IA-64" * by Daniel Kaestner and Sebastian Winkel - * - * @date 22.10.2005 - * @author Christian Wuerdig - * @cvs-id $Id$ + * extended with register pressure constraints by Christian Wuerdig */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -30,7 +51,9 @@ #include "debug.h" #include "irtools.h" #include "irdump.h" +#include "irprintf.h" #include "plist.h" +#include "irprintf.h" #include #include @@ -44,6 +67,9 @@ #include "besched_t.h" #include "beilpsched.h" #include "beutil.h" +#include "bestat.h" +#include "beirg_t.h" +#include "benodesets.h" typedef struct _ilpsched_options_t { unsigned regpress; @@ -118,7 +144,7 @@ typedef struct { /* The ILP scheduling environment */ typedef struct { - phase_t ph; /**< The phase */ + ir_phase ph; /**< The phase */ ir_graph *irg; /**< The current irg */ heights_t *height; /**< The heights object of the irg */ void *irg_env; /**< An environment for the irg scheduling, provided by the backend */ @@ -255,7 +281,7 @@ static int cmp_ilpsched_irn(const void *a, const void *b) { /** * In case there is no phase information for irn, initialize it. */ -static void *init_ilpsched_irn(phase_t *ph, ir_node *irn, void *old) { +static void *init_ilpsched_irn(ir_phase *ph, ir_node *irn, void *old) { be_ilpsched_irn_t *res = old ? old : phase_alloc(ph, sizeof(res[0])); if (res == old) { @@ -1094,6 +1120,33 @@ static void create_variables(be_ilpsched_env_t *env, lpp_t *lpp, be_ilpsched_irn * *******************************************************/ +/** + * Collect all operands and nodes @p irn depends on. + * If there is a Proj within the dependencies, all other Projs of the parent node are added as well. + */ +static nodeset *sta_collect_in_deps(ir_node *irn, nodeset *deps) { + int i; + + for (i = get_irn_ins_or_deps(irn) - 1; i >= 0; --i) { + ir_node *p = get_irn_in_or_dep(irn, i); + + if (is_Proj(p)) { + const ir_edge_t *edge; + + p = get_Proj_pred(p); + foreach_out_edge(p, edge) { + ir_node *src = get_edge_src_irn(edge); + nodeset_insert(deps, src); + } + } + else { + nodeset_insert(deps, p); + } + } + + return deps; +} + /** * Create following ILP constraints: * - the assignment constraints: @@ -1114,10 +1167,12 @@ static void create_assignment_and_precedence_constraints(be_ilpsched_env_t *env, num_cst_assign = num_cst_prec = num_cst_dead = 0; foreach_linked_irns(ba->head_ilp_nodes, irn) { - int cst, tp_idx, i; + int cst, tp_idx; unsigned cur_var; be_ilpsched_irn_t *node; ilpsched_node_attr_t *na; + ir_node *pred; + nodeset *deps = new_nodeset(16); node = get_ilpsched_irn(env, irn); na = get_ilpsched_node_attr(node); @@ -1141,13 +1196,15 @@ static void create_assignment_and_precedence_constraints(be_ilpsched_env_t *env, /* the precedence constraints */ ilp_timer_push(t_cst_prec); bs_block_irns = bitset_clear_all(bs_block_irns); - for (i = get_irn_ins_or_deps(irn) - 1; i >= 0; --i) { - ir_node *pred = skip_normal_Proj(env->arch_env->isa, get_irn_in_or_dep(irn, i)); + + deps = sta_collect_in_deps(irn, deps); + foreach_nodeset(deps, pred) { unsigned t_low, t_high, t; be_ilpsched_irn_t *pred_node; ilpsched_node_attr_t *pna; unsigned delay; + pred = skip_normal_Proj(env->arch_env->isa, pred); if (is_Phi(pred) || block_node->irn != get_nodes_block(pred) || is_NoMem(pred)) continue; @@ -1214,6 +1271,7 @@ static void create_assignment_and_precedence_constraints(be_ilpsched_env_t *env, DEL_ARR_F(tmp_var_idx); } } + del_nodeset(deps); ilp_timer_pop(); } DBG((env->dbg, LEVEL_1, "\t%u assignement constraints (%g sec)\n", @@ -1915,10 +1973,38 @@ static void create_ilp(ir_node *block, void *walk_env) { } /* apply solution */ - if (need_heur) +#ifdef FIRM_STATISTICS + if (be_stat_ev_is_active()) { + be_stat_ev("nodes", ba->block_last_idx); + be_stat_ev("vars", lpp ? lpp->var_next : 0); + be_stat_ev("csts", lpp ? lpp->cst_next : 0); + } +#endif /* FIRM_STATISTICS */ + if (need_heur) { +#ifdef FIRM_STATISTICS + if (be_stat_ev_is_active()) { + be_stat_ev("time", -1); + be_stat_ev_dbl("opt", 0.0); + } +#endif /* FIRM_STATISTICS */ list_sched_single_block(env->birg, block, env->be_opts); - else + } + else { +#ifdef FIRM_STATISTICS + if (be_stat_ev_is_active()) { + if (lpp) { + double opt = lpp->sol_state == lpp_optimal ? 100.0 : 100.0 * lpp->best_bound / lpp->objval; + be_stat_ev_dbl("time", lpp->sol_time); + be_stat_ev_dbl("opt", opt); + } + else { + be_stat_ev_dbl("time", 0.0); + be_stat_ev_dbl("opt", 100.0); + } + } +#endif /* FIRM_STATISTICS */ apply_solution(env, lpp, block); + } if (lpp) free_lpp(lpp); @@ -1932,25 +2018,34 @@ static void create_ilp(ir_node *block, void *walk_env) { */ void be_ilp_sched(const be_irg_t *birg, be_options_t *be_opts) { be_ilpsched_env_t env; - const char *name = "be ilp scheduling"; - arch_isa_t *isa = birg->main_env->arch_env->isa; - const ilp_sched_selector_t *sel = isa->impl->get_ilp_sched_selector(isa); + const char *name = "be ilp scheduling"; + ir_graph *irg = be_get_birg_irg(birg); + const arch_env_t *arch_env = be_get_birg_arch_env(birg); + const arch_isa_t *isa = arch_env->isa; + const ilp_sched_selector_t *sel = isa->impl->get_ilp_sched_selector(isa); FIRM_DBG_REGISTER(env.dbg, "firm.be.sched.ilp"); +#ifdef FIRM_STATISTICS + if (be_stat_ev_is_active()) { + be_stat_tags[STAT_TAG_CLS] = "ilpsched"; + be_stat_ev_push(be_stat_tags, STAT_TAG_LAST, be_stat_file); + } +#endif /* FIRM_STATISTICS */ + // firm_dbg_set_mask(env.dbg, 1); - env.irg_env = be_ilp_sched_init_irg_ilp_schedule(sel, birg->irg); + env.irg_env = be_ilp_sched_init_irg_ilp_schedule(sel, irg); env.sel = sel; - env.irg = birg->irg; - env.height = heights_new(birg->irg); + env.irg = irg; + env.height = heights_new(irg); env.main_env = birg->main_env; - env.arch_env = birg->main_env->arch_env; - env.cpu = arch_isa_get_machine(birg->main_env->arch_env->isa); + env.arch_env = arch_env; + env.cpu = arch_isa_get_machine(arch_env->isa); env.opts = &ilp_opts; env.birg = birg; env.be_opts = be_opts; - phase_init(&env.ph, name, env.irg, PHASE_DEFAULT_GROWTH, init_ilpsched_irn); + phase_init(&env.ph, name, env.irg, PHASE_DEFAULT_GROWTH, init_ilpsched_irn, NULL); /* assign a unique per block number to all interesting nodes */ irg_walk_in_or_dep_graph(env.irg, NULL, build_block_idx, &env); @@ -1992,6 +2087,12 @@ void be_ilp_sched(const be_irg_t *birg, be_options_t *be_opts) { /* notify backend */ be_ilp_sched_finish_irg_ilp_schedule(sel, birg->irg, env.irg_env); + +#ifdef FIRM_STATISTICS + if (be_stat_ev_is_active()) { + be_stat_ev_pop(); + } +#endif /* FIRM_STATISTICS */ } /**