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) && current_ir_graph != get_const_code_irg()) \
40 dump_ir_block_graph(current_ir_graph, "-assert"); \
41 assert((expr) && string); } \
43 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) \
44 fprintf(stderr, #expr " : " string "\n"); \
45 bad_msg = #expr " && " string; \
50 #define ASSERT_AND_RET_DBG(expr, string, ret, blk) \
53 bad_msg = #expr " && " string; \
54 if (opt_do_node_verification != NODE_VERIFICATION_ERROR_ONLY) { blk; } \
55 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) \
56 fprintf(stderr, #expr " : " string "\n"); \
57 else if (opt_do_node_verification == NODE_VERIFICATION_ON) \
58 assert((expr) && string); \
65 /** if this flag is set, verify entity types in Load & Store nodes */
66 static int vrfy_entities = 0;
68 /* @@@ replace use of array "in" by access functions. */
69 ir_node **get_irn_in(ir_node *node);
71 static node_verification_t opt_do_node_verification = NODE_VERIFICATION_ON;
72 static const char *bad_msg;
74 /* enable verification of Load/Store entities */
75 void vrfy_enable_entity_tests(int enable)
77 vrfy_entities = enable;
81 * little helper for NULL modes
83 static const char *get_mode_name_ex(ir_mode *mode)
87 return get_mode_name(mode);
90 void do_node_verification(node_verification_t mode)
92 opt_do_node_verification = mode;
96 * Prints a failure for a Node
98 static void show_node_failure(ir_node *n)
100 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s\n" ,
102 get_irn_opname(n), get_irn_modename(n)
107 * Prints a failure message for a binop
109 static void show_binop_failure(ir_node *n, const char *text)
111 ir_node *left = get_binop_left(n);
112 ir_node *right = get_binop_right(n);
114 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s(%s%s, %s%s) did not match (%s)\n",
116 get_irn_opname(n), get_irn_modename(n),
117 get_irn_opname(left), get_irn_modename(left),
118 get_irn_opname(right), get_irn_modename(right),
123 * Prints a failure message for an unop
125 static void show_unop_failure(ir_node *n, const char *text)
127 ir_node *op = get_unop_op(n);
129 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s(%s%s) did not match (%s)\n",
131 get_irn_opname(n), get_irn_modename(n),
132 get_irn_opname(op), get_irn_modename(op),
137 * Prints a failure message for a proj
139 static void show_proj_failure(ir_node *n)
141 ir_node *op = get_Proj_pred(n);
142 int proj = get_Proj_proj(n);
144 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s %d(%s%s) failed\n" ,
146 get_irn_opname(n), get_irn_modename(n), proj,
147 get_irn_opname(op), get_irn_modename(op));
151 * Prints a failure message for a proj
153 static void show_proj_failure_ent(ir_node *n, entity *ent)
155 ir_node *op = get_Proj_pred(n);
156 int proj = get_Proj_proj(n);
157 ir_mode *m = get_type_mode(get_entity_type(ent));
159 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s %d(%s%s) entity %s(type %s mode %s)failed\n" ,
161 get_irn_opname(n), get_irn_modename(n), proj,
162 get_irn_opname(op), get_irn_modename(op),
163 get_entity_name(ent), get_type_name(get_entity_type(ent)),
164 get_mode_name_ex(m));
168 * Show a node and a graph
170 static void show_node_on_graph(ir_graph *irg, ir_node *n)
172 entity *ent = get_irg_entity(irg);
175 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of entity %s, node %ld %s%s\n",
176 get_entity_name(ent),
177 get_irn_node_nr(n), get_irn_opname(n), get_irn_modename(n));
179 fprintf(stderr, "\nFIRM: irn_vrfy_irg() of graph %p, node %ld %s%s\n",
181 get_irn_node_nr(n), get_irn_opname(n), get_irn_modename(n));
187 static void show_call_param(ir_node *n, type *mt)
191 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Call type-check failed: %s(", get_type_name(mt));
192 for (i = 0; i < get_method_n_params(mt); ++i) {
193 fprintf(stderr, "%s ", get_mode_name_ex(get_type_mode(get_method_param_type(mt, i))));
195 fprintf(stderr, ") != CALL(");
197 for (i = 0; i < get_Call_n_params(n); ++i) {
198 fprintf(stderr, "%s ", get_mode_name_ex(get_irn_mode(get_Call_param(n, i))));
200 fprintf(stderr, ")\n");
207 static void show_return_modes(ir_graph *irg, ir_node *n, type *mt, int i)
209 entity *ent = get_irg_entity(irg);
211 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Return node %ld in entity \"%s\" mode %s different from type mode %s\n",
212 get_irn_node_nr(n), get_entity_name(ent),
213 get_mode_name_ex(get_irn_mode(get_Return_res(n, i))),
214 get_mode_name_ex(get_type_mode(get_method_res_type(mt, i)))
219 * Show return number of results
221 static void show_return_nres(ir_graph *irg, ir_node *n, type *mt)
223 entity *ent = get_irg_entity(irg);
225 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Return node %ld in entity \"%s\" has %d results different from type %d\n",
226 get_irn_node_nr(n), get_entity_name(ent),
227 get_Return_n_ress(n), get_method_n_ress(mt));
233 static void show_phi_failure(ir_node *phi, ir_node *pred, int pos)
235 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Phi node %ld has mode %s different from predeccessor node %ld mode %s\n",
236 get_irn_node_nr(phi), get_mode_name_ex(get_irn_mode(phi)),
237 get_irn_node_nr(pred), get_mode_name_ex(get_irn_mode(pred)));
243 static void show_phi_inputs(ir_node *phi, ir_node *block)
245 fprintf(stderr, "\nFIRM: irn_vrfy_irg() Phi node %ld has %d inputs, its Block %ld has %d\n",
246 get_irn_node_nr(phi), get_irn_arity(phi),
247 get_irn_node_nr(block), get_irn_arity(block));
250 /* If the address is Sel or SymConst, return the entity. */
251 static entity *get_ptr_entity(ir_node *ptr) {
252 if (get_irn_op(ptr) == op_Sel) {
253 return get_Sel_entity(ptr);
254 } else if ((get_irn_op(ptr) == op_SymConst) && (get_SymConst_kind(ptr) == symconst_addr_ent)) {
255 return get_SymConst_entity(ptr);
261 * verify the Proj number
264 vrfy_Proj_proj(ir_node *p, ir_graph *irg) {
269 pred = skip_Id(get_Proj_pred(p));
270 ASSERT_AND_RET(get_irn_mode(pred) == mode_T, "mode of a 'projed' node is not Tuple", 0);
271 mode = get_irn_mode(p);
272 proj = get_Proj_proj(p);
274 switch (get_irn_opcode(pred)) {
278 (proj == pn_Start_X_initial_exec && mode == mode_X) ||
279 (proj == pn_Start_M && mode == mode_M) ||
280 (proj == pn_Start_P_frame_base && mode_is_reference(mode)) ||
281 (proj == pn_Start_P_globals && mode_is_reference(mode)) ||
282 (proj == pn_Start_T_args && mode == mode_T) ||
283 (proj == pn_Start_P_value_arg_base && mode_is_reference(mode)) ||
284 (proj == pn_Start_P_value_arg_base && mode == mode_T) /* FIXME: only one of those */
286 "wrong Proj from Start", 0,
287 show_proj_failure(p);
294 (proj >= 0 && mode == mode_X && get_irn_mode(get_Cond_selector(pred)) == mode_b) || /* compare */
295 (mode == mode_X && mode_is_int(get_irn_mode(get_Cond_selector(pred)))) /* switch */
297 "wrong Proj from Cond", 0,
298 show_proj_failure(p);
304 ((proj == pn_Raise_X && mode == mode_X) || (proj == pn_Raise_M && mode == mode_M)),
305 "wrong Proj from Raise", 0,
306 show_proj_failure(p);
312 (proj >= 0 && mode == mode_X),
313 "wrong Proj from InstOf", 0,
314 show_proj_failure(p);
320 ((proj == pn_Call_M_regular && mode == mode_M) ||
321 (proj == pn_Call_X_except && mode == mode_X) ||
322 (proj == pn_Call_T_result && mode == mode_T) ||
323 (proj == pn_Call_M_except && mode == mode_M) ||
324 (proj == pn_Call_P_value_res_base && mode == mode_P)),
325 "wrong Proj from Call", 0,
326 show_proj_failure(p);
333 ((proj == pn_Call_M_regular && mode == mode_M) ||
334 (proj == pn_Call_X_except && mode == mode_X) ||
335 (proj == pn_Call_T_result && mode == mode_T) ||
336 (proj == pn_Call_M_except && mode == mode_M) ||
337 (proj == pn_Call_P_value_res_base && mode == mode_P)),
338 "wrong Proj from FuncCall", 0,
339 show_proj_failure(p);
345 ((proj == pn_Quot_M && mode == mode_M) ||
346 (proj == pn_Quot_X_except && mode == mode_X) ||
347 (proj == pn_Quot_res && mode_is_float(mode))),
348 "wrong Proj from Quot", 0,
349 show_proj_failure(p);
355 ((proj == pn_DivMod_M && mode == mode_M) ||
356 (proj == pn_DivMod_X_except && mode == mode_X) ||
357 (proj == pn_DivMod_res_div && mode_is_int(mode)) ||
358 (proj == pn_DivMod_res_mod && mode_is_int(mode))),
359 "wrong Proj from DivMod", 0,
360 show_proj_failure(p);
366 ((proj == pn_Div_M && mode == mode_M) ||
367 (proj == pn_Div_X_except && mode == mode_X) ||
368 (proj == pn_Div_res && mode_is_int(mode))),
369 "wrong Proj from Div or Mod", 0,
370 show_proj_failure(p);
376 ((proj == pn_Mod_M && mode == mode_M) ||
377 (proj == pn_Mod_X_except && mode == mode_X) ||
378 (proj == pn_Mod_res && mode_is_int(mode))),
379 "wrong Proj from Div or Mod", 0,
380 show_proj_failure(p);
386 (proj >= 0 && proj <= 15 && mode == mode_b),
387 "wrong Proj from Cmp", 0,
388 show_proj_failure(p);
393 if (proj == pn_Load_res) {
394 ir_node *ptr = get_Load_ptr(pred);
395 entity *ent = get_ptr_entity(ptr);
397 if (vrfy_entities && ent && get_irg_phase_state(current_ir_graph) == phase_high) {
398 /* do NOT check this for lowered phases, see comment on Store */
400 (mode == get_type_mode(get_entity_type(ent))),
401 "wrong data Proj from Load, entity type_mode failed", 0,
402 show_proj_failure_ent(p, ent);
407 mode_is_data(mode) && mode == get_Load_mode(pred),
408 "wrong data Proj from Load", 0,
409 show_proj_failure(p);
414 ((proj == pn_Load_M && mode == mode_M) ||
415 (proj == pn_Load_X_except && mode == mode_X)),
416 "wrong Proj from Load", 0,
417 show_proj_failure(p);
424 ((proj == pn_Store_M && mode == mode_M) ||
425 (proj == pn_Store_X_except && mode == mode_X)),
426 "wrong Proj from Store", 0,
427 show_proj_failure(p);
434 (proj == pn_Alloc_M && mode == mode_M) ||
435 (proj == pn_Alloc_X_except /* && mode == mode_X*/) ||
436 (proj == pn_Alloc_res && mode_is_reference(mode))
438 "wrong Proj from Alloc", 0,
439 show_proj_failure(p);
445 type *mt; /* A method type */
446 long nr = get_Proj_proj(pred);
448 pred = skip_Id(get_Proj_pred(pred));
449 ASSERT_AND_RET((get_irn_mode(pred) == mode_T), "Proj from something not a tuple", 0);
450 switch (get_irn_opcode(pred))
453 mt = get_entity_type(get_irg_entity(irg));
455 if (nr == pn_Start_T_args) {
457 (proj >= 0 && mode_is_data(mode)),
458 "wrong Proj from Proj from Start", 0);
460 (proj < get_method_n_params(mt)),
461 "More Projs for args than args in type", 0
463 if ((mode_is_reference(mode)) && is_compound_type(get_method_param_type(mt, proj)))
464 /* value argument */ break;
467 (mode == get_type_mode(get_method_param_type(mt, proj))),
468 "Mode of Proj from Start doesn't match mode of param type.", 0);
470 else if (nr == pn_Start_P_value_arg_base) {
472 (proj >= 0 && mode_is_reference(mode)),
473 "wrong Proj from Proj from Start", 0
476 (proj < get_method_n_params(mt)),
477 "More Projs for args than args in type", 0
485 (proj >= 0 && mode_is_data(mode)),
486 "wrong Proj from Proj from Call", 0);
487 mt = get_Call_type(pred);
489 (proj < get_method_n_ress(mt)),
490 "More Projs for results than results in type.", 0);
491 if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
492 /* value result */ break;
495 (mode == get_type_mode(get_method_res_type(mt, proj))),
496 "Mode of Proj from Call doesn't match mode of result type.", 0);
504 (proj >= 0 && mode_is_data(mode)),
505 "wrong Proj from Proj from FuncCall", 0);
506 mt = get_FuncCall_type(pred);
508 (proj < get_method_n_ress(mt)),
509 "More Projs for results than results in type.", 0);
510 if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
511 /* value result */ break;
514 (mode == get_type_mode(get_method_res_type(mt, proj))),
515 "Mode of Proj from FuncCall doesn't match mode of result type.", 0);
524 ASSERT_AND_RET(0, "Unknown opcode", 0);
543 ASSERT_AND_RET(0, "Unknown opcode", 0);
550 int irn_vrfy_irg(ir_node *n, ir_graph *irg)
554 ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
555 int op_is_symmetric = 1; /* 0: asymmetric
556 1: operands have identical modes
557 2: modes of operands == mode of this node */
558 type *mt; /* A method type */
563 if (!opt_do_node_verification) return 1;
565 if (! get_interprocedural_view()) {
567 * do NOT check placement in interprocedural view, as we don't always know
568 * the "right" graph ...
571 node_is_in_irgs_storage(irg, n),
572 "Node is not stored on proper IR graph!", 0,
573 show_node_on_graph(irg, n);
577 opcode = get_irn_opcode(n);
579 /* We don't want to test nodes whose predecessors are Bad,
580 as we would have to special case that for each operation. */
581 if (opcode != iro_Phi && opcode != iro_Block)
582 for (i = 0; i < get_irn_arity(n); i++) {
583 opcode1 = get_irn_opcode(get_irn_n(n, i));
584 if (opcode1 == iro_Bad)
588 mymode = get_irn_mode(n);
594 for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
595 ir_node *pred = get_Block_cfgpred(n, i);
599 (get_irn_mode(pred) == mode_X)
602 /* End block may only have Return, Raise or fragile ops as preds. */
603 if (n == get_irg_end_block(irg))
604 for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
605 ir_node *pred = skip_Proj(get_Block_cfgpred(n, i));
606 if (is_Proj(pred) || get_irn_op(pred) == op_Tuple)
607 break; /* We can not test properly. How many tuples are there? */
608 ASSERT_AND_RET(((get_irn_op(pred) == op_Return) ||
610 (get_irn_op(pred) == op_Raise) ||
611 is_fragile_op(pred) ),
612 "End Block node", 0);
614 /* irg attr must == graph we are in. */
615 if (! get_interprocedural_view()) {
616 ASSERT_AND_RET(((get_irn_irg(n) && get_irn_irg(n) == irg)), "Block node has wrong irg attribute", 0);
623 /* Start: BB --> X x M x ref x data1 x ... x datan x ref */
624 mymode == mode_T, "Start node", 0
631 mymode == mode_X, "Jmp node", 0
638 mymode == mode_X, "Jmp node", 0
643 op1mode = get_irn_mode(in[1]);
645 /* Cond: BB x b --> X x X */
646 (op1mode == mode_b ||
647 /* Cond: BB x int --> X^n */
648 mode_is_int(op1mode) ), "Cond node", 0
650 ASSERT_AND_RET(mymode == mode_T, "Cond mode is not a tuple", 0);
654 op1mode = get_irn_mode(in[1]);
655 /* Return: BB x M x data1 x ... x datan --> X */
656 /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
657 ASSERT_AND_RET( op1mode == mode_M, "Return node", 0 ); /* operand M */
658 for (i = 2; i < get_irn_arity(n); i++) {
659 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Return node", 0 ); /* operand datai */
661 ASSERT_AND_RET( mymode == mode_X, "Result X", 0 ); /* result X */
662 /* Compare returned results with result types of method type */
663 mt = get_entity_type(get_irg_entity(irg));
664 ASSERT_AND_RET_DBG( get_Return_n_ress(n) == get_method_n_ress(mt),
665 "Number of results for Return doesn't match number of results in type.", 0,
666 show_return_nres(irg, n, mt););
667 for (i = 0; i < get_Return_n_ress(n); i++) {
668 type *res_type = get_method_res_type(mt, i);
670 if (is_atomic_type(res_type)) {
672 get_irn_mode(get_Return_res(n, i)) == get_type_mode(res_type),
673 "Mode of result for Return doesn't match mode of result type.", 0,
674 show_return_modes(irg, n, mt, i);
679 mode_is_reference(get_irn_mode(get_Return_res(n, i))),
680 "Mode of result for Return doesn't match mode of result type.", 0,
681 show_return_modes(irg, n, mt, i);
688 op1mode = get_irn_mode(in[1]);
689 op2mode = get_irn_mode(in[2]);
691 /* Sel: BB x M x ref --> X x M */
692 op1mode == mode_M && mode_is_reference(op2mode) &&
693 mymode == mode_T, "Raise node", 0
699 /* Const: BB --> data */
700 (mode_is_data (mymode) ||
701 mymode == mode_b) /* we want boolean constants for static evaluation */
702 ,"Const node", 0 /* of Cmp. */
706 if (get_SymConst_kind(n) == symconst_addr_ent) {
707 entity *ent = get_SymConst_entity(n);
708 if (is_method_type(get_entity_type(ent)) &&
709 get_irn_irg(n) != get_const_code_irg()) {
711 ASSERT_AND_RET((get_entity_peculiarity(ent) != peculiarity_description),
712 "A constant must address an existing method.", 0);
717 /* SymConst: BB --> int*/
718 (mode_is_int(mymode) ||
719 /* SymConst: BB --> ref */
720 mode_is_reference(mymode))
721 ,"SymConst node", 0);
725 op1mode = get_irn_mode(in[1]);
726 op2mode = get_irn_mode(in[2]);
728 /* Sel: BB x M x ref x int^n --> ref */
729 (op1mode == mode_M && op2mode == mymode && mode_is_reference(mymode)),
730 "Sel node", 0, show_node_failure(n)
732 for (i=3; i < get_irn_arity(n); i++)
734 ASSERT_AND_RET_DBG(mode_is_int(get_irn_mode(in[i])), "Sel node", 0, show_node_failure(n));
736 ent = get_Sel_entity(n);
737 ASSERT_AND_RET_DBG(ent, "Sel node with empty entity", 0, show_node_failure(n));
741 ASSERT_AND_RET(mode_T == mymode, "mode of Instof is not a tuple", 0);
742 ASSERT_AND_RET(mode_is_data(op1mode), "Instof not on data", 0);
746 op1mode = get_irn_mode(in[1]);
747 op2mode = get_irn_mode(in[2]);
748 /* Call: BB x M x ref x data1 x ... x datan
749 --> M x datan+1 x ... x data n+m */
750 ASSERT_AND_RET( op1mode == mode_M && mode_is_reference(op2mode), "Call node", 0 ); /* operand M x ref */
752 mt = get_Call_type(n);
753 if(get_unknown_type() == mt) {
757 for (i=3; i < get_irn_arity(n); i++) {
758 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Call node", 0 ); /* operand datai */
760 ASSERT_AND_RET( mymode == mode_T, "Call result not a tuple", 0 ); /* result T */
761 /* Compare arguments of node with those of type */
763 if (get_method_variadicity(mt) == variadicity_variadic) {
765 get_Call_n_params(n) >= get_method_n_params(mt),
766 "Number of args for Call doesn't match number of args in variadic type.",
768 fprintf(stderr, "Call has %d params, method %s type %d\n",
769 get_Call_n_params(n), get_type_name(mt), get_method_n_params(mt));
774 get_Call_n_params(n) == get_method_n_params(mt),
775 "Number of args for Call doesn't match number of args in non variadic type.",
779 for (i = 0; i < get_method_n_params(mt); i++) {
780 type *t = get_method_param_type(mt, i);
782 if (is_atomic_type(t)) {
784 get_irn_mode(get_Call_param(n, i)) == get_type_mode(t),
785 "Mode of arg for Call doesn't match mode of arg type.", 0,
786 show_call_param(n, mt);
790 /* call with a compound type, mode must be reference */
792 mode_is_reference(get_irn_mode(get_Call_param(n, i))),
793 "Mode of arg for Call doesn't match mode of arg type.", 0,
794 show_call_param(n, mt);
800 if (Call_has_callees(n)) {
801 for (i = 0; i < get_Call_n_callees(n); i++) {
802 ASSERT_AND_RET(is_entity(get_Call_callee(n, i)), "callee array must contain entities.", 0);
809 op1mode = get_irn_mode(in[1]);
810 op2mode = get_irn_mode(in[2]);
813 /* common Add: BB x numP x numP --> numP */
814 (op1mode == mymode && op2mode == op1mode && mode_is_numP(mymode)) ||
815 /* Pointer Add: BB x ref x int --> ref */
816 (mode_is_reference(op1mode) && mode_is_int(op2mode) && op1mode == mymode) ||
817 /* Pointer Add: BB x int x ref --> ref */
818 (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode))
821 show_binop_failure(n, "/* common Add: BB x numP x numP --> numP */ |\n"
822 "/* Pointer Add: BB x ref x int --> ref */ |\n"
823 "/* Pointer Add: BB x int x ref --> ref */");
825 if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
826 /* BB x ref x int --> ref or BB x int x ref --> ref */
829 /* BB x num x num --> num or BB x ref x ref */
835 op1mode = get_irn_mode(in[1]);
836 op2mode = get_irn_mode(in[2]);
838 /* common Sub: BB x numP x numP --> numP */
839 ((mymode ==op1mode && mymode == op2mode && mode_is_numP(op1mode)) ||
840 /* Pointer Sub: BB x ref x int --> ref */
841 (op1mode == mymode && mode_is_int(op2mode) && mode_is_reference(mymode)) ||
842 /* Pointer Sub: BB x int x ref --> ref */
843 (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode)) ||
844 /* Pointer Sub: BB x ref x ref --> int */
845 (op1mode == op2mode && mode_is_reference(op2mode) && mode_is_int(mymode))),
847 show_binop_failure(n, "/* common Sub: BB x numP x numP --> numP */ |\n"
848 "/* Pointer Sub: BB x ref x int --> ref */ |\n"
849 "/* Pointer Sub: BB x int x ref --> ref */ |\n"
850 "/* Pointer Sub: BB x ref x ref --> int */" );
852 if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
860 op1mode = get_irn_mode(in[1]);
862 /* Minus: BB x float --> float */
863 op1mode == mymode && mode_is_float(op1mode), "Minus node", 0,
864 show_unop_failure(n , "/* Minus: BB x float --> float */");
870 op1mode = get_irn_mode(in[1]);
871 op2mode = get_irn_mode(in[2]);
873 /* Mul: BB x int1 x int1 --> int2 */
874 ((mode_is_int(op1mode) && op2mode == op1mode && mode_is_int(mymode)) ||
875 /* Mul: BB x float x float --> float */
876 (mode_is_float(op1mode) && op2mode == op1mode && mymode == op1mode)),
878 show_binop_failure(n, "/* Mul: BB x int1 x int1 --> int2 */ |\n"
879 "/* Mul: BB x float x float --> float */");
885 op1mode = get_irn_mode(in[1]);
886 op2mode = get_irn_mode(in[2]);
887 op3mode = get_irn_mode(in[3]);
889 /* Quot: BB x M x float x float --> M x X x float */
890 op1mode == mode_M && op2mode == op3mode &&
891 get_mode_sort(op2mode) == irms_float_number &&
894 show_binop_failure(n, "/* Quot: BB x M x float x float --> M x X x float */");
900 op1mode = get_irn_mode(in[1]);
901 op2mode = get_irn_mode(in[2]);
902 op3mode = get_irn_mode(in[3]);
904 /* DivMod: BB x M x int x int --> M x X x int x int */
906 mode_is_int(op2mode) &&
907 op3mode == op2mode &&
916 op1mode = get_irn_mode(in[1]);
917 op2mode = get_irn_mode(in[2]);
918 op3mode = get_irn_mode(in[3]);
920 /* Div or Mod: BB x M x int x int --> M x X x int */
922 op2mode == op3mode &&
923 mode_is_int(op2mode) &&
931 op1mode = get_irn_mode(in[1]);
933 /* Abs: BB x num --> num */
935 mode_is_num (op1mode),
937 show_unop_failure(n, "/* Abs: BB x num --> num */");
945 op1mode = get_irn_mode(in[1]);
946 op2mode = get_irn_mode(in[2]);
948 /* And or Or or Eor: BB x int x int --> int */
949 mode_is_int(mymode) &&
950 op2mode == op1mode &&
952 "And, Or or Eor node", 0,
953 show_binop_failure(n, "/* And or Or or Eor: BB x int x int --> int */");
959 op1mode = get_irn_mode(in[1]);
961 /* Not: BB x int --> int */
962 mode_is_int(mymode) &&
965 show_unop_failure(n, "/* Not: BB x int --> int */");
972 op1mode = get_irn_mode(in[1]);
973 op2mode = get_irn_mode(in[2]);
975 /* Cmp: BB x datab x datab --> b16 */
976 mode_is_data (op1mode) &&
977 op2mode == op1mode &&
980 show_binop_failure(n, "/* Cmp: BB x datab x datab --> b16 */");
987 op1mode = get_irn_mode(in[1]);
988 op2mode = get_irn_mode(in[2]);
990 /* Shl, Shr or Shrs: BB x int x int_u --> int */
991 mode_is_int(op1mode) &&
992 mode_is_int(op2mode) &&
993 !mode_is_signed(op2mode) &&
995 "Shl, Shr, Shr or Rot node", 0,
996 show_binop_failure(n, "/* Shl, Shr or Shrs: BB x int x int_u --> int */");
1001 op1mode = get_irn_mode(in[1]);
1002 op2mode = get_irn_mode(in[2]);
1004 /* Rot: BB x int x int --> int */
1005 mode_is_int(op1mode) &&
1006 mode_is_int(op2mode) &&
1009 show_binop_failure(n, "/* Rot: BB x int x int --> int */");
1014 op1mode = get_irn_mode(in[1]);
1016 /* Conv: BB x datab1 --> datab2 */
1017 mode_is_datab(op1mode) && mode_is_data(mymode),
1019 show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1024 op1mode = get_irn_mode(in[1]);
1026 /* Conv: BB x datab1 --> datab2 */
1027 mode_is_data(op1mode) && op1mode == mymode,
1029 show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1035 ir_node *block = get_nodes_block(n);
1037 if (! is_Bad(block) && get_irg_phase_state(get_irn_irg(n)) != phase_building) {
1038 /* a Phi node MUST have the same number of inputs as its block */
1040 get_irn_arity(n) == get_irn_arity(block),
1041 "wrong number of inputs in Phi node", 0,
1042 show_phi_inputs(n, block);
1046 /* Phi: BB x dataM^n --> dataM */
1047 for (i = 1; i < get_irn_arity(n); i++) {
1048 if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
1050 get_irn_mode(in[i]) == mymode,
1052 show_phi_failure(n, in[i], i);
1055 ASSERT_AND_RET( mode_is_dataM(mymode), "Phi node", 0 );
1059 op1mode = get_irn_mode(in[1]);
1060 op2mode = get_irn_mode(in[2]);
1062 /* Load: BB x M x ref --> M x X x data */
1063 op1mode == mode_M && mode_is_reference(op2mode),
1066 ASSERT_AND_RET( mymode == mode_T, "Load node", 0 );
1069 * jack's gen_add_firm_code:simpleSel seems to build Load (Load
1070 * (Proj (Proj))) sometimes ...
1072 * interprete.c:ai_eval seems to assume that this happens, too
1074 * obset.c:get_abstval_any can't deal with this if the load has
1078 entity *ent = hunt_for_entity (get_Load_ptr (n), n);
1079 assert ((NULL != ent) || (mymode != mode_T));
1086 op1mode = get_irn_mode(in[1]);
1087 op2mode = get_irn_mode(in[2]);
1088 op3mode = get_irn_mode(in[3]);
1090 /* Load: BB x M x ref data --> M x X */
1091 op1mode == mode_M && mode_is_reference(op2mode) && mode_is_data(op3mode),
1094 ASSERT_AND_RET(mymode == mode_T, "Store node", 0);
1096 entity *target = get_ptr_entity(in[2]);
1097 if (vrfy_entities && target && get_irg_phase_state(current_ir_graph) == phase_high) {
1099 * If lowered code, any Sels that add 0 may be removed, causing
1100 * an direct access to entities of array or compound type.
1101 * Prevent this by checking the phase.
1103 ASSERT_AND_RET( op3mode == get_type_mode(get_entity_type(target)),
1110 op1mode = get_irn_mode(in[1]);
1111 op2mode = get_irn_mode(in[2]);
1113 /* Alloc: BB x M x int_u --> M x X x ref */
1114 op1mode == mode_M &&
1115 mode_is_int(op2mode) &&
1116 !mode_is_signed(op2mode) &&
1119 show_binop_failure(n, "/* Alloc: BB x M x int_u --> M x X x ref */");
1124 op1mode = get_irn_mode(in[1]);
1125 op2mode = get_irn_mode(in[2]);
1127 /* Free: BB x M x ref --> M */
1128 op1mode == mode_M && mode_is_reference(op2mode) &&
1131 show_binop_failure(n, "/* Free: BB x M x ref --> M */");
1136 /* Sync: BB x M^n --> M */
1137 for (i=1; i < get_irn_arity(n); i++) {
1138 ASSERT_AND_RET( get_irn_mode(in[i]) == mode_M, "Sync node", 0 );
1140 ASSERT_AND_RET( mymode == mode_M, "Sync node", 0 );
1144 return vrfy_Proj_proj(n, irg);
1148 op1mode = get_irn_mode(in[1]);
1149 op2mode = get_irn_mode(in[2]);
1151 /* Confirm: BB x T x T --> T */
1152 op1mode == mymode &&
1155 show_binop_failure(n, "/* Confirm: BB x T x T --> T */");
1167 int irn_vrfy(ir_node *n)
1170 #ifdef DEBUG_libfirm
1171 res = irn_vrfy_irg(n, current_ir_graph);
1176 /*-----------------------------------------------------------------*/
1177 /* Verify the whole graph. */
1178 /*-----------------------------------------------------------------*/
1180 /* This *is* used, except gcc doesn't notice that */
1181 static void vrfy_wrap(ir_node *node, void *env)
1185 *res = irn_vrfy(node);
1188 int irg_vrfy(ir_graph *irg)
1191 #ifdef DEBUG_libfirm
1194 rem = current_ir_graph;
1195 current_ir_graph = irg;
1197 assert(get_irg_pinned(irg) == op_pin_state_pinned);
1199 irg_walk_graph(irg, vrfy_wrap, NULL, &res);
1201 current_ir_graph = rem;
1203 if (opt_do_node_verification == NODE_VERIFICATION_REPORT && ! res) {
1204 entity *ent = get_irg_entity(current_ir_graph);
1207 fprintf(stderr, "irg_verify: Verifying graph %s failed\n", get_entity_name(ent));
1209 fprintf(stderr, "irg_verify: Verifying graph %p failed\n", (void *)current_ir_graph);
1216 int irn_vrfy_irg_dump(ir_node *n, ir_graph *irg, const char **bad_string)
1219 node_verification_t old = opt_do_node_verification;
1222 opt_do_node_verification = NODE_VERIFICATION_ERROR_ONLY;
1223 res = irn_vrfy_irg(n, irg);
1224 opt_do_node_verification = old;
1225 *bad_string = bad_msg;
1231 typedef struct _vrfy_bad_env_t {
1236 static void check_bads(ir_node *node, void *env)
1238 vrfy_bad_env_t *venv = env;
1239 int i, arity = get_irn_arity(node);
1241 if (is_Block(node)) {
1242 if ((venv->flags & BAD_CF) == 0) {
1244 /* check for Bad Block predecessor */
1245 for (i = 0; i < arity; ++i) {
1246 ir_node *pred = get_irn_n(node, i);
1249 venv->res |= BAD_CF;
1251 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1252 fprintf(stderr, "irg_vrfy_bads: Block %ld has Bad predecessor\n", get_irn_node_nr(node));
1254 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1255 assert(0 && "Bad CF detected");
1262 if ((venv->flags & BAD_BLOCK) == 0) {
1264 /* check for Bad Block */
1265 if (is_Bad(get_nodes_block(node))) {
1266 venv->res |= BAD_BLOCK;
1268 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1269 fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Block\n", get_irn_node_nr(node));
1271 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1272 assert(0 && "Bad CF detected");
1277 if ((venv->flags & TUPLE) == 0) {
1278 if (get_irn_op(node) == op_Tuple) {
1281 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1282 fprintf(stderr, "irg_vrfy_bads: node %ld is a Tuple\n", get_irn_node_nr(node));
1284 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1285 assert(0 && "Tuple detected");
1290 for (i = 0; i < arity; ++i) {
1291 ir_node *pred = get_irn_n(node, i);
1294 /* check for Phi with Bad inputs */
1295 if (is_Phi(node) && !is_Bad(get_nodes_block(node)) && is_Bad(get_irn_n(get_nodes_block(node), i))) {
1296 if (venv->flags & BAD_CF)
1299 venv->res |= BAD_CF;
1301 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1302 fprintf(stderr, "irg_vrfy_bads: Phi %ld has Bad Input\n", get_irn_node_nr(node));
1304 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1305 assert(0 && "Bad CF detected");
1310 /* Bad node input */
1311 if ((venv->flags & BAD_DF) == 0) {
1312 venv->res |= BAD_DF;
1314 if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1315 fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Input\n", get_irn_node_nr(node));
1317 if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1318 assert(0 && "Bad NON-CF detected");
1327 * verify occurance of bad nodes
1329 int irg_vrfy_bads(ir_graph *irg, int flags)
1336 irg_walk_graph(irg, check_bads, NULL, &env);