X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fscalar_replace.c;h=9041a6998aa5240b911c095b58941860124f4d76;hb=8c9921a1fc166552f6e416434fd8394a4fc210a3;hp=d10e2918a2e4ea91f76688a251df4fed83d6200a;hpb=56c66ba8aeb7f35cf8a2e8f17def2e28e698bcbc;p=libfirm diff --git a/ir/opt/scalar_replace.c b/ir/opt/scalar_replace.c index d10e2918a..9041a6998 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,10 +42,11 @@ #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) { @@ -79,7 +79,10 @@ typedef struct path_t { } path_t; /** The size of a path in bytes. */ -#define PATH_SIZE(p) (sizeof(*(p)) + sizeof((p)->path[0]) * ((p)->path_len - 1)) +static size_t path_size(path_t *p) +{ + return sizeof(*p) + sizeof(p->path[0]) * (p->path_len-1); +} typedef struct scalars_t { ir_entity *ent; /**< A entity for scalar replacement. */ @@ -170,7 +173,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; @@ -496,7 +498,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 = (path_t*)set_find(pathes, key, path_size(key), path_hash(key)); if (path) { set_vnum(sel, path->vnum); @@ -504,7 +506,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)); + set_insert(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)); @@ -675,7 +677,7 @@ static void do_scalar_replacements(ir_graph *irg, pset *sels, unsigned nvals, * * @param irg The current ir graph. */ -int scalar_replacement_opt(ir_graph *irg) +static ir_graph_state_t do_scalar_replacement(ir_graph *irg) { unsigned nvals; int i; @@ -685,10 +687,6 @@ int scalar_replacement_opt(ir_graph *irg) set *set_ent; pset *sels; ir_type *ent_type, *frame_tp; - int res = 0; - - /* Call algorithm that computes the out edges */ - assure_irg_outs(irg); /* we use the link field to store the VNUM */ ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK); @@ -713,8 +711,9 @@ int scalar_replacement_opt(ir_graph *irg) ir_entity *ent = get_Sel_entity(succ); /* we are only interested in entities on the frame, NOT - on the value type */ - if (get_entity_owner(ent) != frame_tp) + parameters */ + if (get_entity_owner(ent) != frame_tp + || is_parameter_entity(ent)) continue; if (get_entity_link(ent) == NULL || get_entity_link(ent) == ADDRESS_TAKEN) @@ -756,7 +755,6 @@ int scalar_replacement_opt(ir_graph *irg) * neither changed control flow, cf-backedges should be still * consistent. */ - res = 1; } del_pset(sels); del_set(set_ent); @@ -766,7 +764,19 @@ int scalar_replacement_opt(ir_graph *irg) ir_free_resources(irg, IR_RESOURCE_IRN_LINK); irp_free_resources(irp, IRP_RESOURCE_ENTITY_LINK); - return res; + 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; } ir_graph_pass_t *scalar_replacement_opt_pass(const char *name)