add an get_irg_idx
[libfirm] / ir / ir / irvrfy.c
index 3e98cbb..a2a4e15 100644 (file)
@@ -49,6 +49,8 @@ void vrfy_enable_entity_tests(int enable) {
        vrfy_entities = enable;
 }
 
+#ifndef NDEBUG
+
 /**
  * little helper for NULL modes
  */
@@ -273,6 +275,8 @@ static void show_phi_inputs(ir_node *phi, ir_node *block) {
                get_irn_node_nr(block), get_irn_arity(block));
 }
 
+#endif /* #ifndef NDEBUG */
+
 /** If the address is Sel or SymConst, return the entity. */
 static ir_entity *get_ptr_entity(ir_node *ptr) {
        if (get_irn_op(ptr) == op_Sel) {
@@ -670,11 +674,13 @@ static int verify_node_Proj_Proj(ir_node *pred, ir_node *p) {
                        if ((mode_is_reference(mode)) && is_compound_type(get_method_param_type(mt, proj)))
                                /* value argument */ break;
 
+                       if (get_irg_phase_state(get_irn_irg(pred)) != phase_backend) {
                                ASSERT_AND_RET_DBG(
-                               (mode == get_type_mode(get_method_param_type(mt, proj))),
-                               "Mode of Proj from Start doesn't match mode of param type.", 0,
-                               show_proj_mode_failure(p, get_method_param_type(mt, proj));
-                       );
+                                               (mode == get_type_mode(get_method_param_type(mt, proj))),
+                                               "Mode of Proj from Start doesn't match mode of param type.", 0,
+                                               show_proj_mode_failure(p, get_method_param_type(mt, proj));
+                                               );
+                       }
                } else if (nr == pn_Start_P_value_arg_base) {
                        ASSERT_AND_RET(
                                (proj >= 0 && mode_is_reference(mode)),
@@ -745,9 +751,11 @@ static int verify_node_Proj_CallBegin(ir_node *n, ir_node *p) {
 static int verify_node_Proj_EndReg(ir_node *n, ir_node *p) {
        (void) n;
        (void) p;
+#ifdef INTERPROCEDURAL_VIEW
        ASSERT_AND_RET(
                (get_irp_ip_view_state() != ip_view_no),
                "EndReg may only appear if ip view is constructed.", 0);
+#endif
        return 1;
 }
 
@@ -757,9 +765,11 @@ static int verify_node_Proj_EndReg(ir_node *n, ir_node *p) {
 static int verify_node_Proj_EndExcept(ir_node *n, ir_node *p) {
        (void) n;
        (void) p;
+#ifdef INTERPROCEDURAL_VIEW
        ASSERT_AND_RET(
                (get_irp_ip_view_state() != ip_view_no),
                "EndExcept may only appear if ip view is constructed.", 0);
+#endif
        return 1;
 }
 
@@ -924,8 +934,10 @@ static int verify_node_Break(ir_node *n, ir_graph *irg) {
        ir_mode *mymode = get_irn_mode(n);
        (void) irg;
 
+#ifdef INTERPROCEDURAL_VIEW
        ASSERT_AND_RET((get_irp_ip_view_state() != ip_view_no),
                "Break may only appear if ip view is constructed.", 0);
+#endif
        ASSERT_AND_RET(
                /* Jmp: BB --> X */
                mymode == mode_X, "Break node", 0
@@ -977,18 +989,20 @@ static int verify_node_Return(ir_node *n, ir_graph *irg) {
        for (i = get_Return_n_ress(n) - 1; i >= 0; --i) {
                ir_type *res_type = get_method_res_type(mt, i);
 
-               if (is_atomic_type(res_type)) {
-                       ASSERT_AND_RET_DBG(
-                               get_irn_mode(get_Return_res(n, i)) == get_type_mode(res_type),
-                               "Mode of result for Return doesn't match mode of result type.", 0,
-                               show_return_modes(irg, n, mt, i);
-                       );
-               } else {
-                       ASSERT_AND_RET_DBG(
-                               mode_is_reference(get_irn_mode(get_Return_res(n, i))),
-                               "Mode of result for Return doesn't match mode of result type.", 0,
-                               show_return_modes(irg, n, mt, i);
-                       );
+               if (get_irg_phase_state(irg) != phase_backend) {
+                       if (is_atomic_type(res_type)) {
+                               ASSERT_AND_RET_DBG(
+                                       get_irn_mode(get_Return_res(n, i)) == get_type_mode(res_type),
+                                       "Mode of result for Return doesn't match mode of result type.", 0,
+                                       show_return_modes(irg, n, mt, i);
+                               );
+                       } else {
+                               ASSERT_AND_RET_DBG(
+                                       mode_is_reference(get_irn_mode(get_Return_res(n, i))),
+                                       "Mode of result for Return doesn't match mode of result type.", 0,
+                                       show_return_modes(irg, n, mt, i);
+                               );
+                       }
                }
        }
        return 1;
@@ -1160,19 +1174,21 @@ static int verify_node_Call(ir_node *n, ir_graph *irg) {
        for (i = 0; i < get_method_n_params(mt); i++) {
                ir_type *t = get_method_param_type(mt, i);
 
-               if (is_atomic_type(t)) {
-                       ASSERT_AND_RET_DBG(
-                               get_irn_mode(get_Call_param(n, i)) == get_type_mode(t),
-                               "Mode of arg for Call doesn't match mode of arg type.", 0,
-                               show_call_param(n, mt);
-                       );
-               } else {
-                       /* call with a compound type, mode must be reference */
-                       ASSERT_AND_RET_DBG(
-                               mode_is_reference(get_irn_mode(get_Call_param(n, i))),
-                               "Mode of arg for Call doesn't match mode of arg type.", 0,
-                               show_call_param(n, mt);
-                       );
+               if (get_irg_phase_state(irg) != phase_backend) {
+                       if (is_atomic_type(t)) {
+                               ASSERT_AND_RET_DBG(
+                                       get_irn_mode(get_Call_param(n, i)) == get_type_mode(t),
+                                       "Mode of arg for Call doesn't match mode of arg type.", 0,
+                                       show_call_param(n, mt);
+                               );
+                       } else {
+                               /* call with a compound type, mode must be reference */
+                               ASSERT_AND_RET_DBG(
+                                       mode_is_reference(get_irn_mode(get_Call_param(n, i))),
+                                       "Mode of arg for Call doesn't match mode of arg type.", 0,
+                                       show_call_param(n, mt);
+                               );
+                       }
                }
        }
 
@@ -1268,18 +1284,39 @@ static int verify_node_Mul(ir_node *n, ir_graph *irg) {
 
        ASSERT_AND_RET_DBG(
                (
-                       /* Mul: BB x int1 x int1 --> int2 */
-                       (mode_is_int(op1mode)   && op2mode == op1mode && mode_is_int(mymode)) ||
+                       /* Mul: BB x int_n x int_n --> int_n|int_2n */
+                       (mode_is_int(op1mode)   && op2mode == op1mode && mode_is_int(mymode) &&
+                        (op1mode == mymode || get_mode_size_bits(op1mode) * 2 == get_mode_size_bits(mymode))) ||
                        /* Mul: BB x float x float --> float */
                        (mode_is_float(op1mode) && op2mode == op1mode && mymode == op1mode)
                ),
                "Mul node",0,
-               show_binop_failure(n, "/* Mul: BB x int1 x int1 --> int2 */ |\n"
+               show_binop_failure(n, "/* Mul: BB x int_n x int_n --> int_n|int_2n */ |\n"
                "/* Mul: BB x float x float --> float */");
        );
        return 1;
 }
 
+/**
+ * verify a Mulh node
+ */
+static int verify_node_Mulh(ir_node *n, ir_graph *irg) {
+       ir_mode *mymode  = get_irn_mode(n);
+       ir_mode *op1mode = get_irn_mode(get_Mulh_left(n));
+       ir_mode *op2mode = get_irn_mode(get_Mulh_right(n));
+       (void) irg;
+
+       ASSERT_AND_RET_DBG(
+               (
+                       /* Mulh: BB x int x int --> int */
+                       (mode_is_int(op1mode) && op2mode == op1mode && op1mode == mymode)
+               ),
+               "Mulh node",0,
+               show_binop_failure(n, "/* Mulh: BB x int x int --> int */");
+       );
+       return 1;
+}
+
 /**
  * verify a Quot node
  */
@@ -1498,10 +1535,10 @@ static int verify_node_Conv(ir_node *n, ir_graph *irg) {
        (void) irg;
 
        ASSERT_AND_RET_DBG(
-               /* Conv: BB x datab1 --> datab2 */
-               mode_is_datab(op1mode) && mode_is_datab(mymode),
+               get_irg_phase_state(irg) == phase_backend ||
+               (mode_is_datab(op1mode) && mode_is_data(mymode)),
                "Conv node", 0,
-               show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
+               show_unop_failure(n, "/* Conv: BB x datab --> data */");
        );
        return 1;
 }
@@ -1532,7 +1569,7 @@ static int verify_node_Phi(ir_node *n, ir_graph *irg) {
        int i;
        (void) irg;
 
-       if (! is_Bad(block) && get_irg_phase_state(get_irn_irg(n)) != phase_building) {
+       if (! is_Bad(block) && get_irg_phase_state(get_irn_irg(n)) != phase_building && get_irn_arity(n) > 0) {
                /* a Phi node MUST have the same number of inputs as its block */
                ASSERT_AND_RET_DBG(
                        get_irn_arity(n) == get_irn_arity(block),
@@ -1588,8 +1625,10 @@ static int verify_node_Phi(ir_node *n, ir_graph *irg) {
 static int verify_node_Filter(ir_node *n, ir_graph *irg) {
        (void) n;
        (void) irg;
+#ifdef INTERPROCEDURAL_VIEW
        ASSERT_AND_RET((get_irp_ip_view_state() != ip_view_no),
                "Filter may only appear if ip view is constructed.", 0);
+#endif
        /* We should further do tests as for Proj and Phi. */
        return 1;
 }
@@ -1913,11 +1952,12 @@ int irn_vrfy_irg(ir_node *n, ir_graph *irg) {
 }
 
 int irn_vrfy(ir_node *n) {
-       int res = 1;
 #ifdef DEBUG_libfirm
-       res = irn_vrfy_irg(n, current_ir_graph);
+       return irn_vrfy_irg(n, current_ir_graph);
+#else
+       (void)n;
+       return 1;
 #endif
-       return res;
 }
 
 /*-----------------------------------------------------------------*/
@@ -1984,6 +2024,9 @@ int irg_verify(ir_graph *irg, unsigned flags) {
                else
                        fprintf(stderr, "irg_verify: Verifying graph %p failed\n", (void *)current_ir_graph);
        }
+#else
+       (void)irg;
+       (void)flags;
 #endif /* DEBUG_libfirm */
 
        return res;
@@ -2149,6 +2192,7 @@ void firm_set_default_verifyer(ir_opcode code, ir_op_ops *ops) {
        CASE(Sub);
        CASE(Minus);
        CASE(Mul);
+       CASE(Mulh);
        CASE(Quot);
        CASE(DivMod);
        CASE(Div);