clarify some node comments
[libfirm] / ir / opt / tailrec.c
index 342a05c..a294bde 100644 (file)
@@ -22,7 +22,6 @@
  * @brief   Tail-recursion call optimization.
  * @date    08.06.2004
  * @author  Michael Beck
- * @version $Id$
  */
 #include "config.h"
 
@@ -46,6 +45,7 @@
 #include "irhooks.h"
 #include "ircons_t.h"
 #include "irpass.h"
+#include "opt_manage.h"
 
 DEBUG_ONLY(static firm_dbg_module_t *dbg;)
 
@@ -155,9 +155,6 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env)
        clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_DOMINANCE
                           | IR_GRAPH_STATE_VALID_EXTENDED_BLOCKS);
 
-       /* calls are removed */
-       set_trouts_inconsistent();
-
        /* we must build some new nodes WITHOUT CSE */
        set_optimize(0);
 
@@ -268,7 +265,6 @@ static void do_opt_tail_rec(ir_graph *irg, tr_env *env)
        clear_irg_state(irg, IR_GRAPH_STATE_CONSISTENT_DOMINANCE
                           | IR_GRAPH_STATE_CONSISTENT_LOOPINFO
                           | IR_GRAPH_STATE_VALID_EXTENDED_BLOCKS);
-       set_trouts_inconsistent();
        set_irg_callee_info_state(irg, irg_callee_info_inconsistent);
 
        set_optimize(rem);
@@ -565,7 +561,7 @@ 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)
+static ir_graph_state_t do_tailrec(ir_graph *irg)
 {
        tr_env            env;
        ir_node           *end_block;
@@ -577,8 +573,6 @@ int opt_tail_rec_irg(ir_graph *irg)
 
        FIRM_DBG_REGISTER(dbg, "firm.opt.tailrec");
 
-       assure_irg_outs(irg);
-
        if (! check_lifetime_of_locals(irg))
                return 0;
 
@@ -599,12 +593,6 @@ int opt_tail_rec_irg(ir_graph *irg)
                        env.variants[i] = TR_DIRECT;
        }
 
-       /*
-        * This tail recursion optimization works best
-        * if the Returns are normalized.
-        */
-       normalize_n_returns(irg);
-
        ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
 
        end_block = get_irg_end_block(irg);
@@ -632,10 +620,10 @@ int opt_tail_rec_irg(ir_graph *irg)
                /* check if it's a recursive call */
                call_ptr = get_Call_ptr(call);
 
-               if (! is_Global(call_ptr))
+               if (! is_SymConst_addr_ent(call_ptr))
                        continue;
 
-               ent = get_Global_entity(call_ptr);
+               ent = get_SymConst_entity(call_ptr);
                if (!ent || get_entity_irg(ent) != irg)
                        continue;
 
@@ -666,7 +654,7 @@ int opt_tail_rec_irg(ir_graph *irg)
                                break;
                        }
                        if (var == TR_DIRECT)
-                               var = env.variants[j];
+                       var = env.variants[j];
                        else if (env.variants[j] == TR_DIRECT)
                                env.variants[j] = var;
                        if (env.variants[j] != var) {
@@ -701,7 +689,23 @@ int opt_tail_rec_irg(ir_graph *irg)
        }
        ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
        current_ir_graph = rem;
-       return n_tail_calls;
+       return 0;
+}
+
+
+/*
+ * This tail recursion optimization works best
+ * if the Returns are normalized.
+ */
+static optdesc_t opt_tailrec = {
+       "tail-recursion",
+       IR_GRAPH_STATE_MANY_RETURNS | IR_GRAPH_STATE_NO_BADS | IR_GRAPH_STATE_CONSISTENT_OUTS,
+       do_tailrec,
+};
+
+int opt_tail_rec_irg(ir_graph *irg) {
+       perform_irg_optimization(irg, &opt_tailrec);
+       return 1; /* conservatively report changes */
 }
 
 ir_graph_pass_t *opt_tail_rec_irg_pass(const char *name)