X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fscalar_replace.c;h=09e70986ce7c40f4893705aa2a2313f4d143b8fd;hb=b0b017615d99df915f731aa23842e26a10691f05;hp=85779e1eee5a52d9f6d399a3a5e029eea15d9f56;hpb=e3b765fcef0e337f4fe2e17d57d2fbaf1912ec79;p=libfirm diff --git a/ir/opt/scalar_replace.c b/ir/opt/scalar_replace.c index 85779e1ee..09e70986c 100644 --- a/ir/opt/scalar_replace.c +++ b/ir/opt/scalar_replace.c @@ -1,27 +1,12 @@ /* - * Copyright (C) 1995-2011 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. */ /** * @file * @brief Scalar replacement of compounds. * @author Beyhan Veliev, Michael Beck - * @version $Id$ */ #include "config.h" @@ -47,7 +32,6 @@ #include "xmalloc.h" #include "debug.h" #include "error.h" -#include "opt_manage.h" static unsigned get_vnum(const ir_node *node) { @@ -187,7 +171,7 @@ static bool check_load_store_mode(ir_mode *mode, ir_mode *ent_mode) */ bool is_address_taken(ir_node *sel) { - int i, input_nr, k; + int input_nr; ir_mode *emode, *mode; ir_node *value; ir_entity *ent; @@ -195,7 +179,7 @@ bool is_address_taken(ir_node *sel) if (! is_const_sel(sel)) return true; - for (i = get_irn_n_outs(sel) - 1; i >= 0; --i) { + for (unsigned i = get_irn_n_outs(sel); i-- > 0; ) { ir_node *succ = get_irn_out(sel, i); switch (get_irn_opcode(succ)) { @@ -264,7 +248,7 @@ bool is_address_taken(ir_node *sel) if (pred == sel) { /* we found one input */ - for (k = get_irn_n_outs(succ) - 1; k >= 0; --k) { + for (unsigned k = get_irn_n_outs(succ); k-- > 0; ) { ir_node *proj = get_irn_out(succ, k); if (is_Proj(proj) && get_Proj_proj(proj) == input_nr) { @@ -293,10 +277,9 @@ bool is_address_taken(ir_node *sel) */ static bool link_all_leave_sels(ir_entity *ent, ir_node *sel) { - int i; bool is_leave = true; - for (i = get_irn_n_outs(sel) - 1; i >= 0; --i) { + for (unsigned i = get_irn_n_outs(sel); i-- > 0; ) { ir_node *succ = get_irn_out(sel, i); if (is_Sel(succ)) { @@ -345,7 +328,6 @@ static int find_possible_replacements(ir_graph *irg) ir_node *irg_frame; ir_type *frame_tp; size_t mem_idx; - int i; long static_link_arg; int res = 0; @@ -366,16 +348,14 @@ static int find_possible_replacements(ir_graph *irg) if (is_method_entity(ent)) { ir_graph *inner_irg = get_entity_irg(ent); ir_node *args; - int j; - assure_irg_outs(inner_irg); + assure_irg_properties(inner_irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS); args = get_irg_args(inner_irg); - for (j = get_irn_n_outs(args) - 1; j >= 0; --j) { + for (unsigned j = get_irn_n_outs(args); j-- > 0; ) { ir_node *arg = get_irn_out(args, j); if (get_Proj_proj(arg) == static_link_arg) { - int k; - for (k = get_irn_n_outs(arg) - 1; k >= 0; --k) { + for (unsigned k = get_irn_n_outs(arg); k-- > 0; ) { ir_node *succ = get_irn_out(arg, k); if (is_Sel(succ)) { @@ -398,7 +378,7 @@ static int find_possible_replacements(ir_graph *irg) * equal ADDRESS_TAKEN. */ irg_frame = get_irg_frame(irg); - for (i = get_irn_n_outs(irg_frame) - 1; i >= 0; --i) { + for (unsigned i = get_irn_n_outs(irg_frame); i-- > 0; ) { ir_node *succ = get_irn_out(irg_frame, i); if (is_Sel(succ)) { @@ -499,7 +479,7 @@ static unsigned allocate_value_numbers(pset *sels, ir_entity *ent, unsigned vnum pset_insert_ptr(sels, sel); key = find_path(sel, 0); - path = (path_t*)set_find(pathes, key, path_size(key), path_hash(key)); + path = set_find(path_t, pathes, key, path_size(key), path_hash(key)); if (path) { set_vnum(sel, path->vnum); @@ -507,7 +487,7 @@ static unsigned allocate_value_numbers(pset *sels, ir_entity *ent, unsigned vnum } else { key->vnum = vnum++; - set_insert(pathes, key, path_size(key), path_hash(key)); + (void)set_insert(path_t, pathes, key, path_size(key), path_hash(key)); set_vnum(sel, key->vnum); DB((dbg, SET_LEVEL_3, " %+F represents value %u\n", sel, key->vnum)); @@ -600,11 +580,13 @@ static void walker(ir_node *node, void *ctx) val = new_rd_Conv(get_irn_dbg_info(node), block, val, mode); mem = get_Load_mem(node); - turn_into_tuple(node, pn_Load_max+1); - set_Tuple_pred(node, pn_Load_M, mem); - set_Tuple_pred(node, pn_Load_res, val); - set_Tuple_pred(node, pn_Load_X_regular, new_r_Jmp(block)); - set_Tuple_pred(node, pn_Load_X_except, new_r_Bad(irg, mode_X)); + ir_node *const in[] = { + [pn_Load_M] = mem, + [pn_Load_res] = val, + [pn_Load_X_regular] = new_r_Jmp(block), + [pn_Load_X_except] = new_r_Bad(irg, mode_X), + }; + turn_into_tuple(node, ARRAY_SIZE(in), in); } else if (is_Store(node)) { DB((dbg, SET_LEVEL_3, " checking %+F for replacement ", node)); @@ -637,10 +619,12 @@ static void walker(ir_node *node, void *ctx) set_value(vnum, val); mem = get_Store_mem(node); - turn_into_tuple(node, pn_Store_max+1); - set_Tuple_pred(node, pn_Store_M, mem); - set_Tuple_pred(node, pn_Store_X_regular, new_r_Jmp(block)); - set_Tuple_pred(node, pn_Store_X_except, new_r_Bad(irg, mode_X)); + ir_node *const in[] = { + [pn_Store_M] = mem, + [pn_Store_X_regular] = new_r_Jmp(block), + [pn_Store_X_except] = new_r_Bad(irg, mode_X), + }; + turn_into_tuple(node, ARRAY_SIZE(in), in); } } @@ -678,17 +662,20 @@ static void do_scalar_replacements(ir_graph *irg, pset *sels, unsigned nvals, * * @param irg The current ir graph. */ -static ir_graph_state_t do_scalar_replacement(ir_graph *irg) +void scalar_replacement_opt(ir_graph *irg) { unsigned nvals; - int i; - scalars_t key, *value; + scalars_t key; ir_node *irg_frame; ir_mode **modes; set *set_ent; pset *sels; ir_type *ent_type, *frame_tp; + assure_irg_properties(irg, + IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE + | IR_GRAPH_PROPERTY_CONSISTENT_OUTS); + /* we use the link field to store the VNUM */ ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK); irp_reserve_resources(irp, IRP_RESOURCE_ENTITY_LINK); @@ -705,7 +692,7 @@ static ir_graph_state_t do_scalar_replacement(ir_graph *irg) sels = pset_new_ptr(8); frame_tp = get_irg_frame_type(irg); - for (i = get_irn_n_outs(irg_frame) - 1; i >= 0; --i) { + for (unsigned i = get_irn_n_outs(irg_frame); i-- > 0; ) { ir_node *succ = get_irn_out(irg_frame, i); if (is_Sel(succ)) { @@ -723,7 +710,7 @@ static ir_graph_state_t do_scalar_replacement(ir_graph *irg) ent_type = get_entity_type(ent); key.ent = ent; - set_insert(set_ent, &key, sizeof(key), HASH_PTR(key.ent)); + (void)set_insert(scalars_t, set_ent, &key, sizeof(key), hash_ptr(key.ent)); #ifdef DEBUG_libfirm if (is_Array_type(ent_type)) { @@ -747,7 +734,7 @@ static ir_graph_state_t do_scalar_replacement(ir_graph *irg) if (nvals > 0) { do_scalar_replacements(irg, sels, nvals, modes); - foreach_set(set_ent, scalars_t*, value) { + foreach_set(set_ent, scalars_t, value) { free_entity(value->ent); } @@ -765,25 +752,12 @@ static ir_graph_state_t do_scalar_replacement(ir_graph *irg) ir_free_resources(irg, IR_RESOURCE_IRN_LINK); irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK); - return 0; -} - -static optdesc_t opt_scalar_rep = { - "scalar-replace", - IR_GRAPH_STATE_NO_UNREACHABLE_CODE | IR_GRAPH_STATE_CONSISTENT_OUTS, - do_scalar_replacement, -}; - -int scalar_replacement_opt(ir_graph *irg) -{ - perform_irg_optimization(irg, &opt_scalar_rep); - return 1; + confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_NONE); } ir_graph_pass_t *scalar_replacement_opt_pass(const char *name) { - return def_graph_pass_ret(name ? name : "scalar_rep", - scalar_replacement_opt); + return def_graph_pass(name ? name : "scalar_rep", scalar_replacement_opt); } void firm_init_scalar_replace(void)