X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Ftailrec.c;h=39e54aa3d338e0d4643fa12739d25d61db4837a1;hb=b7b24e372a1338ecd5eb26bdd285a8cbe7b1fec9;hp=de723b29805fac66a8d95a348864396f10201856;hpb=6730cf921d356d992d35526daf57f82af7ab0816;p=libfirm diff --git a/ir/opt/tailrec.c b/ir/opt/tailrec.c index de723b298..39e54aa3d 100644 --- a/ir/opt/tailrec.c +++ b/ir/opt/tailrec.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. * @@ -65,7 +65,7 @@ typedef struct collect_t { */ static void collect_data(ir_node *node, void *env) { - collect_t *data = env; + collect_t *data = (collect_t*)env; ir_node *pred; ir_op *op; @@ -97,7 +97,7 @@ static void collect_data(ir_node *node, void *env) /* * the first block has the initial exec as cfg predecessor */ - if (node != get_irg_start_block(current_ir_graph)) { + if (node != get_irg_start_block(get_irn_irg(node))) { for (i = 0; i < n_pred; ++i) { if (get_Block_cfgpred(node, i) == data->proj_X) { data->block = node; @@ -149,9 +149,6 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) int rem = get_optimize(); ir_entity *ent = get_irg_entity(irg); ir_type *method_tp = get_entity_type(ent); - ir_graph *old = current_ir_graph; - - current_ir_graph = irg; assert(env->n_tail_calls > 0); @@ -180,7 +177,7 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) irg_walk_graph(irg, NULL, collect_data, &data); /* check number of arguments */ - call = get_irn_link(end_block); + call = (ir_node*)get_irn_link(end_block); n_params = get_Call_n_params(call); assert(data.proj_X && "Could not find initial exec from Start"); @@ -197,7 +194,7 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) for (i = 1, p = env->rets; p; p = n) { ir_node *block = get_nodes_block(p); - n = get_irn_link(p); + n = (ir_node*)get_irn_link(p); in[i++] = new_r_Jmp(block); // exchange(p, new_r_Bad(irg)); @@ -223,7 +220,7 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) set_irg_initial_mem(irg, in[i]); ++i; - for (calls = call; calls; calls = get_irn_link(calls)) { + for (calls = call; calls != NULL; calls = (ir_node*)get_irn_link(calls)) { in[i] = get_Call_mem(calls); ++i; } @@ -240,7 +237,8 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) NEW_ARR_A(ir_node **, call_params, env->n_tail_calls); /* collect all parameters */ - for (i = 0, calls = call; calls; calls = get_irn_link(calls)) { + for (i = 0, calls = call; calls != NULL; + calls = (ir_node*)get_irn_link(calls)) { call_params[i] = get_Call_param_arr(calls); ++i; } @@ -268,7 +266,7 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) long proj = get_Proj_proj(p); assert(0 <= proj && proj < n_params); - n = get_irn_link(p); + n = (ir_node*)get_irn_link(p); exchange(p, phis[proj + 1]); } @@ -276,7 +274,7 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) set_irg_doms_inconsistent(irg); set_irg_outs_inconsistent(irg); set_irg_extblk_inconsistent(irg); - set_irg_loopinfo_state(current_ir_graph, loopinfo_cf_inconsistent); + set_irg_loopinfo_state(irg, loopinfo_cf_inconsistent); set_trouts_inconsistent(); set_irg_callee_info_state(irg, irg_callee_info_inconsistent); @@ -322,7 +320,7 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) ir_node *call, *mem, *jmp, *tuple; set_cur_block(block); - n = get_irn_link(p); + n = (ir_node*)get_irn_link(p); call = skip_Proj(get_Return_mem(p)); assert(is_Call(call)); @@ -349,7 +347,6 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) set_Tuple_pred(call, pn_Call_X_regular, jmp); set_Tuple_pred(call, pn_Call_X_except, bad); set_Tuple_pred(call, pn_Call_T_result, tuple); - set_Tuple_pred(call, pn_Call_P_value_res_base, bad); for (i = 0; i < env->n_ress; ++i) { ir_node *res = get_Return_res(p, i); @@ -404,11 +401,10 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) /* no: we can kill all returns */ for (p = env->rets; p; p = n) { - n = get_irn_link(p); + n = (ir_node*)get_irn_link(p); exchange(p, bad); } } - current_ir_graph = old; } /** @@ -720,16 +716,13 @@ ir_graph_pass_t *opt_tail_rec_irg_pass(const char *name) */ void opt_tail_recursion(void) { - int i; - int n_opt_applications = 0; - ir_graph *irg; + size_t i, n; + size_t n_opt_applications = 0; FIRM_DBG_REGISTER(dbg, "firm.opt.tailrec"); - for (i = get_irp_n_irgs() - 1; i >= 0; --i) { - irg = get_irp_irg(i); - - current_ir_graph = irg; + for (i = 0, n = get_irp_n_irgs(); i < n; ++i) { + ir_graph *irg = get_irp_irg(i); ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK); if (opt_tail_rec_irg(irg)) @@ -738,7 +731,7 @@ void opt_tail_recursion(void) ir_free_resources(irg, IR_RESOURCE_IRN_LINK); } - DB((dbg, LEVEL_1, "Performed tail recursion for %d of %d graphs\n", + DB((dbg, LEVEL_1, "Performed tail recursion for %zu of %zu graphs\n", n_opt_applications, get_irp_n_irgs())); }