3 * File name: ir/ir/irvrfy.c
4 * Purpose: Check irnodes for correctness.
5 * Author: Christian Schaefer
6 * Modified by: Goetz Lindenmaier. Till Riedel
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
17 # include "irgraph_t.h"
23 * in RELEASE mode, returns ret if the expression expr evaluates to zero
24 * in ASSERT mode, asserts the expression expr (and the string string).
26 #define ASSERT_AND_RET(expr, string, ret) if (!(expr)) return (ret)
29 * in RELEASE mode, returns ret if the expression expr evaluates to zero
30 * in ASSERT mode, executes blk if the expression expr evaluates to zero and asserts expr
32 #define ASSERT_AND_RET_DBG(expr, string, ret, blk) if (!(expr)) return (ret)
34 #define ASSERT_AND_RET(expr, string, ret) \
36 bad_msg = #expr " && " string; \
37 if (opt_do_node_verification == NODE_VERIFICATION_ON) \
38 assert((expr) && string); \
40 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) \
41 fprintf(stderr, #expr " : " string "\n"); \
46 #define ASSERT_AND_RET_DBG(expr, string, ret, blk) \
49 bad_msg = #expr " && " string; \
50 if (opt_do_node_verification != NODE_VERIFICATION_ERROR_ONLY) { blk; } \
51 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) \
52 fprintf(stderr, #expr " : " string "\n"); \
53 else if (opt_do_node_verification == NODE_VERIFICATION_ON) \
54 assert((expr) && string); \
61 /* @@@ replace use of array "in" by access functions. */
62 ir_node **get_irn_in(ir_node *node);
64 static node_verification_t opt_do_node_verification = NODE_VERIFICATION_ON;
65 static const char *bad_msg;
68 /** Borrowed from interprete.c
69 static entity *hunt_for_entity (ir_node *addr, ir_node *load) {
70 ir_op *op = get_irn_op(addr);
72 return get_Sel_entity(addr);
74 tarval *tv = get_Const_tarval(addr);
75 assert(tarval_is_entity(tv));
76 return get_tarval_entity(tv);
79 if(get_irn_opcode(load) == iro_Load)
81 assert(0 && "unexpected address expression.");
86 * little helper for NULL modes
88 static const char *get_mode_name_ex(ir_mode *mode)
92 return get_mode_name(mode);
95 void do_node_verification(node_verification_t mode)
97 opt_do_node_verification = mode;
101 * Prints a failure for a Node
103 static void show_node_failure(ir_node *n)
105 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s\n" ,
107 get_irn_opname(n), get_irn_modename(n)
112 * Prints a failure message for a binop
114 static void show_binop_failure(ir_node *n, const char *text)
116 ir_node *left = get_binop_left(n);
117 ir_node *right = get_binop_right(n);
119 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s(%s%s, %s%s) did not match (%s)\n",
121 get_irn_opname(n), get_irn_modename(n),
122 get_irn_opname(left), get_irn_modename(left),
123 get_irn_opname(right), get_irn_modename(right),
128 * Prints a failure message for an unop
130 static void show_unop_failure(ir_node *n, const char *text)
132 ir_node *op = get_unop_op(n);
134 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s(%s%s) did not match (%s)\n",
136 get_irn_opname(n), get_irn_modename(n),
137 get_irn_opname(op), get_irn_modename(op),
142 * Prints a failure message for a proj
144 static void show_proj_failure(ir_node *n)
146 ir_node *op = get_Proj_pred(n);
147 int proj = get_Proj_proj(n);
149 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s %d(%s%s) failed\n" ,
151 get_irn_opname(n), get_irn_modename(n), proj,
152 get_irn_opname(op), get_irn_modename(op));
156 * Prints a failure message for a proj
158 static void show_proj_failure_ent(ir_node *n, entity *ent)
160 ir_node *op = get_Proj_pred(n);
161 int proj = get_Proj_proj(n);
162 ir_mode *m = get_type_mode(get_entity_type(ent));
164 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s %d(%s%s) entity %s(type %s mode %s)failed\n" ,
166 get_irn_opname(n), get_irn_modename(n), proj,
167 get_irn_opname(op), get_irn_modename(op),
168 get_entity_name(ent), get_type_name(get_entity_type(ent)),
169 get_mode_name_ex(m));
173 * Show a node and a graph
175 static void show_node_on_graph(ir_graph *irg, ir_node *n)
177 entity *ent = get_irg_ent(irg);
180 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of entity %s, node %ld %s%s\n",
181 get_entity_name(ent),
182 get_irn_node_nr(n), get_irn_opname(n), get_irn_modename(n));
184 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of graph %p, node %ld %s%s\n",
186 get_irn_node_nr(n), get_irn_opname(n), get_irn_modename(n));
192 static void show_call_param(ir_node *n, type *mt)
196 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Call type-check failed: %s(", get_type_name(mt));
197 for (i = 0; i < get_method_n_params(mt); ++i) {
198 fprintf(stderr, "%s ", get_mode_name_ex(get_type_mode(get_method_param_type(mt, i))));
200 fprintf(stderr, ") != CALL(");
202 for (i = 0; i < get_Call_n_params(n); ++i) {
203 fprintf(stderr, "%s ", get_mode_name_ex(get_irn_mode(get_Call_param(n, i))));
205 fprintf(stderr, ")\n");
212 static void show_return_modes(ir_graph *irg, ir_node *n, type *mt, int i)
214 entity *ent = get_irg_ent(irg);
216 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Return node %ld in entity \"%s\" mode %s different from type mode %s\n",
217 get_irn_node_nr(n), get_entity_name(ent),
218 get_mode_name_ex(get_irn_mode(get_Return_res(n, i))),
219 get_mode_name_ex(get_type_mode(get_method_res_type(mt, i)))
224 * Show return number of results
226 static void show_return_nres(ir_graph *irg, ir_node *n, type *mt)
228 entity *ent = get_irg_ent(irg);
230 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Return node %ld in entity \"%s\" has %d results different from type %d\n",
231 get_irn_node_nr(n), get_entity_name(ent),
232 get_Return_n_ress(n), get_method_n_ress(mt));
238 static void show_phi_failure(ir_node *phi, ir_node *pred, int pos)
240 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Phi node %ld has mode %s different from predeccessor node %ld mode %s\n",
241 get_irn_node_nr(phi), get_mode_name_ex(get_irn_mode(phi)),
242 get_irn_node_nr(pred), get_mode_name_ex(get_irn_mode(pred)));
246 * verify the Proj number
249 vrfy_Proj_proj(ir_node *p, ir_graph *irg) {
254 pred = skip_nop(get_Proj_pred(p));
255 assert(get_irn_mode(pred) == mode_T);
256 mode = get_irn_mode(p);
257 proj = get_Proj_proj(p);
259 switch (get_irn_opcode(pred)) {
263 (proj == pns_initial_exec && mode == mode_X) ||
264 (proj == pns_global_store && mode == mode_M) ||
265 (proj == pns_frame_base && mode_is_reference(mode)) ||
266 (proj == pns_globals && mode_is_reference(mode)) ||
267 (proj == pns_args && mode == mode_T) ||
268 (proj == pns_value_arg_base && mode_is_reference(mode)) ||
269 (proj == pns_value_arg_base && mode == mode_T) /* FIXME: only one of those */
271 "wrong Proj from Start", 0,
272 show_proj_failure(p);
278 (proj >= 0 && mode == mode_X),
279 "wrong Proj from Cond", 0,
280 show_proj_failure(p);
286 ((proj == pn_Raise_X && mode == mode_X) || (proj == pn_Raise_M && mode == mode_M)),
287 "wrong Proj from Raise", 0,
288 show_proj_failure(p);
294 (proj >= 0 && mode == mode_X),
295 "wrong Proj from InstOf", 0,
296 show_proj_failure(p);
302 ((proj == pn_Call_M_regular && mode == mode_M) ||
303 (proj == pn_Call_X_except && mode == mode_X) ||
304 (proj == pn_Call_T_result && mode == mode_T) ||
305 (proj == pn_Call_M_except && mode == mode_M) ||
306 (proj == pn_Call_P_value_res_base && mode == mode_P)),
307 "wrong Proj from Call", 0,
308 show_proj_failure(p);
314 ((proj == pn_Call_M_regular && mode == mode_M) ||
315 (proj == pn_Call_X_except && mode == mode_X) ||
316 (proj == pn_Call_T_result && mode == mode_T) ||
317 (proj == pn_Call_M_except && mode == mode_M) ||
318 (proj == pn_Call_P_value_res_base && mode == mode_P)),
319 "wrong Proj from FuncCall", 0,
320 show_proj_failure(p);
326 ((proj == pn_Quot_M && mode == mode_M) ||
327 (proj == pn_Quot_X_except && mode == mode_X) ||
328 (proj == pn_Quot_res && mode_is_float(mode))),
329 "wrong Proj from Quot", 0,
330 show_proj_failure(p);
336 ((proj == pn_DivMod_M && mode == mode_M) ||
337 (proj == pn_DivMod_X_except && mode == mode_X) ||
338 (proj == pn_DivMod_res_div && mode_is_int(mode)) ||
339 (proj == pn_DivMod_res_mod && mode_is_int(mode))),
340 "wrong Proj from DivMod", 0,
341 show_proj_failure(p);
347 ((proj == pn_Div_M && mode == mode_M) ||
348 (proj == pn_Div_X_except && mode == mode_X) ||
349 (proj == pn_Div_res && mode_is_int(mode))),
350 "wrong Proj from Div or Mod", 0,
351 show_proj_failure(p);
357 ((proj == pn_Mod_M && mode == mode_M) ||
358 (proj == pn_Mod_X_except && mode == mode_X) ||
359 (proj == pn_Mod_res && mode_is_int(mode))),
360 "wrong Proj from Div or Mod", 0,
361 show_proj_failure(p);
367 (proj >= 0 && proj <= 15 && mode == mode_b),
368 "wrong Proj from Cmp", 0,
369 show_proj_failure(p);
374 if (proj == pn_Load_res) {
375 ir_node *ptr = get_Load_ptr(pred);
377 if (get_irn_op(ptr) == op_Sel) {
378 ent = get_Sel_entity(ptr);
380 We may not test this, after lowering and optimization the Const can
381 have an unexpected type.
382 else if ((get_irn_op(ptr) == op_Const) &&
383 tarval_is_entity(get_Const_tarval(ptr))) {
384 ent = get_tarval_entity(get_Const_tarval(ptr));
388 (mode == get_type_mode(get_entity_type(ent))),
389 "wrong data Proj from Load, entity type_mode failed", 0,
390 show_proj_failure_ent(p, ent);
396 "wrong data Proj from Load", 0,
397 show_proj_failure(p);
402 ((proj == pn_Load_M && mode == mode_M) ||
403 (proj == pn_Load_X_except && mode == mode_X)),
404 "wrong Proj from Load", 0,
405 show_proj_failure(p);
412 ((proj == pn_Store_M && mode == mode_M) ||
413 (proj == pn_Store_X_except && mode == mode_X)),
414 "wrong Proj from Store", 0,
415 show_proj_failure(p);
422 (proj == pn_Alloc_M && mode == mode_M) ||
423 (proj == pn_Alloc_X_except /* && mode == mode_X*/) ||
424 (proj == pn_Alloc_res && mode_is_reference(mode))
426 "wrong Proj from Alloc", 0,
427 show_proj_failure(p);
433 type *mt; /* A method type */
434 long nr = get_Proj_proj(pred);
436 pred = skip_nop(get_Proj_pred(pred));
437 ASSERT_AND_RET((get_irn_mode(pred) == mode_T), "Proj from something not a tuple", 0);
438 switch (get_irn_opcode(pred))
441 mt = get_entity_type(get_irg_ent(irg));
443 if (nr == pns_args) {
445 (proj >= 0 && mode_is_data(mode)),
446 "wrong Proj from Proj from Start", 0);
448 (proj < get_method_n_params(mt)),
449 "More Projs for args than args in type", 0
451 if ((mode_is_reference(mode)) && is_compound_type(get_method_param_type(mt, proj)))
452 /* value argument */ break;
455 (mode == get_type_mode(get_method_param_type(mt, proj))),
456 "Mode of Proj from Start doesn't match mode of param type.", 0);
458 else if (nr == pns_value_arg_base) {
460 (proj >= 0 && mode_is_reference(mode)),
461 "wrong Proj from Proj from Start", 0
464 (proj < get_method_n_params(mt)),
465 "More Projs for args than args in type", 0
473 (proj >= 0 && mode_is_data(mode)),
474 "wrong Proj from Proj from Call", 0);
475 mt = get_Call_type(pred);
477 (proj < get_method_n_ress(mt)),
478 "More Projs for results than results in type.", 0);
479 if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
480 /* value result */ break;
483 (mode == get_type_mode(get_method_res_type(mt, proj))),
484 "Mode of Proj from Call doesn't match mode of result type.", 0);
491 (proj >= 0 && mode_is_data(mode)),
492 "wrong Proj from Proj from FuncCall", 0);
493 mt = get_FuncCall_type(pred);
495 (proj < get_method_n_ress(mt)),
496 "More Projs for results than results in type.", 0);
497 if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
498 /* value result */ break;
501 (mode == get_type_mode(get_method_res_type(mt, proj))),
502 "Mode of Proj from FuncCall doesn't match mode of result type.", 0);
511 ASSERT_AND_RET(0, "Unknown opcode", 0);
530 ASSERT_AND_RET(0, "Unknown opcode", 0);
537 int irn_vrfy_irg(ir_node *n, ir_graph *irg)
541 ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
542 int op_is_symmetric = 1; /* 0: asymmetric
543 1: operands have identical modes
544 2: modes of operands == mode of this node */
545 type *mt; /* A method type */
550 if (!opt_do_node_verification) return 1;
552 if (! interprocedural_view) {
554 * do NOT check placement in interprocedural view, as we don't always know
555 * the "right" graph ...
558 node_is_in_irgs_storage(irg, n),
559 "Node is not stored on proper IR graph!", 0,
560 show_node_on_graph(irg, n);
564 opcode = get_irn_opcode(n);
566 /* We don't want to test nodes whose predecessors are Bad or Unknown,
567 as we would have to special case that for each operation. */
568 if (opcode != iro_Phi && opcode != iro_Block)
569 for (i = 0; i < get_irn_arity(n); i++) {
570 opcode1 = get_irn_opcode(get_irn_n(n, i));
571 if (opcode1 == iro_Bad /*|| opcode1 == iro_Unknown*/) /* GL: for analyses mode must be correct. */
575 mymode = get_irn_mode(n);
581 for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
582 ir_node *pred = get_Block_cfgpred(n, i);
586 (get_irn_mode(pred) == mode_X)
589 /* End block may only have Return, Raise or fragile ops as preds. */
590 if (n == get_irg_end_block(irg))
591 for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
592 ir_node *pred = skip_Proj(get_Block_cfgpred(n, i));
593 if (is_Proj(pred) || get_irn_op(pred) == op_Tuple)
594 break; /* We can not test properly. How many tuples are there? */
595 ASSERT_AND_RET(((get_irn_op(pred) == op_Return) ||
597 (get_irn_op(pred) == op_Raise) ||
598 is_fragile_op(pred) ),
599 "End Block node", 0);
601 /* irg attr must == graph we are in. */
602 if (! interprocedural_view) {
603 ASSERT_AND_RET(((get_irn_irg(n) && get_irn_irg(n) == irg)), "Block node has wrong irg attribute", 0);
610 /* Start: BB --> X x M x ref x data1 x ... x datan x ref */
611 mymode == mode_T, "Start node", 0
618 mymode == mode_X, "Jmp node", 0
625 mymode == mode_X, "Jmp node", 0
630 op1mode = get_irn_mode(in[1]);
632 /* Cond: BB x b --> X x X */
633 (op1mode == mode_b ||
634 /* Cond: BB x int --> X^n */
635 mode_is_int(op1mode) ), "Cond node", 0
637 ASSERT_AND_RET(mymode == mode_T, "Cond mode is not a tuple", 0);
641 op1mode = get_irn_mode(in[1]);
642 /* Return: BB x M x data1 x ... x datan --> X */
643 /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
644 ASSERT_AND_RET( op1mode == mode_M, "Return node", 0 ); /* operand M */
645 for (i = 2; i < get_irn_arity(n); i++) {
646 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Return node", 0 ); /* operand datai */
648 ASSERT_AND_RET( mymode == mode_X, "Result X", 0 ); /* result X */
649 /* Compare returned results with result types of method type */
650 mt = get_entity_type(get_irg_ent(irg));
651 ASSERT_AND_RET_DBG( get_Return_n_ress(n) == get_method_n_ress(mt),
652 "Number of results for Return doesn't match number of results in type.", 0,
653 show_return_nres(irg, n, mt););
654 for (i = 0; i < get_Return_n_ress(n); i++) {
655 type *res_type = get_method_res_type(mt, i);
657 if (is_atomic_type(res_type)) {
659 get_irn_mode(get_Return_res(n, i)) == get_type_mode(res_type),
660 "Mode of result for Return doesn't match mode of result type.", 0,
661 show_return_modes(irg, n, mt, i);
666 mode_is_reference(get_irn_mode(get_Return_res(n, i))),
667 "Mode of result for Return doesn't match mode of result type.", 0,
668 show_return_modes(irg, n, mt, i);
675 op1mode = get_irn_mode(in[1]);
676 op2mode = get_irn_mode(in[2]);
678 /* Sel: BB x M x ref --> X x M */
679 op1mode == mode_M && mode_is_reference(op2mode) &&
680 mymode == mode_T, "Raise node", 0
686 /* Const: BB --> data */
687 (mode_is_data (mymode) ||
688 mymode == mode_b) /* we want boolean constants for static evaluation */
689 ,"Const node", 0 /* of Cmp. */
695 /* SymConst: BB --> int*/
696 (mode_is_int(mymode) ||
697 /* SymConst: BB --> ref */
698 mode_is_reference(mymode))
699 ,"SymConst node", 0);
703 op1mode = get_irn_mode(in[1]);
704 op2mode = get_irn_mode(in[2]);
706 /* Sel: BB x M x ref x int^n --> ref */
707 (op1mode == mode_M && op2mode == mymode && mode_is_reference(mymode)),
708 "Sel node", 0, show_node_failure(n)
710 for (i=3; i < get_irn_arity(n); i++)
712 ASSERT_AND_RET_DBG(mode_is_int(get_irn_mode(in[i])), "Sel node", 0, show_node_failure(n));
714 ent = get_Sel_entity(n);
715 ASSERT_AND_RET_DBG(ent, "Sel node with empty entity", 0, show_node_failure(n));
719 ASSERT_AND_RET(mode_T == mymode, "mode of Instof is not a tuple", 0);
720 ASSERT_AND_RET(mode_is_data(op1mode), "Instof not on data", 0);
724 op1mode = get_irn_mode(in[1]);
725 op2mode = get_irn_mode(in[2]);
726 /* Call: BB x M x ref x data1 x ... x datan
727 --> M x datan+1 x ... x data n+m */
728 ASSERT_AND_RET( op1mode == mode_M && mode_is_reference(op2mode), "Call node", 0 ); /* operand M x ref */
729 for (i=3; i < get_irn_arity(n); i++) {
730 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Call node", 0 ); /* operand datai */
732 ASSERT_AND_RET( mymode == mode_T, "Call result not a tuple", 0 ); /* result T */
733 /* Compare arguments of node with those of type */
734 mt = get_Call_type(n);
736 if (get_method_variadicity(mt) == variadicity_variadic) {
738 get_Call_n_params(n) >= get_method_n_params(mt),
739 "Number of args for Call doesn't match number of args in variadic type.",
741 fprintf(stderr, "Call has %d params, method %s type %d\n",
742 get_Call_n_params(n), get_type_name(mt), get_method_n_params(mt));
747 get_Call_n_params(n) == get_method_n_params(mt),
748 "Number of args for Call doesn't match number of args in non variadic type.",
752 for (i = 0; i < get_method_n_params(mt); i++) {
753 type *t = get_method_param_type(mt, i);
755 if (is_atomic_type(t)) {
757 get_irn_mode(get_Call_param(n, i)) == get_type_mode(t),
758 "Mode of arg for Call doesn't match mode of arg type.", 0,
759 show_call_param(n, mt);
763 /* call with a compound type, mode must be reference */
765 mode_is_reference(get_irn_mode(get_Call_param(n, i))),
766 "Mode of arg for Call doesn't match mode of arg type.", 0,
767 show_call_param(n, mt);
774 op1mode = get_irn_mode(in[1]);
775 op2mode = get_irn_mode(in[2]);
778 /* common Add: BB x numP x numP --> numP */
779 (op1mode == mymode && op2mode == op1mode && mode_is_numP(mymode)) ||
780 /* Pointer Add: BB x ref x int --> ref */
781 (mode_is_reference(op1mode) && mode_is_int(op2mode) && op1mode == mymode) ||
782 /* Pointer Add: BB x int x ref --> ref */
783 (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode))
786 show_binop_failure(n, "/* common Add: BB x numP x numP --> numP */ |\n"
787 "/* Pointer Add: BB x ref x int --> ref */ |\n"
788 "/* Pointer Add: BB x int x ref --> ref */");
790 if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
791 /* BB x ref x int --> ref or BB x int x ref --> ref */
794 /* BB x num x num --> num or BB x ref x ref */
800 op1mode = get_irn_mode(in[1]);
801 op2mode = get_irn_mode(in[2]);
803 /* common Sub: BB x numP x numP --> numP */
804 ((mymode ==op1mode && mymode == op2mode && mode_is_numP(op1mode)) ||
805 /* Pointer Sub: BB x ref x int --> ref */
806 (op1mode == mymode && mode_is_int(op2mode) && mode_is_reference(mymode)) ||
807 /* Pointer Sub: BB x int x ref --> ref */
808 (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode)) ||
809 /* Pointer Sub: BB x ref x ref --> int */
810 (op1mode == op2mode && mode_is_reference(op2mode) && mode_is_int(mymode))),
812 show_binop_failure(n, "/* common Sub: BB x numP x numP --> numP */ |\n"
813 "/* Pointer Sub: BB x ref x int --> ref */ |\n"
814 "/* Pointer Sub: BB x int x ref --> ref */ |\n"
815 "/* Pointer Sub: BB x ref x ref --> int */" );
817 if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
825 op1mode = get_irn_mode(in[1]);
827 /* Minus: BB x float --> float */
828 op1mode == mymode && get_mode_sort(op1mode) == irms_float_number, "Minus node", 0,
829 show_unop_failure(n , "/* Minus: BB x float --> float */");
835 op1mode = get_irn_mode(in[1]);
836 op2mode = get_irn_mode(in[2]);
838 /* Mul: BB x int1 x int1 --> int2 */
839 ((mode_is_int(op1mode) && op2mode == op1mode && mode_is_int(mymode)) ||
840 /* Mul: BB x float x float --> float */
841 (mode_is_float(op1mode) && op2mode == op1mode && mymode == op1mode)),
843 show_binop_failure(n, "/* Mul: BB x int1 x int1 --> int2 */ |\n"
844 "/* Mul: BB x float x float --> float */");
850 op1mode = get_irn_mode(in[1]);
851 op2mode = get_irn_mode(in[2]);
852 op3mode = get_irn_mode(in[3]);
854 /* Quot: BB x M x float x float --> M x X x float */
855 op1mode == mode_M && op2mode == op3mode &&
856 get_mode_sort(op2mode) == irms_float_number &&
859 show_binop_failure(n, "/* Quot: BB x M x float x float --> M x X x float */");
865 op1mode = get_irn_mode(in[1]);
866 op2mode = get_irn_mode(in[2]);
867 op3mode = get_irn_mode(in[3]);
869 /* DivMod: BB x M x int x int --> M x X x int x int */
871 mode_is_int(op2mode) &&
872 op3mode == op2mode &&
881 op1mode = get_irn_mode(in[1]);
882 op2mode = get_irn_mode(in[2]);
883 op3mode = get_irn_mode(in[3]);
885 /* Div or Mod: BB x M x int x int --> M x X x int */
887 op2mode == op3mode &&
888 mode_is_int(op2mode) &&
896 op1mode = get_irn_mode(in[1]);
898 /* Abs: BB x num --> num */
900 mode_is_num (op1mode),
902 show_unop_failure(n, "/* Abs: BB x num --> num */");
910 op1mode = get_irn_mode(in[1]);
911 op2mode = get_irn_mode(in[2]);
913 /* And or Or or Eor: BB x int x int --> int */
914 mode_is_int(mymode) &&
915 op2mode == op1mode &&
917 "And, Or or Eor node", 0,
918 show_binop_failure(n, "/* And or Or or Eor: BB x int x int --> int */");
924 op1mode = get_irn_mode(in[1]);
926 /* Not: BB x int --> int */
927 mode_is_int(mymode) &&
930 show_unop_failure(n, "/* Not: BB x int --> int */");
937 op1mode = get_irn_mode(in[1]);
938 op2mode = get_irn_mode(in[2]);
940 /* Cmp: BB x datab x datab --> b16 */
941 mode_is_data (op1mode) &&
942 op2mode == op1mode &&
945 show_binop_failure(n, "/* Cmp: BB x datab x datab --> b16 */");
952 op1mode = get_irn_mode(in[1]);
953 op2mode = get_irn_mode(in[2]);
955 /* Shl, Shr or Shrs: BB x int x int_u --> int */
956 mode_is_int(op1mode) &&
957 mode_is_int(op2mode) &&
958 !mode_is_signed(op2mode) &&
960 "Shl, Shr, Shr or Rot node", 0,
961 show_binop_failure(n, "/* Shl, Shr or Shrs: BB x int x int_u --> int */");
966 op1mode = get_irn_mode(in[1]);
967 op2mode = get_irn_mode(in[2]);
969 /* Rot: BB x int x int --> int */
970 mode_is_int(op1mode) &&
971 mode_is_int(op2mode) &&
974 show_binop_failure(n, "/* Rot: BB x int x int --> int */");
979 op1mode = get_irn_mode(in[1]);
981 /* Conv: BB x datab1 --> datab2 */
982 mode_is_datab(op1mode) && mode_is_data(mymode),
984 show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
989 op1mode = get_irn_mode(in[1]);
991 /* Conv: BB x datab1 --> datab2 */
992 mode_is_data(op1mode) && op1mode == mymode,
994 show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
999 /* Phi: BB x dataM^n --> dataM */
1000 for (i = 1; i < get_irn_arity(n); i++) {
1001 if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
1003 get_irn_mode(in[i]) == mymode,
1005 show_phi_failure(n, in[i], i);
1008 ASSERT_AND_RET( mode_is_dataM(mymode), "Phi node", 0 );
1012 op1mode = get_irn_mode(in[1]);
1013 op2mode = get_irn_mode(in[2]);
1015 /* Load: BB x M x ref --> M x X x data */
1016 op1mode == mode_M && mode_is_reference(op2mode),
1019 ASSERT_AND_RET( mymode == mode_T, "Load node", 0 );
1022 * jack's gen_add_firm_code:simpleSel seems to build Load (Load
1023 * (Proj (Proj))) sometimes ...
1025 * interprete.c:ai_eval seems to assume that this happens, too
1027 * obset.c:get_abstval_any can't deal with this if the load has
1031 entity *ent = hunt_for_entity (get_Load_ptr (n), n);
1032 assert ((NULL != ent) || (mymode != mode_T));
1039 op1mode = get_irn_mode(in[1]);
1040 op2mode = get_irn_mode(in[2]);
1041 op3mode = get_irn_mode(in[3]);
1043 /* Load: BB x M x ref data --> M x X */
1044 op1mode == mode_M && mode_is_reference(op2mode) && mode_is_data(op3mode),
1047 ASSERT_AND_RET(mymode == mode_T, "Store node", 0);
1051 op1mode = get_irn_mode(in[1]);
1052 op2mode = get_irn_mode(in[2]);
1054 /* Alloc: BB x M x int_u --> M x X x ref */
1055 op1mode == mode_M &&
1056 mode_is_int(op2mode) &&
1057 !mode_is_signed(op2mode) &&
1060 show_binop_failure(n, "/* Alloc: BB x M x int_u --> M x X x ref */");
1065 op1mode = get_irn_mode(in[1]);
1066 op2mode = get_irn_mode(in[2]);
1068 /* Free: BB x M x ref --> M */
1069 op1mode == mode_M && mode_is_reference(op2mode) &&
1072 show_binop_failure(n, "/* Free: BB x M x ref --> M */");
1077 /* Sync: BB x M^n --> M */
1078 for (i=1; i < get_irn_arity(n); i++) {
1079 ASSERT_AND_RET( get_irn_mode(in[i]) == mode_M, "Sync node", 0 );
1081 ASSERT_AND_RET( mymode == mode_M, "Sync node", 0 );
1085 return vrfy_Proj_proj(n, irg);
1089 op1mode = get_irn_mode(in[1]);
1090 op2mode = get_irn_mode(in[2]);
1092 /* Confirm: BB x T x T --> T */
1093 op1mode == mymode &&
1096 show_binop_failure(n, "/* Confirm: BB x T x T --> T */");
1108 int irn_vrfy(ir_node *n)
1111 #ifdef DEBUG_libfirm
1112 res = irn_vrfy_irg(n, current_ir_graph);
1117 /*-----------------------------------------------------------------*/
1118 /* Verify the whole graph. */
1119 /*-----------------------------------------------------------------*/
1121 /* This *is* used, except gcc doesn't notice that */
1122 static void vrfy_wrap(ir_node *node, void *env)
1126 *res = irn_vrfy(node);
1129 int irg_vrfy(ir_graph *irg)
1132 #ifdef DEBUG_libfirm
1135 rem = current_ir_graph;
1136 current_ir_graph = irg;
1138 assert(get_irg_pinned(irg) == pinned);
1140 irg_walk(irg->end, vrfy_wrap, NULL, &res);
1142 current_ir_graph = rem;
1144 if (opt_do_node_verification == NODE_VERIFICATION_REPORT && ! res) {
1145 entity *ent = get_irg_entity(current_ir_graph);
1148 fprintf(stderr, "irg_verify: Verifying graph %s failed\n", get_entity_name(ent));
1150 fprintf(stderr, "irg_verify: Verifying graph %p failed\n", (void *)current_ir_graph);
1157 int irn_vrfy_irg_dump(ir_node *n, ir_graph *irg, const char **bad_string)
1160 node_verification_t old = opt_do_node_verification;
1163 opt_do_node_verification = NODE_VERIFICATION_ERROR_ONLY;
1164 res = irn_vrfy_irg(n, irg);
1165 opt_do_node_verification = old;
1166 *bad_string = bad_msg;