made some function parameters const
[libfirm] / ir / ir / irnode.c
index 104c8d5..ddd76ec 100644 (file)
@@ -72,26 +72,25 @@ const char *get_pnc_string(int pnc) {
 /*
  * Calculates the negated (Complement(R)) pnc condition.
  */
-int get_negated_pnc(int pnc, ir_mode *mode) {
+pn_Cmp get_negated_pnc(long pnc, ir_mode *mode) {
        pnc ^= pn_Cmp_True;
 
        /* do NOT add the Uo bit for non-floating point values */
        if (! mode_is_float(mode))
                pnc &= ~pn_Cmp_Uo;
 
-       return pnc;
+       return (pn_Cmp) pnc;
 }
 
 /* Calculates the inversed (R^-1) pnc condition, i.e., "<" --> ">" */
-int
-get_inversed_pnc(int pnc) {
-       int code    = pnc & ~(pn_Cmp_Lt|pn_Cmp_Gt);
-       int lesser  = pnc & pn_Cmp_Lt;
-       int greater = pnc & pn_Cmp_Gt;
+pn_Cmp get_inversed_pnc(long pnc) {
+       long code    = pnc & ~(pn_Cmp_Lt|pn_Cmp_Gt);
+       long lesser  = pnc & pn_Cmp_Lt;
+       long greater = pnc & pn_Cmp_Gt;
 
        code |= (lesser ? pn_Cmp_Gt : 0) | (greater ? pn_Cmp_Lt : 0);
 
-       return code;
+       return (pn_Cmp) code;
 }
 
 /**
@@ -664,6 +663,13 @@ set_nodes_block(ir_node *node, ir_node *block) {
        set_irn_n(node, -1, block);
 }
 
+/* this works for all except Block */
+ir_node *
+get_nodes_MacroBlock(const ir_node *node) {
+       assert(node->op != op_Block);
+       return get_Block_MacroBlock(get_irn_n(node, -1));
+}
+
 /* Test whether arbitrary node is frame pointer, i.e. Proj(pn_Start_P_frame_base)
  * from Start.  If so returns frame type, else Null. */
 ir_type *is_frame_pointer(ir_node *n) {
@@ -726,7 +732,7 @@ int
 }
 
 ir_node *
-(get_Block_cfgpred)(ir_node *node, int pos) {
+(get_Block_cfgpred)(const ir_node *node, int pos) {
        return _get_Block_cfgpred(node, pos);
 }
 
@@ -737,12 +743,12 @@ set_Block_cfgpred(ir_node *node, int pos, ir_node *pred) {
 }
 
 ir_node  *
-(get_Block_cfgpred_block)(ir_node *node, int pos) {
+(get_Block_cfgpred_block)(const ir_node *node, int pos) {
        return _get_Block_cfgpred_block(node, pos);
 }
 
 int
-get_Block_matured(ir_node *node) {
+get_Block_matured(const ir_node *node) {
        assert(node->op == op_Block);
        return (int)node->attr.block.is_matured;
 }
@@ -791,6 +797,7 @@ set_Block_graph_arr (ir_node *node, int pos, ir_node *value) {
        node->attr.block.graph_arr[pos+1] = value;
 }
 
+#ifdef INTERPROCEDURAL_VIEW
 void set_Block_cg_cfgpred_arr(ir_node *node, int arity, ir_node *in[]) {
        assert(node->op == op_Block);
        if (node->attr.block.in_cg == NULL || arity != ARR_LEN(node->attr.block.in_cg) - 1) {
@@ -835,6 +842,7 @@ void remove_Block_cg_cfgpred_arr(ir_node *node) {
        assert(node->op == op_Block);
        node->attr.block.in_cg = NULL;
 }
+#endif
 
 ir_node *(set_Block_dead)(ir_node *block) {
        return _set_Block_dead(block);
@@ -1111,6 +1119,7 @@ int (is_Const_all_one)(const ir_node *node) {
 ir_type *
 get_Const_type(ir_node *node) {
        assert(node->op == op_Const);
+       node->attr.con.tp = skip_tid(node->attr.con.tp);
        return node->attr.con.tp;
 }
 
@@ -1293,7 +1302,7 @@ set_Sel_entity(ir_node *node, ir_entity *ent) {
 
 
 ir_node *
-get_Call_mem(ir_node *node) {
+get_Call_mem(const ir_node *node) {
        assert(node->op == op_Call);
        return get_irn_n(node, 0);
 }
@@ -1305,7 +1314,7 @@ set_Call_mem(ir_node *node, ir_node *mem) {
 }
 
 ir_node *
-get_Call_ptr(ir_node *node) {
+get_Call_ptr(const ir_node *node) {
        assert(node->op == op_Call);
        return get_irn_n(node, 1);
 }
@@ -1323,13 +1332,13 @@ get_Call_param_arr(ir_node *node) {
 }
 
 int
-get_Call_n_params(ir_node *node)  {
+get_Call_n_params(const ir_node *node)  {
        assert(node->op == op_Call);
        return (get_irn_arity(node) - CALL_PARAM_OFFSET);
 }
 
 int
-get_Call_arity(ir_node *node) {
+get_Call_arity(const ir_node *node) {
        assert(node->op == op_Call);
        return get_Call_n_params(node);
 }
@@ -1341,7 +1350,7 @@ set_Call_arity(ir_node *node, ir_node *arity) {
 */
 
 ir_node *
-get_Call_param(ir_node *node, int pos) {
+get_Call_param(const ir_node *node, int pos) {
        assert(node->op == op_Call);
        return get_irn_n(node, pos + CALL_PARAM_OFFSET);
 }
@@ -1365,23 +1374,23 @@ set_Call_type(ir_node *node, ir_type *tp) {
        node->attr.call.cld_tp = tp;
 }
 
-int Call_has_callees(ir_node *node) {
+int Call_has_callees(const ir_node *node) {
        assert(node && node->op == op_Call);
        return ((get_irg_callee_info_state(get_irn_irg(node)) != irg_callee_info_none) &&
                (node->attr.call.callee_arr != NULL));
 }
 
-int get_Call_n_callees(ir_node * node) {
+int get_Call_n_callees(const ir_node *node) {
   assert(node && node->op == op_Call && node->attr.call.callee_arr);
   return ARR_LEN(node->attr.call.callee_arr);
 }
 
-ir_entity * get_Call_callee(ir_node * node, int pos) {
+ir_entity * get_Call_callee(const ir_node *node, int pos) {
        assert(pos >= 0 && pos < get_Call_n_callees(node));
        return node->attr.call.callee_arr[pos];
 }
 
-void set_Call_callee_arr(ir_node * node, const int n, ir_entity ** arr) {
+void set_Call_callee_arr(ir_node *node, const int n, ir_entity ** arr) {
        assert(node->op == op_Call);
        if (node->attr.call.callee_arr == NULL || get_Call_n_callees(node) != n) {
                node->attr.call.callee_arr = NEW_ARR_D(ir_entity *, current_ir_graph->obst, n);
@@ -1389,7 +1398,7 @@ void set_Call_callee_arr(ir_node * node, const int n, ir_entity ** arr) {
        memcpy(node->attr.call.callee_arr, arr, n * sizeof(ir_entity *));
 }
 
-void remove_Call_callee_arr(ir_node * node) {
+void remove_Call_callee_arr(ir_node *node) {
        assert(node->op == op_Call);
        node->attr.call.callee_arr = NULL;
 }
@@ -1494,7 +1503,7 @@ BINOP(Cmp)
 UNOP(Conv)
 UNOP(Cast)
 
-int get_Conv_strict(ir_node *node) {
+int get_Conv_strict(const ir_node *node) {
        assert(node->op == op_Conv);
        return node->attr.conv.strict;
 }
@@ -1507,6 +1516,7 @@ void set_Conv_strict(ir_node *node, int strict_flag) {
 ir_type *
 get_Cast_type(ir_node *node) {
        assert(node->op == op_Cast);
+       node->attr.cast.totype = skip_tid(node->attr.cast.totype);
        return node->attr.cast.totype;
 }
 
@@ -1524,9 +1534,8 @@ set_Cast_type(ir_node *node, ir_type *to_tp) {
 int is_Cast_upcast(ir_node *node) {
        ir_type *totype   = get_Cast_type(node);
        ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node));
-       ir_graph *myirg = get_irn_irg(node);
 
-       assert(get_irg_typeinfo_state(myirg) == ir_typeinfo_consistent);
+       assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent);
        assert(fromtype);
 
        while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) {
@@ -1613,19 +1622,9 @@ set_binop_right(ir_node *node, ir_node *right) {
        set_irn_n(node, node->op->op_index + 1, right);
 }
 
-int is_Phi(const ir_node *n) {
-       ir_op *op;
-
-       assert(n);
-       op = get_irn_op(n);
-
-       if (op == op_Filter) return get_interprocedural_view();
-
-       if (op == op_Phi)
-               return ((get_irg_phase_state(get_irn_irg(n)) !=  phase_building) ||
-                       (get_irn_arity(n) > 0));
-
-       return 0;
+int
+(is_Phi)(const ir_node *n) {
+       return _is_Phi(n);
 }
 
 int is_Phi0(const ir_node *n) {
@@ -1849,14 +1848,14 @@ set_Alloc_type(ir_node *node, ir_type *tp) {
        node->attr.alloc.type = tp;
 }
 
-where_alloc
+ir_where_alloc
 get_Alloc_where(ir_node *node) {
        assert(node->op == op_Alloc);
        return node->attr.alloc.where;
 }
 
 void
-set_Alloc_where(ir_node *node, where_alloc where) {
+set_Alloc_where(ir_node *node, ir_where_alloc where) {
        assert(node->op == op_Alloc);
        node->attr.alloc.where = where;
 }
@@ -1910,14 +1909,14 @@ set_Free_type(ir_node *node, ir_type *tp) {
        node->attr.free.type = tp;
 }
 
-where_alloc
+ir_where_alloc
 get_Free_where(ir_node *node) {
        assert(node->op == op_Free);
        return node->attr.free.where;
 }
 
 void
-set_Free_where(ir_node *node, where_alloc where) {
+set_Free_where(ir_node *node, ir_where_alloc where) {
        assert(node->op == op_Free);
        node->attr.free.where = where;
 }
@@ -2114,12 +2113,12 @@ set_Filter_proj(ir_node *node, long proj) {
 
 /* Don't use get_irn_arity, get_irn_n in implementation as access
    shall work independent of view!!! */
-void set_Filter_cg_pred_arr(ir_node * node, int arity, ir_node ** in) {
+void set_Filter_cg_pred_arr(ir_node *node, int arity, ir_node ** in) {
        assert(node->op == op_Filter);
        if (node->attr.filter.in_cg == NULL || arity != ARR_LEN(node->attr.filter.in_cg) - 1) {
+               ir_graph *irg = get_irn_irg(node);
                node->attr.filter.in_cg = NEW_ARR_D(ir_node *, current_ir_graph->obst, arity + 1);
-               node->attr.filter.backedge = NEW_ARR_D (int, current_ir_graph->obst, arity);
-               memset(node->attr.filter.backedge, 0, sizeof(int) * arity);
+               node->attr.filter.backedge = new_backedge_arr(irg->obst, arity);
                node->attr.filter.in_cg[0] = node->in[0];
        }
        memcpy(node->attr.filter.in_cg + 1, in, sizeof(ir_node *) * arity);
@@ -2205,30 +2204,26 @@ void set_Mux_true(ir_node *node, ir_node *ir_true) {
 
 /* Psi support */
 ir_node *get_Psi_cond(ir_node *node, int pos) {
-       int num_conds = get_Psi_n_conds(node);
        assert(node->op == op_Psi);
-       assert(pos < num_conds);
+       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) {
-       int num_conds = get_Psi_n_conds(node);
        assert(node->op == op_Psi);
-       assert(pos < num_conds);
+       assert(pos < get_Psi_n_conds(node));
        set_irn_n(node, 2 * pos, cond);
 }
 
 ir_node *get_Psi_val(ir_node *node, int pos) {
-       int num_vals = get_Psi_n_conds(node);
        assert(node->op == op_Psi);
-       assert(pos < num_vals);
+       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) {
-       int num_vals = get_Psi_n_conds(node);
        assert(node->op == op_Psi);
-       assert(pos < num_vals);
+       assert(pos < get_Psi_n_conds(node));
        set_irn_n(node, 2 * pos + 1, val);
 }
 
@@ -2716,6 +2711,11 @@ int
        return _is_Conv(node);
 }
 
+int
+(is_strictConv)(const ir_node *node) {
+       return _is_strictConv(node);
+}
+
 int
 (is_Cast)(const ir_node *node) {
        return _is_Cast(node);
@@ -2839,16 +2839,15 @@ int
 }
 
 int
-is_Proj(const ir_node *node) {
+(is_Proj)(const ir_node *node) {
        assert(node);
        return node->op == op_Proj ||
               (!get_interprocedural_view() && node->op == op_Filter);
 }
 
 /* Returns true if the operation manipulates control flow. */
-int
-is_cfop(const ir_node *node) {
-       return is_cfopcode(get_irn_op(node));
+int is_cfop(const ir_node *node) {
+       return is_op_cfopcode(get_irn_op(node));
 }
 
 /* Returns true if the operation manipulates interprocedural control flow:
@@ -2878,7 +2877,8 @@ ir_node *get_fragile_op_mem(ir_node *node) {
        case iro_Store :
        case iro_Alloc :
        case iro_Bound :
-               return get_irn_n(node, 0);
+       case iro_CopyB :
+               return get_irn_n(node, pn_Generic_M_regular);
        case iro_Bad   :
        case iro_Unknown:
                return node;
@@ -3095,5 +3095,5 @@ void dump_irn(ir_node *n) {
 }
 
 #else  /* DEBUG_libfirm */
-void dump_irn(ir_node *n) {}
+void dump_irn(ir_node *n) { (void) n; }
 #endif /* DEBUG_libfirm */