becopyheur4: Clean up co_mst_irn_init().
[libfirm] / ir / opt / boolopt.c
index 74dfc32..2632da6 100644 (file)
@@ -1,27 +1,12 @@
 /*
- * Copyright (C) 1995-2011 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
  * @brief   boolean condition/control flow optimizations
  * @author  Matthias Braun, Christoph Mallon, Michael Beck
- * @version $Id: cfopt.c 22579 2008-10-07 14:54:04Z beck $
  */
 #include "config.h"
 
@@ -39,7 +24,6 @@
 #include "tv.h"
 #include "irpass.h"
 #include "debug.h"
-#include "opt_manage.h"
 
 /** Describes a pair of relative conditions lo < hi, lo rel_lo x, hi rel_hi x */
 typedef struct cond_pair {
@@ -585,8 +569,6 @@ restart:
                ir_node      *lower_block;
                ir_node      *lower_cf;
                ir_node      *cond;
-               ir_node      *cond_selector;
-               ir_node      *lower_pred;
 
                lower_cf = get_Block_cfgpred(block, low_idx);
                lower_cf = skip_empty_blocks(lower_cf);
@@ -605,17 +587,11 @@ restart:
                if (get_Block_mark(lower_block))
                        continue;
 
-               cond_selector = get_Cond_selector(cond);
-               if (get_irn_mode(cond_selector) != mode_b)
-                       continue;
-
-               lower_pred = get_Block_cfgpred_block(lower_block, 0);
-
+               ir_node *const cond_selector = get_Cond_selector(cond);
+               ir_node *const lower_pred    = get_Block_cfgpred_block(lower_block, 0);
                for (up_idx = 0; up_idx < n_cfgpreds; ++up_idx) {
                        ir_node   *upper_block;
                        ir_node   *upper_cf;
-                       ir_node   *upper_cond;
-                       ir_node   *upper_cond_selector;
                        ir_node   *replacement;
                        cond_pair  cpair;
 
@@ -629,13 +605,6 @@ restart:
                        if (!block_dominates(upper_block, block))
                                continue;
 
-                       assert(is_Proj(upper_cf));
-                       upper_cond = get_Proj_pred(upper_cf);
-                       assert(is_Cond(upper_cond));
-                       upper_cond_selector = get_Cond_selector(upper_cond);
-                       if (get_irn_mode(upper_cond_selector) != mode_b)
-                               continue;
-
                        /* we have found the structure */
                        /* check Phis: There must be NO Phi in block that
                           depends on the existence of low block */
@@ -643,11 +612,13 @@ restart:
                                continue;
 
                        /* all fine, try it */
+                       ir_node *const upper_cond          = get_Proj_pred(upper_cf);
+                       ir_node *const upper_cond_selector = get_Cond_selector(upper_cond);
                        if (!find_cond_pair(cond_selector, upper_cond_selector, &cpair))
                                continue;
 
                        /* normalize pncs: we need the true case to jump into the
-                        * common block (ie. conjunctive normal form) */
+                        * common block (i.e. conjunctive normal form) */
                        if (get_Proj_proj(lower_cf) == pn_Cond_false) {
                                if (cpair.cmp_lo == cond_selector) {
                                        ir_node  *cmp   = cpair.cmp_lo;
@@ -717,10 +688,9 @@ restart:
        }
 }
 
-static ir_graph_state_t do_simplify_bool(ir_graph *const irg)
+void opt_bool(ir_graph *const irg)
 {
        bool_opt_env_t env;
-       ir_graph_state_t res = 0;
 
        /* register a debug mask */
        FIRM_DBG_REGISTER(dbg, "firm.opt.bool");
@@ -730,30 +700,14 @@ static ir_graph_state_t do_simplify_bool(ir_graph *const irg)
        /* optimize simple Andb and Orb cases */
        irg_walk_graph(irg, NULL, bool_walk, &env);
 
-       ir_reserve_resources(irg, IR_RESOURCE_BLOCK_MARK | IR_RESOURCE_PHI_LIST);
-
        /* now more complicated cases: find control flow And/Or and optimize. */
+       ir_reserve_resources(irg, IR_RESOURCE_BLOCK_MARK | IR_RESOURCE_PHI_LIST);
        irg_walk_graph(irg, clear_block_infos, collect_phis, NULL);
        irg_block_walk_graph(irg, NULL, find_cf_and_or_walker, &env);
-
-       if (! env.changed) {
-               res |= IR_GRAPH_STATE_CONSISTENT_DOMINANCE;
-       }
-
        ir_free_resources(irg, IR_RESOURCE_BLOCK_MARK | IR_RESOURCE_PHI_LIST);
 
-       return res;
-}
-
-optdesc_t opt_simplify_bool = {
-       "bool-simplification",
-       IR_GRAPH_STATE_ONE_RETURN, /* works better with one return block only */
-       do_simplify_bool,
-};
-
-void opt_bool(ir_graph *irg)
-{
-       perform_irg_optimization(irg, &opt_simplify_bool);
+       confirm_irg_properties(irg,
+               env.changed ? IR_GRAPH_PROPERTIES_NONE : IR_GRAPH_PROPERTIES_ALL);
 }
 
 /* Creates an ir_graph pass for opt_bool. */