X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fescape_ana.c;h=6f4acd963d4b02127e8505ecb722dc4480ab20d7;hb=8a907f80824671f3ff21569442566dceca8d4f5f;hp=e0f13f915335f77adfadc0fe8ab13c593eaef5bd;hpb=1ec30d95387eb392ba5a1adc7958ebd91383d59c;p=libfirm diff --git a/ir/opt/escape_ana.c b/ir/opt/escape_ana.c index e0f13f915..6f4acd963 100644 --- a/ir/opt/escape_ana.c +++ b/ir/opt/escape_ana.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -33,9 +33,7 @@ * * A fast and simple Escape analysis. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" #include "iroptimize.h" @@ -47,7 +45,9 @@ #include "analyze_irg_args.h" #include "irgmod.h" #include "ircons.h" +#include "irprintf.h" #include "debug.h" +#include "error.h" /** * walker environment @@ -92,16 +92,14 @@ static int is_method_leaving_raise(ir_node *raise) /* Hmm: no ProjX from a Raise? This should be a verification * error. For now we just assert and return. */ - assert(! "No ProjX after Raise found"); - return 1; + panic("No ProjX after Raise found"); } if (get_irn_n_outs(proj) != 1) { /* Hmm: more than one user of ProjX: This is a verification * error. */ - assert(! "More than one user of ProjX"); - return 1; + panic("More than one user of ProjX"); } n = get_irn_out(proj, 0); @@ -114,11 +112,37 @@ static int is_method_leaving_raise(ir_node *raise) return 0; } +/** + * returns an Alloc node if the node adr Select + * from one + */ +static ir_node *is_depend_alloc(ir_node *adr) +{ + ir_node *alloc; + + if (!is_Sel(adr)) + return NULL; + + /* should be a simple Sel */ + if (get_Sel_n_indexs(adr) != 0) + return NULL; + + alloc = skip_Proj(get_Sel_ptr(adr)); + if (!is_Alloc(alloc)) + return NULL; + + /* hmm, we depend on this Alloc */ + ir_printf("depend alloc %+F\n", alloc); + + return NULL; +} + /** * determine if a value calculated by n "escape", ie * is stored somewhere we could not track */ -static int can_escape(ir_node *n) { +static int can_escape(ir_node *n) +{ int i, j, k; /* should always be pointer mode or we made some mistake */ @@ -130,6 +154,15 @@ static int can_escape(ir_node *n) { switch (get_irn_opcode(succ)) { case iro_Store: if (get_Store_value(succ) == n) { + ir_node *adr = get_Store_ptr(succ); + + /* + * if this Alloc depends on another one, + * we can enqueue it + */ + if (is_depend_alloc(adr)) + break; + /* * We are storing n. As long as we do not further * evaluate things, the pointer 'escape' here @@ -149,8 +182,7 @@ static int can_escape(ir_node *n) { ir_node *ptr = get_Call_ptr(succ); ir_entity *ent; - if (get_irn_op(ptr) == op_SymConst && - get_SymConst_kind(ptr) == symconst_addr_ent) { + if (is_SymConst_addr_ent(ptr)) { ent = get_SymConst_entity(ptr); /* we know the called entity */ @@ -163,7 +195,7 @@ static int can_escape(ir_node *n) { } } } - else if (get_irn_op(ptr) == op_Sel) { + else if (is_Sel(ptr)) { /* go through all possible callees */ for (k = get_Call_n_callees(succ) - 1; k >= 0; --k) { ent = get_Call_callee(succ, k); @@ -297,7 +329,7 @@ static void find_allocation_calls(ir_node *call, void *ctx) if (! is_Call(call)) return; adr = get_Call_ptr(call); - if (! is_SymConst(adr) || get_SymConst_kind(adr) != symconst_addr_ent) + if (! is_SymConst_addr_ent(adr)) return; ent = get_SymConst_entity(adr); if (! env->callback(ent)) @@ -361,7 +393,7 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env) blk = get_nodes_block(alloc); 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(irg, blk)); + set_Tuple_pred(alloc, pn_Alloc_X_regular, new_r_Jmp(blk)); set_Tuple_pred(alloc, pn_Alloc_X_except, new_r_Bad(irg)); ++env->nr_deads; @@ -371,7 +403,7 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env) ftp = get_irg_frame_type(irg); for (alloc = env->found_allocs; alloc; alloc = next) { next = get_irn_link(alloc); - size = get_Alloc_size(alloc); + size = get_Alloc_count(alloc); atp = get_Alloc_type(alloc); tp = NULL; @@ -385,7 +417,7 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env) if (tv != tarval_bad && tarval_is_long(tv) && get_type_state(atp) == layout_fixed && - get_tarval_long(tv) == get_type_size_bytes(atp)) { + (unsigned)get_tarval_long(tv) == get_type_size_bytes(atp)) { /* a already lowered type size */ tp = atp; } @@ -394,19 +426,20 @@ static void transform_allocs(ir_graph *irg, walk_env_t *env) if (tp && tp != firm_unknown_type) { /* we could determine the type, so we could place it on the frame */ dbg = get_irn_dbg_info(alloc); + blk = get_nodes_block(alloc); DBG((dbgHandle, LEVEL_DEFAULT, "%+F allocation of %+F type %+F placed on frame\n", irg, alloc, tp)); snprintf(name, sizeof(name), "%s_NE_%u", get_entity_name(get_irg_entity(irg)), nr++); + name[sizeof(name) - 1] = '\0'; ent = new_d_entity(ftp, new_id_from_str(name), get_Alloc_type(alloc), dbg); - sel = new_rd_simpleSel(dbg, irg, get_nodes_block(alloc), - get_irg_no_mem(irg), get_irg_frame(irg), ent); + sel = new_rd_simpleSel(dbg, get_nodes_block(alloc), get_irg_no_mem(irg), get_irg_frame(irg), ent); mem = get_Alloc_mem(alloc); 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(irg, blk)); + 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_res, sel); @@ -453,11 +486,10 @@ static void transform_alloc_calls(ir_graph *irg, walk_env_t *env) mem = get_Call_mem(call); blk = get_nodes_block(call); turn_into_tuple(call, pn_Call_max); - set_Tuple_pred(call, pn_Call_M_regular, mem); - set_Tuple_pred(call, pn_Call_X_regular, new_r_Jmp(irg, 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_M_except, mem); + 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)); ++env->nr_deads; @@ -510,6 +542,7 @@ void escape_analysis(int run_scalar_replace, check_alloc_entity_func callback) int i; struct obstack obst; walk_env_t *env, *elist; + (void) run_scalar_replace; if (get_irp_callee_info_state() != irg_callee_info_consistent) { assert(! "need callee info"); @@ -527,7 +560,7 @@ void escape_analysis(int run_scalar_replace, check_alloc_entity_func callback) obstack_init(&obst); elist = NULL; - env = obstack_alloc(&obst, sizeof(*env)); + env = OALLOC(&obst, walk_env_t); env->found_allocs = NULL; env->dead_allocs = NULL; env->callback = callback; @@ -553,7 +586,7 @@ void escape_analysis(int run_scalar_replace, check_alloc_entity_func callback) elist = env; - env = obstack_alloc(&obst, sizeof(*env)); + env = OALLOC(&obst, walk_env_t); env->found_allocs = NULL; env->dead_allocs = NULL; env->callback = callback;