X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fldstopt.c;h=d5358791797c6785cb8362fee62dfff30fb89c6c;hb=5992483ac7f47c78e5315897faf715fc840f32ce;hp=043a3b2a3b0e1a3d044054738dfa598639dd7f1d;hpb=e11232be68a7fbe13e49ec3be0a51a779c1cc435;p=libfirm diff --git a/ir/opt/ldstopt.c b/ir/opt/ldstopt.c index 043a3b2a3..d53587917 100644 --- a/ir/opt/ldstopt.c +++ b/ir/opt/ldstopt.c @@ -308,20 +308,21 @@ static long get_Sel_array_index_long(ir_node *n, int dim) { } static compound_graph_path *rec_get_accessed_path(ir_node *ptr, int depth) { - compound_graph_path *res; + compound_graph_path *res = NULL; + entity *root, *field; + int path_len, pos; + if (get_irn_op(ptr) == op_SymConst) { assert(get_SymConst_kind(ptr) == symconst_addr_ent); - entity *root = get_SymConst_entity(ptr); - if (depth == 0) - res = NULL; - else - res = new_compound_graph_path(get_entity_type(root), depth); - } else { + root = get_SymConst_entity(ptr); + res = (depth == 0) ? NULL : new_compound_graph_path(get_entity_type(root), depth); + } + else { assert(get_irn_op(ptr) == op_Sel); res = rec_get_accessed_path(get_Sel_ptr(ptr), depth+1); - entity *field = get_Sel_entity(ptr); - int path_len = get_compound_graph_path_length(res); - int pos = path_len - depth -1; + field = get_Sel_entity(ptr); + path_len = get_compound_graph_path_length(res); + pos = path_len - depth - 1; set_compound_graph_path_node(res, pos, field); if (is_Array_type(get_entity_owner(field))) { assert(get_Sel_n_indexs(ptr) == 1 && "multi dim arrays not implemented"); @@ -338,7 +339,6 @@ static compound_graph_path *get_accessed_path(ir_node *ptr) { return rec_get_accessed_path(ptr, 0); } - /** * optimize a Load */ @@ -346,7 +346,7 @@ static int optimize_load(ir_node *load) { ldst_info_t *info = get_irn_link(load); ir_mode *load_mode = get_Load_mode(load); - ir_node *pred, *mem, *ptr; + ir_node *pred, *mem, *ptr, *new_node; entity *ent; int res = 0; @@ -365,7 +365,7 @@ static int optimize_load(ir_node *load) if (get_irn_op(ptr) == op_Sel) { ir_node *mem = get_Sel_mem(ptr); - if (get_irn_op(mem) == op_Alloc) { + if (get_irn_op(skip_Proj(mem)) == op_Alloc) { /* ok, check the types */ entity *ent = get_Sel_entity(ptr); type *s_type = get_entity_type(ent); @@ -380,7 +380,8 @@ static int optimize_load(ir_node *load) } } } - else if (get_irn_op(ptr) == op_Alloc) { + else if ((get_irn_op(skip_Proj(ptr)) == op_Alloc) || + ((get_irn_op(ptr) == op_Cast) && (get_irn_op(skip_Proj(get_Cast_op(ptr))) == op_Alloc))) { /* simple case: a direct load after an Alloc. Firm Alloc throw * an exception in case of out-of-memory. So, there is no way for an * exception in this load. @@ -408,7 +409,7 @@ static int optimize_load(ir_node *load) /* Load from a constant polymorphic field, where we can resolve polymorphy. */ - ir_node *new_node = transform_node_Load(load); + new_node = transform_node_Load(load); if (new_node != load) { if (info->projs[pn_Load_M]) { exchange(info->projs[pn_Load_M], mem); @@ -438,10 +439,11 @@ static int optimize_load(ir_node *load) } if (variability_constant == get_entity_variability(ent) - && is_atomic_entity(ent)) { /* Might not be atomic after - lowering of Sels. In this - case we could also load, but - it's more complicated. */ + && 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 */ @@ -463,43 +465,56 @@ static int optimize_load(ir_node *load) } } else if (variability_constant == get_entity_variability(ent)) { + compound_graph_path *path; + /* printf(">>>>>>>>>>>>> Found access to constant entity %s in function %s\n", get_entity_name(ent), - get_entity_name(get_irg_entity(current_ir_graph))); - printf(" load: "); DDMN(load); - printf(" ptr: "); DDMN(ptr); - - compound_graph_path *path = get_accessed_path(ptr); - if (path) { - assert(is_proper_compound_graph_path(path, get_compound_graph_path_length(path)-1)); - ir_node *c = get_compound_ent_value_by_path(ent, path); - - printf(" cons: "); DDMN(c); - - if (info->projs[pn_Load_M]) - exchange(info->projs[pn_Load_M], mem); - if (info->projs[pn_Load_res]) - exchange(info->projs[pn_Load_res], copy_const_value(c)); - - { - int j; - for (j = 0; j < get_compound_graph_path_length(path); ++j) { - entity *node = get_compound_graph_path_node(path, j); - fprintf(stdout, ".%s", get_entity_name(node)); - if (is_Array_type(get_entity_owner(node))) - fprintf(stdout, "[%d]", get_compound_graph_path_array_index(path, j)); - } - printf("\n"); - } - } else { - printf("cannot optimize.\n"); + get_entity_name(get_irg_entity(current_ir_graph))); + printf(" load: "); DDMN(load); + printf(" ptr: "); DDMN(ptr); + */ + path = get_accessed_path(ptr); + if (path) { + ir_node *c; + + assert(is_proper_compound_graph_path(path, get_compound_graph_path_length(path)-1)); + c = get_compound_ent_value_by_path(ent, path); + + /* printf(" cons: "); DDMN(c); */ + + if (info->projs[pn_Load_M]) + exchange(info->projs[pn_Load_M], mem); + if (info->projs[pn_Load_res]) + exchange(info->projs[pn_Load_res], copy_const_value(c)); + /* + { + int j; + for (j = 0; j < get_compound_graph_path_length(path); ++j) { + entity *node = get_compound_graph_path_node(path, j); + fprintf(stdout, ".%s", get_entity_name(node)); + if (is_Array_type(get_entity_owner(node))) + fprintf(stdout, "[%d]", get_compound_graph_path_array_index(path, j)); + } + printf("\n"); + } + */ + } else { + /* We can not determine a correct access path. E.g., in jack, we load + a byte from an object to generate an exception. Happens in test program + Reflectiontest. + printf(">>>>>>>>>>>>> Found access to constant entity %s in function %s\n", get_entity_name(ent), + get_entity_name(get_irg_entity(current_ir_graph))); + printf(" load: "); DDMN(load); + printf(" ptr: "); DDMN(ptr); + if (get_irn_op(ptr) == op_SymConst && + get_SymConst_kind(ptr) == symconst_addr_ent) { printf(" "); DDMEO(get_SymConst_entity(ptr)); } + printf("cannot optimize.\n"); + */ } } /* we changed the irg, but try further */ res = 1; } - - } /* Check, if the address of this load is used more than once. @@ -534,8 +549,10 @@ static int optimize_load(ir_node *load) */ if ((!pred_info->projs[pn_Store_X_except] && !info->projs[pn_Load_X_except]) || get_nodes_block(load) == get_nodes_block(pred)) { - DBG_OPT_RAW(load, pred); - exchange( info->projs[pn_Load_res], get_Store_value(pred) ); + ir_node *value = get_Store_value(pred); + + DBG_OPT_RAW(load, value); + exchange(info->projs[pn_Load_res], value); if (info->projs[pn_Load_M]) exchange(info->projs[pn_Load_M], mem);