X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbecopyheur3.c;h=18cae3964d163c6c11473eb5199725394f3b11df;hb=c4d387cb4389654e978ea808027ea2be724c513c;hp=1c2decdd2e0ab280ce6580fb8803fe57bba7bfe6;hpb=cb0c12e4aa9e238abd067ec1e9bc8a55115e29a4;p=libfirm diff --git a/ir/be/becopyheur3.c b/ir/be/becopyheur3.c index 1c2decdd2..18cae3964 100644 --- a/ir/be/becopyheur3.c +++ b/ir/be/becopyheur3.c @@ -1,18 +1,37 @@ +/* + * Copyright (C) 1995-2008 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. + */ /** - * More experiments on coalescing. - * @author Sebastian Hack - * @date 25.07.2006 + * @file + * @brief More experiments on coalescing with Java implementation. + * @author Sebastian Hack + * @date 25.07.2006 + * @version $Id$ */ - #ifdef HAVE_CONFIG_H #include "config.h" #endif -#ifdef WITH_LIBCORE -#include -#include -#endif /* WITH_LIBCORE */ +#ifdef WITH_JVM + +#include "lc_opts.h" +#include "lc_opts_enum.h" #include #include @@ -24,13 +43,14 @@ #include "debug.h" #include "bitfiddle.h" #include "bitset.h" +#include "raw_bitset.h" -#include "irphase_t.h" #include "irgraph_t.h" #include "irnode_t.h" #include "irprintf.h" #include "irtools.h" +#include "bemodule.h" #include "beabi.h" #include "benode_t.h" #include "becopyopt.h" @@ -45,10 +65,9 @@ #define DUMP_AFTER 2 #define DUMP_ALL 2 * DUMP_AFTER - 1 -static int dump_flags = 0; -static int dbg_level = 0; +static unsigned dump_flags = 0; +static int dbg_level = 0; -#ifdef WITH_LIBCORE static const lc_opt_enum_mask_items_t dump_items[] = { { "before", DUMP_BEFORE }, { "after", DUMP_AFTER }, @@ -61,37 +80,43 @@ static lc_opt_enum_mask_var_t dump_var = { }; static const lc_opt_table_entry_t options[] = { - LC_OPT_ENT_ENUM_MASK("dump", "dump ifg before, after or after each cloud", &dump_var), + LC_OPT_ENT_ENUM_MASK("dump", "dump ifg cloud", &dump_var), LC_OPT_ENT_INT ("dbg", "debug level for the Java coalescer", &dbg_level), - { NULL } + LC_OPT_LAST }; -void be_co3_register_options(lc_opt_entry_t *grp) +void be_init_copyheur3(void) { - lc_opt_entry_t *co3_grp = lc_opt_get_grp(grp, "co3"); + lc_opt_entry_t *be_grp = lc_opt_get_grp(firm_opt_get_root(), "be"); + lc_opt_entry_t *ra_grp = lc_opt_get_grp(be_grp, "ra"); + lc_opt_entry_t *chordal_grp = lc_opt_get_grp(ra_grp, "chordal"); + lc_opt_entry_t *co3_grp = lc_opt_get_grp(chordal_grp, "co3"); + lc_opt_add_table(co3_grp, options); } -#endif +BE_REGISTER_MODULE_CONSTRUCTOR(be_init_copyheur3); -static void set_admissible_regs(java_coal_t *coal, copy_opt_t *co, ir_node *irn, int t_idx, int *col_map) +static void set_admissible_regs(be_java_coal_t *coal, copy_opt_t *co, ir_node *irn, int t_idx, int *col_map) { - unsigned i; - arch_register_req_t req; - unsigned n_regs = co->cls->n_regs; - unsigned idx = get_irn_idx(irn); - - arch_get_register_req(co->aenv, &req, irn, BE_OUT_POS(0)); - if(arch_register_req_is(&req, limited)) { - bitset_t *adm = bitset_alloca(n_regs); - req.limited(req.limited_env, adm); - for(i = 0; i < n_regs; ++i) - if(!bitset_is_set(adm, i) && col_map[i] >= 0) - java_coal_forbid_color(coal, t_idx, col_map[i]); + const arch_register_req_t *req; + + req = arch_get_register_req(co->aenv, irn, BE_OUT_POS(0)); + + // ir_printf("%+F\n", irn); + if(arch_register_req_is(req, limited)) { + unsigned i; + unsigned n_regs = co->cls->n_regs; + + for(i = 0; i < n_regs; ++i) { + if(!rbitset_is_set(req->limited, i) && col_map[i] >= 0) { + be_java_coal_forbid_color(coal, t_idx, col_map[i]); + } + } } } -void co_solve_heuristic_java(copy_opt_t *co) +int co_solve_heuristic_java(copy_opt_t *co) { be_ifg_t *ifg = co->cenv->ifg; void *nodes_it = be_ifg_nodes_iter_alloca(ifg); @@ -99,6 +124,7 @@ void co_solve_heuristic_java(copy_opt_t *co) bitset_t *nodes = bitset_malloc(get_irg_last_idx(co->irg)); unsigned n_regs = co->cenv->cls->n_regs; + char dbg[256]; unsigned i, j, curr_idx; int *col_map; int *inv_col_map; @@ -106,28 +132,26 @@ void co_solve_heuristic_java(copy_opt_t *co) int *node_map; int *inv_node_map; - java_coal_t *coal; + be_java_coal_t *coal; ir_node *n, *m; - int max_idx = 0; col_map = alloca(n_regs * sizeof(col_map[0])); inv_col_map = alloca(n_regs * sizeof(inv_col_map[0])); - memset(inv_col_map, 0, sizeof(inv_col_map[0]) * n_regs); + memset(inv_col_map, -1, sizeof(inv_col_map[0]) * n_regs); for(i = 0, j = 0; i < n_regs; ++i) { const arch_register_t *reg = &co->cls->regs[i]; - col_map[i] = i; - inv_col_map[i] = i; + col_map[i] = -1; if(!arch_register_type_is(reg, ignore)) { - //col_map[i] = j; - //inv_col_map[j] = i; + col_map[i] = j; + inv_col_map[j] = i; ++j; } } - node_map = malloc((get_irg_last_idx(co->irg) + 1) * sizeof(node_map[0])); - inv_node_map = malloc((get_irg_last_idx(co->irg) + 1) * sizeof(inv_node_map[0])); + node_map = xmalloc((get_irg_last_idx(co->irg) + 1) * sizeof(node_map[0])); + inv_node_map = xmalloc((get_irg_last_idx(co->irg) + 1) * sizeof(inv_node_map[0])); curr_idx = 0; be_ifg_foreach_node(ifg, nodes_it, n) { @@ -144,10 +168,10 @@ void co_solve_heuristic_java(copy_opt_t *co) free(node_map); free(inv_node_map); bitset_free(nodes); - return; + return 0; } - coal = java_coal_init("test", curr_idx, j, dbg_level); + coal = be_java_coal_init("test", curr_idx, j, dbg_level); /* Check, if all neighbours are indeed connected to the node. */ be_ifg_foreach_node(ifg, nodes_it, n) { @@ -157,14 +181,16 @@ void co_solve_heuristic_java(copy_opt_t *co) if(bitset_is_set(nodes, n_idx)) { affinity_node_t *an = get_affinity_info(co, n); - java_coal_set_color(coal, t_idx, col_map[arch_get_irn_register(co->aenv, n)->index]); + ir_snprintf(dbg, sizeof(dbg), "%+F", n); + be_java_coal_set_debug(coal, t_idx, dbg); + be_java_coal_set_color(coal, t_idx, col_map[arch_get_irn_register(co->aenv, n)->index]); set_admissible_regs(coal, co, n, t_idx, col_map); be_ifg_foreach_neighbour(ifg, neigh_it, n, m) { int m_idx = get_irn_idx(m); int s_idx = node_map[m_idx]; if(n_idx < m_idx && bitset_is_set(nodes, m_idx)) { - java_coal_add_int_edge(coal, s_idx, t_idx); + be_java_coal_add_int_edge(coal, s_idx, t_idx); } } @@ -175,7 +201,7 @@ void co_solve_heuristic_java(copy_opt_t *co) int s_idx = node_map[m_idx]; if(n_idx < m_idx && bitset_is_set(nodes, m_idx)) { - java_coal_add_aff_edge(coal, s_idx, t_idx, neigh->costs); + be_java_coal_add_aff_edge(coal, s_idx, t_idx, neigh->costs); } } } @@ -185,17 +211,20 @@ void co_solve_heuristic_java(copy_opt_t *co) if(dump_flags & DUMP_BEFORE) { char fn[512]; ir_snprintf(fn, sizeof(fn), "%F-%s-before.dot", co->cenv->irg, co->cenv->cls->name); - java_coal_dump(coal, fn); + be_java_coal_dump(coal, fn); } - java_coal_coalesce(coal); + be_java_coal_coalesce(coal); be_ifg_foreach_node(ifg, nodes_it, n) { unsigned idx = get_irn_idx(n); if(bitset_is_set(nodes, idx)) { unsigned t_idx = node_map[idx]; - unsigned col = inv_col_map[java_coal_get_color(coal, t_idx)]; - const arch_register_t *reg = &co->cls->regs[col]; + unsigned col = inv_col_map[be_java_coal_get_color(coal, t_idx)]; + const arch_register_t *reg; + + assert(col < n_regs); + reg = &co->cls->regs[col]; arch_set_irn_register(co->aenv, n, reg); } } @@ -203,9 +232,12 @@ void co_solve_heuristic_java(copy_opt_t *co) if(dump_flags & DUMP_AFTER) { char fn[512]; ir_snprintf(fn, sizeof(fn), "%F-%s-after.dot", co->cenv->irg, co->cenv->cls->name); - java_coal_dump(coal, fn); + be_java_coal_dump(coal, fn); } - java_coal_destroy(coal); + be_java_coal_destroy(coal); bitset_free(nodes); + return 0; } + +#endif