automatically generated pn_ numbers from the spec file
[libfirm] / ir / ir / iropt.c
index 6d95904..2ca7947 100644 (file)
@@ -697,8 +697,7 @@ static tarval *computed_value_Proj(const ir_node *proj)
 tarval *computed_value(const ir_node *n)
 {
        vrp_attr *vrp = vrp_get_info(n);
-       if (vrp && tarval_is_all_one(
-                               tarval_or(vrp->bits_set, vrp->bits_not_set))) {
+       if (vrp && vrp->valid && tarval_cmp(vrp->bits_set, vrp->bits_not_set) == pn_Cmp_Eq) {
                return vrp->bits_set;
        }
        if (n->op->ops.computed_value)
@@ -754,7 +753,8 @@ static ir_op_ops *firm_set_default_computed_value(ir_opcode code, ir_op_ops *ops
        CASE_PROJ(Quot);
        CASE(Proj);
        default:
-               /* leave NULL */;
+               /* leave NULL */
+               break;
        }
 
        return ops;
@@ -1636,7 +1636,7 @@ static ir_node *equivalent_node_Proj_CopyB(ir_node *proj)
        if (a == b) {
                /* Turn CopyB into a tuple (mem, jmp, bad, bad) */
                switch (get_Proj_proj(proj)) {
-               case pn_CopyB_M_regular:
+               case pn_CopyB_M:
                        proj = get_CopyB_mem(copyb);
                        DBG_OPT_ALGSIM0(oldn, proj, FS_OPT_NOP);
                        break;
@@ -1699,7 +1699,7 @@ static ir_node *equivalent_node_Proj_Bound(ir_node *proj)
                        break;
                default:
                        /* cannot optimize pn_Bound_X_regular, handled in transform ... */
-                       ;
+                       break;
                }
        }
        return proj;
@@ -1980,7 +1980,8 @@ static ir_op_ops *firm_set_default_equivalent_node(ir_opcode code, ir_op_ops *op
        CASE(Mux);
        CASE(Confirm);
        default:
-               /* leave NULL */;
+               /* leave NULL */
+               break;
        }
 
        return ops;
@@ -2279,6 +2280,7 @@ static ir_node *transform_node_AddSub(ir_node *n)
 }  /* transform_node_AddSub */
 
 #define HANDLE_BINOP_PHI(eval, a, b, c, mode)                     \
+  do {                                                            \
   c = NULL;                                                       \
   if (is_Const(b) && is_const_Phi(a)) {                           \
     /* check for Op(Phi, Const) */                                \
@@ -2295,9 +2297,11 @@ static ir_node *transform_node_AddSub(ir_node *n)
   if (c) {                                                        \
     DBG_OPT_ALGSIM0(oldn, c, FS_OPT_CONST_PHI);                   \
     return c;                                                     \
-  }
+  }                                                               \
+  } while(0)
 
 #define HANDLE_UNOP_PHI(eval, a, c)               \
+  do {                                            \
   c = NULL;                                       \
   if (is_const_Phi(a)) {                          \
     /* check for Op(Phi) */                       \
@@ -2306,7 +2310,8 @@ static ir_node *transform_node_AddSub(ir_node *n)
       DBG_OPT_ALGSIM0(oldn, c, FS_OPT_CONST_PHI); \
       return c;                                   \
     }                                             \
-  }
+  }                                               \
+  } while(0)
 
 /**
  * Do the AddSub optimization, then Transform
@@ -2321,6 +2326,7 @@ static ir_node *transform_node_Add(ir_node *n)
 {
        ir_mode *mode;
        ir_node *a, *b, *c, *oldn = n;
+       vrp_attr *a_vrp, *b_vrp;
 
        n = transform_node_AddSub(n);
 
@@ -2332,7 +2338,7 @@ static ir_node *transform_node_Add(ir_node *n)
        if (mode_is_reference(mode)) {
                ir_mode *lmode = get_irn_mode(a);
 
-               if (is_Const(b) && is_Const_null(b) && mode_is_int(lmode)) {
+               if (is_Const(b) && is_Const_null(b) && mode_is_int(lmode)) {
                        /* an Add(a, NULL) is a hidden Conv */
                        dbg_info *dbg = get_irn_dbg_info(n);
                        return new_rd_Conv(dbg, get_nodes_block(n), a, mode);
@@ -2412,15 +2418,13 @@ static ir_node *transform_node_Add(ir_node *n)
                }
        }
 
-       vrp_attr *a_vrp, *b_vrp;
        a_vrp = vrp_get_info(a);
        b_vrp = vrp_get_info(b);
 
-
        if (a_vrp && b_vrp) {
                tarval *c = tarval_and(
-                                       tarval_not(a_vrp->bits_not_set),
-                                       tarval_not(b_vrp->bits_not_set)
+                                       a_vrp->bits_not_set,
+                                       b_vrp->bits_not_set
                                        );
 
                if (tarval_is_null(c)) {
@@ -3470,6 +3474,7 @@ static ir_node *transform_node_And(ir_node *n)
        ir_node *a = get_And_left(n);
        ir_node *b = get_And_right(n);
        ir_mode *mode;
+       vrp_attr *a_vrp, *b_vrp;
 
        mode = get_irn_mode(n);
        HANDLE_BINOP_PHI((eval_func) tarval_and, a, b, c, mode);
@@ -3480,13 +3485,12 @@ static ir_node *transform_node_And(ir_node *n)
                ir_node *pred_b = get_Proj_pred(b);
                if (pred_a == pred_b) {
                        dbg_info *dbgi  = get_irn_dbg_info(n);
-                       ir_node  *block = get_nodes_block(pred_a);
                        pn_Cmp pn_a     = get_Proj_proj(a);
                        pn_Cmp pn_b     = get_Proj_proj(b);
                        /* yes, we can simply calculate with pncs */
                        pn_Cmp new_pnc  = pn_a & pn_b;
 
-                       return new_rd_Proj(dbgi, block, pred_a, mode_b, new_pnc);
+                       return new_rd_Proj(dbgi, pred_a, mode_b, new_pnc);
                }
        }
        if (is_Or(a)) {
@@ -3590,22 +3594,18 @@ static ir_node *transform_node_And(ir_node *n)
                return n;
        }
 
-       vrp_attr *a_vrp, *b_vrp;
-       a_vrp = vrp_get_info(a);
        b_vrp = vrp_get_info(b);
+       if (is_Const(a) && b_vrp && (tarval_cmp(tarval_or(get_Const_tarval(a),
+                                               b_vrp->bits_not_set), get_Const_tarval(a)) == pn_Cmp_Eq)) {
 
-       if (is_Const(a) && b_vrp && (tarval_is_all_one(tarval_or(get_Const_tarval(a),
-                                               b_vrp->bits_not_set)))) {
-               return new_rd_Id(get_irn_dbg_info(n), get_nodes_block(n),
-                                                       b, get_irn_mode(n));
+               return b;
 
        }
 
-       if (is_Const(b) && a_vrp && (tarval_is_all_one(tarval_or(get_Const_tarval(b),
-                                               a_vrp->bits_not_set)))) {
-               return new_rd_Id(get_irn_dbg_info(n), get_nodes_block(n),
-                                                       a, get_irn_mode(n));
-
+       a_vrp = vrp_get_info(a);
+       if (is_Const(b) && a_vrp && (tarval_cmp(tarval_or(get_Const_tarval(b),
+                                               a_vrp->bits_not_set), get_Const_tarval(b)) == pn_Cmp_Eq)) {
+               return a;
        }
 
        n = transform_bitwise_distributive(n, transform_node_And);
@@ -3631,13 +3631,12 @@ static ir_node *transform_node_Eor(ir_node *n)
                ir_node *pred_b = get_Proj_pred(b);
                if (pred_a == pred_b) {
                        dbg_info *dbgi  = get_irn_dbg_info(n);
-                       ir_node  *block = get_nodes_block(pred_a);
                        pn_Cmp pn_a     = get_Proj_proj(a);
                        pn_Cmp pn_b     = get_Proj_proj(b);
                        /* yes, we can simply calculate with pncs */
                        pn_Cmp new_pnc  = pn_a ^ pn_b;
 
-                       return new_rd_Proj(dbgi, block, pred_a, mode_b, new_pnc);
+                       return new_rd_Proj(dbgi, pred_a, mode_b, new_pnc);
                }
        }
 
@@ -3681,9 +3680,8 @@ static ir_node *transform_node_Not(ir_node *n)
        if (mode == mode_b && is_Proj(a)) {
                ir_node *a_pred = get_Proj_pred(a);
                if (is_Cmp(a_pred)) {
-                       ir_node *cmp_block = get_nodes_block(a_pred);
                        /* We negate a Cmp. The Cmp has the negated result anyways! */
-                       n = new_r_Proj(cmp_block, get_Proj_pred(a),
+                       n = new_r_Proj(get_Proj_pred(a),
                                       mode_b, get_negated_pnc(get_Proj_proj(a), mode_b));
                        DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_CMP);
                        return n;
@@ -4105,16 +4103,16 @@ static ir_node *transform_node_Proj_Cond(ir_node *proj)
                                                pn_Cmp cmp_result = tarval_cmp(b_vrp->range_bottom, tp);
                                                pn_Cmp cmp_result2 = tarval_cmp(b_vrp->range_top, tp);
 
-                                               if ((cmp_result & pn_Cmp_Lt) == cmp_result && (cmp_result2
-                                                                       & pn_Cmp_Gt) == cmp_result2) {
+                                               if ((cmp_result & pn_Cmp_Gt) == cmp_result && (cmp_result2
+                                                                       & pn_Cmp_Lt) == cmp_result2) {
                                                        return get_irg_bad(current_ir_graph);
                                                }
                                        } else if (b_vrp->range_type == VRP_ANTIRANGE) {
                                                pn_Cmp cmp_result = tarval_cmp(b_vrp->range_bottom, tp);
                                                pn_Cmp cmp_result2 = tarval_cmp(b_vrp->range_top, tp);
 
-                                               if ((cmp_result & pn_Cmp_Ge) == cmp_result && (cmp_result2
-                                                                       & pn_Cmp_Le) == cmp_result2) {
+                                               if ((cmp_result & pn_Cmp_Le) == cmp_result && (cmp_result2
+                                                                       & pn_Cmp_Ge) == cmp_result2) {
                                                        return get_irg_bad(current_ir_graph);
                                                }
                                        }
@@ -4130,8 +4128,8 @@ static ir_node *transform_node_Proj_Cond(ir_node *proj)
                                        if (!(tarval_cmp(
                                                                        tarval_and(
                                                                                tarval_not(tp),
-                                                                               b_vrp->bits_not_set),
-                                                                       b_vrp->bits_not_set)
+                                                                               tarval_not(b_vrp->bits_not_set)),
+                                                                       tarval_not(b_vrp->bits_not_set))
                                                                         == pn_Cmp_Eq)) {
 
                                                return get_irg_bad(current_ir_graph);
@@ -4797,7 +4795,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj)
 
                /* create a new compare */
                n = new_rd_Cmp(get_irn_dbg_info(n), block, left, right);
-               proj = new_rd_Proj(get_irn_dbg_info(proj), block, n, get_irn_mode(proj), proj_nr);
+               proj = new_rd_Proj(get_irn_dbg_info(proj), n, get_irn_mode(proj), proj_nr);
        }
 
        return proj;
@@ -5180,13 +5178,12 @@ static ir_node *transform_node_Or(ir_node *n)
                ir_node *pred_b = get_Proj_pred(b);
                if (pred_a == pred_b) {
                        dbg_info *dbgi  = get_irn_dbg_info(n);
-                       ir_node  *block = get_nodes_block(pred_a);
                        pn_Cmp pn_a     = get_Proj_proj(a);
                        pn_Cmp pn_b     = get_Proj_proj(b);
                        /* yes, we can simply calculate with pncs */
                        pn_Cmp new_pnc  = pn_a | pn_b;
 
-                       return new_rd_Proj(dbgi, block, pred_a, mode_b, new_pnc);
+                       return new_rd_Proj(dbgi, pred_a, mode_b, new_pnc);
                }
        }
 
@@ -5371,7 +5368,6 @@ static ir_node *transform_node_shl_shr(ir_node *n)
        ir_node  *left;
        ir_node  *right = get_binop_right(n);
        ir_node  *x;
-       ir_graph *irg;
        ir_node  *block;
        ir_mode  *mode;
        dbg_info *dbgi;
@@ -5436,7 +5432,6 @@ static ir_node *transform_node_shl_shr(ir_node *n)
        assert(tv_mask != tarval_bad);
        assert(get_tarval_mode(tv_mask) == mode);
 
-       irg   = get_irn_irg(n);
        block = get_nodes_block(n);
        dbgi  = get_irn_dbg_info(n);
 
@@ -5723,7 +5718,7 @@ static ir_node *transform_node_Mux(ir_node *n)
 
                                /* Mux(x, 0, y) => Mux(x, y, 0) */
                                pn_Cmp pnc = get_Proj_proj(sel);
-                               sel = new_r_Proj(get_nodes_block(cmp), cmp, mode_b,
+                               sel = new_r_Proj(cmp, mode_b,
                                        get_negated_pnc(pnc, get_irn_mode(get_Cmp_left(cmp))));
                                n        = new_rd_Mux(get_irn_dbg_info(n), get_nodes_block(n), sel, t, f, mode);
                                tmp = t;
@@ -6147,36 +6142,30 @@ static int node_cmp_attr_Const(ir_node *a, ir_node *b)
 /** Compares the attributes of two Proj nodes. */
 static int node_cmp_attr_Proj(ir_node *a, ir_node *b)
 {
-       return get_irn_proj_attr(a) != get_irn_proj_attr(b);
+       return a->attr.proj != b->attr.proj;
 }  /* node_cmp_attr_Proj */
 
-/** Compares the attributes of two Filter nodes. */
-static int node_cmp_attr_Filter(ir_node *a, ir_node *b)
-{
-       return get_Filter_proj(a) != get_Filter_proj(b);
-}  /* node_cmp_attr_Filter */
-
 /** Compares the attributes of two Alloc nodes. */
 static int node_cmp_attr_Alloc(ir_node *a, ir_node *b)
 {
-       const alloc_attr *pa = get_irn_alloc_attr(a);
-       const alloc_attr *pb = get_irn_alloc_attr(b);
+       const alloc_attr *pa = &a->attr.alloc;
+       const alloc_attr *pb = &b->attr.alloc;
        return (pa->where != pb->where) || (pa->type != pb->type);
 }  /* node_cmp_attr_Alloc */
 
 /** Compares the attributes of two Free nodes. */
 static int node_cmp_attr_Free(ir_node *a, ir_node *b)
 {
-       const free_attr *pa = get_irn_free_attr(a);
-       const free_attr *pb = get_irn_free_attr(b);
+       const free_attr *pa = &a->attr.free;
+       const free_attr *pb = &b->attr.free;
        return (pa->where != pb->where) || (pa->type != pb->type);
 }  /* node_cmp_attr_Free */
 
 /** Compares the attributes of two SymConst nodes. */
 static int node_cmp_attr_SymConst(ir_node *a, ir_node *b)
 {
-       const symconst_attr *pa = get_irn_symconst_attr(a);
-       const symconst_attr *pb = get_irn_symconst_attr(b);
+       const symconst_attr *pa = &a->attr.symc;
+       const symconst_attr *pb = &b->attr.symc;
        return (pa->kind       != pb->kind)
            || (pa->sym.type_p != pb->sym.type_p)
            || (pa->tp         != pb->tp);
@@ -6185,8 +6174,8 @@ static int node_cmp_attr_SymConst(ir_node *a, ir_node *b)
 /** Compares the attributes of two Call nodes. */
 static int node_cmp_attr_Call(ir_node *a, ir_node *b)
 {
-       const call_attr *pa = get_irn_call_attr(a);
-       const call_attr *pb = get_irn_call_attr(b);
+       const call_attr *pa = &a->attr.call;
+       const call_attr *pb = &b->attr.call;
        return (pa->type != pb->type)
                || (pa->tail_call != pb->tail_call);
 }  /* node_cmp_attr_Call */
@@ -6196,16 +6185,6 @@ static int node_cmp_attr_Sel(ir_node *a, ir_node *b)
 {
        const ir_entity *a_ent = get_Sel_entity(a);
        const ir_entity *b_ent = get_Sel_entity(b);
-#if 0
-       return
-               (a_ent->kind    != b_ent->kind)    ||
-               (a_ent->name    != b_ent->name)    ||
-               (a_ent->owner   != b_ent->owner)   ||
-               (a_ent->ld_name != b_ent->ld_name) ||
-               (a_ent->type    != b_ent->type);
-#endif
-       /* Matze: inlining of functions can produce 2 entities with same type,
-        * name, etc. */
        return a_ent != b_ent;
 }  /* node_cmp_attr_Sel */
 
@@ -6216,7 +6195,7 @@ static int node_cmp_attr_Phi(ir_node *a, ir_node *b)
           hence it is enough to check if one of them is a Phi0 */
        if (is_Phi0(a)) {
                /* check the Phi0 pos attribute */
-               return get_irn_phi_attr(a)->u.pos != get_irn_phi_attr(b)->u.pos;
+               return a->attr.phi.u.pos != b->attr.phi.u.pos;
        }
        return 0;
 }  /* node_cmp_attr_Phi */
@@ -6262,8 +6241,8 @@ static int node_cmp_attr_Store(ir_node *a, ir_node *b)
 /** Compares two exception attributes */
 static int node_cmp_exception(ir_node *a, ir_node *b)
 {
-       const except_attr *ea = get_irn_except_attr(a);
-       const except_attr *eb = get_irn_except_attr(b);
+       const except_attr *ea = &a->attr.except;
+       const except_attr *eb = &b->attr.except;
 
        return ea->pin_state != eb->pin_state;
 }
@@ -6273,8 +6252,8 @@ static int node_cmp_exception(ir_node *a, ir_node *b)
 /** Compares the attributes of two Div nodes. */
 static int node_cmp_attr_Div(ir_node *a, ir_node *b)
 {
-       const divmod_attr *ma = get_irn_divmod_attr(a);
-       const divmod_attr *mb = get_irn_divmod_attr(b);
+       const divmod_attr *ma = &a->attr.divmod;
+       const divmod_attr *mb = &b->attr.divmod;
        return ma->exc.pin_state != mb->exc.pin_state ||
                   ma->resmode       != mb->resmode ||
                   ma->no_remainder  != mb->no_remainder;
@@ -6283,8 +6262,8 @@ static int node_cmp_attr_Div(ir_node *a, ir_node *b)
 /** Compares the attributes of two DivMod nodes. */
 static int node_cmp_attr_DivMod(ir_node *a, ir_node *b)
 {
-       const divmod_attr *ma = get_irn_divmod_attr(a);
-       const divmod_attr *mb = get_irn_divmod_attr(b);
+       const divmod_attr *ma = &a->attr.divmod;
+       const divmod_attr *mb = &b->attr.divmod;
        return ma->exc.pin_state != mb->exc.pin_state ||
                   ma->resmode       != mb->resmode;
 }  /* node_cmp_attr_DivMod */
@@ -6292,19 +6271,13 @@ static int node_cmp_attr_DivMod(ir_node *a, ir_node *b)
 /** Compares the attributes of two Mod nodes. */
 static int node_cmp_attr_Mod(ir_node *a, ir_node *b)
 {
-       const divmod_attr *ma = get_irn_divmod_attr(a);
-       const divmod_attr *mb = get_irn_divmod_attr(b);
-       return ma->exc.pin_state != mb->exc.pin_state ||
-                  ma->resmode       != mb->resmode;
+       return node_cmp_attr_DivMod(a, b);
 }  /* node_cmp_attr_Mod */
 
 /** Compares the attributes of two Quot nodes. */
 static int node_cmp_attr_Quot(ir_node *a, ir_node *b)
 {
-       const divmod_attr *ma = get_irn_divmod_attr(a);
-       const divmod_attr *mb = get_irn_divmod_attr(b);
-       return ma->exc.pin_state != mb->exc.pin_state ||
-                  ma->resmode       != mb->resmode;
+       return node_cmp_attr_DivMod(a, b);
 }  /* node_cmp_attr_Quot */
 
 /** Compares the attributes of two Confirm nodes. */
@@ -6317,11 +6290,8 @@ static int node_cmp_attr_Confirm(ir_node *a, ir_node *b)
 /** Compares the attributes of two Builtin nodes. */
 static int node_cmp_attr_Builtin(ir_node *a, ir_node *b)
 {
-       const builtin_attr *ma = get_irn_builtin_attr(a);
-       const builtin_attr *mb = get_irn_builtin_attr(b);
-
        /* no need to compare the type, equal kind means equal type */
-       return ma->kind != mb->kind;
+       return get_Builtin_kind(a) != get_Builtin_kind(b);
 }  /* node_cmp_attr_Builtin */
 
 /** Compares the attributes of two ASM nodes. */
@@ -6398,7 +6368,6 @@ static ir_op_ops *firm_set_default_node_cmp_attr(ir_opcode code, ir_op_ops *ops)
        switch (code) {
        CASE(Const);
        CASE(Proj);
-       CASE(Filter);
        CASE(Alloc);
        CASE(Free);
        CASE(SymConst);
@@ -6420,7 +6389,8 @@ static ir_op_ops *firm_set_default_node_cmp_attr(ir_opcode code, ir_op_ops *ops)
        CASE(Dummy);
        /* FIXME CopyB */
        default:
-         /* leave NULL */;
+               /* leave NULL */
+               break;
        }
 
        return ops;
@@ -6443,13 +6413,13 @@ int identities_cmp(const void *elt, const void *key)
            (get_irn_mode(a) != get_irn_mode(b))) return 1;
 
        /* compare if a's in and b's in are of equal length */
-       irn_arity_a = get_irn_intra_arity(a);
-       if (irn_arity_a != get_irn_intra_arity(b))
+       irn_arity_a = get_irn_arity(a);
+       if (irn_arity_a != get_irn_arity(b))
                return 1;
 
        if (get_irn_pinned(a) == op_pin_state_pinned) {
                /* for pinned nodes, the block inputs must be equal */
-               if (get_irn_intra_n(a, -1) != get_irn_intra_n(b, -1))
+               if (get_irn_n(a, -1) != get_irn_n(b, -1))
                        return 1;
        } else if (! get_opt_global_cse()) {
                /* for block-local CSE both nodes must be in the same MacroBlock */
@@ -6459,8 +6429,8 @@ int identities_cmp(const void *elt, const void *key)
 
        /* compare a->in[0..ins] with b->in[0..ins] */
        for (i = 0; i < irn_arity_a; ++i) {
-               ir_node *pred_a = get_irn_intra_n(a, i);
-               ir_node *pred_b = get_irn_intra_n(b, i);
+               ir_node *pred_a = get_irn_n(a, i);
+               ir_node *pred_b = get_irn_n(b, i);
                if (pred_a != pred_b) {
                        /* if both predecessors are CSE neutral they might be different */
                        if (!is_irn_cse_neutral(pred_a) || !is_irn_cse_neutral(pred_b))
@@ -6970,7 +6940,7 @@ static unsigned hash_Const(const ir_node *node)
        unsigned h;
 
        /* special value for const, as they only differ in their tarval. */
-       h = HASH_PTR(node->attr.con.tv);
+       h = HASH_PTR(node->attr.con.tarval);
 
        return h;
 }  /* hash_Const */