ia32: cleanup handling of 8/16bit operations
[libfirm] / ir / ana / irconsconfirm.c
index 5d9daa7..9c10ca3 100644 (file)
@@ -42,7 +42,6 @@
 #include "debug.h"
 #include "error.h"
 #include "irflag.h"
-#include "opt_manage.h"
 
 /**
  * Walker environment.
@@ -109,16 +108,14 @@ static ir_node *get_case_value(ir_node *switchn, long pn)
  */
 static void handle_case(ir_node *block, ir_node *switchn, long pn, env_t *env)
 {
-       ir_node         *c = NULL;
-       ir_node         *selector = get_Switch_selector(switchn);
-       const ir_edge_t *edge;
-       const ir_edge_t *next;
+       ir_node *c = NULL;
+       ir_node *selector = get_Switch_selector(switchn);
 
        /* we can't do usefull things with the default label */
        if (pn == pn_Switch_default)
                return;
 
-       foreach_out_edge_safe(selector, edge, next) {
+       foreach_out_edge_safe(selector, edge) {
                ir_node *succ = get_edge_src_irn(edge);
                int     pos   = get_edge_src_pos(edge);
                ir_node *blk  = get_effective_use_block(succ, pos);
@@ -154,14 +151,12 @@ static void handle_modeb(ir_node *block, ir_node *selector, pn_Cond pnc, env_t *
 {
        ir_node *cond, *old, *other_blk = NULL, *con = NULL;
        ir_node *c_b = NULL, *c_o = NULL;
-       const ir_edge_t *edge, *next;
 
-       for (edge = get_irn_out_edge_first(selector); edge; edge = next) {
+       foreach_out_edge_safe(selector, edge) {
                ir_node *user     = get_edge_src_irn(edge);
                int     pos       = get_edge_src_pos(edge);
                ir_node *user_blk = get_effective_use_block(user, pos);
 
-               next = get_irn_out_edge_next(selector, edge);
                if (block_dominates(block, user_blk)) {
                        /*
                         * Ok, we found a usage of selector in a block
@@ -271,22 +266,18 @@ static void handle_if(ir_node *block, ir_node *cmp, ir_relation rel, env_t *env)
        ir_node *left  = get_Cmp_left(cmp);
        ir_node *right = get_Cmp_right(cmp);
        ir_node *cond_block;
-       ir_op *op;
-       const ir_edge_t *edge, *next;
 
        /* Beware of Bads */
        if (is_Bad(left) || is_Bad(right))
                return;
 
-       op = get_irn_op(left);
-
        /* Do not create Confirm nodes for Cmp(Const, Const) constructs.
           These are removed anyway */
-       if (op == op_Const && is_Const(right))
+       if (is_Const(left) && is_Const(right))
                return;
 
        /* try to place the constant on the right side for a Confirm */
-       if (op == op_Const || op == op_SymConst) {
+       if (is_Const(left) || is_SymConst(left)) {
                ir_node *t = left;
 
                left  = right;
@@ -301,12 +292,11 @@ static void handle_if(ir_node *block, ir_node *cmp, ir_relation rel, env_t *env)
         */
        if (rel == ir_relation_equal) {
                cond_block = get_Block_cfgpred_block(block, 0);
-               for (edge = get_irn_out_edge_first(left); edge; edge = next) {
+               foreach_out_edge_safe(left, edge) {
                        ir_node *user = get_edge_src_irn(edge);
                        int     pos   = get_edge_src_pos(edge);
                        ir_node *blk  = get_effective_use_block(user, pos);
 
-                       next = get_irn_out_edge_next(left, edge);
                        if (block_dominates(block, blk)) {
                                /*
                                 * Ok, we found a usage of left in a block
@@ -326,9 +316,7 @@ static void handle_if(ir_node *block, ir_node *cmp, ir_relation rel, env_t *env)
                                 * left == Const and we found a movable user of left in a
                                 * dominator of the Cond block
                                 */
-                               const ir_edge_t *user_edge;
-                               const ir_edge_t *user_next;
-                               foreach_out_edge_safe(user, user_edge, user_next) {
+                               foreach_out_edge_safe(user, user_edge) {
                                        ir_node *usr_of_usr = get_edge_src_irn(user_edge);
                                        int      npos       = get_edge_src_pos(user_edge);
                                        ir_node *user_blk   = get_effective_use_block(usr_of_usr, npos);
@@ -360,7 +348,7 @@ static void handle_if(ir_node *block, ir_node *cmp, ir_relation rel, env_t *env)
        } else { /* not ir_relation_equal cases */
                ir_node *c = NULL;
 
-               foreach_out_edge_safe(left, edge, next) {
+               foreach_out_edge_safe(left, edge) {
                        ir_node *succ = get_edge_src_irn(edge);
                        int     pos   = get_edge_src_pos(edge);
                        ir_node *blk  = get_effective_use_block(succ, pos);
@@ -387,7 +375,7 @@ static void handle_if(ir_node *block, ir_node *cmp, ir_relation rel, env_t *env)
                        ir_node *rc = NULL;
 
                        rel = get_inversed_relation(rel);
-                       foreach_out_edge_safe(right, edge, next) {
+                       foreach_out_edge_safe(right, edge) {
                                ir_node *succ = get_edge_src_irn(edge);
                                int     pos;
                                ir_node *blk;
@@ -498,10 +486,9 @@ static int is_non_null_Confirm(const ir_node *ptr)
  */
 static void insert_non_null(ir_node *ptr, ir_node *block, env_t *env)
 {
-       const ir_edge_t *edge, *next;
-       ir_node         *c = NULL;
+       ir_node *c = NULL;
 
-       foreach_out_edge_safe(ptr, edge, next) {
+       foreach_out_edge_safe(ptr, edge) {
                ir_node *succ = get_edge_src_irn(edge);
                int     pos;
                ir_node *blk;
@@ -563,14 +550,16 @@ static void insert_Confirm(ir_node *node, void *data)
        }
 }
 
-/*
- * Construct Confirm nodes
- */
-static ir_graph_properties_t do_construct_confirms(ir_graph *irg)
+void construct_confirms(ir_graph *irg)
 {
        env_t env;
        FIRM_DBG_REGISTER(dbg, "firm.ana.confirm");
 
+       assure_irg_properties(irg,
+             IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES
+               | IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE
+               | IR_GRAPH_PROPERTY_NO_CRITICAL_EDGES);
+
        assert(get_irg_pinned(irg) == op_pin_state_pinned &&
               "Nodes must be placed to insert Confirms");
 
@@ -591,20 +580,8 @@ static ir_graph_properties_t do_construct_confirms(ir_graph *irg)
        DB((dbg, LEVEL_1, "# Const replacements: %u\n", env.num_consts));
        DB((dbg, LEVEL_1, "# node equalities   : %u\n", env.num_eq));
        DB((dbg, LEVEL_1, "# non-null Confirms : %u\n", env.num_non_null));
-       return 0;
-}
-
-static optdesc_t opt_confirms = {
-       "confirms",
-       IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES
-       | IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE
-       | IR_GRAPH_PROPERTY_NO_CRITICAL_EDGES,
-       do_construct_confirms
-};
 
-void construct_confirms(ir_graph *irg)
-{
-       perform_irg_optimization(irg, &opt_confirms);
+       confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_CONTROL_FLOW);
 }
 
 ir_graph_pass_t *construct_confirms_pass(const char *name)
@@ -627,6 +604,7 @@ static void remove_confirm(ir_node *n, void *env)
 void remove_confirms(ir_graph *irg)
 {
        irg_walk_graph(irg, NULL, remove_confirm, NULL);
+       confirm_irg_properties(irg, IR_GRAPH_PROPERTIES_CONTROL_FLOW);
 }
 
 ir_graph_pass_t *remove_confirms_pass(const char *name)