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.
18 # include "irgraph_t.h"
25 * in RELEASE mode, returns ret if the expression expr evaluates to zero
26 * in ASSERT mode, asserts the expression expr (and the string string).
28 #define ASSERT_AND_RET(expr, string, ret) if (!(expr)) return (ret)
31 * in RELEASE mode, returns ret if the expression expr evaluates to zero
32 * in ASSERT mode, executes blk if the expression expr evaluates to zero and asserts expr
34 #define ASSERT_AND_RET_DBG(expr, string, ret, blk) if (!(expr)) return (ret)
36 #define ASSERT_AND_RET(expr, string, ret) \
38 if (opt_do_node_verification == NODE_VERIFICATION_ON) {\
39 if (!(expr)) dump_ir_block_graph(current_ir_graph, "-assert"); \
40 assert((expr) && string); } \
42 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) \
43 fprintf(stderr, #expr " : " string "\n"); \
44 bad_msg = #expr " && " string; \
49 #define ASSERT_AND_RET_DBG(expr, string, ret, blk) \
52 bad_msg = #expr " && " string; \
53 if (opt_do_node_verification != NODE_VERIFICATION_ERROR_ONLY) { blk; } \
54 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) \
55 fprintf(stderr, #expr " : " string "\n"); \
56 else if (opt_do_node_verification == NODE_VERIFICATION_ON) \
57 assert((expr) && string); \
64 /** if this flag is set, verify entity types in Load & Store nodes */
65 static int vrfy_entities = 0;
67 /* @@@ replace use of array "in" by access functions. */
68 ir_node **get_irn_in(ir_node *node);
70 static node_verification_t opt_do_node_verification = NODE_VERIFICATION_ON;
71 static const char *bad_msg;
73 /* enable verification of Load/Store entities */
74 void vrfy_enable_entity_tests(int enable)
76 vrfy_entities = enable;
80 * little helper for NULL modes
82 static const char *get_mode_name_ex(ir_mode *mode)
86 return get_mode_name(mode);
89 void do_node_verification(node_verification_t mode)
91 opt_do_node_verification = mode;
95 * Prints a failure for a Node
97 static void show_node_failure(ir_node *n)
99 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s\n" ,
101 get_irn_opname(n), get_irn_modename(n)
106 * Prints a failure message for a binop
108 static void show_binop_failure(ir_node *n, const char *text)
110 ir_node *left = get_binop_left(n);
111 ir_node *right = get_binop_right(n);
113 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s(%s%s, %s%s) did not match (%s)\n",
115 get_irn_opname(n), get_irn_modename(n),
116 get_irn_opname(left), get_irn_modename(left),
117 get_irn_opname(right), get_irn_modename(right),
122 * Prints a failure message for an unop
124 static void show_unop_failure(ir_node *n, const char *text)
126 ir_node *op = get_unop_op(n);
128 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s(%s%s) did not match (%s)\n",
130 get_irn_opname(n), get_irn_modename(n),
131 get_irn_opname(op), get_irn_modename(op),
136 * Prints a failure message for a proj
138 static void show_proj_failure(ir_node *n)
140 ir_node *op = get_Proj_pred(n);
141 int proj = get_Proj_proj(n);
143 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s %d(%s%s) failed\n" ,
145 get_irn_opname(n), get_irn_modename(n), proj,
146 get_irn_opname(op), get_irn_modename(op));
150 * Prints a failure message for a proj
152 static void show_proj_failure_ent(ir_node *n, entity *ent)
154 ir_node *op = get_Proj_pred(n);
155 int proj = get_Proj_proj(n);
156 ir_mode *m = get_type_mode(get_entity_type(ent));
158 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s %d(%s%s) entity %s(type %s mode %s)failed\n" ,
160 get_irn_opname(n), get_irn_modename(n), proj,
161 get_irn_opname(op), get_irn_modename(op),
162 get_entity_name(ent), get_type_name(get_entity_type(ent)),
163 get_mode_name_ex(m));
167 * Show a node and a graph
169 static void show_node_on_graph(ir_graph *irg, ir_node *n)
171 entity *ent = get_irg_entity(irg);
174 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of entity %s, node %ld %s%s\n",
175 get_entity_name(ent),
176 get_irn_node_nr(n), get_irn_opname(n), get_irn_modename(n));
178 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of graph %p, node %ld %s%s\n",
180 get_irn_node_nr(n), get_irn_opname(n), get_irn_modename(n));
186 static void show_call_param(ir_node *n, type *mt)
190 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Call type-check failed: %s(", get_type_name(mt));
191 for (i = 0; i < get_method_n_params(mt); ++i) {
192 fprintf(stderr, "%s ", get_mode_name_ex(get_type_mode(get_method_param_type(mt, i))));
194 fprintf(stderr, ") != CALL(");
196 for (i = 0; i < get_Call_n_params(n); ++i) {
197 fprintf(stderr, "%s ", get_mode_name_ex(get_irn_mode(get_Call_param(n, i))));
199 fprintf(stderr, ")\n");
206 static void show_return_modes(ir_graph *irg, ir_node *n, type *mt, int i)
208 entity *ent = get_irg_entity(irg);
210 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Return node %ld in entity \"%s\" mode %s different from type mode %s\n",
211 get_irn_node_nr(n), get_entity_name(ent),
212 get_mode_name_ex(get_irn_mode(get_Return_res(n, i))),
213 get_mode_name_ex(get_type_mode(get_method_res_type(mt, i)))
218 * Show return number of results
220 static void show_return_nres(ir_graph *irg, ir_node *n, type *mt)
222 entity *ent = get_irg_entity(irg);
224 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Return node %ld in entity \"%s\" has %d results different from type %d\n",
225 get_irn_node_nr(n), get_entity_name(ent),
226 get_Return_n_ress(n), get_method_n_ress(mt));
232 static void show_phi_failure(ir_node *phi, ir_node *pred, int pos)
234 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Phi node %ld has mode %s different from predeccessor node %ld mode %s\n",
235 get_irn_node_nr(phi), get_mode_name_ex(get_irn_mode(phi)),
236 get_irn_node_nr(pred), get_mode_name_ex(get_irn_mode(pred)));
242 static void show_phi_inputs(ir_node *phi, ir_node *block)
244 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Phi node %ld has %d inputs, its Block %ld has %d\n",
245 get_irn_node_nr(phi), get_irn_arity(phi),
246 get_irn_node_nr(block), get_irn_arity(block));
249 /* If the address is Sel or SymConst, return the entity. */
250 static entity *get_ptr_entity(ir_node *ptr) {
251 if (get_irn_op(ptr) == op_Sel) {
252 return get_Sel_entity(ptr);
253 } else if ((get_irn_op(ptr) == op_SymConst) && (get_SymConst_kind(ptr) == symconst_addr_ent)) {
254 return get_SymConst_entity(ptr);
260 * verify the Proj number
263 vrfy_Proj_proj(ir_node *p, ir_graph *irg) {
268 pred = skip_Id(get_Proj_pred(p));
269 ASSERT_AND_RET(get_irn_mode(pred) == mode_T, "mode of a 'projed' node is not Tuple", 0);
270 mode = get_irn_mode(p);
271 proj = get_Proj_proj(p);
273 switch (get_irn_opcode(pred)) {
277 (proj == pn_Start_X_initial_exec && mode == mode_X) ||
278 (proj == pn_Start_M && mode == mode_M) ||
279 (proj == pn_Start_P_frame_base && mode_is_reference(mode)) ||
280 (proj == pn_Start_P_globals && mode_is_reference(mode)) ||
281 (proj == pn_Start_T_args && mode == mode_T) ||
282 (proj == pn_Start_P_value_arg_base && mode_is_reference(mode)) ||
283 (proj == pn_Start_P_value_arg_base && mode == mode_T) /* FIXME: only one of those */
285 "wrong Proj from Start", 0,
286 show_proj_failure(p);
293 (proj >= 0 && mode == mode_X && get_irn_mode(get_Cond_selector(pred)) == mode_b) || /* compare */
294 (mode == mode_X && mode_is_int(get_irn_mode(get_Cond_selector(pred)))) /* switch */
296 "wrong Proj from Cond", 0,
297 show_proj_failure(p);
303 ((proj == pn_Raise_X && mode == mode_X) || (proj == pn_Raise_M && mode == mode_M)),
304 "wrong Proj from Raise", 0,
305 show_proj_failure(p);
311 (proj >= 0 && mode == mode_X),
312 "wrong Proj from InstOf", 0,
313 show_proj_failure(p);
319 ((proj == pn_Call_M_regular && mode == mode_M) ||
320 (proj == pn_Call_X_except && mode == mode_X) ||
321 (proj == pn_Call_T_result && mode == mode_T) ||
322 (proj == pn_Call_M_except && mode == mode_M) ||
323 (proj == pn_Call_P_value_res_base && mode == mode_P)),
324 "wrong Proj from Call", 0,
325 show_proj_failure(p);
331 ((proj == pn_Call_M_regular && mode == mode_M) ||
332 (proj == pn_Call_X_except && mode == mode_X) ||
333 (proj == pn_Call_T_result && mode == mode_T) ||
334 (proj == pn_Call_M_except && mode == mode_M) ||
335 (proj == pn_Call_P_value_res_base && mode == mode_P)),
336 "wrong Proj from FuncCall", 0,
337 show_proj_failure(p);
343 ((proj == pn_Quot_M && mode == mode_M) ||
344 (proj == pn_Quot_X_except && mode == mode_X) ||
345 (proj == pn_Quot_res && mode_is_float(mode))),
346 "wrong Proj from Quot", 0,
347 show_proj_failure(p);
353 ((proj == pn_DivMod_M && mode == mode_M) ||
354 (proj == pn_DivMod_X_except && mode == mode_X) ||
355 (proj == pn_DivMod_res_div && mode_is_int(mode)) ||
356 (proj == pn_DivMod_res_mod && mode_is_int(mode))),
357 "wrong Proj from DivMod", 0,
358 show_proj_failure(p);
364 ((proj == pn_Div_M && mode == mode_M) ||
365 (proj == pn_Div_X_except && mode == mode_X) ||
366 (proj == pn_Div_res && mode_is_int(mode))),
367 "wrong Proj from Div or Mod", 0,
368 show_proj_failure(p);
374 ((proj == pn_Mod_M && mode == mode_M) ||
375 (proj == pn_Mod_X_except && mode == mode_X) ||
376 (proj == pn_Mod_res && mode_is_int(mode))),
377 "wrong Proj from Div or Mod", 0,
378 show_proj_failure(p);
384 (proj >= 0 && proj <= 15 && mode == mode_b),
385 "wrong Proj from Cmp", 0,
386 show_proj_failure(p);
391 if (proj == pn_Load_res) {
392 ir_node *ptr = get_Load_ptr(pred);
393 entity *ent = get_ptr_entity(ptr);
394 if (vrfy_entities && ent && get_irg_phase_state(current_ir_graph) == phase_high) {
395 /* do NOT check this for lowered phases, see comment on Store */
397 (mode == get_type_mode(get_entity_type(ent))),
398 "wrong data Proj from Load, entity type_mode failed", 0,
399 show_proj_failure_ent(p, ent);
405 "wrong data Proj from Load", 0,
406 show_proj_failure(p);
411 ((proj == pn_Load_M && mode == mode_M) ||
412 (proj == pn_Load_X_except && mode == mode_X)),
413 "wrong Proj from Load", 0,
414 show_proj_failure(p);
421 ((proj == pn_Store_M && mode == mode_M) ||
422 (proj == pn_Store_X_except && mode == mode_X)),
423 "wrong Proj from Store", 0,
424 show_proj_failure(p);
431 (proj == pn_Alloc_M && mode == mode_M) ||
432 (proj == pn_Alloc_X_except /* && mode == mode_X*/) ||
433 (proj == pn_Alloc_res && mode_is_reference(mode))
435 "wrong Proj from Alloc", 0,
436 show_proj_failure(p);
442 type *mt; /* A method type */
443 long nr = get_Proj_proj(pred);
445 pred = skip_Id(get_Proj_pred(pred));
446 ASSERT_AND_RET((get_irn_mode(pred) == mode_T), "Proj from something not a tuple", 0);
447 switch (get_irn_opcode(pred))
450 mt = get_entity_type(get_irg_entity(irg));
452 if (nr == pn_Start_T_args) {
454 (proj >= 0 && mode_is_data(mode)),
455 "wrong Proj from Proj from Start", 0);
457 (proj < get_method_n_params(mt)),
458 "More Projs for args than args in type", 0
460 if ((mode_is_reference(mode)) && is_compound_type(get_method_param_type(mt, proj)))
461 /* value argument */ break;
464 (mode == get_type_mode(get_method_param_type(mt, proj))),
465 "Mode of Proj from Start doesn't match mode of param type.", 0);
467 else if (nr == pn_Start_P_value_arg_base) {
469 (proj >= 0 && mode_is_reference(mode)),
470 "wrong Proj from Proj from Start", 0
473 (proj < get_method_n_params(mt)),
474 "More Projs for args than args in type", 0
482 (proj >= 0 && mode_is_data(mode)),
483 "wrong Proj from Proj from Call", 0);
484 mt = get_Call_type(pred);
486 (proj < get_method_n_ress(mt)),
487 "More Projs for results than results in type.", 0);
488 if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
489 /* value result */ break;
492 (mode == get_type_mode(get_method_res_type(mt, proj))),
493 "Mode of Proj from Call doesn't match mode of result type.", 0);
500 (proj >= 0 && mode_is_data(mode)),
501 "wrong Proj from Proj from FuncCall", 0);
502 mt = get_FuncCall_type(pred);
504 (proj < get_method_n_ress(mt)),
505 "More Projs for results than results in type.", 0);
506 if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
507 /* value result */ break;
510 (mode == get_type_mode(get_method_res_type(mt, proj))),
511 "Mode of Proj from FuncCall doesn't match mode of result type.", 0);
520 ASSERT_AND_RET(0, "Unknown opcode", 0);
539 ASSERT_AND_RET(0, "Unknown opcode", 0);
546 int irn_vrfy_irg(ir_node *n, ir_graph *irg)
550 ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
551 int op_is_symmetric = 1; /* 0: asymmetric
552 1: operands have identical modes
553 2: modes of operands == mode of this node */
554 type *mt; /* A method type */
559 if (!opt_do_node_verification) return 1;
561 if (! interprocedural_view) {
563 * do NOT check placement in interprocedural view, as we don't always know
564 * the "right" graph ...
567 node_is_in_irgs_storage(irg, n),
568 "Node is not stored on proper IR graph!", 0,
569 show_node_on_graph(irg, n);
573 opcode = get_irn_opcode(n);
575 /* We don't want to test nodes whose predecessors are Bad,
576 as we would have to special case that for each operation. */
577 if (opcode != iro_Phi && opcode != iro_Block)
578 for (i = 0; i < get_irn_arity(n); i++) {
579 opcode1 = get_irn_opcode(get_irn_n(n, i));
580 if (opcode1 == iro_Bad)
584 mymode = get_irn_mode(n);
590 for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
591 ir_node *pred = get_Block_cfgpred(n, i);
595 (get_irn_mode(pred) == mode_X)
598 /* End block may only have Return, Raise or fragile ops as preds. */
599 if (n == get_irg_end_block(irg))
600 for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
601 ir_node *pred = skip_Proj(get_Block_cfgpred(n, i));
602 if (is_Proj(pred) || get_irn_op(pred) == op_Tuple)
603 break; /* We can not test properly. How many tuples are there? */
604 ASSERT_AND_RET(((get_irn_op(pred) == op_Return) ||
606 (get_irn_op(pred) == op_Raise) ||
607 is_fragile_op(pred) ),
608 "End Block node", 0);
610 /* irg attr must == graph we are in. */
611 if (! interprocedural_view) {
612 ASSERT_AND_RET(((get_irn_irg(n) && get_irn_irg(n) == irg)), "Block node has wrong irg attribute", 0);
619 /* Start: BB --> X x M x ref x data1 x ... x datan x ref */
620 mymode == mode_T, "Start node", 0
627 mymode == mode_X, "Jmp node", 0
634 mymode == mode_X, "Jmp node", 0
639 op1mode = get_irn_mode(in[1]);
641 /* Cond: BB x b --> X x X */
642 (op1mode == mode_b ||
643 /* Cond: BB x int --> X^n */
644 mode_is_int(op1mode) ), "Cond node", 0
646 ASSERT_AND_RET(mymode == mode_T, "Cond mode is not a tuple", 0);
650 op1mode = get_irn_mode(in[1]);
651 /* Return: BB x M x data1 x ... x datan --> X */
652 /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
653 ASSERT_AND_RET( op1mode == mode_M, "Return node", 0 ); /* operand M */
654 for (i = 2; i < get_irn_arity(n); i++) {
655 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Return node", 0 ); /* operand datai */
657 ASSERT_AND_RET( mymode == mode_X, "Result X", 0 ); /* result X */
658 /* Compare returned results with result types of method type */
659 mt = get_entity_type(get_irg_entity(irg));
660 ASSERT_AND_RET_DBG( get_Return_n_ress(n) == get_method_n_ress(mt),
661 "Number of results for Return doesn't match number of results in type.", 0,
662 show_return_nres(irg, n, mt););
663 for (i = 0; i < get_Return_n_ress(n); i++) {
664 type *res_type = get_method_res_type(mt, i);
666 if (is_atomic_type(res_type)) {
668 get_irn_mode(get_Return_res(n, i)) == get_type_mode(res_type),
669 "Mode of result for Return doesn't match mode of result type.", 0,
670 show_return_modes(irg, n, mt, i);
675 mode_is_reference(get_irn_mode(get_Return_res(n, i))),
676 "Mode of result for Return doesn't match mode of result type.", 0,
677 show_return_modes(irg, n, mt, i);
684 op1mode = get_irn_mode(in[1]);
685 op2mode = get_irn_mode(in[2]);
687 /* Sel: BB x M x ref --> X x M */
688 op1mode == mode_M && mode_is_reference(op2mode) &&
689 mymode == mode_T, "Raise node", 0
695 /* Const: BB --> data */
696 (mode_is_data (mymode) ||
697 mymode == mode_b) /* we want boolean constants for static evaluation */
698 ,"Const node", 0 /* of Cmp. */
702 if (get_SymConst_kind(n) == symconst_addr_ent) {
703 entity *ent = get_SymConst_entity(n);
704 if (is_method_type(get_entity_type(ent)) &&
705 get_irn_irg(n) != get_const_code_irg()) {
707 ASSERT_AND_RET((get_entity_peculiarity(ent) != peculiarity_description),
708 "A constant must address an existing method.", 0);
713 /* SymConst: BB --> int*/
714 (mode_is_int(mymode) ||
715 /* SymConst: BB --> ref */
716 mode_is_reference(mymode))
717 ,"SymConst node", 0);
721 op1mode = get_irn_mode(in[1]);
722 op2mode = get_irn_mode(in[2]);
724 /* Sel: BB x M x ref x int^n --> ref */
725 (op1mode == mode_M && op2mode == mymode && mode_is_reference(mymode)),
726 "Sel node", 0, show_node_failure(n)
728 for (i=3; i < get_irn_arity(n); i++)
730 ASSERT_AND_RET_DBG(mode_is_int(get_irn_mode(in[i])), "Sel node", 0, show_node_failure(n));
732 ent = get_Sel_entity(n);
733 ASSERT_AND_RET_DBG(ent, "Sel node with empty entity", 0, show_node_failure(n));
737 ASSERT_AND_RET(mode_T == mymode, "mode of Instof is not a tuple", 0);
738 ASSERT_AND_RET(mode_is_data(op1mode), "Instof not on data", 0);
742 op1mode = get_irn_mode(in[1]);
743 op2mode = get_irn_mode(in[2]);
744 /* Call: BB x M x ref x data1 x ... x datan
745 --> M x datan+1 x ... x data n+m */
746 ASSERT_AND_RET( op1mode == mode_M && mode_is_reference(op2mode), "Call node", 0 ); /* operand M x ref */
747 for (i=3; i < get_irn_arity(n); i++) {
748 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Call node", 0 ); /* operand datai */
750 ASSERT_AND_RET( mymode == mode_T, "Call result not a tuple", 0 ); /* result T */
751 /* Compare arguments of node with those of type */
752 mt = get_Call_type(n);
754 if (get_method_variadicity(mt) == variadicity_variadic) {
756 get_Call_n_params(n) >= get_method_n_params(mt),
757 "Number of args for Call doesn't match number of args in variadic type.",
759 fprintf(stderr, "Call has %d params, method %s type %d\n",
760 get_Call_n_params(n), get_type_name(mt), get_method_n_params(mt));
765 get_Call_n_params(n) == get_method_n_params(mt),
766 "Number of args for Call doesn't match number of args in non variadic type.",
770 for (i = 0; i < get_method_n_params(mt); i++) {
771 type *t = get_method_param_type(mt, i);
773 if (is_atomic_type(t)) {
775 get_irn_mode(get_Call_param(n, i)) == get_type_mode(t),
776 "Mode of arg for Call doesn't match mode of arg type.", 0,
777 show_call_param(n, mt);
781 /* call with a compound type, mode must be reference */
783 mode_is_reference(get_irn_mode(get_Call_param(n, i))),
784 "Mode of arg for Call doesn't match mode of arg type.", 0,
785 show_call_param(n, mt);
792 op1mode = get_irn_mode(in[1]);
793 op2mode = get_irn_mode(in[2]);
796 /* common Add: BB x numP x numP --> numP */
797 (op1mode == mymode && op2mode == op1mode && mode_is_numP(mymode)) ||
798 /* Pointer Add: BB x ref x int --> ref */
799 (mode_is_reference(op1mode) && mode_is_int(op2mode) && op1mode == mymode) ||
800 /* Pointer Add: BB x int x ref --> ref */
801 (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode))
804 show_binop_failure(n, "/* common Add: BB x numP x numP --> numP */ |\n"
805 "/* Pointer Add: BB x ref x int --> ref */ |\n"
806 "/* Pointer Add: BB x int x ref --> ref */");
808 if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
809 /* BB x ref x int --> ref or BB x int x ref --> ref */
812 /* BB x num x num --> num or BB x ref x ref */
818 op1mode = get_irn_mode(in[1]);
819 op2mode = get_irn_mode(in[2]);
821 /* common Sub: BB x numP x numP --> numP */
822 ((mymode ==op1mode && mymode == op2mode && mode_is_numP(op1mode)) ||
823 /* Pointer Sub: BB x ref x int --> ref */
824 (op1mode == mymode && mode_is_int(op2mode) && mode_is_reference(mymode)) ||
825 /* Pointer Sub: BB x int x ref --> ref */
826 (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode)) ||
827 /* Pointer Sub: BB x ref x ref --> int */
828 (op1mode == op2mode && mode_is_reference(op2mode) && mode_is_int(mymode))),
830 show_binop_failure(n, "/* common Sub: BB x numP x numP --> numP */ |\n"
831 "/* Pointer Sub: BB x ref x int --> ref */ |\n"
832 "/* Pointer Sub: BB x int x ref --> ref */ |\n"
833 "/* Pointer Sub: BB x ref x ref --> int */" );
835 if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
843 op1mode = get_irn_mode(in[1]);
845 /* Minus: BB x float --> float */
846 op1mode == mymode && mode_is_float(op1mode), "Minus node", 0,
847 show_unop_failure(n , "/* Minus: BB x float --> float */");
853 op1mode = get_irn_mode(in[1]);
854 op2mode = get_irn_mode(in[2]);
856 /* Mul: BB x int1 x int1 --> int2 */
857 ((mode_is_int(op1mode) && op2mode == op1mode && mode_is_int(mymode)) ||
858 /* Mul: BB x float x float --> float */
859 (mode_is_float(op1mode) && op2mode == op1mode && mymode == op1mode)),
861 show_binop_failure(n, "/* Mul: BB x int1 x int1 --> int2 */ |\n"
862 "/* Mul: BB x float x float --> float */");
868 op1mode = get_irn_mode(in[1]);
869 op2mode = get_irn_mode(in[2]);
870 op3mode = get_irn_mode(in[3]);
872 /* Quot: BB x M x float x float --> M x X x float */
873 op1mode == mode_M && op2mode == op3mode &&
874 get_mode_sort(op2mode) == irms_float_number &&
877 show_binop_failure(n, "/* Quot: BB x M x float x float --> M x X x float */");
883 op1mode = get_irn_mode(in[1]);
884 op2mode = get_irn_mode(in[2]);
885 op3mode = get_irn_mode(in[3]);
887 /* DivMod: BB x M x int x int --> M x X x int x int */
889 mode_is_int(op2mode) &&
890 op3mode == op2mode &&
899 op1mode = get_irn_mode(in[1]);
900 op2mode = get_irn_mode(in[2]);
901 op3mode = get_irn_mode(in[3]);
903 /* Div or Mod: BB x M x int x int --> M x X x int */
905 op2mode == op3mode &&
906 mode_is_int(op2mode) &&
914 op1mode = get_irn_mode(in[1]);
916 /* Abs: BB x num --> num */
918 mode_is_num (op1mode),
920 show_unop_failure(n, "/* Abs: BB x num --> num */");
928 op1mode = get_irn_mode(in[1]);
929 op2mode = get_irn_mode(in[2]);
931 /* And or Or or Eor: BB x int x int --> int */
932 mode_is_int(mymode) &&
933 op2mode == op1mode &&
935 "And, Or or Eor node", 0,
936 show_binop_failure(n, "/* And or Or or Eor: BB x int x int --> int */");
942 op1mode = get_irn_mode(in[1]);
944 /* Not: BB x int --> int */
945 mode_is_int(mymode) &&
948 show_unop_failure(n, "/* Not: BB x int --> int */");
955 op1mode = get_irn_mode(in[1]);
956 op2mode = get_irn_mode(in[2]);
958 /* Cmp: BB x datab x datab --> b16 */
959 mode_is_data (op1mode) &&
960 op2mode == op1mode &&
963 show_binop_failure(n, "/* Cmp: BB x datab x datab --> b16 */");
970 op1mode = get_irn_mode(in[1]);
971 op2mode = get_irn_mode(in[2]);
973 /* Shl, Shr or Shrs: BB x int x int_u --> int */
974 mode_is_int(op1mode) &&
975 mode_is_int(op2mode) &&
976 !mode_is_signed(op2mode) &&
978 "Shl, Shr, Shr or Rot node", 0,
979 show_binop_failure(n, "/* Shl, Shr or Shrs: BB x int x int_u --> int */");
984 op1mode = get_irn_mode(in[1]);
985 op2mode = get_irn_mode(in[2]);
987 /* Rot: BB x int x int --> int */
988 mode_is_int(op1mode) &&
989 mode_is_int(op2mode) &&
992 show_binop_failure(n, "/* Rot: BB x int x int --> int */");
997 op1mode = get_irn_mode(in[1]);
999 /* Conv: BB x datab1 --> datab2 */
1000 mode_is_datab(op1mode) && mode_is_data(mymode),
1002 show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1007 op1mode = get_irn_mode(in[1]);
1009 /* Conv: BB x datab1 --> datab2 */
1010 mode_is_data(op1mode) && op1mode == mymode,
1012 show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1018 ir_node *block = get_nodes_block(n);
1020 if (! is_Bad(block) && get_irg_phase_state(get_irn_irg(n)) != phase_building) {
1021 /* a Phi node MUST have the same number of inputs as its block */
1023 get_irn_arity(n) == get_irn_arity(block),
1024 "wrong number of inputs in Phi node", 0,
1025 show_phi_inputs(n, block);
1029 /* Phi: BB x dataM^n --> dataM */
1030 for (i = 1; i < get_irn_arity(n); i++) {
1031 if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
1033 get_irn_mode(in[i]) == mymode,
1035 show_phi_failure(n, in[i], i);
1038 ASSERT_AND_RET( mode_is_dataM(mymode), "Phi node", 0 );
1042 op1mode = get_irn_mode(in[1]);
1043 op2mode = get_irn_mode(in[2]);
1045 /* Load: BB x M x ref --> M x X x data */
1046 op1mode == mode_M && mode_is_reference(op2mode),
1049 ASSERT_AND_RET( mymode == mode_T, "Load node", 0 );
1052 * jack's gen_add_firm_code:simpleSel seems to build Load (Load
1053 * (Proj (Proj))) sometimes ...
1055 * interprete.c:ai_eval seems to assume that this happens, too
1057 * obset.c:get_abstval_any can't deal with this if the load has
1061 entity *ent = hunt_for_entity (get_Load_ptr (n), n);
1062 assert ((NULL != ent) || (mymode != mode_T));
1069 op1mode = get_irn_mode(in[1]);
1070 op2mode = get_irn_mode(in[2]);
1071 op3mode = get_irn_mode(in[3]);
1073 /* Load: BB x M x ref data --> M x X */
1074 op1mode == mode_M && mode_is_reference(op2mode) && mode_is_data(op3mode),
1077 ASSERT_AND_RET(mymode == mode_T, "Store node", 0);
1079 entity *target = get_ptr_entity(in[2]);
1080 if (vrfy_entities && target && get_irg_phase_state(current_ir_graph) == phase_high) {
1082 * If lowered code, any Sels that add 0 may be removed, causing
1083 * an direct access to entities of array or compound type.
1084 * Prevent this by checking the phase.
1086 ASSERT_AND_RET( op3mode == get_type_mode(get_entity_type(target)),
1093 op1mode = get_irn_mode(in[1]);
1094 op2mode = get_irn_mode(in[2]);
1096 /* Alloc: BB x M x int_u --> M x X x ref */
1097 op1mode == mode_M &&
1098 mode_is_int(op2mode) &&
1099 !mode_is_signed(op2mode) &&
1102 show_binop_failure(n, "/* Alloc: BB x M x int_u --> M x X x ref */");
1107 op1mode = get_irn_mode(in[1]);
1108 op2mode = get_irn_mode(in[2]);
1110 /* Free: BB x M x ref --> M */
1111 op1mode == mode_M && mode_is_reference(op2mode) &&
1114 show_binop_failure(n, "/* Free: BB x M x ref --> M */");
1119 /* Sync: BB x M^n --> M */
1120 for (i=1; i < get_irn_arity(n); i++) {
1121 ASSERT_AND_RET( get_irn_mode(in[i]) == mode_M, "Sync node", 0 );
1123 ASSERT_AND_RET( mymode == mode_M, "Sync node", 0 );
1127 return vrfy_Proj_proj(n, irg);
1131 op1mode = get_irn_mode(in[1]);
1132 op2mode = get_irn_mode(in[2]);
1134 /* Confirm: BB x T x T --> T */
1135 op1mode == mymode &&
1138 show_binop_failure(n, "/* Confirm: BB x T x T --> T */");
1150 int irn_vrfy(ir_node *n)
1153 #ifdef DEBUG_libfirm
1154 res = irn_vrfy_irg(n, current_ir_graph);
1159 /*-----------------------------------------------------------------*/
1160 /* Verify the whole graph. */
1161 /*-----------------------------------------------------------------*/
1163 /* This *is* used, except gcc doesn't notice that */
1164 static void vrfy_wrap(ir_node *node, void *env)
1168 *res = irn_vrfy(node);
1171 int irg_vrfy(ir_graph *irg)
1174 #ifdef DEBUG_libfirm
1177 rem = current_ir_graph;
1178 current_ir_graph = irg;
1180 assert(get_irg_pinned(irg) == op_pin_state_pinned);
1182 irg_walk_graph(irg, vrfy_wrap, NULL, &res);
1184 current_ir_graph = rem;
1186 if (opt_do_node_verification == NODE_VERIFICATION_REPORT && ! res) {
1187 entity *ent = get_irg_entity(current_ir_graph);
1190 fprintf(stderr, "irg_verify: Verifying graph %s failed\n", get_entity_name(ent));
1192 fprintf(stderr, "irg_verify: Verifying graph %p failed\n", (void *)current_ir_graph);
1199 int irn_vrfy_irg_dump(ir_node *n, ir_graph *irg, const char **bad_string)
1202 node_verification_t old = opt_do_node_verification;
1205 opt_do_node_verification = NODE_VERIFICATION_ERROR_ONLY;
1206 res = irn_vrfy_irg(n, irg);
1207 opt_do_node_verification = old;
1208 *bad_string = bad_msg;
1214 typedef struct _vrfy_bad_env_t {
1219 static void check_bads(ir_node *node, void *env)
1221 vrfy_bad_env_t *venv = env;
1222 int i, arity = get_irn_arity(node);
1224 if (is_Block(node)) {
1225 if ((venv->flags & BAD_CF) == 0) {
1227 /* check for Bad Block predecessor */
1228 for (i = 0; i < arity; ++i) {
1229 ir_node *pred = get_irn_n(node, i);
1232 venv->res |= BAD_CF;
1234 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1235 fprintf(stderr, "irg_vrfy_bads: Block %ld has Bad predecessor\n", get_irn_node_nr(node));
1237 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1238 assert(0 && "Bad CF detected");
1245 if ((venv->flags & BAD_BLOCK) == 0) {
1247 /* check for Bad Block */
1248 if (is_Bad(get_nodes_block(node))) {
1249 venv->res |= BAD_BLOCK;
1251 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1252 fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Block\n", get_irn_node_nr(node));
1254 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1255 assert(0 && "Bad CF detected");
1260 if ((venv->flags & TUPLE) == 0) {
1261 if (get_irn_op(node) == op_Tuple) {
1264 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1265 fprintf(stderr, "irg_vrfy_bads: node %ld is a Tuple\n", get_irn_node_nr(node));
1267 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1268 assert(0 && "Tuple detected");
1273 for (i = 0; i < arity; ++i) {
1274 ir_node *pred = get_irn_n(node, i);
1277 /* check for Phi with Bad inputs */
1278 if (is_Phi(node) && !is_Bad(get_nodes_block(node)) && is_Bad(get_irn_n(get_nodes_block(node), i))) {
1279 if (venv->flags & BAD_CF)
1282 venv->res |= BAD_CF;
1284 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1285 fprintf(stderr, "irg_vrfy_bads: Phi %ld has Bad Input\n", get_irn_node_nr(node));
1287 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1288 assert(0 && "Bad CF detected");
1293 /* Bad node input */
1294 if ((venv->flags & BAD_DF) == 0) {
1295 venv->res |= BAD_DF;
1297 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1298 fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Input\n", get_irn_node_nr(node));
1300 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1301 assert(0 && "Bad NON-CF detected");
1310 * verify occurance of bad nodes
1312 int irg_vrfy_bads(ir_graph *irg, int flags)
1319 irg_walk_graph(irg, check_bads, NULL, &env);