bepbqpcoloring: Remove duplicate macros.
[libfirm] / ir / opt / ifconv.c
index 22ab6f0..327465a 100644 (file)
@@ -1,24 +1,10 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
-/*
- * @file    ir/opt/ifconv.c
+/**
+ * @file
  * @brief   If conversion
  * @author  Christoph Mallon
  */
@@ -39,7 +25,6 @@
 #include "array_t.h"
 #include "irpass_t.h"
 #include "be.h"
-#include "opt_manage.h"
 
 #include "irdump.h"
 #include "debug.h"
@@ -193,8 +178,8 @@ static void rewire(ir_node* node, int i, int j, ir_node* new_pred)
  */
 static void split_block(ir_node* block, int i, int j)
 {
-       ir_node  *pred_block = get_nodes_block(get_irn_n(block, i));
-       int       arity      = get_irn_arity(block);
+       ir_node  *pred_block = get_nodes_block(get_Block_cfgpred(block, i));
+       int       arity      = get_Block_n_cfgpreds(block);
        ir_node **ins        = ALLOCAN(ir_node*, arity + 1);
        int       new_pred_arity;
        ir_node  *phi;
@@ -214,10 +199,10 @@ static void split_block(ir_node* block, int i, int j)
                set_irn_in(phi, k, ins);
        }
 
-       for (k = 0; k < i; ++k) ins[k] = get_irn_n(block, k);
+       for (k = 0; k < i; ++k) ins[k] = get_Block_cfgpred(block, k);
        ins[k++] = get_irn_n(pred_block, j);
-       for (; k < arity; ++k) ins[k] = get_irn_n(block, k);
-       ins[k++] = get_irn_n(block, i);
+       for (; k < arity; ++k) ins[k] = get_Block_cfgpred(block, k);
+       ins[k++] = get_Block_cfgpred(block, i);
        set_irn_in(block, k, ins);
 
        new_pred_arity = get_irn_arity(pred_block) - 1;
@@ -246,7 +231,7 @@ static void split_block(ir_node* block, int i, int j)
 
 static void prepare_path(ir_node* block, int i, const ir_node* dependency)
 {
-       ir_node* pred = get_nodes_block(get_irn_n(block, i));
+       ir_node* pred = get_nodes_block(get_Block_cfgpred(block, i));
        int pred_arity;
        int j;
 
@@ -297,9 +282,6 @@ restart:
                        if (! is_Cond(cond))
                                continue;
 
-                       /* We only handle boolean decisions, no switches */
-                       if (get_irn_mode(get_Cond_selector(cond)) != mode_b) continue;
-
                        for (j = i + 1; j < arity; ++j) {
                                ir_node* projx1;
                                ir_node* sel;
@@ -334,7 +316,11 @@ restart:
                                                mux_true  = get_Phi_pred(p, i);
                                                mux_false = get_Phi_pred(p, j);
                                        }
-                                       if (!env->allow_ifconv(sel, mux_false, mux_true)) {
+                                       if (mux_true == mux_false)
+                                               continue;
+                                       ir_mode *mode = get_irn_mode(mux_true);
+                                       if (mode == mode_M
+                                               || !env->allow_ifconv(sel, mux_false, mux_true)) {
                                                supported = false;
                                                break;
                                        }
@@ -393,29 +379,16 @@ restart:
                                } while (phi != NULL);
 
                                /* move mux operands into mux_block */
-                               exchange(get_nodes_block(get_irn_n(block, i)), mux_block);
-                               exchange(get_nodes_block(get_irn_n(block, j)), mux_block);
+                               exchange(get_nodes_block(get_Block_cfgpred(block, i)), mux_block);
+                               exchange(get_nodes_block(get_Block_cfgpred(block, j)), mux_block);
 
                                if (arity == 2) {
                                        unsigned mark;
-#if 0
-                                       DB((dbg, LEVEL_1,  "Welding block %+F and %+F\n", block, mux_block));
-                                       /* copy the block-info from the Mux-block to the block before merging */
-
-                                       mark =  get_Block_mark(mux_block) | get_Block_mark(block);
-                                       set_Block_mark(block, mark);
-                                       set_Block_phis(block, get_Block_phis(mux_block));
-
-                                       set_irn_in(block, get_irn_arity(mux_block), get_irn_in(mux_block) + 1);
-                                       exchange_cdep(mux_block, block);
-                                       exchange(mux_block, block);
-#else
                                        DB((dbg, LEVEL_1,  "Welding block %+F to %+F\n", block, mux_block));
                                        mark =  get_Block_mark(mux_block) | get_Block_mark(block);
                                        /* mark both block just to be sure, should be enough to mark mux_block */
                                        set_Block_mark(mux_block, mark);
                                        exchange(block, mux_block);
-#endif
                                        return;
                                } else {
                                        rewire(block, i, j, new_r_Jmp(mux_block));
@@ -464,11 +437,17 @@ static void collect_phis(ir_node *node, void *env)
        }
 }
 
-static ir_graph_state_t do_ifconv(ir_graph *irg)
+void opt_if_conv(ir_graph *irg)
 {
        walker_env            env;
        const backend_params *be_params = be_get_backend_param();
 
+       assure_irg_properties(irg,
+               IR_GRAPH_PROPERTY_NO_CRITICAL_EDGES
+               | IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE
+               | IR_GRAPH_PROPERTY_NO_BADS
+               | IR_GRAPH_PROPERTY_ONE_RETURN);
+
        /* get the parameters */
        env.allow_ifconv = be_params->allow_ifconv;
        env.changed      = false;
@@ -493,18 +472,9 @@ static ir_graph_state_t do_ifconv(ir_graph *irg)
 
        free_cdep(irg);
 
-       return IR_GRAPH_STATE_NO_CRITICAL_EDGES | IR_GRAPH_STATE_ONE_RETURN;
-}
-
-static optdesc_t opt_ifconv = {
-       "if-conversion",
-       IR_GRAPH_STATE_NO_CRITICAL_EDGES | IR_GRAPH_STATE_NO_UNREACHABLE_CODE | IR_GRAPH_STATE_NO_BADS | IR_GRAPH_STATE_ONE_RETURN,
-       do_ifconv,
-};
-
-void opt_if_conv(ir_graph *irg)
-{
-       perform_irg_optimization(irg, &opt_ifconv);
+       confirm_irg_properties(irg,
+               IR_GRAPH_PROPERTY_NO_CRITICAL_EDGES
+               | IR_GRAPH_PROPERTY_ONE_RETURN);
 }
 
 ir_graph_pass_t *opt_if_conv_pass(const char *name)