X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fscalar_replace.c;h=076b9fb4b88f6c82545259554e183363a46fa1bc;hb=0aa3f54e9f29fbed49bb4781c28ab1157499a92e;hp=01f9d47a0dbde6186d171bbaa135b74317605ad2;hpb=2232b14b4acf810ae96a69d1d2a33cf150b695d9;p=libfirm diff --git a/ir/opt/scalar_replace.c b/ir/opt/scalar_replace.c index 01f9d47a0..076b9fb4b 100644 --- a/ir/opt/scalar_replace.c +++ b/ir/opt/scalar_replace.c @@ -21,7 +21,6 @@ * @file * @brief Scalar replacement of compounds. * @author Beyhan Veliev, Michael Beck - * @version $Id$ */ #include "config.h" @@ -43,11 +42,10 @@ #include "irgmod.h" #include "irnode_t.h" #include "irpass.h" -#include "irtools.h" +#include "util.h" #include "xmalloc.h" #include "debug.h" #include "error.h" -#include "opt_manage.h" static unsigned get_vnum(const ir_node *node) { @@ -174,7 +172,6 @@ static bool check_load_store_mode(ir_mode *mode, ir_mode *ent_mode) if (ent_mode != mode) { if (ent_mode == NULL || get_mode_size_bits(ent_mode) != get_mode_size_bits(mode) || - get_mode_sort(ent_mode) != get_mode_sort(mode) || get_mode_arithmetic(ent_mode) != irma_twos_complement || get_mode_arithmetic(mode) != irma_twos_complement) return false; @@ -188,7 +185,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; @@ -196,7 +193,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)) { @@ -265,7 +262,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) { @@ -294,10 +291,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)) { @@ -346,7 +342,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; @@ -367,16 +362,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)) { @@ -399,7 +392,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)) { @@ -500,7 +493,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); @@ -508,7 +501,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)); @@ -679,17 +672,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); @@ -706,7 +702,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)) { @@ -724,7 +720,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)) { @@ -748,7 +744,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); } @@ -766,25 +762,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; -} - -optdesc_t opt_scalar_rep = { - "scalar-replace", - IR_GRAPH_STATE_NO_UNREACHABLE_BLOCKS | 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)