1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
4 * Authors: Christian Schaefer
15 # include "irgraph_t.h"
21 * in RELEASE mode, returns ret if the expression expr evaluates to zero
22 * in ASSERT mode, asserts the expression expr (and the string string).
24 #define ASSERT_AND_RET(expr, string, ret) if (!(expr)) return (ret)
27 * in RELEASE mode, returns ret if the expression expr evaluates to zero
28 * in ASSERT mode, executes blk if the expression expr evaluates to zero and asserts
30 #define ASSERT_AND_RET_DBG(expr, string, ret, blk) if (!(expr)) return (ret)
32 #define ASSERT_AND_RET(expr, string, ret) do { assert((expr) && string); if (!(expr)) return (ret); } while(0)
33 #define ASSERT_AND_RET_DBG(expr, string, ret, blk) do { if (!(expr)) { { blk } assert(0 && string); return (ret); } } while(0)
36 /* @@@ replace use of array "in" by access functions. */
37 ir_node **get_irn_in(ir_node *node);
40 vrfy_Proj_proj(ir_node *p, ir_graph *irg) {
45 pred = skip_nop(get_Proj_pred(p));
46 assert(get_irn_mode(pred) == mode_T);
47 mode = get_irn_mode(p);
48 proj = get_Proj_proj(p);
50 switch (get_irn_opcode(pred)) {
54 (proj == pns_initial_exec && mode == mode_X) ||
55 (proj == pns_global_store && mode == mode_M) ||
56 (proj == pns_frame_base && mode_is_reference(mode)) ||
57 (proj == pns_globals && mode_is_reference(mode)) ||
58 (proj == pns_args && mode == mode_T) ||
59 (proj == pns_value_arg_base && mode_is_reference(mode))
61 "wrong Proj from Start", 0);
65 ASSERT_AND_RET( (proj >= 0 && mode == mode_X), "wrong Proj from Cond", 0);
70 ((proj == 0 && mode == mode_X) ||
71 (proj == 1 && mode == mode_M)),
72 "wrong Proj from Raise", 0);
76 ASSERT_AND_RET( (proj >= 0 && mode == mode_X), "wrong Proj from InstOf", 0);
81 ((proj == 0 && mode == mode_M) ||
82 (proj == 1 && mode == mode_X) ||
83 (proj == 2 && mode == mode_T) ||
84 (proj == 3 && mode == mode_M)),
85 "wrong Proj from Call", 0);
90 ((proj == 0 && mode == mode_M) ||
91 (proj == 1 && mode == mode_X) ||
92 (proj == 2 && mode_is_float(mode))),
93 "wrong Proj from Quot", 0);
98 ((proj == 0 && mode == mode_M) ||
99 (proj == 1 && mode == mode_X) ||
100 (proj == 2 && mode == mode_Is) ||
101 (proj == 3 && mode_is_int(mode))),
102 "wrong Proj from DivMod", 0);
108 ((proj == 0 && mode == mode_M) ||
109 (proj == 1 && mode == mode_X) ||
110 (proj == 2 && mode_is_int(mode))),
111 "wrong Proj from Div or Mod", 0);
116 (proj >= 0 && proj <= 15 && mode == mode_b),
117 "wrong Proj from Cmp", 0);
122 ((proj == 0 && mode == mode_M) ||
123 (proj == 1 && mode == mode_X) ||
124 (proj == 2 && mode_is_data(mode))),
125 "wrong Proj from Load", 0);
130 ((proj == 0 && mode == mode_M) ||
131 (proj == 1 && mode == mode_X)),
132 "wrong Proj from Store", 0);
138 (proj == 0 && mode == mode_M) ||
139 (proj == 1 /* && mode == mode_X*/) ||
140 (proj == 2 && mode_is_reference(mode))
142 "wrong Proj from Alloc", 0);
147 type *mt; /* A method type */
148 pred = skip_nop(get_Proj_pred(pred));
149 ASSERT_AND_RET((get_irn_mode(pred) == mode_T), "Proj from something not a tuple", 0);
150 switch (get_irn_opcode(pred))
155 (proj >= 0 && mode_is_data(mode)),
156 "wrong Proj from Proj from Start", 0);
157 mt = get_entity_type(get_irg_ent(irg));
159 (proj < get_method_n_params(mt)),
160 "More Projs for args than args in type", 0);
161 if ((mode_is_reference(mode)) && is_compound_type(get_method_param_type(mt, proj)))
162 /* value argument */ break;
165 (mode == get_type_mode(get_method_param_type(mt, proj))),
166 "Mode of Proj from Start doesn't match mode of param type.", 0);
173 (proj >= 0 && mode_is_data(mode)),
174 "wrong Proj from Proj from Call", 0);
175 mt = get_Call_type(pred);
177 (proj < get_method_n_ress(mt)),
178 "More Projs for results than results in type.", 0);
179 if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
180 /* value result */ break;
183 (mode == get_type_mode(get_method_res_type(mt, proj))),
184 "Mode of Proj from Call doesn't match mode of result type.", 0);
193 ASSERT_AND_RET(0, "Unknown opcode", 0);
212 ASSERT_AND_RET(0, "Unknown opcode", 0);
219 int irn_vrfy_irg(ir_node *n, ir_graph *irg)
223 ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
224 int op_is_symmetric = 1; /* 0: asymmetric
225 1: operands have identical modes
226 2: modes of operands == mode of this node */
227 type *mt; /* A method type */
231 if (! interprocedural_view) {
233 * do NOT check placement in interprocedural view, as we don't always know
234 * the "right" graph ...
236 ASSERT_AND_RET(node_is_in_irgs_storage(irg, n), "Node is not stored on proper IR graph!", 0);
239 opcode = get_irn_opcode (n);
241 /* We don't want to test nodes whose predecessors are Bad or Unknown,
242 as we would have to special case that for each operation. */
243 if (opcode != iro_Phi && opcode != iro_Block)
244 for (i = 0; i < get_irn_arity(n); i++) {
245 opcode1 = get_irn_opcode(get_irn_n(n, i));
246 if (opcode1 == iro_Bad || opcode1 == iro_Unknown)
250 mymode = get_irn_mode (n);
257 /* Start: BB --> X x M x ref x data1 x ... x datan x ref */
258 mymode == mode_T, "Start node", 0
265 mymode == mode_X, "Jmp node", 0
272 mymode == mode_X, "Jmp node", 0
277 op1mode = get_irn_mode(in[1]);
279 /* Cond: BB x b --> X x X */
280 (op1mode == mode_b ||
281 /* Cond: BB x int --> X^n */
282 mode_is_int(op1mode) ), "Cond node", 0
284 ASSERT_AND_RET(mymode == mode_T, "Cond mode is not a tuple", 0);
288 op1mode = get_irn_mode(in[1]);
289 /* Return: BB x M x data1 x ... x datan --> X */
290 /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
291 ASSERT_AND_RET( op1mode == mode_M, "Return node", 0 ); /* operand M */
292 for (i=2; i < get_irn_arity(n); i++) {
293 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Return node", 0 ); /* operand datai */
295 ASSERT_AND_RET( mymode == mode_X, "Result X", 0 ); /* result X */
296 /* Compare returned results with result types of method type */
297 mt = get_entity_type(get_irg_ent(irg));
298 ASSERT_AND_RET( get_Return_n_ress(n) == get_method_n_ress(mt),
299 "Number of results for Return doesn't match number of results in type.", 0 );
300 for (i = 0; i < get_Return_n_ress(n); i++)
302 get_irn_mode(get_Return_res(n, i)) == get_type_mode(get_method_res_type(mt, i)),
303 "Mode of result for Return doesn't match mode of result type.", 0);
307 op1mode = get_irn_mode(in[1]);
308 op2mode = get_irn_mode(in[2]);
310 /* Sel: BB x M x ref --> X x M */
311 op1mode == mode_M && mode_is_reference(op2mode) &&
312 mymode == mode_T, "Raise node", 0
318 /* Const: BB --> data */
319 (mode_is_data (mymode) ||
320 mymode == mode_b) /* we want boolean constants for static evaluation */
321 ,"Const node", 0 /* of Cmp. */
327 /* SymConst: BB --> int*/
328 (mode_is_int(mymode) ||
329 /* SymConst: BB --> ref */
330 mode_is_reference(mymode))
331 ,"SymConst node", 0);
335 op1mode = get_irn_mode(in[1]);
336 op2mode = get_irn_mode(in[2]);
338 /* Sel: BB x M x ref x int^n --> ref */
339 (op1mode == mode_M && op2mode == mymode && mode_is_reference(mymode)),
342 for (i=3; i < get_irn_arity(n); i++)
344 ASSERT_AND_RET(mode_is_int(get_irn_mode(in[i])), "Sel node", 0);
349 ASSERT_AND_RET(mode_T == mymode, "mode of Instof is not a tuple", 0);
350 ASSERT_AND_RET(mode_is_data(op1mode), "Instof not on data", 0);
354 op1mode = get_irn_mode(in[1]);
355 op2mode = get_irn_mode(in[2]);
356 /* Call: BB x M x ref x data1 x ... x datan
357 --> M x datan+1 x ... x data n+m */
358 ASSERT_AND_RET( op1mode == mode_M && mode_is_reference(op2mode), "Call node", 0 ); /* operand M x ref */
359 for (i=3; i < get_irn_arity(n); i++) {
360 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Call node", 0 ); /* operand datai */
362 ASSERT_AND_RET( mymode == mode_T, "Call result not a tuple", 0 ); /* result T */
363 /* Compare arguments of node with those of type */
364 mt = get_Call_type(n);
366 if (get_method_variadicity(mt) == variadic) {
368 get_Call_n_params(n) >= get_method_n_params(mt),
369 "Number of args for Call doesn't match number of args in variadic type.",
374 get_Call_n_params(n) == get_method_n_params(mt),
375 "Number of args for Call doesn't match number of args in non variadic type.",
379 for (i = 0; i < get_method_n_params(mt); i++) {
381 get_irn_mode(get_Call_param(n, i)) == get_type_mode(get_method_param_type(mt, i)),
382 "Mode of arg for Call doesn't match mode of arg type.", 0,
386 fprintf(stderr, "Assertion for Call type-check failed: %s(", get_type_name(mt));
387 for (i = 0; i < get_method_n_params(mt); ++i) {
388 fprintf(stderr, "%s ", get_mode_name(get_type_mode(get_method_param_type(mt, i))));
390 fprintf(stderr, ") != CALL(");
392 for (i = 0; i < get_Call_n_params(n); ++i) {
393 fprintf(stderr, "%s ", get_mode_name(get_irn_mode(get_Call_param(n, i))));
395 fprintf(stderr, ")\n");
403 op1mode = get_irn_mode(in[1]);
404 op2mode = get_irn_mode(in[2]);
407 /* common Add: BB x numP x numP --> numP */
408 (op1mode == mymode && op2mode == op1mode && mode_is_numP(mymode)) ||
409 /* Pointer Add: BB x ref x int --> ref */
410 (mode_is_reference(op1mode) && mode_is_int(op2mode) && op1mode == mymode) ||
411 /* Pointer Add: BB x int x ref --> ref */
412 (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode))
416 if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
417 /* BB x ref x int --> ref or BB x int x ref --> ref */
418 op_is_symmetric = 0; /* ArmRoq */
420 /* BB x num x num --> num or BB x ref x ref */
426 op1mode = get_irn_mode(in[1]);
427 op2mode = get_irn_mode(in[2]);
429 /* common Sub: BB x numP x numP --> numP */
430 ((mymode ==op1mode && mymode == op2mode && mode_is_numP(op1mode)) ||
431 /* Pointer Sub: BB x ref x int --> ref */
432 (op1mode == mymode && mode_is_int(op2mode) && mode_is_reference(mymode)) ||
433 /* Pointer Sub: BB x int x ref --> ref */
434 (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode)) ||
435 /* Pointer Sub: BB x ref x ref --> int */
436 (op1mode == op2mode && mode_is_reference(op2mode) && mode_is_int(mymode))),
439 if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
440 op_is_symmetric = 0; /* ArmRoq */
447 op1mode = get_irn_mode(in[1]);
449 /* Minus: BB x float --> float */
450 op1mode == mymode && get_mode_sort(op1mode) == irms_float_number, "Minus node", 0
456 op1mode = get_irn_mode(in[1]);
457 op2mode = get_irn_mode(in[2]);
459 /* Mul: BB x int1 x int1 --> int2 */
460 ((mode_is_int(op1mode) && op2mode == op1mode && mode_is_int(mymode)) ||
461 (mode_is_float(op1mode) && op2mode == op1mode && mymode == op1mode)),
468 op1mode = get_irn_mode(in[1]);
469 op2mode = get_irn_mode(in[2]);
470 op3mode = get_irn_mode(in[3]);
472 /* Quot: BB x M x float x float --> M x X x float */
473 op1mode == mode_M && op2mode == op3mode &&
474 get_mode_sort(op2mode) == irms_float_number &&
482 op1mode = get_irn_mode(in[1]);
483 op2mode = get_irn_mode(in[2]);
484 op3mode = get_irn_mode(in[3]);
486 /* DivMod: BB x M x int x int --> M x X x int x int */
488 mode_is_int(op2mode) &&
489 op3mode == op2mode &&
498 op1mode = get_irn_mode(in[1]);
499 op2mode = get_irn_mode(in[2]);
500 op3mode = get_irn_mode(in[3]);
502 /* Div or Mod: BB x M x int x int --> M x X x int */
504 op2mode == op3mode &&
505 mode_is_int(op2mode) &&
513 op1mode = get_irn_mode(in[1]);
515 /* Abs: BB x num --> num */
517 mode_is_num (op1mode),
526 op1mode = get_irn_mode(in[1]);
527 op2mode = get_irn_mode(in[2]);
529 /* And or Or or Eor: BB x int x int --> int */
530 mode_is_int(mymode) &&
531 op2mode == op1mode &&
533 "And, Or or Eor node", 0
539 op1mode = get_irn_mode(in[1]);
541 /* Not: BB x int --> int */
542 mode_is_int(mymode) &&
551 op1mode = get_irn_mode(in[1]);
552 op2mode = get_irn_mode(in[2]);
554 /* Cmp: BB x datab x datab --> b16 */
555 mode_is_data (op1mode) &&
556 op2mode == op1mode &&
565 op1mode = get_irn_mode(in[1]);
566 op2mode = get_irn_mode(in[2]);
568 /* Shl, Shr or Shrs: BB x int x int_u --> int */
569 mode_is_int(op1mode) &&
570 mode_is_int(op2mode) &&
571 !mode_is_signed(op2mode) &&
573 "Shl, Shr, Shr or Rot node"
578 op1mode = get_irn_mode(in[1]);
579 op2mode = get_irn_mode(in[2]);
581 /* Rot: BB x int x int --> int */
582 mode_is_int(op1mode) &&
583 mode_is_int(op2mode) &&
590 op1mode = get_irn_mode(in[1]);
592 /* Conv: BB x datab1 --> datab2 */
593 mode_is_datab(op1mode) && mode_is_data(mymode),
599 op1mode = get_irn_mode(in[1]);
601 /* Conv: BB x datab1 --> datab2 */
602 mode_is_data(op1mode) && op1mode == mymode,
608 /* Phi: BB x dataM^n --> dataM */
609 /* for some reason "<=" aborts. int there a problem with get_store? */
610 for (i=1; i < get_irn_arity(n); i++) {
611 if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
612 ASSERT_AND_RET( get_irn_mode(in[i]) == mymode, "Phi node", 0);
614 ASSERT_AND_RET( mode_is_dataM(mymode), "Phi node", 0 );
618 op1mode = get_irn_mode(in[1]);
619 op2mode = get_irn_mode(in[2]);
621 /* Load: BB x M x ref --> M x X x data */
622 op1mode == mode_M && mode_is_reference(op2mode),
625 ASSERT_AND_RET( mymode == mode_T, "Load node", 0 );
629 op1mode = get_irn_mode(in[1]);
630 op2mode = get_irn_mode(in[2]);
631 op3mode = get_irn_mode(in[3]);
633 /* Load: BB x M x ref data --> M x X */
634 op1mode == mode_M && mode_is_reference(op2mode) && mode_is_data(op3mode),
637 ASSERT_AND_RET(mymode == mode_T, "Store node", 0);
641 op1mode = get_irn_mode(in[1]);
642 op2mode = get_irn_mode(in[2]);
644 /* Alloc: BB x M x int_u --> M x X x ref */
646 mode_is_int(op2mode) &&
647 !mode_is_signed(op2mode) &&
654 op1mode = get_irn_mode(in[1]);
655 op2mode = get_irn_mode(in[2]);
657 /* Free: BB x M x ref --> M */
658 op1mode == mode_M && mode_is_reference(op2mode) &&
665 /* Sync: BB x M^n --> M */
666 for (i=1; i < get_irn_arity(n); i++) {
667 ASSERT_AND_RET( get_irn_mode(in[i]) == mode_M, "Sync node", 0 );
669 ASSERT_AND_RET( mymode == mode_M, "Sync node", 0 );
673 return vrfy_Proj_proj(n, irg);
684 int irn_vrfy(ir_node *n)
686 return irn_vrfy_irg(n, current_ir_graph);
689 /*******************************************************************/
690 /* Verify the whole graph. */
691 /*******************************************************************/
693 static void vrfy_wrap(ir_node *node, void *env)
697 *res = irn_vrfy(node);
700 int irg_vrfy(ir_graph *irg)
705 rem = current_ir_graph;
706 current_ir_graph = irg;
708 assert(get_irg_pinned(irg) == pinned);
710 irg_walk(irg->end, vrfy_wrap, NULL, &res);
712 current_ir_graph = rem;