X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fopt_ldst.c;h=e330ff0092aaa7ff3ddb1e1f860df4f5a13008ce;hb=4d7f507c357a0bdb1433ef3973645ece971e3824;hp=6c75e3223a40b08caf712a58f33879b18eb512aa;hpb=fc80e89b7d176590d74e02ddad62481e7275a7c0;p=libfirm diff --git a/ir/opt/opt_ldst.c b/ir/opt/opt_ldst.c index 6c75e3223..e330ff009 100644 --- a/ir/opt/opt_ldst.c +++ b/ir/opt/opt_ldst.c @@ -38,7 +38,7 @@ #include "irgopt.h" #include "iropt.h" #include "iroptimize.h" -#include "irnodemap.h" +#include "irnodehashmap.h" #include "raw_bitset.h" #include "debug.h" #include "error.h" @@ -90,7 +90,7 @@ struct memop_t { memop_t *next; /**< links to the next memory op in the block in forward order. */ memop_t *prev; /**< links to the previous memory op in the block in forward order. */ unsigned flags; /**< memop flags */ - ir_node *projs[MAX_PROJ]; /**< Projs of this memory op */ + ir_node *projs[MAX_PROJ+1]; /**< Projs of this memory op */ }; /** @@ -115,8 +115,8 @@ struct block_t { * Metadata for this pass. */ typedef struct ldst_env_t { - struct obstack obst; /**< obstack for temporary data */ - ir_nodemap_t adr_map; /**< Map addresses to */ + struct obstack obst; /**< obstack for temporary data */ + ir_nodehashmap_t adr_map; /**< Map addresses to */ block_t *forward; /**< Inverse post-order list of all blocks Start->End */ block_t *backward; /**< Inverse post-order list of all blocks End->Start */ ir_node *start_bl; /**< start block of the current graph */ @@ -312,14 +312,14 @@ restart: goto restart; } - entry = (address_entry*)ir_nodemap_get(&env.adr_map, adr); + entry = (address_entry*)ir_nodehashmap_get(&env.adr_map, adr); if (entry == NULL) { /* new address */ entry = OALLOC(&env.obst, address_entry); entry->id = env.curr_adr_id++; - ir_nodemap_insert(&env.adr_map, adr, entry); + ir_nodehashmap_insert(&env.adr_map, adr, entry); DB((dbg, LEVEL_3, "ADDRESS %+F has ID %u\n", adr, entry->id)); #ifdef DEBUG_libfirm @@ -525,8 +525,8 @@ static unsigned get_Call_memory_properties(ir_node *call) /* try the called entity */ ir_node *ptr = get_Call_ptr(call); - if (is_Global(ptr)) { - ir_entity *ent = get_Global_entity(ptr); + if (is_SymConst_addr_ent(ptr)) { + ir_entity *ent = get_SymConst_entity(ptr); prop = get_entity_additional_properties(ent); } @@ -578,9 +578,9 @@ static ir_entity *find_constant_entity(ir_node *ptr) if (tlower == tarval_bad || tupper == tarval_bad) return NULL; - if (tarval_cmp(tv, tlower) & pn_Cmp_Lt) + if (tarval_cmp(tv, tlower) == ir_relation_less) return NULL; - if (tarval_cmp(tupper, tv) & pn_Cmp_Lt) + if (tarval_cmp(tupper, tv) == ir_relation_less) return NULL; /* ok, bounds check finished */ @@ -640,11 +640,11 @@ 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, size_t depth) { compound_graph_path *res = NULL; ir_entity *root, *field, *ent; - int path_len, pos, idx; + size_t path_len, pos, idx; ir_tarval *tv; ir_type *tp; @@ -725,9 +725,9 @@ ptr_arith: if (tlower == tarval_bad || tupper == tarval_bad) return NULL; - if (tarval_cmp(tv_index, tlower) & pn_Cmp_Lt) + if (tarval_cmp(tv_index, tlower) == ir_relation_less) return NULL; - if (tarval_cmp(tupper, tv_index) & pn_Cmp_Lt) + if (tarval_cmp(tupper, tv_index) == ir_relation_less) return NULL; /* ok, bounds check finished */ @@ -799,7 +799,7 @@ static compound_graph_path *get_accessed_path(ir_node *ptr) typedef struct path_entry { ir_entity *ent; struct path_entry *next; - long index; + size_t index; } path_entry; static ir_node *rec_find_compound_ent_value(ir_node *ptr, path_entry *next) @@ -809,7 +809,7 @@ static ir_node *rec_find_compound_ent_value(ir_node *ptr, path_entry *next) ir_initializer_t *initializer; ir_tarval *tv; ir_type *tp; - unsigned n; + size_t n; entry.next = next; if (is_SymConst(ptr)) { @@ -832,7 +832,7 @@ static ir_node *rec_find_compound_ent_value(ir_node *ptr, path_entry *next) continue; } } - if (p->index >= (int) n) + if (p->index >= n) return NULL; initializer = get_initializer_compound_value(initializer, p->index); @@ -865,7 +865,7 @@ static ir_node *rec_find_compound_ent_value(ir_node *ptr, path_entry *next) assert(get_Sel_n_indexs(ptr) == 1 && "multi dim arrays not implemented"); entry.index = get_Sel_array_index_long(ptr, 0) - get_array_lower_bound_int(tp, 0); } else { - int i, n_members = get_compound_n_members(tp); + size_t i, n_members = get_compound_n_members(tp); for (i = 0; i < n_members; ++i) { if (get_compound_member(tp, i) == field) break; @@ -923,7 +923,7 @@ ptr_arith: for (ent = field;;) { unsigned size; ir_tarval *sz, *tv_index, *tlower, *tupper; - long index; + size_t index; ir_node *bound; tp = get_entity_type(ent); @@ -951,9 +951,9 @@ ptr_arith: if (tlower == tarval_bad || tupper == tarval_bad) return NULL; - if (tarval_cmp(tv_index, tlower) & pn_Cmp_Lt) + if (tarval_cmp(tv_index, tlower) == ir_relation_less) return NULL; - if (tarval_cmp(tupper, tv_index) & pn_Cmp_Lt) + if (tarval_cmp(tupper, tv_index) == ir_relation_less) return NULL; /* ok, bounds check finished */ @@ -1065,7 +1065,7 @@ static void update_Load_memop(memop_t *m) /* no exception, clear the m fields as it might be checked later again */ if (m->projs[pn_Load_X_except]) { ir_graph *irg = get_irn_irg(ptr); - exchange(m->projs[pn_Load_X_except], new_r_Bad(irg)); + exchange(m->projs[pn_Load_X_except], new_r_Bad(irg, mode_X)); m->projs[pn_Load_X_except] = NULL; m->flags &= ~FLAG_EXCEPTION; env.changed = 1; @@ -1201,11 +1201,11 @@ static void update_Call_memop(memop_t *m) } /* update_Call_memop */ /** - * Update a memop for a Div/Mod/Quot/DivMod. + * Update a memop for a Div/Mod. * * @param m the memop */ -static void update_DivOp_memop(memop_t *m) +static void update_Div_memop(memop_t *m) { ir_node *div = m->node; int i; @@ -1218,15 +1218,38 @@ static void update_DivOp_memop(memop_t *m) continue; switch (get_Proj_proj(proj)) { - case pn_Generic_X_except: + case pn_Div_X_except: m->flags |= FLAG_EXCEPTION; break; - case pn_Generic_M: + case pn_Div_M: m->mem = proj; break; } } -} /* update_DivOp_memop */ +} + +static void update_Mod_memop(memop_t *m) +{ + ir_node *div = m->node; + int i; + + for (i = get_irn_n_outs(div) - 1; i >= 0; --i) { + ir_node *proj = get_irn_out(div, i); + + /* beware of keep edges */ + if (is_End(proj)) + continue; + + switch (get_Proj_proj(proj)) { + case pn_Mod_X_except: + m->flags |= FLAG_EXCEPTION; + break; + case pn_Mod_M: + m->mem = proj; + break; + } + } +} /** * Update a memop for a Phi. @@ -1235,7 +1258,7 @@ static void update_DivOp_memop(memop_t *m) */ static void update_Phi_memop(memop_t *m) { - /* the Phi is it's own mem */ + /* the Phi is its own mem */ m->mem = m->node; } /* update_Phi_memop */ @@ -1291,10 +1314,10 @@ static void collect_memops(ir_node *irn, void *ctx) /* we can those to find the memory edge */ break; case iro_Div: - case iro_DivMod: - case iro_Quot: + update_Div_memop(op); + break; case iro_Mod: - update_DivOp_memop(op); + update_Mod_memop(op); break; case iro_Builtin: @@ -1748,7 +1771,7 @@ static void replace_load(memop_t *op) proj = op->projs[pn_Load_X_except]; if (proj != NULL) { ir_graph *irg = get_irn_irg(load); - exchange(proj, new_r_Bad(irg)); + exchange(proj, new_r_Bad(irg, mode_X)); } proj = op->projs[pn_Load_X_regular]; if (proj != NULL) { @@ -1775,7 +1798,7 @@ static void remove_store(memop_t *op) proj = op->projs[pn_Store_X_except]; if (proj != NULL) { ir_graph *irg = get_irn_irg(store); - exchange(proj, new_r_Bad(irg)); + exchange(proj, new_r_Bad(irg, mode_X)); } proj = op->projs[pn_Store_X_regular]; if (proj != NULL) { @@ -1941,7 +1964,6 @@ static int insert_Load(block_t *bl) ir_node *block = bl->block; int i, n = get_Block_n_cfgpreds(block); size_t end = env.rbs_size - 1; - size_t pos; DB((dbg, LEVEL_3, "processing %+F\n", block)); @@ -1952,7 +1974,7 @@ static int insert_Load(block_t *bl) if (n > 1) { ir_node **ins; - int pos; + size_t pos; NEW_ARR_A(ir_node *, ins, n); @@ -2045,6 +2067,8 @@ static int insert_Load(block_t *bl) } if (n > 1) { + size_t pos; + /* check for partly redundant values */ for (pos = rbitset_next(bl->anticL_in, 0, 1); pos < end; @@ -2326,7 +2350,7 @@ int opt_ldst(ir_graph *irg) } obstack_init(&env.obst); - ir_nodemap_init(&env.adr_map); + ir_nodehashmap_init(&env.adr_map); env.forward = NULL; env.backward = NULL; @@ -2436,12 +2460,12 @@ int opt_ldst(ir_graph *irg) /* not only invalidate but free them. We might allocate new out arrays on our obstack which will be deleted yet. */ free_irg_outs(irg); - set_irg_entity_usage_state(irg, ir_entity_usage_not_computed); + clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_ENTITY_USAGE); } end: ir_free_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_BLOCK_MARK); - ir_nodemap_destroy(&env.adr_map); + ir_nodehashmap_destroy(&env.adr_map); obstack_free(&env.obst, NULL); #ifdef DEBUG_libfirm