remove extended basic block support
[libfirm] / ir / opt / boolopt.c
index fa2d2b7..204b3c2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
@@ -21,7 +21,6 @@
  * @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,6 +38,7 @@
 #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 {
@@ -56,7 +56,7 @@ typedef struct {
        int changed;  /**< Set if the graph was changed. */
 } bool_opt_env_t;
 
-DEBUG_ONLY(static firm_dbg_module_t *dbg);
+DEBUG_ONLY(static firm_dbg_module_t *dbg;)
 
 /**
  * Check if tho given nodes, l and r, represent two compares with
@@ -64,62 +64,61 @@ DEBUG_ONLY(static firm_dbg_module_t *dbg);
  */
 static bool find_cond_pair(ir_node *const l, ir_node *const r, cond_pair *const res)
 {
-       if (!is_Cmp(l) || !is_Cmp(r))
-               return false;
-
-       ir_node    *const lol   = get_Cmp_left(l);
-       ir_node    *const lor   = get_Cmp_right(l);
-       ir_node    *const rol   = get_Cmp_left(r);
-       ir_node    *const ror   = get_Cmp_right(r);
-       ir_relation const pnc_l = get_Cmp_relation(l);
-       ir_relation const pnc_r = get_Cmp_relation(r);
-
-       if (is_Const(lor) && is_Const_null(lor) &&
-               is_Const(ror) && is_Const_null(ror) &&
-               pnc_l == pnc_r &&
-               (pnc_l == ir_relation_less_greater || pnc_l == ir_relation_equal)) {
-               /* l == (lol !=|== NULL) && r == (rol !=|== NULL) */
-               res->cmp_lo  = l;
-               res->cmp_hi  = r;
-               res->rel_lo  = pnc_l;
-               res->rel_hi  = pnc_l;
-               res->tv_lo   = get_Const_tarval(lor);
-               res->tv_hi   = get_Const_tarval(ror);
-               res->lo_mode = get_irn_mode(lor);
-
-               return true;
-       }
-
-       if (lol == rol && lor != ror && is_Const(lor) && is_Const(ror)) {
-               /* l == (x CMP c_l), r == (x cmp c_r) */
-               ir_tarval  *const tv_l  = get_Const_tarval(lor);
-               ir_tarval  *const tv_r  = get_Const_tarval(ror);
-               ir_relation const rel   = tarval_cmp(tv_l, tv_r);
-
-               res->lo_mode = get_irn_mode(lol);
-
-               if (rel == ir_relation_less) {
-                       /* c_l < c_r */
+       if (is_Cmp(l) && is_Cmp(r)) {
+               ir_node    *const lol   = get_Cmp_left(l);
+               ir_node    *const lor   = get_Cmp_right(l);
+               ir_node    *const rol   = get_Cmp_left(r);
+               ir_node    *const ror   = get_Cmp_right(r);
+               ir_relation const pnc_l = get_Cmp_relation(l);
+               ir_relation const pnc_r = get_Cmp_relation(r);
+
+               if (is_Const(lor) && is_Const_null(lor) &&
+                       is_Const(ror) && is_Const_null(ror) &&
+                       pnc_l == pnc_r &&
+                       (pnc_l == ir_relation_less_greater || pnc_l == ir_relation_equal)) {
+                       /* l == (lol !=|== NULL) && r == (rol !=|== NULL) */
                        res->cmp_lo  = l;
                        res->cmp_hi  = r;
                        res->rel_lo  = pnc_l;
-                       res->rel_hi  = pnc_r;
-                       res->tv_lo   = tv_l;
-                       res->tv_hi   = tv_r;
-               } else if (rel == ir_relation_greater) {
-                       /* c_l > c_r */
-                       res->cmp_lo  = r;
-                       res->cmp_hi  = l;
-                       res->rel_lo  = pnc_r;
                        res->rel_hi  = pnc_l;
-                       res->tv_lo   = tv_r;
-                       res->tv_hi   = tv_l;
-               } else {
-                       /* The constants shall be unequal but comparable.
-                        * Local optimizations handle the equal case. */
-                       return false;
+                       res->tv_lo   = get_Const_tarval(lor);
+                       res->tv_hi   = get_Const_tarval(ror);
+                       res->lo_mode = get_irn_mode(lor);
+
+                       return true;
+               }
+
+               if (lol == rol && lor != ror && is_Const(lor) && is_Const(ror)) {
+                       /* l == (x CMP c_l), r == (x cmp c_r) */
+                       ir_tarval  *const tv_l  = get_Const_tarval(lor);
+                       ir_tarval  *const tv_r  = get_Const_tarval(ror);
+                       ir_relation const rel   = tarval_cmp(tv_l, tv_r);
+
+                       res->lo_mode = get_irn_mode(lol);
+
+                       if (rel == ir_relation_less) {
+                               /* c_l < c_r */
+                               res->cmp_lo  = l;
+                               res->cmp_hi  = r;
+                               res->rel_lo  = pnc_l;
+                               res->rel_hi  = pnc_r;
+                               res->tv_lo   = tv_l;
+                               res->tv_hi   = tv_r;
+                       } else if (rel == ir_relation_greater) {
+                               /* c_l > c_r */
+                               res->cmp_lo  = r;
+                               res->cmp_hi  = l;
+                               res->rel_lo  = pnc_r;
+                               res->rel_hi  = pnc_l;
+                               res->tv_lo   = tv_r;
+                               res->tv_hi   = tv_l;
+                       } else {
+                               /* The constants shall be unequal but comparable.
+                                * Local optimizations handle the equal case. */
+                               return false;
+                       }
+                       return true;
                }
-               return true;
        }
        return false;
 }
@@ -717,16 +716,14 @@ restart:
        }
 }
 
-void opt_bool(ir_graph *const irg)
+static ir_graph_state_t do_simplify_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");
 
-       /* works better with one return block only */
-       normalize_one_return(irg);
-
        env.changed = 0;
 
        /* optimize simple Andb and Orb cases */
@@ -738,14 +735,24 @@ void opt_bool(ir_graph *const irg)
        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) {
-               set_irg_outs_inconsistent(irg);
-               set_irg_doms_inconsistent(irg);
-               set_irg_extblk_inconsistent(irg);
-               set_irg_loopinfo_inconsistent(irg);
+       if (! env.changed) {
+               res |= IR_GRAPH_STATE_CONSISTENT_DOMINANCE;
        }
 
        ir_free_resources(irg, IR_RESOURCE_BLOCK_MARK | IR_RESOURCE_PHI_LIST);
+
+       return res;
+}
+
+static 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);
 }
 
 /* Creates an ir_graph pass for opt_bool. */