X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbessaconstr.c;h=768280ad6c456dacfe3bdd20bcefd840a5bdbef5;hb=0ac0b440ce2d239c5e7e7db56b8273559d9a7741;hp=7421805fcde47adead153c79dc1c2ea4575e2031;hpb=c719c20ba0a93056a054bd07f46de3f3a8838672;p=libfirm diff --git a/ir/be/bessaconstr.c b/ir/be/bessaconstr.c index 7421805fc..768280ad6 100644 --- a/ir/be/bessaconstr.c +++ b/ir/be/bessaconstr.c @@ -1,20 +1,6 @@ /* - * 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. + * Copyright (C) 2012 University of Karlsruhe. */ /** @@ -68,6 +54,7 @@ #include "ircons.h" #include "iredges_t.h" +#include "statev_t.h" DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;) @@ -133,15 +120,6 @@ static bool is_definition(be_ssa_construction_env_t *env, ir_node *node) return info != NULL && info->is_definition; } -/** - * @return Whether the node is a use. - */ -static bool is_use(const be_ssa_construction_env_t *env, ir_node *node) -{ - constr_info *info = get_info(env, node); - return info != NULL && info->is_use; -} - /** * Introduces a definition at the corresponding block. */ @@ -268,19 +246,26 @@ static ir_node *get_def_at_idom(be_ssa_construction_env_t *env, ir_node *block) return search_def_end_of_block(env, dom); } +static ir_node *get_def_from_preds(be_ssa_construction_env_t *const env, ir_node *const block) +{ + /* Create a phi if the block is in the dominance frontier. */ + if (Block_block_visited(block)) { + return insert_dummy_phi(env, block); + } else { + return get_def_at_idom(env, block); + } +} + /** * Fixes all operands of a use. * * If an operand of the use is a (original) definition, * it will be replaced by the given definition. */ -static void set_operands(be_ssa_construction_env_t *env, ir_node *use, ir_node *def) +static void set_operands(be_ssa_construction_env_t *env, ir_node *use, ir_node *def, constr_info *const use_info) { - constr_info *info = get_info(env, use); - int arity = get_irn_arity(use); - int i; - - for (i = 0; i < arity; ++i) { + int arity = get_irn_arity(use); + for (int i = 0; i < arity; ++i) { ir_node *op = get_irn_n(use, i); if (is_definition(env, op)) { @@ -289,7 +274,7 @@ static void set_operands(be_ssa_construction_env_t *env, ir_node *use, ir_node * } } - info->already_processed = true; + use_info->already_processed = true; } /** @@ -297,7 +282,6 @@ static void set_operands(be_ssa_construction_env_t *env, ir_node *use, ir_node * */ static void process_block(be_ssa_construction_env_t *env, ir_node *block) { - ir_node *node; ir_node *def = NULL; constr_info *block_info = get_or_set_info(env, block); @@ -307,24 +291,22 @@ static void process_block(be_ssa_construction_env_t *env, ir_node *block) DBG((dbg, LEVEL_3, "\tprocessing block %+F\n", block)); sched_foreach(block, node) { - if (is_use(env, node) && !is_Phi(node)) { + constr_info *const info = get_info(env, node); + if (!info) + continue; + + if (info->is_use && !is_Phi(node)) { DBG((dbg, LEVEL_3, "\t...found use %+F\n", node)); if (def == NULL) { /* Create a phi if the block is in the dominance frontier. */ - if (Block_block_visited(block)) { - def = insert_dummy_phi(env, block); - } - else { - def = get_def_at_idom(env, block); - } + def = get_def_from_preds(env, block); } - set_operands(env, node, def); + set_operands(env, node, def, info); } - if (is_definition(env, node)) { - constr_info *info = get_info(env, node); + if (info->is_definition) { def = info->u.definition; DBG((dbg, LEVEL_3, "\t...found definition %+F\n", def)); } @@ -353,36 +335,23 @@ static ir_node *search_def_end_of_block(be_ssa_construction_env_t *env, } } else { - ir_node *def = NULL; - /* Search the last definition of the block. */ sched_foreach_reverse(block, def) { - if (is_definition(env, def)) { - constr_info *info = get_info(env, def); - def = info->u.definition; - DBG((dbg, LEVEL_3, "\t...found definition %+F\n", def)); - + constr_info const *const info = get_info(env, def); + if (info && info->is_definition) { + DBG((dbg, LEVEL_3, "\t...found definition %+F\n", info->u.definition)); + block_info->u.last_definition = info->u.definition; break; } } - assert(def && "No definition found"); - - block_info->u.last_definition = def; + assert(block_info->u.last_definition && "No definition found"); } return block_info->u.last_definition; - } else if (Block_block_visited(block)) { - ir_node *phi = insert_dummy_phi(env, block); - - block_info->u.last_definition = phi; - - return phi; } else { - ir_node *def = get_def_at_idom(env, block); - + ir_node *const def = get_def_from_preds(env, block); block_info->u.last_definition = def; - return def; } } @@ -390,7 +359,7 @@ static ir_node *search_def_end_of_block(be_ssa_construction_env_t *env, /** * Fixes all operands of the given use. */ -static void search_def_at_block(be_ssa_construction_env_t *env, ir_node *use) +static void search_def_at_block(be_ssa_construction_env_t *const env, ir_node *const use, constr_info *const info) { ir_node *block = get_nodes_block(use); constr_info *block_info = get_or_set_info(env, block); @@ -400,27 +369,18 @@ static void search_def_at_block(be_ssa_construction_env_t *env, ir_node *use) if (has_definition(block)) { process_block(env, block); - } else if (Block_block_visited(block)) { - ir_node *phi = insert_dummy_phi(env, block); - - set_operands(env, use, phi); } else { - ir_node *def = get_def_at_idom(env, block); - - set_operands(env, use, def); + ir_node *const def = get_def_from_preds(env, block); + set_operands(env, use, def, info); } } void be_ssa_construction_init(be_ssa_construction_env_t *env, ir_graph *irg) { - ir_node *sb = get_irg_start_block(irg); - int n_blocks = get_Block_dom_max_subtree_pre_num(sb); - - stat_ev_ctx_push_fobj("bessaconstr", irg); + stat_ev_ctx_push_fmt("bessaconstr", "%+F", irg); stat_ev_tim_push(); - (void) n_blocks; - stat_ev_dbl("bessaconstr_n_blocks", n_blocks); + stat_ev_dbl("bessaconstr_n_blocks", get_Block_dom_max_subtree_pre_num(get_irg_start_block(irg))); memset(env, 0, sizeof(env[0])); @@ -521,12 +481,6 @@ void be_ssa_construction_add_copies(be_ssa_construction_env_t *env, } } -void be_ssa_construction_set_ignore_uses(be_ssa_construction_env_t *env, - const ir_nodeset_t *ignore_uses) -{ - env->ignore_uses = ignore_uses; -} - ir_node **be_ssa_construction_get_new_phis(be_ssa_construction_env_t *env) { return env->new_phis; @@ -537,16 +491,14 @@ ir_node **be_ssa_construction_get_new_phis(be_ssa_construction_env_t *env) * * @see insert_dummy_phi */ -static void fix_phi_arguments(be_ssa_construction_env_t *env, ir_node *phi) +static void fix_phi_arguments(be_ssa_construction_env_t *const env, ir_node *const phi, constr_info *const info) { - constr_info *info = get_info(env, phi); - ir_node *block = get_nodes_block(phi); - int i; - int n_preds = get_Block_n_cfgpreds(block); + ir_node *block = get_nodes_block(phi); + int n_preds = get_Block_n_cfgpreds(block); DBG((dbg, LEVEL_3, "\tfixing phi arguments %+F\n", phi)); - for (i = 0; i < n_preds; ++i) { + for (int i = 0; i < n_preds; ++i) { ir_node *op = get_irn_n(phi, i); if (is_definition(env, op) || is_Dummy(op)) { @@ -581,18 +533,12 @@ void be_ssa_construction_fix_users_array(be_ssa_construction_env_t *env, stat_ev_tim_push(); for (i = 0; i < nodes_len; ++i) { - const ir_edge_t *edge, *next; ir_node *value = nodes[i]; DBG((dbg, LEVEL_3, "\tfixing users of %+F\n", value)); introduce_definition(env, value); - foreach_out_edge_safe(value, edge, next) { - ir_node *use = get_edge_src_irn(edge); - - if (env->ignore_uses != NULL && - ir_nodeset_contains(env->ignore_uses, use)) - continue; - + foreach_out_edge_safe(value, edge) { + ir_node *const use = get_edge_src_irn(edge); if (is_Anchor(use) || is_End(use)) continue; @@ -610,11 +556,11 @@ void be_ssa_construction_fix_users_array(be_ssa_construction_env_t *env, continue; if (is_Phi(use)) { - fix_phi_arguments(env, use); + fix_phi_arguments(env, use, info); } else { DBG((dbg, LEVEL_3, "\tsearching def for %+F at %+F\n", use, get_nodes_block(use))); - search_def_at_block(env, use); + search_def_at_block(env, use, info); } stat_ev_cnt_inc(uses);