#include "irflag.h"
#include "firmstat.h"
+static int n_opt_applications = 0;
+
/**
* the environment for colelcting data
*/
in[i] = get_Call_mem(calls);
++i;
}
+ assert(i == n_tail_calls + 1);
+
phis[0] = new_rd_Phi(NULL, irg, block, n_tail_calls + 1, in, mode_M);
/* build the data phi's */
n_preds = get_Block_n_cfgpreds(end_block);
for (i = 0; i < n_preds; ++i) {
ir_node *ret = get_Block_cfgpred(end_block, i);
- ir_node *proj_m, *call, *call_ptr;
+ ir_node *call, *call_ptr;
entity *ent;
int j, n_ress;
ir_node **ress;
continue;
/* check, if it's a Return self() */
- proj_m = get_Return_mem(ret);
-
- if (get_irn_op(proj_m) != op_Proj)
- continue;
-
- call = get_Proj_pred(proj_m);
+ call = skip_Proj(get_Return_mem(ret));
if (get_irn_op(call) != op_Call)
continue;
if (get_irn_op(call_ptr) != op_SymConst)
continue;
+ if (get_SymConst_kind(call_ptr) != symconst_addr_ent)
+ continue;
+
ent = get_SymConst_entity(call_ptr);
if (!ent || get_entity_irg(ent) != irg)
continue;
ress = get_Return_res_arr(ret);
for (j = 0; j < n_ress; ++j) {
- ir_node *proj = ress[j];
- ir_node *proj_proj;
- ir_node *irn;
-
- if (get_irn_op(proj) != op_Proj) {
- /* not routed to a call */
- break;
- }
-
- proj_proj = get_Proj_pred(proj);
-
- if (get_irn_op(proj) != op_Proj) {
- /* not routed to a call */
- break;
- }
-
- irn = get_Proj_pred(proj_proj);
+ ir_node *irn = skip_Proj(skip_Proj(ress[j]));
if (irn != call) {
/* not routed to a call */
if (! n_tail_calls)
return;
+ if (get_opt_tail_recursion_verbose() && get_firm_verbosity() > 1)
+ printf(" Performing tail recursion for graph %s and %d Calls\n",
+ get_entity_ld_name(get_irg_entity(irg)), n_tail_calls);
+ n_opt_applications++;
+
do_opt_tail_rec(irg, rets, n_tail_calls);
}
if (! get_opt_tail_recursion() || ! get_opt_optimize())
return;
+ n_opt_applications = 0;
+
for (i = 0; i < get_irp_n_irgs(); i++) {
current_ir_graph = get_irp_irg(i);
opt_tail_rec_irg(current_ir_graph);
}
+
+ if (get_opt_tail_recursion_verbose())
+ printf("Performed tail recursion for %d of %d graphs\n", n_opt_applications, get_irp_n_irgs());
}