X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fescape_ana.c;h=9ecc50b795f495d03cc7cc1dfd8d046933dc1320;hb=3142e505b37d6e992ebfe599ee69027fea55f75c;hp=7b25511a17de44c4f3ba43ca0666bec919f5833c;hpb=9d3c8631459f431c313160dab5778e8a7b88dd92;p=libfirm diff --git a/ir/opt/escape_ana.c b/ir/opt/escape_ana.c index 7b25511a1..9ecc50b79 100644 --- a/ir/opt/escape_ana.c +++ b/ir/opt/escape_ana.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -143,7 +143,7 @@ static ir_node *is_depend_alloc(ir_node *adr) */ static int can_escape(ir_node *n) { - int i, j, k; + int i; /* should always be pointer mode or we made some mistake */ assert(mode_is_reference(get_irn_mode(n))); @@ -183,30 +183,33 @@ static int can_escape(ir_node *n) ir_entity *ent; if (is_SymConst_addr_ent(ptr)) { + size_t j; ent = get_SymConst_entity(ptr); /* we know the called entity */ - for (j = get_Call_n_params(succ) - 1; j >= 0; --j) { - if (get_Call_param(succ, j) == n) { + for (j = get_Call_n_params(succ); j > 0;) { + if (get_Call_param(succ, --j) == n) { /* n is the j'th param of the call */ if (get_method_param_access(ent, j) & ptr_access_store) /* n is store in ent */ return 1; } } - } - else if (is_Sel(ptr)) { + } else if (is_Sel(ptr)) { + size_t k; + /* go through all possible callees */ - for (k = get_Call_n_callees(succ) - 1; k >= 0; --k) { - ent = get_Call_callee(succ, k); + for (k = get_Call_n_callees(succ); k > 0;) { + size_t j; + ent = get_Call_callee(succ, --k); if (ent == unknown_entity) { /* we don't know what will be called, a possible escape */ return 1; } - for (j = get_Call_n_params(succ) - 1; j >= 0; --j) { - if (get_Call_param(succ, j) == n) { + for (j = get_Call_n_params(succ); j > 0;) { + if (get_Call_param(succ, --j) == n) { /* n is the j'th param of the call */ if (get_method_param_access(ent, j) & ptr_access_store) /* n is store in ent */ @@ -214,8 +217,7 @@ static int can_escape(ir_node *n) } } } - } - else /* we don't know want will called */ + } else /* we don't know want will called */ return 1; break; @@ -233,6 +235,7 @@ static int can_escape(ir_node *n) case iro_Tuple: { ir_node *proj; + int j, k; /* Bad: trace the tuple backwards */ for (j = get_irn_arity(succ) - 1; j >= 0; --j) @@ -278,9 +281,9 @@ static int can_escape(ir_node *n) */ static void find_allocations(ir_node *alloc, void *ctx) { + walk_env_t *env = (walk_env_t*)ctx; int i; ir_node *adr; - walk_env_t *env = ctx; if (! is_Alloc(alloc)) return; @@ -321,10 +324,10 @@ static void find_allocations(ir_node *alloc, void *ctx) */ static void find_allocation_calls(ir_node *call, void *ctx) { + walk_env_t *env = (walk_env_t*)ctx; int i; ir_node *adr; ir_entity *ent; - walk_env_t *env = ctx; if (! is_Call(call)) return; @@ -385,7 +388,7 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env) /* kill all dead allocs */ for (alloc = env->dead_allocs; alloc; alloc = next) { - next = get_irn_link(alloc); + next = (ir_node*)get_irn_link(alloc); DBG((dbgHandle, LEVEL_1, "%+F allocation of %+F unused, deleted.\n", irg, alloc)); @@ -394,7 +397,7 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env) turn_into_tuple(alloc, pn_Alloc_max); set_Tuple_pred(alloc, pn_Alloc_M, mem); set_Tuple_pred(alloc, pn_Alloc_X_regular, new_r_Jmp(blk)); - set_Tuple_pred(alloc, pn_Alloc_X_except, new_r_Bad(irg)); + set_Tuple_pred(alloc, pn_Alloc_X_except, new_r_Bad(irg, mode_X)); ++env->nr_deads; } @@ -402,7 +405,7 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env) /* convert all non-escaped heap allocs into frame variables */ ftp = get_irg_frame_type(irg); for (alloc = env->found_allocs; alloc; alloc = next) { - next = get_irn_link(alloc); + next = (ir_node*)get_irn_link(alloc); size = get_Alloc_count(alloc); atp = get_Alloc_type(alloc); @@ -439,7 +442,7 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env) turn_into_tuple(alloc, pn_Alloc_max); set_Tuple_pred(alloc, pn_Alloc_M, mem); set_Tuple_pred(alloc, pn_Alloc_X_regular, new_r_Jmp(blk)); - set_Tuple_pred(alloc, pn_Alloc_X_except, new_r_Bad(irg)); + set_Tuple_pred(alloc, pn_Alloc_X_except, new_r_Bad(irg, mode_X)); set_Tuple_pred(alloc, pn_Alloc_res, sel); ++env->nr_removed; @@ -457,13 +460,9 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env) } /* if allocs were removed somehow */ - if (env->nr_removed | env->nr_deads) { - set_irg_outs_inconsistent(irg); - - if (env->nr_deads) { - /* exception control flow might have been changed */ - set_irg_doms_inconsistent(irg); - } + if (env->nr_removed && env->nr_deads) { + /* exception control flow might have been changed */ + set_irg_doms_inconsistent(irg); } } @@ -478,18 +477,17 @@ static void transform_alloc_calls(ir_graph *irg, walk_env_t *env) /* kill all dead allocs */ for (call = env->dead_allocs; call; call = next) { - next = get_irn_link(call); + next = (ir_node*)get_irn_link(call); DBG((dbgHandle, LEVEL_1, "%+F allocation of %+F unused, deleted.\n", irg, call)); mem = get_Call_mem(call); blk = get_nodes_block(call); turn_into_tuple(call, pn_Call_max); - set_Tuple_pred(call, pn_Call_M, mem); - set_Tuple_pred(call, pn_Call_X_regular, new_r_Jmp(blk)); - set_Tuple_pred(call, pn_Call_X_except, new_r_Bad(irg)); - set_Tuple_pred(call, pn_Call_T_result, new_r_Bad(irg)); - set_Tuple_pred(call, pn_Call_P_value_res_base, new_r_Bad(irg)); + set_Tuple_pred(call, pn_Call_M, mem); + set_Tuple_pred(call, pn_Call_X_regular, new_r_Jmp(blk)); + set_Tuple_pred(call, pn_Call_X_except, new_r_Bad(irg, mode_X)); + set_Tuple_pred(call, pn_Call_T_result, new_r_Bad(irg, mode_T)); ++env->nr_deads; } @@ -497,7 +495,7 @@ static void transform_alloc_calls(ir_graph *irg, walk_env_t *env) /* convert all non-escaped heap allocs into frame variables */ ftp = get_irg_frame_type(irg); for (call = env->found_allocs; call; call = next) { - next = get_irn_link(call); + next = (ir_node*)get_irn_link(call); } } @@ -537,8 +535,7 @@ void escape_enalysis_irg(ir_graph *irg, check_alloc_entity_func callback) /* Do simple and fast escape analysis for all graphs. */ void escape_analysis(int run_scalar_replace, check_alloc_entity_func callback) { - ir_graph *irg; - int i; + size_t i, n; struct obstack obst; walk_env_t *env, *elist; (void) run_scalar_replace; @@ -564,8 +561,8 @@ void escape_analysis(int run_scalar_replace, check_alloc_entity_func callback) env->dead_allocs = NULL; env->callback = callback; - for (i = get_irp_n_irgs() - 1; i >= 0; --i) { - irg = get_irp_irg(i); + for (i = 0, n = get_irp_n_irgs(); i < n; ++i) { + ir_graph *irg = get_irp_irg(i); assure_irg_outs(irg);