- Changed keep logic: all nodes can be keeped yet, thi is necessary to fix fehler152
[libfirm] / ir / ir / irnode.c
index d6b9289..b0d062f 100644 (file)
@@ -138,7 +138,9 @@ new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mod
        char *p;
        int i;
 
-       assert(irg && op && mode);
+       assert(irg);
+       assert(op);
+       assert(mode);
        p = obstack_alloc(irg->obst, node_size);
        memset(p, 0, node_size);
        res = (ir_node *)(p + firm_add_node_size);
@@ -900,8 +902,12 @@ ir_node *get_End_keepalive(const ir_node *end, int pos) {
 }
 
 void add_End_keepalive(ir_node *end, ir_node *ka) {
+       ir_graph *irg = get_irn_irg(end);
        assert(is_End(end));
-       assert((is_Phi(ka) || is_Proj(ka) || is_Block(ka) || is_irn_keep(ka)) && "Only Phi, Block or Keep nodes can be kept alive!");
+
+       if (get_irg_phase_state(irg) == phase_building) {
+               assert((is_Phi(ka) || is_Block(ka) || is_irn_keep(ka)) && "Only Phi, Block or Keep nodes can be kept alive!");
+       }
        add_irn_n(end, ka);
 }
 
@@ -1146,10 +1152,13 @@ set_SymConst_kind(ir_node *node, symconst_kind kind) {
 }
 
 ir_type *
-get_SymConst_type(ir_node *node) {
+get_SymConst_type(const ir_node *node) {
+       /* the cast here is annoying, but we have to compensate for
+          the skip_tip() */
+       ir_node *irn = (ir_node *)node;
        assert(is_SymConst(node) &&
               (SYMCONST_HAS_TYPE(get_SymConst_kind(node))));
-       return node->attr.symc.sym.type_p = skip_tid(node->attr.symc.sym.type_p);
+       return irn->attr.symc.sym.type_p = skip_tid(irn->attr.symc.sym.type_p);
 }
 
 void
@@ -1332,7 +1341,7 @@ set_Call_ptr(ir_node *node, ir_node *ptr) {
 ir_node **
 get_Call_param_arr(ir_node *node) {
        assert(is_Call(node));
-       return (ir_node **)&get_irn_in(node)[CALL_PARAM_OFFSET + 1];
+       return &get_irn_in(node)[CALL_PARAM_OFFSET + 1];
 }
 
 int
@@ -1501,6 +1510,7 @@ void set_##OP##_resmode(ir_node *node, ir_mode *mode) { \
 
 
 BINOP(Add)
+BINOP(Carry)
 BINOP(Sub)
 UNOP(Minus)
 BINOP(Mul)
@@ -2203,101 +2213,33 @@ ir_node *get_Filter_cg_pred(ir_node *node, int pos) {
 
 /* Mux support */
 ir_node *get_Mux_sel(const ir_node *node) {
-       if (is_Psi(node)) {
-               assert(get_irn_arity(node) == 3);
-               return get_Psi_cond(node, 0);
-       }
        assert(is_Mux(node));
        return node->in[1];
 }
 
 void set_Mux_sel(ir_node *node, ir_node *sel) {
-       if (is_Psi(node)) {
-               assert(get_irn_arity(node) == 3);
-               set_Psi_cond(node, 0, sel);
-       } else {
-               assert(is_Mux(node));
-               node->in[1] = sel;
-       }
+       assert(is_Mux(node));
+       node->in[1] = sel;
 }
 
 ir_node *get_Mux_false(const ir_node *node) {
-       if (is_Psi(node)) {
-               assert(get_irn_arity(node) == 3);
-               return get_Psi_default(node);
-       }
        assert(is_Mux(node));
        return node->in[2];
 }
 
 void set_Mux_false(ir_node *node, ir_node *ir_false) {
-       if (is_Psi(node)) {
-               assert(get_irn_arity(node) == 3);
-               set_Psi_default(node, ir_false);
-       } else {
-               assert(is_Mux(node));
-               node->in[2] = ir_false;
-       }
+       assert(is_Mux(node));
+       node->in[2] = ir_false;
 }
 
 ir_node *get_Mux_true(const ir_node *node) {
-       if (is_Psi(node)) {
-               assert(get_irn_arity(node) == 3);
-               return get_Psi_val(node, 0);
-       }
        assert(is_Mux(node));
        return node->in[3];
 }
 
 void set_Mux_true(ir_node *node, ir_node *ir_true) {
-       if (is_Psi(node)) {
-               assert(get_irn_arity(node) == 3);
-               set_Psi_val(node, 0, ir_true);
-       } else {
-               assert(is_Mux(node));
-               node->in[3] = ir_true;
-       }
-}
-
-/* Psi support */
-ir_node *get_Psi_cond(const ir_node *node, int pos) {
-       assert(is_Psi(node));
-       assert(pos < get_Psi_n_conds(node));
-       return get_irn_n(node, 2 * pos);
-}
-
-void set_Psi_cond(ir_node *node, int pos, ir_node *cond) {
-       assert(is_Psi(node));
-       assert(pos < get_Psi_n_conds(node));
-       set_irn_n(node, 2 * pos, cond);
-}
-
-ir_node *get_Psi_val(const ir_node *node, int pos) {
-       assert(is_Psi(node));
-       assert(pos < get_Psi_n_conds(node));
-       return get_irn_n(node, 2 * pos + 1);
-}
-
-void set_Psi_val(ir_node *node, int pos, ir_node *val) {
-       assert(is_Psi(node));
-       assert(pos < get_Psi_n_conds(node));
-       set_irn_n(node, 2 * pos + 1, val);
-}
-
-ir_node *get_Psi_default(const ir_node *node) {
-       int def_pos = get_irn_arity(node) - 1;
-       assert(is_Psi(node));
-       return get_irn_n(node, def_pos);
-}
-
-void set_Psi_default(ir_node *node, ir_node *val) {
-       int def_pos = get_irn_arity(node);
-       assert(is_Psi(node));
-       set_irn_n(node, def_pos, val);
-}
-
-int (get_Psi_n_conds)(const ir_node *node) {
-       return _get_Psi_n_conds(node);
+       assert(is_Mux(node));
+       node->in[3] = ir_true;
 }
 
 /* CopyB support */
@@ -2582,11 +2524,25 @@ restart:
 
 /* returns operand of node if node is a Cast */
 ir_node *skip_Cast(ir_node *node) {
-       if (get_irn_op(node) == op_Cast)
+       if (is_Cast(node))
                return get_Cast_op(node);
        return node;
 }
 
+/* returns operand of node if node is a Cast */
+const ir_node *skip_Cast_const(const ir_node *node) {
+       if (is_Cast(node))
+               return get_Cast_op(node);
+       return node;
+}
+
+/* returns operand of node if node is a Pin */
+ir_node *skip_Pin(ir_node *node) {
+       if (is_Pin(node))
+               return get_Pin_op(node);
+       return node;
+}
+
 /* returns operand of node if node is a Confirm */
 ir_node *skip_Confirm(ir_node *node) {
        if (get_irn_op(node) == op_Confirm)
@@ -2699,6 +2655,11 @@ int
        return _is_Add(node);
 }
 
+int
+(is_Carry)(const ir_node *node) {
+       return _is_Carry(node);
+}
+
 int
 (is_And)(const ir_node *node) {
        return _is_And(node);
@@ -2744,11 +2705,6 @@ int
        return _is_Not(node);
 }
 
-int
-(is_Psi)(const ir_node *node) {
-       return _is_Psi(node);
-}
-
 int
 (is_Id)(const ir_node *node) {
        return _is_Id(node);
@@ -2834,7 +2790,7 @@ int
        return _is_Sel(node);
 }
 
-/* returns true if node is a Mux node or a Psi with only one condition. */
+/* returns true if node is a Mux node. */
 int
 (is_Mux)(const ir_node *node) {
        return _is_Mux(node);