X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fopt_ldst.c;h=5b3fc868462ae54652cef70592641453517ba50e;hb=854e25593766c0e302befc8e397d99861cf90710;hp=f9e03d9cc6fafbf1260b624b9cff2f020ce7653c;hpb=41c2717f1830bad40a586be3f1ed5379834bd935;p=libfirm diff --git a/ir/opt/opt_ldst.c b/ir/opt/opt_ldst.c index f9e03d9cc..5b3fc8684 100644 --- a/ir/opt/opt_ldst.c +++ b/ir/opt/opt_ldst.c @@ -42,6 +42,7 @@ #include "raw_bitset.h" #include "debug.h" #include "error.h" +#include "irpass.h" /* maximum number of output Proj's */ #define MAX_PROJ (pn_Load_max > pn_Store_max ? pn_Load_max : pn_Store_max) @@ -144,7 +145,8 @@ static firm_dbg_module_t *dbg; * * @param ldst environment */ -static void dump_block_list(ldst_env *env) { +static void dump_block_list(ldst_env *env) +{ block_t *entry; memop_t *op; int i; @@ -175,7 +177,8 @@ static void dump_block_list(ldst_env *env) { * @param bl current block * @param s name of the set */ -static void dump_curr(block_t *bl, const char *s) { +static void dump_curr(block_t *bl, const char *s) +{ unsigned end = env.rbs_size - 1; unsigned pos; int i; @@ -196,24 +199,28 @@ static void dump_curr(block_t *bl, const char *s) { } /* dump_curr */ #else -static void dump_block_list(ldst_env *env) { +static void dump_block_list(ldst_env *env) +{ (void) env; } -static void dump_curr(block_t *bl, const char *s) { +static void dump_curr(block_t *bl, const char *s) +{ (void) bl; (void) s; } #endif /* DEBUG_libfirm */ /** Get the block entry for a block node */ -static block_t *get_block_entry(const ir_node *block) { +static block_t *get_block_entry(const ir_node *block) +{ assert(is_Block(block)); return get_irn_link(block); } /* get_block_entry */ /** Get the memop entry for a memory operation node */ -static memop_t *get_irn_memop(const ir_node *irn) { +static memop_t *get_irn_memop(const ir_node *irn) +{ assert(! is_Block(irn)); return get_irn_link(irn); } /* get_irn_memop */ @@ -227,7 +234,8 @@ static memop_t *get_irn_memop(const ir_node *irn) { * @param post post walker function * @param ctx context parameter for the walker functions */ -static void walk_memory(ir_node *irn, irg_walk_func *pre, irg_walk_func *post, void *ctx) { +static void walk_memory(ir_node *irn, irg_walk_func *pre, irg_walk_func *post, void *ctx) +{ int i; ir_mode *mode; @@ -266,7 +274,8 @@ static void walk_memory(ir_node *irn, irg_walk_func *pre, irg_walk_func *post, v * @param post post walker function * @param ctx context parameter for the walker functions */ -static void walk_memory_irg(ir_graph *irg, irg_walk_func pre, irg_walk_func post, void *ctx) { +static void walk_memory_irg(ir_graph *irg, irg_walk_func pre, irg_walk_func post, void *ctx) +{ inc_irg_visited(irg); ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED); @@ -287,7 +296,8 @@ static void walk_memory_irg(ir_graph *irg, irg_walk_func pre, irg_walk_func post * * @return the allocated id */ -static unsigned register_address(ir_node *adr) { +static unsigned register_address(ir_node *adr) +{ address_entry *entry; /* skip Confirms and Casts */ @@ -305,7 +315,7 @@ restart: if (entry == NULL) { /* new address */ - entry = obstack_alloc(&env.obst, sizeof(*entry)); + entry = OALLOC(&env.obst, address_entry); entry->id = env.curr_adr_id++; ir_nodemap_insert(&env.adr_map, adr, entry); @@ -327,7 +337,8 @@ restart: * @param block the block * @param pos the position of the predecessor in block */ -static ir_node *phi_translate(ir_node *address, const ir_node *block, int pos) { +static ir_node *phi_translate(ir_node *address, const ir_node *block, int pos) +{ if (is_Phi(address) && get_nodes_block(address) == block) address = get_Phi_pred(address, pos); return address; @@ -337,11 +348,12 @@ static ir_node *phi_translate(ir_node *address, const ir_node *block, int pos) { * Walker: allocate an block entry for every block * and register all potential addresses. */ -static void prepare_blocks(ir_node *irn, void *ctx) { +static void prepare_blocks(ir_node *irn, void *ctx) +{ (void)ctx; if (is_Block(irn)) { - block_t *entry = obstack_alloc(&env.obst, sizeof(*entry)); + block_t *entry = OALLOC(&env.obst, block_t); int n; entry->memop_forward = NULL; @@ -382,7 +394,8 @@ static void prepare_blocks(ir_node *irn, void *ctx) { /** * Post-Walker, link in all Phi's */ -static void link_phis(ir_node *irn, void *ctx) { +static void link_phis(ir_node *irn, void *ctx) +{ (void)ctx; if (is_Phi(irn)) { @@ -394,7 +407,8 @@ static void link_phis(ir_node *irn, void *ctx) { /** * Block walker: creates the inverse post-order list for the CFG. */ -static void inverse_post_order(ir_node *block, void *ctx) { +static void inverse_post_order(ir_node *block, void *ctx) +{ block_t *entry = get_block_entry(block); (void)ctx; @@ -414,7 +428,8 @@ static void inverse_post_order(ir_node *block, void *ctx) { /** * Block walker: create backward links for the memops of a block. */ -static void collect_backward(ir_node *block, void *ctx) { +static void collect_backward(ir_node *block, void *ctx) +{ block_t *entry = get_block_entry(block); memop_t *last, *op; @@ -449,8 +464,9 @@ static void collect_backward(ir_node *block, void *ctx) { * * @return the allocated memop */ -static memop_t *alloc_memop(ir_node *irn) { - memop_t *m = obstack_alloc(&env.obst, sizeof(*m)); +static memop_t *alloc_memop(ir_node *irn) +{ + memop_t *m = OALLOC(&env.obst, memop_t); m->value.address = NULL; m->value.value = NULL; @@ -475,8 +491,9 @@ static memop_t *alloc_memop(ir_node *irn) { * @param op the memop to clone * @param phi the Phi-node representing the new value */ -static memop_t *clone_memop_phi(memop_t *op, ir_node *phi) { - memop_t *m = obstack_alloc(&env.obst, sizeof(*m)); +static memop_t *clone_memop_phi(memop_t *op, ir_node *phi) +{ + memop_t *m = OALLOC(&env.obst, memop_t); m->value = op->value; m->value.value = phi; @@ -497,7 +514,8 @@ static memop_t *clone_memop_phi(memop_t *op, ir_node *phi) { * * return a bitset of mtp_property_const and mtp_property_pure */ -static unsigned get_Call_memory_properties(ir_node *call) { +static unsigned get_Call_memory_properties(ir_node *call) +{ ir_type *call_tp = get_Call_type(call); unsigned prop = get_method_additional_properties(call_tp); @@ -522,7 +540,8 @@ static unsigned get_Call_memory_properties(ir_node *call) { * * @return an entity or NULL */ -static ir_entity *find_constant_entity(ir_node *ptr) { +static ir_entity *find_constant_entity(ir_node *ptr) +{ for (;;) { if (is_SymConst(ptr) && get_SymConst_kind(ptr) == symconst_addr_ent) { return get_SymConst_entity(ptr); @@ -567,7 +586,7 @@ static ir_entity *find_constant_entity(ir_node *ptr) { } } - if (variability_constant == get_entity_variability(ent)) + if (get_entity_linkage(ent) == IR_LINKAGE_CONSTANT) return ent; /* try next */ @@ -605,7 +624,8 @@ static ir_entity *find_constant_entity(ir_node *ptr) { /** * Return the Selection index of a Sel node from dimension n */ -static long get_Sel_array_index_long(ir_node *n, int dim) { +static long get_Sel_array_index_long(ir_node *n, int dim) +{ ir_node *index = get_Sel_index(n, dim); assert(is_Const(index)); return get_tarval_long(get_Const_tarval(index)); @@ -619,7 +639,8 @@ static long get_Sel_array_index_long(ir_node *n, int dim) { * @param depth current depth in steps upward from the root * of the address */ -static compound_graph_path *rec_get_accessed_path(ir_node *ptr, int depth) { +static compound_graph_path *rec_get_accessed_path(ir_node *ptr, int depth) +{ compound_graph_path *res = NULL; ir_entity *root, *field, *ent; int path_len, pos, idx; @@ -766,7 +787,8 @@ ptr_arith: * Returns an access path or NULL. The access path is only * valid, if the graph is in phase_high and _no_ address computation is used. */ -static compound_graph_path *get_accessed_path(ir_node *ptr) { +static compound_graph_path *get_accessed_path(ir_node *ptr) +{ compound_graph_path *gr = rec_get_accessed_path(ptr, 0); return gr; } /* get_accessed_path */ @@ -777,7 +799,8 @@ typedef struct path_entry { long index; } path_entry; -static ir_node *rec_find_compound_ent_value(ir_node *ptr, path_entry *next) { +static ir_node *rec_find_compound_ent_value(ir_node *ptr, path_entry *next) +{ path_entry entry, *p; ir_entity *ent, *field; ir_initializer_t *initializer; @@ -951,7 +974,8 @@ ptr_arith: return NULL; } /* rec_find_compound_ent_value */ -static ir_node *find_compound_ent_value(ir_node *ptr) { +static ir_node *find_compound_ent_value(ir_node *ptr) +{ return rec_find_compound_ent_value(ptr, NULL); } /* find_compound_ent_value */ @@ -960,7 +984,8 @@ static ir_node *find_compound_ent_value(ir_node *ptr) { * * @param op the Load memop */ -static void mark_replace_load(memop_t *op, ir_node *def) { +static void mark_replace_load(memop_t *op, ir_node *def) +{ op->replace = def; op->flags |= FLAG_KILLED_NODE; env.changed = 1; @@ -971,7 +996,8 @@ static void mark_replace_load(memop_t *op, ir_node *def) { * * @param op the Store memop */ -static void mark_remove_store(memop_t *op) { +static void mark_remove_store(memop_t *op) +{ op->flags |= FLAG_KILLED_NODE; env.changed = 1; } /* mark_remove_store */ @@ -981,7 +1007,8 @@ static void mark_remove_store(memop_t *op) { * * @param m the memop */ -static void update_Load_memop(memop_t *m) { +static void update_Load_memop(memop_t *m) +{ int i; ir_node *load = m->node; ir_node *ptr; @@ -1025,9 +1052,7 @@ static void update_Load_memop(memop_t *m) { /* check if we can determine the entity that will be loaded */ ent = find_constant_entity(ptr); - if (ent != NULL && - allocation_static == get_entity_allocation(ent) && - visibility_external_allocated != get_entity_visibility(ent)) { + if (ent != NULL && get_entity_visibility(ent) != ir_visibility_external) { /* a static allocation that is not external: there should be NO exception * when loading even if we cannot replace the load itself. */ ir_node *value = NULL; @@ -1045,17 +1070,11 @@ static void update_Load_memop(memop_t *m) { env.changed = 1; } - if (variability_constant == get_entity_variability(ent)) { - if (is_atomic_entity(ent)) { - /* Might not be atomic after lowering of Sels. In this case we - * could also load, but it's more complicated. */ - /* more simpler case: we load the content of a constant value: - * replace it by the constant itself */ - value = get_atomic_ent_value(ent); - } else if (ent->has_initializer) { + if (get_entity_linkage(ent) & IR_LINKAGE_CONSTANT) { + if (ent->initializer) { /* new style initializer */ value = find_compound_ent_value(ptr); - } else { + } else if (entity_has_compound_ent_values(ent)) { /* old style initializer */ compound_graph_path *path = get_accessed_path(ptr); @@ -1094,7 +1113,8 @@ static void update_Load_memop(memop_t *m) { * * @param m the memop */ -static void update_Store_memop(memop_t *m) { +static void update_Store_memop(memop_t *m) +{ int i; ir_node *store = m->node; ir_node *adr = get_Store_ptr(store); @@ -1141,7 +1161,8 @@ static void update_Store_memop(memop_t *m) { * * @param m the memop */ -static void update_Call_memop(memop_t *m) { +static void update_Call_memop(memop_t *m) +{ ir_node *call = m->node; unsigned prop = get_Call_memory_properties(call); int i; @@ -1166,7 +1187,7 @@ static void update_Call_memop(memop_t *m) { case pn_Call_X_except: m->flags |= FLAG_EXCEPTION; break; - case pn_Call_M_regular: + case pn_Call_M: m->mem = proj; break; } @@ -1178,7 +1199,8 @@ static void update_Call_memop(memop_t *m) { * * @param m the memop */ -static void update_DivOp_memop(memop_t *m) { +static void update_DivOp_memop(memop_t *m) +{ ir_node *div = m->node; int i; @@ -1193,7 +1215,7 @@ static void update_DivOp_memop(memop_t *m) { case pn_Generic_X_except: m->flags |= FLAG_EXCEPTION; break; - case pn_Generic_M_regular: + case pn_Generic_M: m->mem = proj; break; } @@ -1205,7 +1227,8 @@ static void update_DivOp_memop(memop_t *m) { * * @param m the memop */ -static void update_Phi_memop(memop_t *m) { +static void update_Phi_memop(memop_t *m) +{ /* the Phi is it's own mem */ m->mem = m->node; } /* update_Phi_memop */ @@ -1213,7 +1236,8 @@ static void update_Phi_memop(memop_t *m) { /** * Memory walker: collect all memory ops and build topological lists. */ -static void collect_memops(ir_node *irn, void *ctx) { +static void collect_memops(ir_node *irn, void *ctx) +{ memop_t *op; ir_node *block; block_t *entry; @@ -1293,7 +1317,8 @@ static void collect_memops(ir_node *irn, void *ctx) { * not exists in the set or cannot be converted into * the requested mode */ -static memop_t *find_address(const value_t *value) { +static memop_t *find_address(const value_t *value) +{ if (rbitset_is_set(env.curr_set, value->id)) { memop_t *res = env.curr_id_2_memop[value->id]; @@ -1313,7 +1338,8 @@ static memop_t *find_address(const value_t *value) { * * @param bl the block */ -static memop_t *find_address_avail(const block_t *bl, unsigned id, const ir_mode *mode) { +static memop_t *find_address_avail(const block_t *bl, unsigned id, const ir_mode *mode) +{ if (rbitset_is_set(bl->avail_out, id)) { memop_t *res = bl->id_2_memop_avail[id]; @@ -1331,7 +1357,8 @@ static memop_t *find_address_avail(const block_t *bl, unsigned id, const ir_mode /** * Kill all addresses from the current set. */ -static void kill_all(void) { +static void kill_all(void) +{ rbitset_clear_all(env.curr_set, env.rbs_size); /* set sentinel */ @@ -1343,7 +1370,8 @@ static void kill_all(void) { * * @param value the Store value */ -static void kill_memops(const value_t *value) { +static void kill_memops(const value_t *value) +{ unsigned end = env.rbs_size - 1; unsigned pos; @@ -1364,7 +1392,8 @@ static void kill_memops(const value_t *value) { * * @param op the memory op */ -static void add_memop(memop_t *op) { +static void add_memop(memop_t *op) +{ rbitset_set(env.curr_set, op->value.id); env.curr_id_2_memop[op->value.id] = op; } /* add_memop */ @@ -1375,7 +1404,8 @@ static void add_memop(memop_t *op) { * @param bl the block * @param op the memory op */ -static void add_memop_avail(block_t *bl, memop_t *op) { +static void add_memop_avail(block_t *bl, memop_t *op) +{ rbitset_set(bl->avail_out, op->value.id); bl->id_2_memop_avail[op->value.id] = op; } /* add_memop_avail */ @@ -1387,7 +1417,8 @@ static void add_memop_avail(block_t *bl, memop_t *op) { * @param from the original mode * @param to the destination mode */ -static int can_convert_to(const ir_mode *from, const ir_mode *to) { +static int can_convert_to(const ir_mode *from, const ir_mode *to) +{ if (get_mode_arithmetic(from) == irma_twos_complement && get_mode_arithmetic(to) == irma_twos_complement && get_mode_size_bits(from) == get_mode_size_bits(to)) @@ -1404,7 +1435,8 @@ static int can_convert_to(const ir_mode *from, const ir_mode *to) { * @return the possible converted node or NULL * if the conversion is not possible */ -static ir_node *conv_to(ir_node *irn, ir_mode *mode) { +static ir_node *conv_to(ir_node *irn, ir_mode *mode) +{ ir_mode *other = get_irn_mode(irn); if (other != mode) { /* different modes: check if conversion is possible without changing the bits */ @@ -1424,7 +1456,8 @@ static ir_node *conv_to(ir_node *irn, ir_mode *mode) { * * @param value the value whose address is updated */ -static void update_address(value_t *value) { +static void update_address(value_t *value) +{ if (is_Proj(value->address)) { ir_node *load = get_Proj_pred(value->address); @@ -1443,7 +1476,8 @@ static void update_address(value_t *value) { * * @param bl the block */ -static void calc_gen_kill_avail(block_t *bl) { +static void calc_gen_kill_avail(block_t *bl) +{ memop_t *op; ir_node *def; @@ -1532,7 +1566,8 @@ static void calc_gen_kill_avail(block_t *bl) { * * @param block the block */ -static void forward_avail(block_t *bl) { +static void forward_avail(block_t *bl) +{ /* fill the data from the current block */ env.curr_id_2_memop = bl->id_2_memop_avail; env.curr_set = bl->avail_out; @@ -1549,7 +1584,8 @@ static void forward_avail(block_t *bl) { * * @return non-zero if the set has changed since last iteration */ -static int backward_antic(block_t *bl) { +static int backward_antic(block_t *bl) +{ memop_t *op; ir_node *block = bl->block; int n = get_Block_n_cfg_outs(block); @@ -1565,9 +1601,7 @@ static int backward_antic(block_t *bl) { if (bl->trans_results == NULL) { /* allocate the translate cache */ - unsigned size = env.curr_adr_id * sizeof(bl->trans_results[0]); - bl->trans_results = obstack_alloc(&env.obst, size); - memset(bl->trans_results, 0, size); + bl->trans_results = OALLOCNZ(&env.obst, memop_t*, env.curr_adr_id); } /* check for partly redundant values */ @@ -1656,7 +1690,7 @@ static int backward_antic(block_t *bl) { } memcpy(bl->id_2_memop_antic, env.curr_id_2_memop, env.rbs_size * sizeof(env.curr_id_2_memop[0])); - if (! rbitset_equal(bl->anticL_in, env.curr_set, env.rbs_size)) { + if (! rbitsets_equal(bl->anticL_in, env.curr_set, env.rbs_size)) { /* changed */ rbitset_copy(bl->anticL_in, env.curr_set, env.rbs_size); dump_curr(bl, "AnticL_in*"); @@ -1671,7 +1705,8 @@ static int backward_antic(block_t *bl) { * * @param op the Load memop */ -static void replace_load(memop_t *op) { +static void replace_load(memop_t *op) +{ ir_node *load = op->node; ir_node *def = skip_Id(op->replace); ir_node *proj; @@ -1718,7 +1753,8 @@ static void replace_load(memop_t *op) { * * @param op the Store memop */ -static void remove_store(memop_t *op) { +static void remove_store(memop_t *op) +{ ir_node *store = op->node; ir_node *proj; @@ -1744,7 +1780,8 @@ static void remove_store(memop_t *op) { * * @param bl the block */ -static void do_replacements(block_t *bl) { +static void do_replacements(block_t *bl) +{ memop_t *op; for (op = bl->memop_forward; op != NULL; op = op->next) { @@ -1764,7 +1801,8 @@ static void do_replacements(block_t *bl) { /** * Calculate the Avail_out sets for all basic blocks. */ -static void calcAvail(void) { +static void calcAvail(void) +{ memop_t **tmp_memop = env.curr_id_2_memop; unsigned *tmp_set = env.curr_set; block_t *bl; @@ -1785,7 +1823,8 @@ static void calcAvail(void) { /** * Calculate the Antic_in sets for all basic blocks. */ -static void calcAntic(void) { +static void calcAntic(void) +{ int i, need_iter; /* calculate antic_out */ @@ -1812,7 +1851,8 @@ static void calcAntic(void) { * * @param bl the block */ -static ir_node *find_last_memory(block_t *bl) { +static ir_node *find_last_memory(block_t *bl) +{ for (;;) { if (bl->memop_backward != NULL) { return bl->memop_backward->mem; @@ -1829,7 +1869,8 @@ static ir_node *find_last_memory(block_t *bl) { * @param omem the old memory IR-node * @param nmem the new memory IR-node */ -static void reroute_all_mem_users(ir_node *omem, ir_node *nmem) { +static void reroute_all_mem_users(ir_node *omem, ir_node *nmem) +{ int i; for (i = get_irn_n_outs(omem) - 1; i >= 0; --i) { @@ -1851,7 +1892,8 @@ static void reroute_all_mem_users(ir_node *omem, ir_node *nmem) { * @param nmem the new memory IR-node * @param pass_bl the block the memory must pass */ -static void reroute_mem_through(ir_node *omem, ir_node *nmem, ir_node *pass_bl) { +static void reroute_mem_through(ir_node *omem, ir_node *nmem, ir_node *pass_bl) +{ int i, j, n = get_irn_n_outs(omem); ir_def_use_edge *edges = NEW_ARR_D(ir_def_use_edge, &env.obst, n + 1); @@ -1885,7 +1927,8 @@ static void reroute_mem_through(ir_node *omem, ir_node *nmem, ir_node *pass_bl) /** * insert Loads, making partly redundant Loads fully redundant */ -static int insert_Load(block_t *bl) { +static int insert_Load(block_t *bl) +{ ir_node *block = bl->block; int i, n = get_Block_n_cfgpreds(block); unsigned end = env.rbs_size - 1; @@ -2070,11 +2113,11 @@ static int insert_Load(block_t *bl) { assert(last_mem != NULL); adr = phi_translate(op->value.address, block, i); load = new_rd_Load(db, pred, last_mem, adr, mode, cons_none); - def = new_r_Proj(pred, load, mode, pn_Load_res); + def = new_r_Proj(load, mode, pn_Load_res); DB((dbg, LEVEL_1, "Created new %+F in %+F for party redundant %+F\n", load, pred, op->node)); new_op = alloc_memop(load); - new_op->mem = new_r_Proj(pred, load, mode_M, pn_Load_M); + new_op->mem = new_r_Proj(load, mode_M, pn_Load_M); new_op->value.address = adr; new_op->value.id = op->value.id; new_op->value.mode = mode; @@ -2123,7 +2166,7 @@ static int insert_Load(block_t *bl) { /* always update the map after gen/kill, as values might have been changed due to RAR/WAR/WAW */ memcpy(bl->id_2_memop_avail, env.curr_id_2_memop, env.rbs_size * sizeof(env.curr_id_2_memop[0])); - if (!rbitset_equal(bl->avail_out, env.curr_set, env.rbs_size)) { + if (!rbitsets_equal(bl->avail_out, env.curr_set, env.rbs_size)) { /* the avail set has changed */ rbitset_copy(bl->avail_out, env.curr_set, env.rbs_size); dump_curr(bl, "Avail_out*"); @@ -2136,7 +2179,8 @@ static int insert_Load(block_t *bl) { /** * Insert Loads upwards. */ -static void insert_Loads_upwards(void) { +static void insert_Loads_upwards(void) +{ int i, need_iter; block_t *bl; @@ -2164,7 +2208,8 @@ static void insert_Loads_upwards(void) { * * @param irg the graph to operate on */ -static void kill_unreachable_blocks(ir_graph *irg) { +static void kill_unreachable_blocks(ir_graph *irg) +{ block_t *bl; ir_node **ins; int changed = 0; @@ -2255,7 +2300,8 @@ static void kill_unreachable_blocks(ir_graph *irg) { } } /* kill_unreachable_blocks */ -int opt_ldst(ir_graph *irg) { +int opt_ldst(ir_graph *irg) +{ block_t *bl; ir_graph *rem = current_ir_graph; @@ -2405,3 +2451,8 @@ end: current_ir_graph = rem; return env.changed != 0; } /* opt_ldst */ + +ir_graph_pass_t *opt_ldst_pass(const char *name) +{ + return def_graph_pass_ret(name ? name : "ldst_df", opt_ldst); +} /* opt_ldst_pass */