fix trailing whitespaces and tabulators in the middle of a line
[libfirm] / ir / opt / tailrec.c
index 9bf3fa3..dd946b4 100644 (file)
 #include "irouts.h"
 #include "irhooks.h"
 #include "ircons_t.h"
-#include "irtools.h"
+#include "irpass.h"
 
 DEBUG_ONLY(static firm_dbg_module_t *dbg);
 
 /**
  * the environment for collecting data
  */
-typedef struct _collect_t {
+typedef struct collect_t {
        ir_node *proj_X;      /**< initial exec proj */
        ir_node *block;       /**< old first block */
        int     blk_idx;      /**< cfgpred index of the initial exec in block */
@@ -63,7 +63,8 @@ typedef struct _collect_t {
 /**
  * walker for collecting data, fills a collect_t environment
  */
-static void collect_data(ir_node *node, void *env) {
+static void collect_data(ir_node *node, void *env)
+{
        collect_t *data = env;
        ir_node *pred;
        ir_op *op;
@@ -135,7 +136,8 @@ typedef struct tr_env {
  * @param rets          linked list of all rets
  * @param n_tail_calls  number of tail-recursion calls
  */
-static void do_opt_tail_rec(ir_graph *irg, tr_env *env) {
+static void do_opt_tail_rec(ir_graph *irg, tr_env *env)
+{
        ir_node *end_block = get_irg_end_block(irg);
        ir_node *block, *jmp, *call, *calls;
        ir_node **in;
@@ -217,7 +219,7 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) {
 
        /* build the memory phi */
        i = 0;
-       in[i] = new_r_Proj(get_irg_start_block(irg), get_irg_start(irg), mode_M, pn_Start_M);
+       in[i] = new_r_Proj(get_irg_start(irg), mode_M, pn_Start_M);
        set_irg_initial_mem(irg, in[i]);
        ++i;
 
@@ -249,7 +251,7 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) {
                for (i = 0; i < n_params; ++i) {
                        ir_mode *mode = get_type_mode(get_method_param_type(method_tp, i));
 
-                       in[0] = new_r_Proj(args_bl, args, mode, i);
+                       in[0] = new_r_Proj(args, mode, i);
                        for (j = 0; j < env->n_tail_calls; ++j)
                                in[j + 1] = call_params[j][i];
 
@@ -347,7 +349,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_M_except,         mem);
                        set_Tuple_pred(call, pn_Call_P_value_res_base, bad);
 
                        for (i = 0; i < env->n_ress; ++i) {
@@ -417,7 +418,8 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env) {
  *
  * @return non-zero if it's ok to do tail recursion
  */
-static int check_lifetime_of_locals(ir_graph *irg) {
+static int check_lifetime_of_locals(ir_graph *irg)
+{
        ir_node *irg_frame;
        int i;
        ir_type *frame_tp = get_irg_frame_type(irg);
@@ -442,7 +444,8 @@ static int check_lifetime_of_locals(ir_graph *irg) {
 /**
  * Examine irn and detect the recursion variant.
  */
-static tail_rec_variants find_variant(ir_node *irn, ir_node *call) {
+static tail_rec_variants find_variant(ir_node *irn, ir_node *call)
+{
        ir_node           *a, *b;
        tail_rec_variants va, vb, res;
 
@@ -454,7 +457,7 @@ static tail_rec_variants find_variant(ir_node *irn, ir_node *call) {
        case iro_Add:
                /* try additive */
                a = get_Add_left(irn);
-               if (get_irn_MacroBlock(a) != get_irn_MacroBlock(call)) {
+               if (get_nodes_block(a) != get_nodes_block(call)) {
                        /* we are outside, ignore */
                        va = TR_UNKNOWN;
                } else {
@@ -463,7 +466,7 @@ static tail_rec_variants find_variant(ir_node *irn, ir_node *call) {
                                return TR_BAD;
                }
                b = get_Add_right(irn);
-               if (get_irn_MacroBlock(b) != get_irn_MacroBlock(call)) {
+               if (get_nodes_block(b) != get_nodes_block(call)) {
                        /* we are outside, ignore */
                        vb = TR_UNKNOWN;
                } else {
@@ -490,7 +493,7 @@ static tail_rec_variants find_variant(ir_node *irn, ir_node *call) {
        case iro_Sub:
                /* try additive, but return value must be left */
                a = get_Sub_left(irn);
-               if (get_irn_MacroBlock(a) != get_irn_MacroBlock(call)) {
+               if (get_nodes_block(a) != get_nodes_block(call)) {
                        /* we are outside, ignore */
                        va = TR_UNKNOWN;
                } else {
@@ -499,7 +502,7 @@ static tail_rec_variants find_variant(ir_node *irn, ir_node *call) {
                                return TR_BAD;
                }
                b = get_Sub_right(irn);
-               if (get_irn_MacroBlock(b) != get_irn_MacroBlock(call)) {
+               if (get_nodes_block(b) != get_nodes_block(call)) {
                        /* we are outside, ignore */
                        vb = TR_UNKNOWN;
                } else {
@@ -516,7 +519,7 @@ static tail_rec_variants find_variant(ir_node *irn, ir_node *call) {
        case iro_Mul:
                /* try multiplicative */
                a = get_Mul_left(irn);
-               if (get_irn_MacroBlock(a) != get_irn_MacroBlock(call)) {
+               if (get_nodes_block(a) != get_nodes_block(call)) {
                        /* we are outside, ignore */
                        va = TR_UNKNOWN;
                } else {
@@ -525,7 +528,7 @@ static tail_rec_variants find_variant(ir_node *irn, ir_node *call) {
                                return TR_BAD;
                }
                b = get_Mul_right(irn);
-               if (get_irn_MacroBlock(b) != get_irn_MacroBlock(call)) {
+               if (get_nodes_block(b) != get_nodes_block(call)) {
                        /* we are outside, ignore */
                        vb = TR_UNKNOWN;
                } else {
@@ -569,7 +572,8 @@ static tail_rec_variants find_variant(ir_node *irn, ir_node *call) {
 /*
  * convert simple tail-calls into loops
  */
-int opt_tail_rec_irg(ir_graph *irg) {
+int opt_tail_rec_irg(ir_graph *irg)
+{
        tr_env            env;
        ir_node           *end_block;
        int               i, n_ress, n_tail_calls = 0;
@@ -577,12 +581,13 @@ int opt_tail_rec_irg(ir_graph *irg) {
        ir_type           *mtd_type, *call_type;
        ir_entity         *ent;
 
+       FIRM_DBG_REGISTER(dbg, "firm.opt.tailrec");
+
        assure_irg_outs(irg);
 
        if (! check_lifetime_of_locals(irg))
                return 0;
 
-
        ent      = get_irg_entity(irg);
        mtd_type = get_entity_type(ent);
     n_ress   = get_method_n_ress(mtd_type);
@@ -703,15 +708,16 @@ int opt_tail_rec_irg(ir_graph *irg) {
        return n_tail_calls;
 }
 
-ir_graph_pass_t *opt_tail_rec_irg_pass(const char *name, int verify, int dump)
+ir_graph_pass_t *opt_tail_rec_irg_pass(const char *name)
 {
-       return def_graph_pass_ret(name ? name : "tailrec", verify, dump, opt_tail_rec_irg);
+       return def_graph_pass_ret(name ? name : "tailrec", opt_tail_rec_irg);
 }
 
 /*
  * optimize tail recursion away
  */
-void opt_tail_recursion(void) {
+void opt_tail_recursion(void)
+{
        int i;
        int n_opt_applications = 0;
        ir_graph *irg;
@@ -734,7 +740,7 @@ void opt_tail_recursion(void) {
            n_opt_applications, get_irp_n_irgs()));
 }
 
-ir_prog_pass_t *opt_tail_recursion_pass(const char *name, int verify, int dump)
+ir_prog_pass_t *opt_tail_recursion_pass(const char *name)
 {
-       return def_prog_pass(name ? name : "tailrec", verify, dump, opt_tail_recursion);
+       return def_prog_pass(name ? name : "tailrec", opt_tail_recursion);
 }