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);
395 if (vrfy_entities && ent && get_irg_phase_state(current_ir_graph) == phase_high) {
396 /* do NOT check this for lowered phases, see comment on Store */
398 (mode == get_type_mode(get_entity_type(ent))),
399 "wrong data Proj from Load, entity type_mode failed", 0,
400 show_proj_failure_ent(p, ent);
405 mode_is_data(mode) && mode == get_Load_mode(pred),
406 "wrong data Proj from Load", 0,
407 show_proj_failure(p);
412 ((proj == pn_Load_M && mode == mode_M) ||
413 (proj == pn_Load_X_except && mode == mode_X)),
414 "wrong Proj from Load", 0,
415 show_proj_failure(p);
422 ((proj == pn_Store_M && mode == mode_M) ||
423 (proj == pn_Store_X_except && mode == mode_X)),
424 "wrong Proj from Store", 0,
425 show_proj_failure(p);
432 (proj == pn_Alloc_M && mode == mode_M) ||
433 (proj == pn_Alloc_X_except /* && mode == mode_X*/) ||
434 (proj == pn_Alloc_res && mode_is_reference(mode))
436 "wrong Proj from Alloc", 0,
437 show_proj_failure(p);
443 type *mt; /* A method type */
444 long nr = get_Proj_proj(pred);
446 pred = skip_Id(get_Proj_pred(pred));
447 ASSERT_AND_RET((get_irn_mode(pred) == mode_T), "Proj from something not a tuple", 0);
448 switch (get_irn_opcode(pred))
451 mt = get_entity_type(get_irg_entity(irg));
453 if (nr == pn_Start_T_args) {
455 (proj >= 0 && mode_is_data(mode)),
456 "wrong Proj from Proj from Start", 0);
458 (proj < get_method_n_params(mt)),
459 "More Projs for args than args in type", 0
461 if ((mode_is_reference(mode)) && is_compound_type(get_method_param_type(mt, proj)))
462 /* value argument */ break;
465 (mode == get_type_mode(get_method_param_type(mt, proj))),
466 "Mode of Proj from Start doesn't match mode of param type.", 0);
468 else if (nr == pn_Start_P_value_arg_base) {
470 (proj >= 0 && mode_is_reference(mode)),
471 "wrong Proj from Proj from Start", 0
474 (proj < get_method_n_params(mt)),
475 "More Projs for args than args in type", 0
483 (proj >= 0 && mode_is_data(mode)),
484 "wrong Proj from Proj from Call", 0);
485 mt = get_Call_type(pred);
487 (proj < get_method_n_ress(mt)),
488 "More Projs for results than results in type.", 0);
489 if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
490 /* value result */ break;
493 (mode == get_type_mode(get_method_res_type(mt, proj))),
494 "Mode of Proj from Call doesn't match mode of result type.", 0);
501 (proj >= 0 && mode_is_data(mode)),
502 "wrong Proj from Proj from FuncCall", 0);
503 mt = get_FuncCall_type(pred);
505 (proj < get_method_n_ress(mt)),
506 "More Projs for results than results in type.", 0);
507 if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
508 /* value result */ break;
511 (mode == get_type_mode(get_method_res_type(mt, proj))),
512 "Mode of Proj from FuncCall doesn't match mode of result type.", 0);
521 ASSERT_AND_RET(0, "Unknown opcode", 0);
540 ASSERT_AND_RET(0, "Unknown opcode", 0);
547 int irn_vrfy_irg(ir_node *n, ir_graph *irg)
551 ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
552 int op_is_symmetric = 1; /* 0: asymmetric
553 1: operands have identical modes
554 2: modes of operands == mode of this node */
555 type *mt; /* A method type */
560 if (!opt_do_node_verification) return 1;
562 if (! interprocedural_view) {
564 * do NOT check placement in interprocedural view, as we don't always know
565 * the "right" graph ...
568 node_is_in_irgs_storage(irg, n),
569 "Node is not stored on proper IR graph!", 0,
570 show_node_on_graph(irg, n);
574 opcode = get_irn_opcode(n);
576 /* We don't want to test nodes whose predecessors are Bad,
577 as we would have to special case that for each operation. */
578 if (opcode != iro_Phi && opcode != iro_Block)
579 for (i = 0; i < get_irn_arity(n); i++) {
580 opcode1 = get_irn_opcode(get_irn_n(n, i));
581 if (opcode1 == iro_Bad)
585 mymode = get_irn_mode(n);
591 for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
592 ir_node *pred = get_Block_cfgpred(n, i);
596 (get_irn_mode(pred) == mode_X)
599 /* End block may only have Return, Raise or fragile ops as preds. */
600 if (n == get_irg_end_block(irg))
601 for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
602 ir_node *pred = skip_Proj(get_Block_cfgpred(n, i));
603 if (is_Proj(pred) || get_irn_op(pred) == op_Tuple)
604 break; /* We can not test properly. How many tuples are there? */
605 ASSERT_AND_RET(((get_irn_op(pred) == op_Return) ||
607 (get_irn_op(pred) == op_Raise) ||
608 is_fragile_op(pred) ),
609 "End Block node", 0);
611 /* irg attr must == graph we are in. */
612 if (! interprocedural_view) {
613 ASSERT_AND_RET(((get_irn_irg(n) && get_irn_irg(n) == irg)), "Block node has wrong irg attribute", 0);
620 /* Start: BB --> X x M x ref x data1 x ... x datan x ref */
621 mymode == mode_T, "Start node", 0
628 mymode == mode_X, "Jmp node", 0
635 mymode == mode_X, "Jmp node", 0
640 op1mode = get_irn_mode(in[1]);
642 /* Cond: BB x b --> X x X */
643 (op1mode == mode_b ||
644 /* Cond: BB x int --> X^n */
645 mode_is_int(op1mode) ), "Cond node", 0
647 ASSERT_AND_RET(mymode == mode_T, "Cond mode is not a tuple", 0);
651 op1mode = get_irn_mode(in[1]);
652 /* Return: BB x M x data1 x ... x datan --> X */
653 /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
654 ASSERT_AND_RET( op1mode == mode_M, "Return node", 0 ); /* operand M */
655 for (i = 2; i < get_irn_arity(n); i++) {
656 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Return node", 0 ); /* operand datai */
658 ASSERT_AND_RET( mymode == mode_X, "Result X", 0 ); /* result X */
659 /* Compare returned results with result types of method type */
660 mt = get_entity_type(get_irg_entity(irg));
661 ASSERT_AND_RET_DBG( get_Return_n_ress(n) == get_method_n_ress(mt),
662 "Number of results for Return doesn't match number of results in type.", 0,
663 show_return_nres(irg, n, mt););
664 for (i = 0; i < get_Return_n_ress(n); i++) {
665 type *res_type = get_method_res_type(mt, i);
667 if (is_atomic_type(res_type)) {
669 get_irn_mode(get_Return_res(n, i)) == get_type_mode(res_type),
670 "Mode of result for Return doesn't match mode of result type.", 0,
671 show_return_modes(irg, n, mt, i);
676 mode_is_reference(get_irn_mode(get_Return_res(n, i))),
677 "Mode of result for Return doesn't match mode of result type.", 0,
678 show_return_modes(irg, n, mt, i);
685 op1mode = get_irn_mode(in[1]);
686 op2mode = get_irn_mode(in[2]);
688 /* Sel: BB x M x ref --> X x M */
689 op1mode == mode_M && mode_is_reference(op2mode) &&
690 mymode == mode_T, "Raise node", 0
696 /* Const: BB --> data */
697 (mode_is_data (mymode) ||
698 mymode == mode_b) /* we want boolean constants for static evaluation */
699 ,"Const node", 0 /* of Cmp. */
703 if (get_SymConst_kind(n) == symconst_addr_ent) {
704 entity *ent = get_SymConst_entity(n);
705 if (is_method_type(get_entity_type(ent)) &&
706 get_irn_irg(n) != get_const_code_irg()) {
708 ASSERT_AND_RET((get_entity_peculiarity(ent) != peculiarity_description),
709 "A constant must address an existing method.", 0);
714 /* SymConst: BB --> int*/
715 (mode_is_int(mymode) ||
716 /* SymConst: BB --> ref */
717 mode_is_reference(mymode))
718 ,"SymConst node", 0);
722 op1mode = get_irn_mode(in[1]);
723 op2mode = get_irn_mode(in[2]);
725 /* Sel: BB x M x ref x int^n --> ref */
726 (op1mode == mode_M && op2mode == mymode && mode_is_reference(mymode)),
727 "Sel node", 0, show_node_failure(n)
729 for (i=3; i < get_irn_arity(n); i++)
731 ASSERT_AND_RET_DBG(mode_is_int(get_irn_mode(in[i])), "Sel node", 0, show_node_failure(n));
733 ent = get_Sel_entity(n);
734 ASSERT_AND_RET_DBG(ent, "Sel node with empty entity", 0, show_node_failure(n));
738 ASSERT_AND_RET(mode_T == mymode, "mode of Instof is not a tuple", 0);
739 ASSERT_AND_RET(mode_is_data(op1mode), "Instof not on data", 0);
743 op1mode = get_irn_mode(in[1]);
744 op2mode = get_irn_mode(in[2]);
745 /* Call: BB x M x ref x data1 x ... x datan
746 --> M x datan+1 x ... x data n+m */
747 ASSERT_AND_RET( op1mode == mode_M && mode_is_reference(op2mode), "Call node", 0 ); /* operand M x ref */
748 for (i=3; i < get_irn_arity(n); i++) {
749 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Call node", 0 ); /* operand datai */
751 ASSERT_AND_RET( mymode == mode_T, "Call result not a tuple", 0 ); /* result T */
752 /* Compare arguments of node with those of type */
753 mt = get_Call_type(n);
755 if (get_method_variadicity(mt) == variadicity_variadic) {
757 get_Call_n_params(n) >= get_method_n_params(mt),
758 "Number of args for Call doesn't match number of args in variadic type.",
760 fprintf(stderr, "Call has %d params, method %s type %d\n",
761 get_Call_n_params(n), get_type_name(mt), get_method_n_params(mt));
766 get_Call_n_params(n) == get_method_n_params(mt),
767 "Number of args for Call doesn't match number of args in non variadic type.",
771 for (i = 0; i < get_method_n_params(mt); i++) {
772 type *t = get_method_param_type(mt, i);
774 if (is_atomic_type(t)) {
776 get_irn_mode(get_Call_param(n, i)) == get_type_mode(t),
777 "Mode of arg for Call doesn't match mode of arg type.", 0,
778 show_call_param(n, mt);
782 /* call with a compound type, mode must be reference */
784 mode_is_reference(get_irn_mode(get_Call_param(n, i))),
785 "Mode of arg for Call doesn't match mode of arg type.", 0,
786 show_call_param(n, mt);
793 op1mode = get_irn_mode(in[1]);
794 op2mode = get_irn_mode(in[2]);
797 /* common Add: BB x numP x numP --> numP */
798 (op1mode == mymode && op2mode == op1mode && mode_is_numP(mymode)) ||
799 /* Pointer Add: BB x ref x int --> ref */
800 (mode_is_reference(op1mode) && mode_is_int(op2mode) && op1mode == mymode) ||
801 /* Pointer Add: BB x int x ref --> ref */
802 (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode))
805 show_binop_failure(n, "/* common Add: BB x numP x numP --> numP */ |\n"
806 "/* Pointer Add: BB x ref x int --> ref */ |\n"
807 "/* Pointer Add: BB x int x ref --> ref */");
809 if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
810 /* BB x ref x int --> ref or BB x int x ref --> ref */
813 /* BB x num x num --> num or BB x ref x ref */
819 op1mode = get_irn_mode(in[1]);
820 op2mode = get_irn_mode(in[2]);
822 /* common Sub: BB x numP x numP --> numP */
823 ((mymode ==op1mode && mymode == op2mode && mode_is_numP(op1mode)) ||
824 /* Pointer Sub: BB x ref x int --> ref */
825 (op1mode == mymode && mode_is_int(op2mode) && mode_is_reference(mymode)) ||
826 /* Pointer Sub: BB x int x ref --> ref */
827 (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode)) ||
828 /* Pointer Sub: BB x ref x ref --> int */
829 (op1mode == op2mode && mode_is_reference(op2mode) && mode_is_int(mymode))),
831 show_binop_failure(n, "/* common Sub: BB x numP x numP --> numP */ |\n"
832 "/* Pointer Sub: BB x ref x int --> ref */ |\n"
833 "/* Pointer Sub: BB x int x ref --> ref */ |\n"
834 "/* Pointer Sub: BB x ref x ref --> int */" );
836 if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
844 op1mode = get_irn_mode(in[1]);
846 /* Minus: BB x float --> float */
847 op1mode == mymode && mode_is_float(op1mode), "Minus node", 0,
848 show_unop_failure(n , "/* Minus: BB x float --> float */");
854 op1mode = get_irn_mode(in[1]);
855 op2mode = get_irn_mode(in[2]);
857 /* Mul: BB x int1 x int1 --> int2 */
858 ((mode_is_int(op1mode) && op2mode == op1mode && mode_is_int(mymode)) ||
859 /* Mul: BB x float x float --> float */
860 (mode_is_float(op1mode) && op2mode == op1mode && mymode == op1mode)),
862 show_binop_failure(n, "/* Mul: BB x int1 x int1 --> int2 */ |\n"
863 "/* Mul: BB x float x float --> float */");
869 op1mode = get_irn_mode(in[1]);
870 op2mode = get_irn_mode(in[2]);
871 op3mode = get_irn_mode(in[3]);
873 /* Quot: BB x M x float x float --> M x X x float */
874 op1mode == mode_M && op2mode == op3mode &&
875 get_mode_sort(op2mode) == irms_float_number &&
878 show_binop_failure(n, "/* Quot: BB x M x float x float --> M x X x float */");
884 op1mode = get_irn_mode(in[1]);
885 op2mode = get_irn_mode(in[2]);
886 op3mode = get_irn_mode(in[3]);
888 /* DivMod: BB x M x int x int --> M x X x int x int */
890 mode_is_int(op2mode) &&
891 op3mode == op2mode &&
900 op1mode = get_irn_mode(in[1]);
901 op2mode = get_irn_mode(in[2]);
902 op3mode = get_irn_mode(in[3]);
904 /* Div or Mod: BB x M x int x int --> M x X x int */
906 op2mode == op3mode &&
907 mode_is_int(op2mode) &&
915 op1mode = get_irn_mode(in[1]);
917 /* Abs: BB x num --> num */
919 mode_is_num (op1mode),
921 show_unop_failure(n, "/* Abs: BB x num --> num */");
929 op1mode = get_irn_mode(in[1]);
930 op2mode = get_irn_mode(in[2]);
932 /* And or Or or Eor: BB x int x int --> int */
933 mode_is_int(mymode) &&
934 op2mode == op1mode &&
936 "And, Or or Eor node", 0,
937 show_binop_failure(n, "/* And or Or or Eor: BB x int x int --> int */");
943 op1mode = get_irn_mode(in[1]);
945 /* Not: BB x int --> int */
946 mode_is_int(mymode) &&
949 show_unop_failure(n, "/* Not: BB x int --> int */");
956 op1mode = get_irn_mode(in[1]);
957 op2mode = get_irn_mode(in[2]);
959 /* Cmp: BB x datab x datab --> b16 */
960 mode_is_data (op1mode) &&
961 op2mode == op1mode &&
964 show_binop_failure(n, "/* Cmp: BB x datab x datab --> b16 */");
971 op1mode = get_irn_mode(in[1]);
972 op2mode = get_irn_mode(in[2]);
974 /* Shl, Shr or Shrs: BB x int x int_u --> int */
975 mode_is_int(op1mode) &&
976 mode_is_int(op2mode) &&
977 !mode_is_signed(op2mode) &&
979 "Shl, Shr, Shr or Rot node", 0,
980 show_binop_failure(n, "/* Shl, Shr or Shrs: BB x int x int_u --> int */");
985 op1mode = get_irn_mode(in[1]);
986 op2mode = get_irn_mode(in[2]);
988 /* Rot: BB x int x int --> int */
989 mode_is_int(op1mode) &&
990 mode_is_int(op2mode) &&
993 show_binop_failure(n, "/* Rot: BB x int x int --> int */");
998 op1mode = get_irn_mode(in[1]);
1000 /* Conv: BB x datab1 --> datab2 */
1001 mode_is_datab(op1mode) && mode_is_data(mymode),
1003 show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1008 op1mode = get_irn_mode(in[1]);
1010 /* Conv: BB x datab1 --> datab2 */
1011 mode_is_data(op1mode) && op1mode == mymode,
1013 show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1019 ir_node *block = get_nodes_block(n);
1021 if (! is_Bad(block) && get_irg_phase_state(get_irn_irg(n)) != phase_building) {
1022 /* a Phi node MUST have the same number of inputs as its block */
1024 get_irn_arity(n) == get_irn_arity(block),
1025 "wrong number of inputs in Phi node", 0,
1026 show_phi_inputs(n, block);
1030 /* Phi: BB x dataM^n --> dataM */
1031 for (i = 1; i < get_irn_arity(n); i++) {
1032 if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
1034 get_irn_mode(in[i]) == mymode,
1036 show_phi_failure(n, in[i], i);
1039 ASSERT_AND_RET( mode_is_dataM(mymode), "Phi node", 0 );
1043 op1mode = get_irn_mode(in[1]);
1044 op2mode = get_irn_mode(in[2]);
1046 /* Load: BB x M x ref --> M x X x data */
1047 op1mode == mode_M && mode_is_reference(op2mode),
1050 ASSERT_AND_RET( mymode == mode_T, "Load node", 0 );
1053 * jack's gen_add_firm_code:simpleSel seems to build Load (Load
1054 * (Proj (Proj))) sometimes ...
1056 * interprete.c:ai_eval seems to assume that this happens, too
1058 * obset.c:get_abstval_any can't deal with this if the load has
1062 entity *ent = hunt_for_entity (get_Load_ptr (n), n);
1063 assert ((NULL != ent) || (mymode != mode_T));
1070 op1mode = get_irn_mode(in[1]);
1071 op2mode = get_irn_mode(in[2]);
1072 op3mode = get_irn_mode(in[3]);
1074 /* Load: BB x M x ref data --> M x X */
1075 op1mode == mode_M && mode_is_reference(op2mode) && mode_is_data(op3mode),
1078 ASSERT_AND_RET(mymode == mode_T, "Store node", 0);
1080 entity *target = get_ptr_entity(in[2]);
1081 if (vrfy_entities && target && get_irg_phase_state(current_ir_graph) == phase_high) {
1083 * If lowered code, any Sels that add 0 may be removed, causing
1084 * an direct access to entities of array or compound type.
1085 * Prevent this by checking the phase.
1087 ASSERT_AND_RET( op3mode == get_type_mode(get_entity_type(target)),
1094 op1mode = get_irn_mode(in[1]);
1095 op2mode = get_irn_mode(in[2]);
1097 /* Alloc: BB x M x int_u --> M x X x ref */
1098 op1mode == mode_M &&
1099 mode_is_int(op2mode) &&
1100 !mode_is_signed(op2mode) &&
1103 show_binop_failure(n, "/* Alloc: BB x M x int_u --> M x X x ref */");
1108 op1mode = get_irn_mode(in[1]);
1109 op2mode = get_irn_mode(in[2]);
1111 /* Free: BB x M x ref --> M */
1112 op1mode == mode_M && mode_is_reference(op2mode) &&
1115 show_binop_failure(n, "/* Free: BB x M x ref --> M */");
1120 /* Sync: BB x M^n --> M */
1121 for (i=1; i < get_irn_arity(n); i++) {
1122 ASSERT_AND_RET( get_irn_mode(in[i]) == mode_M, "Sync node", 0 );
1124 ASSERT_AND_RET( mymode == mode_M, "Sync node", 0 );
1128 return vrfy_Proj_proj(n, irg);
1132 op1mode = get_irn_mode(in[1]);
1133 op2mode = get_irn_mode(in[2]);
1135 /* Confirm: BB x T x T --> T */
1136 op1mode == mymode &&
1139 show_binop_failure(n, "/* Confirm: BB x T x T --> T */");
1151 int irn_vrfy(ir_node *n)
1154 #ifdef DEBUG_libfirm
1155 res = irn_vrfy_irg(n, current_ir_graph);
1160 /*-----------------------------------------------------------------*/
1161 /* Verify the whole graph. */
1162 /*-----------------------------------------------------------------*/
1164 /* This *is* used, except gcc doesn't notice that */
1165 static void vrfy_wrap(ir_node *node, void *env)
1169 *res = irn_vrfy(node);
1172 int irg_vrfy(ir_graph *irg)
1175 #ifdef DEBUG_libfirm
1178 rem = current_ir_graph;
1179 current_ir_graph = irg;
1181 assert(get_irg_pinned(irg) == op_pin_state_pinned);
1183 irg_walk_graph(irg, vrfy_wrap, NULL, &res);
1185 current_ir_graph = rem;
1187 if (opt_do_node_verification == NODE_VERIFICATION_REPORT && ! res) {
1188 entity *ent = get_irg_entity(current_ir_graph);
1191 fprintf(stderr, "irg_verify: Verifying graph %s failed\n", get_entity_name(ent));
1193 fprintf(stderr, "irg_verify: Verifying graph %p failed\n", (void *)current_ir_graph);
1200 int irn_vrfy_irg_dump(ir_node *n, ir_graph *irg, const char **bad_string)
1203 node_verification_t old = opt_do_node_verification;
1206 opt_do_node_verification = NODE_VERIFICATION_ERROR_ONLY;
1207 res = irn_vrfy_irg(n, irg);
1208 opt_do_node_verification = old;
1209 *bad_string = bad_msg;
1215 typedef struct _vrfy_bad_env_t {
1220 static void check_bads(ir_node *node, void *env)
1222 vrfy_bad_env_t *venv = env;
1223 int i, arity = get_irn_arity(node);
1225 if (is_Block(node)) {
1226 if ((venv->flags & BAD_CF) == 0) {
1228 /* check for Bad Block predecessor */
1229 for (i = 0; i < arity; ++i) {
1230 ir_node *pred = get_irn_n(node, i);
1233 venv->res |= BAD_CF;
1235 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1236 fprintf(stderr, "irg_vrfy_bads: Block %ld has Bad predecessor\n", get_irn_node_nr(node));
1238 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1239 assert(0 && "Bad CF detected");
1246 if ((venv->flags & BAD_BLOCK) == 0) {
1248 /* check for Bad Block */
1249 if (is_Bad(get_nodes_block(node))) {
1250 venv->res |= BAD_BLOCK;
1252 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1253 fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Block\n", get_irn_node_nr(node));
1255 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1256 assert(0 && "Bad CF detected");
1261 if ((venv->flags & TUPLE) == 0) {
1262 if (get_irn_op(node) == op_Tuple) {
1265 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1266 fprintf(stderr, "irg_vrfy_bads: node %ld is a Tuple\n", get_irn_node_nr(node));
1268 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1269 assert(0 && "Tuple detected");
1274 for (i = 0; i < arity; ++i) {
1275 ir_node *pred = get_irn_n(node, i);
1278 /* check for Phi with Bad inputs */
1279 if (is_Phi(node) && !is_Bad(get_nodes_block(node)) && is_Bad(get_irn_n(get_nodes_block(node), i))) {
1280 if (venv->flags & BAD_CF)
1283 venv->res |= BAD_CF;
1285 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1286 fprintf(stderr, "irg_vrfy_bads: Phi %ld has Bad Input\n", get_irn_node_nr(node));
1288 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1289 assert(0 && "Bad CF detected");
1294 /* Bad node input */
1295 if ((venv->flags & BAD_DF) == 0) {
1296 venv->res |= BAD_DF;
1298 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1299 fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Input\n", get_irn_node_nr(node));
1301 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1302 assert(0 && "Bad NON-CF detected");
1311 * verify occurance of bad nodes
1313 int irg_vrfy_bads(ir_graph *irg, int flags)
1320 irg_walk_graph(irg, check_bads, NULL, &env);