Moved functions from opt_confirms.h into official header, do edgjfe can use them.
[libfirm] / ir / opt / opt_osr.c
index e303072..165fff0 100644 (file)
@@ -58,10 +58,10 @@ DEBUG_ONLY(static firm_dbg_module_t *dbg;)
 
 /** A scc. */
 typedef struct scc {
-       ir_node  *head;         /**< the head of the list */
-       tarval   *init;     /**< the init value iff only one exists. */
-       tarval   *incr;     /**< the induction variable increment if only a single const exists. */
-       unsigned code;      /**< == iro_Add if +incr, iro_Sub if -incr, 0 if not analysed, iro_Bad else */
+       ir_node   *head; /**< the head of the list */
+       ir_tarval *init; /**< the init value iff only one exists. */
+       ir_tarval *incr; /**< the induction variable increment if only a single const exists. */
+       unsigned   code; /**< == iro_Add if +incr, iro_Sub if -incr, 0 if not analysed, iro_Bad else */
 } scc;
 
 /** A node entry */
@@ -164,7 +164,6 @@ static void LFTR_add(ir_node *src, ir_node *dst, ir_opcode code, ir_node *rc, iv
         * There might be more than one edge here. This is rather bad
         * because we currently store only one.
         */
-//     assert(LFTR_find(src, env) == NULL);
        set_insert(env->lftr_edges, &key, sizeof(key), HASH_PTR(src));
 }  /* LFTR_add */
 
@@ -490,7 +489,7 @@ static int replace(ir_node *irn, ir_node *iv, ir_node *rc, iv_env *env)
        if (result != irn) {
                node_entry *e;
 
-               hook_strength_red(current_ir_graph, irn);
+               hook_strength_red(get_irn_irg(irn), irn);
                exchange(irn, result);
                e = get_irn_ne(result, env);
                if (e->pscc == NULL) {
@@ -517,7 +516,7 @@ static int is_x86_shift_const(ir_node *mul)
        /* normalization put constants on the right side */
        rc = get_Mul_right(mul);
        if (is_Const(rc)) {
-               tarval *tv = get_Const_tarval(rc);
+               ir_tarval *tv = get_Const_tarval(rc);
 
                if (tarval_is_long(tv)) {
                        long value = get_tarval_long(tv);
@@ -1047,13 +1046,11 @@ static void dfs(ir_node *irn, iv_env *env)
  */
 static void do_dfs(ir_graph *irg, iv_env *env)
 {
-       ir_graph *rem = current_ir_graph;
        ir_node  *end = get_irg_end(irg);
        int i;
 
        ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
 
-       current_ir_graph = irg;
        inc_irg_visited(irg);
 
        /* visit all visible nodes */
@@ -1068,8 +1065,6 @@ static void do_dfs(ir_graph *irg, iv_env *env)
        }
 
        ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
-
-       current_ir_graph = rem;
 }  /* do_dfs */
 
 /**
@@ -1103,9 +1098,10 @@ static void assign_po(ir_node *block, void *ctx)
 static ir_node *applyOneEdge(ir_node *iv, ir_node *rc, LFTR_edge *e, iv_env *env)
 {
        if (env->osr_flags & osr_flag_lftr_with_ov_check) {
-               tarval *tv_l, *tv_r, *tv, *tv_init, *tv_incr, *tv_end;
+               ir_tarval *tv_l, *tv_r, *tv, *tv_init, *tv_incr, *tv_end;
                tarval_int_overflow_mode_t ovmode;
                scc *pscc;
+               ir_graph *irg;
 
                if (! is_counter_iv(iv, env)) {
                        DB((dbg, LEVEL_4, " not counter IV"));
@@ -1173,7 +1169,8 @@ static ir_node *applyOneEdge(ir_node *iv, ir_node *rc, LFTR_edge *e, iv_env *env
                        DB((dbg, LEVEL_4, " = OVERFLOW"));
                        return NULL;
                }
-               return new_Const(tv);
+               irg = get_irn_irg(iv);
+               return new_r_Const(irg, tv);
        }
        return do_apply(e->code, NULL, rc, e->rc, get_irn_mode(e->dst));
 }  /* applyOneEdge */
@@ -1296,12 +1293,8 @@ static void clear_and_fix(ir_node *irn, void *env)
 /* Remove any Phi cycles with only one real input. */
 void remove_phi_cycles(ir_graph *irg)
 {
-       iv_env   env;
-       ir_graph *rem;
-       int      projs_moved;
-
-       rem = current_ir_graph;
-       current_ir_graph = irg;
+       iv_env env;
+       int    projs_moved;
 
        FIRM_DBG_REGISTER(dbg, "firm.opt.remove_phi");
 
@@ -1347,8 +1340,6 @@ void remove_phi_cycles(ir_graph *irg)
 
        DEL_ARR_F(env.stack);
        obstack_free(&env.obst, NULL);
-
-       current_ir_graph = rem;
 }  /* remove_phi_cycles */
 
 ir_graph_pass_t *remove_phi_cycles_pass(const char *name)
@@ -1415,13 +1406,9 @@ static void fix_adds_and_subs(ir_node *irn, void *ctx)
 void opt_osr(ir_graph *irg, unsigned flags)
 {
        iv_env   env;
-       ir_graph *rem;
        int      edges;
        int      projs_moved;
 
-       rem = current_ir_graph;
-       current_ir_graph = irg;
-
        FIRM_DBG_REGISTER(dbg, "firm.opt.osr");
 
        DB((dbg, LEVEL_1, "Doing Operator Strength Reduction for %+F\n", irg));
@@ -1481,8 +1468,6 @@ void opt_osr(ir_graph *irg, unsigned flags)
 
        if (! edges)
                edges_deactivate(irg);
-
-       current_ir_graph = rem;
 }  /* opt_osr */
 
 struct pass_t {