1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
4 * Authors: Christian Schaefer
15 # include "irgraph_t.h"
20 #define ASSERT_AND_RET(expr, string, ret) if (!(expr)) return (ret)
22 #define ASSERT_AND_RET(expr, string, ret) do { assert((expr) && string); if (!(expr)) return (ret); } while(0)
25 /* @@@ replace use of array "in" by access functions. */
26 ir_node **get_irn_in(ir_node *node);
29 vrfy_Proj_proj(ir_node *p, ir_graph *irg) {
34 pred = skip_nop(get_Proj_pred(p));
35 assert(get_irn_mode(pred) == mode_T);
36 mode = get_irn_mode(p);
37 proj = get_Proj_proj(p);
39 switch (get_irn_opcode(pred)) {
42 ((proj == 0 && mode == mode_X) ||
43 (proj == 1 && mode == mode_M) ||
44 (proj == 2 && mode == mode_P) ||
45 (proj == 3 && mode == mode_P) ||
46 (proj == 4 && mode == mode_T)),
47 "wrong Proj from Start", 0);
51 ASSERT_AND_RET( (proj >= 0 && mode == mode_X), "wrong Proj from Cond", 0);
56 ((proj == 0 && mode == mode_X) ||
57 (proj == 1 && mode == mode_M)),
58 "wrong Proj from Raise", 0);
62 ASSERT_AND_RET( (proj >= 0 && mode == mode_X), "wrong Proj from InstOf", 0);
67 ((proj == 0 && mode == mode_M) ||
68 (proj == 1 && mode == mode_X) ||
69 (proj == 2 && mode == mode_T) ||
70 (proj == 3 && mode == mode_M)),
71 "wrong Proj from Call", 0);
76 ((proj == 0 && mode == mode_M) ||
77 (proj == 1 && mode == mode_X) ||
78 (proj == 2 && mode_is_float(mode))),
79 "wrong Proj from Quot", 0);
84 ((proj == 0 && mode == mode_M) ||
85 (proj == 1 && mode == mode_X) ||
86 (proj == 2 && mode == mode_Is) ||
87 (proj == 3 && mode_is_int(mode))),
88 "wrong Proj from DivMod", 0);
94 ((proj == 0 && mode == mode_M) ||
95 (proj == 1 && mode == mode_X) ||
96 (proj == 2 && mode_is_int(mode))),
97 "wrong Proj from Div or Mod", 0);
102 (proj >= 0 && proj <= 15 && mode == mode_b),
103 "wrong Proj from Cmp", 0);
108 ((proj == 0 && mode == mode_M) ||
109 (proj == 1 && mode == mode_X) ||
110 (proj == 2 && mode_is_data(mode))),
111 "wrong Proj from Load", 0);
116 ((proj == 0 && mode == mode_M) ||
117 (proj == 1 && mode == mode_X)),
118 "wrong Proj from Store", 0);
123 ((proj == 0 && mode == mode_M) ||
124 (proj == 1 /* && mode == mode_X*/) ||
125 (proj == 2 && mode == mode_P)),
126 "wrong Proj from Alloc", 0);
131 type *mt; /* A method type */
132 pred = skip_nop(get_Proj_pred(pred));
133 ASSERT_AND_RET((get_irn_mode(pred) == mode_T), "Proj from something not a tuple", 0);
134 switch (get_irn_opcode(pred))
139 (proj >= 0 && mode_is_data(mode)),
140 "wrong Proj from Proj from Start", 0);
141 mt = get_entity_type(get_irg_ent(irg));
143 (proj < get_method_n_params(mt)),
144 "More Projs for args than args in type", 0);
145 if ((mode == mode_P) && is_compound_type(get_method_param_type(mt, proj)))
146 /* value argument */ break;
149 (mode == get_type_mode(get_method_param_type(mt, proj))),
150 "Mode of Proj from Start doesn't match mode of param type.", 0);
157 (proj >= 0 && mode_is_data(mode)),
158 "wrong Proj from Proj from Call", 0);
159 mt = get_Call_type(pred);
161 (proj < get_method_n_ress(mt)),
162 "More Projs for results than results in type.", 0);
163 if ((mode == mode_P) && is_compound_type(get_method_res_type(mt, proj)))
164 /* value result */ break;
167 (mode == get_type_mode(get_method_res_type(mt, proj))),
168 "Mode of Proj from Call doesn't match mode of result type.", 0);
177 ASSERT_AND_RET(0, "Unknown opcode", 0);
196 ASSERT_AND_RET(0, "Unknown opcode", 0);
203 int irn_vrfy_irg(ir_node *n, ir_graph *irg)
207 ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
208 int op_is_symmetric = 1; /* 0: asymmetric
209 1: operands have identical modes
210 2: modes of operands == mode of this node */
211 type *mt; /* A method type */
215 if (! interprocedural_view) {
217 * do NOT check placement in interprocedural view, as we don't always know
218 * the "right" graph ...
220 ASSERT_AND_RET(node_is_in_irgs_storage(irg, n), "Node is not stored on proper IR graph!", 0);
223 opcode = get_irn_opcode (n);
225 /* We don't want to test nodes whose predecessors are Bad or Unknown,
226 as we would have to special case that for each operation. */
227 if (opcode != iro_Phi && opcode != iro_Block)
228 for (i = 0; i < get_irn_arity(n); i++) {
229 opcode1 = get_irn_opcode(get_irn_n(n, i));
230 if (opcode1 == iro_Bad || opcode1 == iro_Unknown)
234 mymode = get_irn_mode (n);
241 /* Start: BB --> X x M x P x data1 x ... x datan */
242 mymode == mode_T, "Start node", 0
249 mymode == mode_X, "Jmp node", 0
256 mymode == mode_X, "Jmp node", 0
261 op1mode = get_irn_mode(in[1]);
263 /* Cond: BB x b --> X x X */
264 (op1mode == mode_b ||
265 /* Cond: BB x int --> X^n */
266 mode_is_int(op1mode) ), "Cond node", 0
268 ASSERT_AND_RET(mymode == mode_T, "Cond mode is not a tuple", 0);
272 op1mode = get_irn_mode(in[1]);
273 /* Return: BB x M x data1 x ... x datan --> X */
274 /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
275 ASSERT_AND_RET( op1mode == mode_M, "Return node", 0 ); /* operand M */
276 for (i=2; i < get_irn_arity(n); i++) {
277 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Return node", 0 ); /* operand datai */
279 ASSERT_AND_RET( mymode == mode_X, "Result X", 0 ); /* result X */
280 /* Compare returned results with result types of method type */
281 mt = get_entity_type(get_irg_ent(irg));
282 ASSERT_AND_RET( get_Return_n_ress(n) == get_method_n_ress(mt),
283 "Number of results for Return doesn't match number of results in type.", 0 );
284 for (i = 0; i < get_Return_n_ress(n); i++)
286 get_irn_mode(get_Return_res(n, i)) == get_type_mode(get_method_res_type(mt, i)),
287 "Mode of result for Return doesn't match mode of result type.", 0);
291 op1mode = get_irn_mode(in[1]);
292 op2mode = get_irn_mode(in[2]);
294 /* Sel: BB x M x P --> X x M */
295 op1mode == mode_M && op2mode == mode_P &&
296 mymode == mode_T, "Raise node", 0
302 /* Const: BB --> data */
303 (mode_is_data (mymode) ||
304 mymode == mode_b) /* we want boolean constants for static evaluation */
305 ,"Const node", 0 /* of Cmp. */
311 /* SymConst: BB --> int*/
312 (mode_is_int(mymode) ||
313 /* SymConst: BB --> P*/
315 ,"SymConst node", 0);
319 op1mode = get_irn_mode(in[1]);
320 op2mode = get_irn_mode(in[2]);
322 /* Sel: BB x M x P x int^n --> P */
323 op1mode == mode_M && op2mode == mode_P &&
324 mymode == mode_P, "Sel node", 0
326 for (i=3; i < get_irn_arity(n); i++)
328 ASSERT_AND_RET(mode_is_int(get_irn_mode(in[i])), "Sel node", 0);
333 ASSERT_AND_RET(mode_T == mymode, "mode of Instof is not a tuple", 0);
334 ASSERT_AND_RET(mode_is_data(op1mode), "Instof not on data", 0);
338 op1mode = get_irn_mode(in[1]);
339 op2mode = get_irn_mode(in[2]);
340 /* Call: BB x M x P x data1 x ... x datan
341 --> M x datan+1 x ... x data n+m */
342 ASSERT_AND_RET( op1mode == mode_M && op2mode == mode_P, "Call node", 0 ); /* operand M x P */
343 for (i=3; i < get_irn_arity(n); i++) {
344 ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Call node", 0 ); /* operand datai */
346 ASSERT_AND_RET( mymode == mode_T, "Call result not a tuple", 0 ); /* result T */
347 /* Compare arguments of node with those of type */
348 mt = get_Call_type(n);
350 if (get_method_variadicity(mt) == variadic) {
352 get_Call_n_params(n) >= get_method_n_params(mt),
353 "Number of args for Call doesn't match number of args in variadic type.",
358 get_Call_n_params(n) == get_method_n_params(mt),
359 "Number of args for Call doesn't match number of args in non variadic type.",
363 for (i = 0; i < get_method_n_params(mt); i++) {
365 get_irn_mode(get_Call_param(n, i)) == get_type_mode(get_method_param_type(mt, i)),
366 "Mode of arg for Call doesn't match mode of arg type.", 0);
371 op1mode = get_irn_mode(in[1]);
372 op2mode = get_irn_mode(in[2]);
374 /* common Add: BB x num x num --> num */
375 (( op1mode == mymode && op2mode == op1mode && mode_is_num(mymode)) ||
376 /* Pointer Add: BB x P x int --> P */
377 (op1mode == mode_P && mode_is_int(op2mode) && mymode == mode_P) ||
378 /* Pointer Add: BB x int x P --> P */
379 (mode_is_int(op1mode) && op2mode == mode_P && mymode == mode_P)),
382 if (op1mode == mode_P || op2mode == mode_P) {
383 /* BB x P x int --> P or BB x int x P --> P */
384 op_is_symmetric = 0; /* ArmRoq */
386 /* BB x num x num --> num */
392 op1mode = get_irn_mode(in[1]);
393 op2mode = get_irn_mode(in[2]);
395 /* common Sub: BB x num x num --> num */
396 ((mymode ==op1mode && mymode == op2mode && mode_is_num(op1mode)) ||
397 /* Pointer Sub: BB x P x int --> P */
398 (op1mode == mode_P && mode_is_int(op2mode) && mymode == mode_P) ||
399 /* Pointer Sub: BB x int x P --> P */
400 (mode_is_int(op1mode) && op2mode == mode_P && mymode == mode_P) ||
401 /* Pointer Sub: BB x P x P --> int */
402 (op1mode == mode_P && op2mode == mode_P && mode_is_int(mymode))),
405 if (op1mode == mode_P && op2mode == mode_P) {
406 op_is_symmetric = 1; /* ArmRoq */
407 } else if (op1mode == mode_P || op2mode == mode_P) {
408 op_is_symmetric = 0; /* ArmRoq */
415 op1mode = get_irn_mode(in[1]);
417 /* Minus: BB x float --> float */
418 op1mode == mymode && get_mode_sort(op1mode) == irms_float_number, "Minus node", 0
424 op1mode = get_irn_mode(in[1]);
425 op2mode = get_irn_mode(in[2]);
427 /* Mul: BB x int1 x int1 --> int2 */
428 mode_is_int(op1mode) &&
429 op2mode == op1mode &&
437 op1mode = get_irn_mode(in[1]);
438 op2mode = get_irn_mode(in[2]);
439 op3mode = get_irn_mode(in[3]);
441 /* Quot: BB x M x float x float --> M x X x float */
442 op1mode == mode_M && op2mode == op3mode &&
443 get_mode_sort(op2mode) == irms_float_number &&
451 op1mode = get_irn_mode(in[1]);
452 op2mode = get_irn_mode(in[2]);
453 op3mode = get_irn_mode(in[3]);
455 /* DivMod: BB x M x int x int --> M x X x int x int */
457 mode_is_int(op2mode) &&
458 op3mode == op2mode &&
467 op1mode = get_irn_mode(in[1]);
468 op2mode = get_irn_mode(in[2]);
469 op3mode = get_irn_mode(in[3]);
471 /* Div or Mod: BB x M x int x int --> M x X x int */
473 op2mode == op3mode &&
474 mode_is_int(op2mode) &&
482 op1mode = get_irn_mode(in[1]);
484 /* Abs: BB x num --> num */
486 mode_is_num (op1mode),
495 op1mode = get_irn_mode(in[1]);
496 op2mode = get_irn_mode(in[2]);
498 /* And or Or or Eor: BB x int x int --> int */
499 mode_is_int(mymode) &&
500 op2mode == op1mode &&
502 "And, Or or Eor node", 0
508 op1mode = get_irn_mode(in[1]);
510 /* Not: BB x int --> int */
511 mode_is_int(mymode) &&
520 op1mode = get_irn_mode(in[1]);
521 op2mode = get_irn_mode(in[2]);
523 /* Cmp: BB x datab x datab --> b16 */
524 mode_is_data (op1mode) &&
525 op2mode == op1mode &&
534 op1mode = get_irn_mode(in[1]);
535 op2mode = get_irn_mode(in[2]);
537 /* Shl, Shr or Shrs: BB x int x int_u --> int */
538 mode_is_int(op1mode) &&
539 mode_is_int(op2mode) &&
540 !mode_is_signed(op2mode) &&
542 "Shl, Shr, Shr or Rot node"
547 op1mode = get_irn_mode(in[1]);
548 op2mode = get_irn_mode(in[2]);
550 /* Rot: BB x int x int --> int */
551 mode_is_int(op1mode) &&
552 mode_is_int(op2mode) &&
559 op1mode = get_irn_mode(in[1]);
561 /* Conv: BB x datab1 --> datab2 */
562 mode_is_datab(op1mode) && mode_is_data(mymode),
568 /* Phi: BB x dataM^n --> dataM */
569 /* for some reason "<=" aborts. int there a problem with get_store? */
570 for (i=1; i < get_irn_arity(n); i++) {
571 if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
572 ASSERT_AND_RET( get_irn_mode(in[i]) == mymode, "Phi node", 0);
574 ASSERT_AND_RET( mode_is_dataM(mymode), "Phi node", 0 );
578 op1mode = get_irn_mode(in[1]);
579 op2mode = get_irn_mode(in[2]);
581 /* Load: BB x M x P --> M x X x data */
582 op1mode == mode_M && op2mode == mode_P,
585 ASSERT_AND_RET( mymode == mode_T, "Load node", 0 );
589 op1mode = get_irn_mode(in[1]);
590 op2mode = get_irn_mode(in[2]);
591 op3mode = get_irn_mode(in[3]);
593 /* Load: BB x M x P x data --> M x X */
594 op1mode == mode_M && op2mode == mode_P && mode_is_data(op3mode),
597 ASSERT_AND_RET(mymode == mode_T, "Store node", 0);
601 op1mode = get_irn_mode(in[1]);
602 op2mode = get_irn_mode(in[2]);
604 /* Alloc: BB x M x int_u --> M x X x P */
606 mode_is_int(op2mode) &&
607 !mode_is_signed(op2mode) &&
614 op1mode = get_irn_mode(in[1]);
615 op2mode = get_irn_mode(in[2]);
617 /* Free: BB x M x P --> M */
618 op1mode == mode_M && op2mode == mode_P &&
625 /* Sync: BB x M^n --> M */
626 for (i=1; i < get_irn_arity(n); i++) {
627 ASSERT_AND_RET( get_irn_mode(in[i]) == mode_M, "Sync node", 0 );
629 ASSERT_AND_RET( mymode == mode_M, "Sync node", 0 );
633 return vrfy_Proj_proj(n, irg);
644 int irn_vrfy(ir_node *n)
646 return irn_vrfy_irg(n, current_ir_graph);
649 /*******************************************************************/
650 /* Verify the whole graph. */
651 /*******************************************************************/
653 static void vrfy_wrap(ir_node *node, void *env)
657 *res = irn_vrfy(node);
660 int irg_vrfy(ir_graph *irg)
665 rem = current_ir_graph;
666 current_ir_graph = irg;
668 assert(get_irg_pinned(irg) == pinned);
670 irg_walk(irg->end, vrfy_wrap, NULL, &res);
672 current_ir_graph = rem;