X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fscalar_replace.c;h=cd0ffd9039b79e95957ce7b1d8d4efea18233802;hb=a1e9069afa4fa1e16e2d176bcd7905d6a1ed4677;hp=59588da8b3adc9602e42494eb172c567cd4af943;hpb=4b363c6a4e0584ce755b5f82fc3d7a9dc38658b2;p=libfirm diff --git a/ir/opt/scalar_replace.c b/ir/opt/scalar_replace.c index 59588da8b..cd0ffd903 100644 --- a/ir/opt/scalar_replace.c +++ b/ir/opt/scalar_replace.c @@ -29,6 +29,7 @@ #include "iroptimize.h" #include "scalar_replace.h" +#include "opt_init.h" #include "irflag_t.h" #include "irouts.h" #include "set.h" @@ -63,7 +64,7 @@ typedef union { * An access path, used to assign value numbers * to variables that will be scalar replaced. */ -typedef struct _path_t { +typedef struct path_t { unsigned vnum; /**< The value number. */ unsigned path_len; /**< The length of the access path. */ path_elem_t path[1]; /**< The path. */ @@ -72,9 +73,8 @@ typedef struct _path_t { /** The size of a path in bytes. */ #define PATH_SIZE(p) (sizeof(*(p)) + sizeof((p)->path[0]) * ((p)->path_len - 1)) -typedef struct _scalars_t { +typedef struct scalars_t { ir_entity *ent; /**< A entity for scalar replacement. */ - ir_type *ent_owner; /**< The owner of this entity. */ } scalars_t; DEBUG_ONLY(static firm_dbg_module_t *dbg;) @@ -84,7 +84,8 @@ DEBUG_ONLY(static firm_dbg_module_t *dbg;) * * @return 0 if they are identically */ -static int path_cmp(const void *elt, const void *key, size_t size) { +static int path_cmp(const void *elt, const void *key, size_t size) +{ const path_t *p1 = elt; const path_t *p2 = key; (void) size; @@ -98,7 +99,8 @@ static int path_cmp(const void *elt, const void *key, size_t size) { * * @return 0 if they are identically */ -static int ent_cmp(const void *elt, const void *key, size_t size) { +static int ent_cmp(const void *elt, const void *key, size_t size) +{ const scalars_t *c1 = elt; const scalars_t *c2 = key; (void) size; @@ -109,7 +111,8 @@ static int ent_cmp(const void *elt, const void *key, size_t size) { /** * Calculate a hash value for a path. */ -static unsigned path_hash(const path_t *path) { +static unsigned path_hash(const path_t *path) +{ unsigned hash = 0; unsigned i; @@ -124,7 +127,8 @@ static unsigned path_hash(const path_t *path) { * * @param sel the Sel node that will be checked */ -static int is_const_sel(ir_node *sel) { +static int is_const_sel(ir_node *sel) +{ int i, n = get_Sel_n_indexs(sel); for (i = 0; i < n; ++i) { @@ -153,7 +157,8 @@ static int is_const_sel(ir_node *sel) { * @param mode the mode of the Load/Store * @param ent_mode the mode of the accessed entity */ -static int check_load_store_mode(ir_mode *mode, ir_mode *ent_mode) { +static int 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) || @@ -275,7 +280,8 @@ int is_address_taken(ir_node *sel) * @param ent the entity that will be scalar replaced * @param sel a Sel node that selects some fields of this entity */ -static int link_all_leave_sels(ir_entity *ent, ir_node *sel) { +static int link_all_leave_sels(ir_entity *ent, ir_node *sel) +{ int i, is_leave = 1; for (i = get_irn_n_outs(sel) - 1; i >= 0; --i) { @@ -322,7 +328,8 @@ static void *ADDRESS_TAKEN = &_x; * @return non-zero if at least one entity could be replaced * potentially */ -static int find_possible_replacements(ir_graph *irg) { +static int find_possible_replacements(ir_graph *irg) +{ ir_node *irg_frame; ir_type *frame_tp; int i, j, k, static_link_arg; @@ -429,7 +436,8 @@ static int find_possible_replacements(ir_graph *irg) { * @param sel the Sel node * @param len the length of the path so far */ -static path_t *find_path(ir_node *sel, unsigned len) { +static path_t *find_path(ir_node *sel, unsigned len) +{ int pos, i, n; path_t *res; ir_node *pred = get_Sel_ptr(sel); @@ -529,7 +537,7 @@ static unsigned allocate_value_numbers(pset *sels, ir_entity *ent, unsigned vnum /** * A list entry for the fixing lists */ -typedef struct _list_entry_t { +typedef struct list_entry_t { ir_node *node; /**< the node that must be fixed */ unsigned vnum; /**< the value number of this node */ } list_entry_t; @@ -537,7 +545,7 @@ typedef struct _list_entry_t { /** * environment for memory walker */ -typedef struct _env_t { +typedef struct env_t { int nvals; /**< number of values */ ir_mode **modes; /**< the modes of the values */ pset *sels; /**< A set of all Sel nodes that have a value number */ @@ -546,7 +554,8 @@ typedef struct _env_t { /** * topological post-walker. */ -static void topologic_walker(ir_node *node, void *ctx) { +static void topologic_walker(ir_node *node, void *ctx) +{ env_t *env = ctx; ir_node *adr, *block, *mem, *val; ir_mode *mode; @@ -643,7 +652,8 @@ static void topologic_walker(ir_node *node, void *ctx) { * @param modes A flexible array, containing all the modes of * the value numbers. */ -static void do_scalar_replacements(pset *sels, int nvals, ir_mode **modes) { +static void do_scalar_replacements(pset *sels, int nvals, ir_mode **modes) +{ env_t env; ssa_cons_start(current_ir_graph, nvals); @@ -667,7 +677,8 @@ static void do_scalar_replacements(pset *sels, int nvals, ir_mode **modes) { * * @param irg The current ir graph. */ -int scalar_replacement_opt(ir_graph *irg) { +int scalar_replacement_opt(ir_graph *irg) +{ unsigned nvals; int i; scalars_t key, *value; @@ -679,9 +690,6 @@ int scalar_replacement_opt(ir_graph *irg) { ir_graph *rem; int res = 0; - if (! get_opt_scalar_replacement()) - return 0; - rem = current_ir_graph; current_ir_graph = irg; @@ -721,7 +729,6 @@ int scalar_replacement_opt(ir_graph *irg) { ent_type = get_entity_type(ent); key.ent = ent; - key.ent_owner = get_entity_owner(ent); set_insert(set_ent, &key, sizeof(key), HASH_PTR(key.ent)); #ifdef DEBUG_libfirm @@ -747,7 +754,7 @@ int scalar_replacement_opt(ir_graph *irg) { do_scalar_replacements(sels, nvals, modes); foreach_set(set_ent, value) { - remove_class_member(value->ent_owner, value->ent); + free_entity(value->ent); } /* @@ -772,11 +779,13 @@ int scalar_replacement_opt(ir_graph *irg) { return res; } -ir_graph_pass_t *scalar_replacement_opt_pass(const char *name) { +ir_graph_pass_t *scalar_replacement_opt_pass(const char *name) +{ return def_graph_pass_ret(name ? name : "scalar_rep", scalar_replacement_opt); } -void firm_init_scalar_replace(void) { +void firm_init_scalar_replace(void) +{ FIRM_DBG_REGISTER(dbg, "firm.opt.scalar_replace"); }