1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
4 * Authors: Christian Schaefer
15 # include "irgraph_t.h"
19 /* @@@ replace use of array "in" by access functions. */
20 ir_node **get_irn_in (ir_node *node);
23 vrfy_Proj_proj(ir_node *p) {
28 pred = skip_nop(get_Proj_pred(p));
29 assert(get_irn_mode(pred) == mode_T);
30 mode = get_irn_mode(p);
31 proj = get_Proj_proj(p);
33 switch (get_irn_opcode(pred)) {
35 assert (((proj == 0 && mode == mode_X) ||
36 (proj == 1 && mode == mode_M) ||
37 (proj == 2 && mode == mode_P) ||
38 (proj == 3 && mode == mode_P) ||
39 (proj == 4 && mode == mode_T)) &&
40 "wrong Proj from Start" );
43 assert ((proj >= 0 && mode == mode_X) &&
44 "wrong Proj from Cond");
47 assert (((proj == 0 && mode == mode_X) ||
48 (proj == 1 && mode == mode_M)) &&
49 "wrong Proj from Raise" );
52 assert (((proj >= 0 && mode == mode_X) &&
53 "wrong Proj from InstOf"));
56 assert (((proj == 0 && mode == mode_M) ||
57 (proj == 1 && mode == mode_X) ||
58 (proj == 2 && mode == mode_T) ||
59 (proj == 3 && mode == mode_M)) &&
60 "wrong Proj from Call" );
63 assert (((proj == 0 && mode == mode_M) ||
64 (proj == 1 && mode == mode_X) ||
65 (proj == 2 && mode_is_float(mode))) &&
66 "wrong Proj from Quot");
69 assert (((proj == 0 && mode == mode_M) ||
70 (proj == 1 && mode == mode_X) ||
71 (proj == 2 && mode == mode_Is) ||
72 (proj == 3 && mode == mode_Is)) &&
73 "wrong Proj from DivMod" );
77 assert (((proj == 0 && mode == mode_M) ||
78 (proj == 1 && mode == mode_X) ||
79 (proj == 2 && mode == mode_Is)) &&
80 "wrong Proj from Div or Mod" );
83 assert ((proj >= 0 && proj <= 15 && mode == mode_b) &&
84 "wrong Proj from Cmp");
87 assert (((proj == 0 && mode == mode_M) ||
88 (proj == 1 && mode == mode_X) ||
89 (proj == 2 && mode_is_data(mode))) &&
90 "wrong Proj from Load");
93 assert (((proj == 0 && mode == mode_M) ||
94 (proj == 1 && mode == mode_X)) &&
95 "wrong Proj from Store");
98 assert (((proj == 0 && mode == mode_M) ||
99 (proj == 1 /* && mode == mode_X*/) ||
100 (proj == 2 && mode == mode_P)) &&
101 "wrong Proj from Alloc");
104 type *mt; /* A method type */
105 pred = skip_nop(get_Proj_pred(pred));
106 assert(get_irn_mode(pred) == mode_T);
107 switch (get_irn_opcode(pred)) {
109 assert (proj >= 0 && mode_is_data(mode) &&
110 "wrong Proj from Proj from Start");
111 mt = get_entity_type(get_irg_ent(current_ir_graph));
112 assert(proj < get_method_n_params(mt) &&
113 "More Projs for args than args in type");
114 assert(mode == get_type_mode(get_method_param_type(mt, proj)) &&
115 "Mode of Proj from Start doesn't match mode of param type.");
118 assert (proj >= 0 && mode_is_data(mode) &&
119 "wrong Proj from Proj from Call");
120 mt = get_Call_type(pred);
121 assert(proj < get_method_n_ress(mt) &&
122 "More Projs for results than results in type.");
123 assert(mode == get_type_mode(get_method_res_type(mt, proj)) &&
124 "Mode of Proj from Call doesn't match mode of result type.");
146 irn_vrfy (ir_node *n)
150 ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
151 int op_is_symmetric = 1; /* 0: asymmetric
152 1: operands have identical modes
153 2: modes of operands == mode of this node */
154 type *mt; /* A method type */
158 opcode = get_irn_opcode (n);
160 if (opcode != iro_Phi && opcode != iro_Block)
161 for (i = 0; i < get_irn_arity(n); i++)
162 if (get_irn_opcode(get_irn_n(n, i)) == iro_Bad
163 || get_irn_opcode(get_irn_n(n, i)) == iro_Unknown)
166 mymode = get_irn_mode (n);
173 /* Start: BB --> X x M x P x data1 x ... x datan */
174 mymode == mode_T && "Start node"
180 mymode == mode_X && "Jmp node"
186 mymode == mode_X && "Jmp node"
190 op1mode = get_irn_mode(in[1]);
192 /* Cond: BB x b --> X x X */
194 /* Cond: BB x Iu --> X^n */
195 || op1mode == mode_Iu) && "Cond node"
197 assert (mymode == mode_T);
200 op1mode = get_irn_mode(in[1]);
201 /* Return: BB x M x data1 x ... x datan --> X */
202 /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
203 assert ( op1mode == mode_M && "Return node" ); /* operand M */
204 for (i=2; i < get_irn_arity(n); i++) {
205 assert ( mode_is_data(get_irn_mode(in[i])) && "Return node"); /* operand datai */
207 assert ( mymode == mode_X ); /* result X */
208 /* Compare returned results with result types of method type */
209 mt = get_entity_type(get_irg_ent(current_ir_graph));
210 assert(get_Return_n_ress(n) == get_method_n_ress(mt) &&
211 "Number of results for Return doesn't match number of results in type.");
212 for (i = 0; i < get_Return_n_ress(n); i++)
213 assert((get_irn_mode(get_Return_res(n, i))
214 == get_type_mode(get_method_res_type(mt, i))) &&
215 "Mode of result for Return doesn't match mode of result type.");
219 op1mode = get_irn_mode(in[1]);
220 op2mode = get_irn_mode(in[2]);
222 /* Sel: BB x M x P --> X x M */
223 op1mode == mode_M && op2mode == mode_P
224 && mymode == mode_T && "Raise node"
229 /* Const: BB --> data */
230 (mode_is_data (mymode) ||
231 mymode == mode_b) /* we want boolean constants for static evaluation */
232 && "Const node" /* of Cmp. */
237 /* SymConst: BB --> Iu or
239 ((mymode == mode_Iu) || (mymode == mode_P)) && "SymConst node"
243 op1mode = get_irn_mode(in[1]);
244 op2mode = get_irn_mode(in[2]);
246 /* Sel: BB x M x P x Iu^n --> P */
247 op1mode == mode_M && op2mode == mode_P
248 && mymode == mode_P && "Sel node"
250 for (i=3; i < get_irn_arity(n); i++) {
251 assert (get_irn_mode(in[i]) == mode_Iu && "Sel node"); }
254 assert (mode_T == mymode);
255 assert (mode_is_data (op1mode));
258 op1mode = get_irn_mode(in[1]);
259 op2mode = get_irn_mode(in[2]);
260 /* Call: BB x M x P x data1 x ... x datan
261 --> M x datan+1 x ... x data n+m */
262 assert ( op1mode == mode_M && op2mode == mode_P && "Call node"); /* operand M x P */
263 for (i=3; i < get_irn_arity(n); i++) {
264 assert ( mode_is_data(get_irn_mode(in[i])) && "Call node"); /* operand datai */
266 assert ( mymode == mode_T ); /* result T */
267 /* Compare arguments of node with those of type */
268 mt = get_Call_type(n);
269 assert(get_Call_n_params(n) == get_method_n_params(mt) &&
270 "Number of args for Call doesn't match number of args in type.");
271 for (i = 0; i < get_Call_n_params(n); i++)
272 assert((get_irn_mode(get_Call_param(n, i))
273 == get_type_mode(get_method_param_type(mt, i))) &&
274 "Mode of arg for Call doesn't match mode of arg type.");
277 op1mode = get_irn_mode(in[1]);
278 op2mode = get_irn_mode(in[2]);
280 /* common Add: BB x num x num --> num */
281 ((mymode == op1mode && mymode == op2mode
282 && mode_is_num(mymode))
283 || /* Pointer Add: BB x P x Is --> P */
284 (op1mode == mode_P && op2mode == mode_Is && mymode == mode_P)
285 || /* Pointer Add: BB x Is x P --> P */
286 (op1mode == mode_Is && op2mode == mode_P && mymode == mode_P))
289 if (op1mode == mode_P || op2mode == mode_P) {
290 /* BB x P x Is --> P or BB x Is x P --> P */
291 op_is_symmetric = 0; /* ArmRoq */
293 /* BB x num x num --> num */
298 op1mode = get_irn_mode(in[1]);
299 op2mode = get_irn_mode(in[2]);
301 /* common Sub: BB x num x num --> num */
302 ((mymode ==op1mode && mymode == op2mode
303 && mode_is_num(op1mode))
304 || /* Pointer Sub: BB x P x Is --> P */
305 (op1mode == mode_P && op2mode == mode_Is && mymode == mode_P)
306 || /* Pointer Sub: BB x Is x P --> P */
307 (op1mode == mode_Is && op2mode == mode_P && mymode == mode_P)
308 || /* Pointer Sub: BB x P x P --> Is */
309 (op1mode == mode_P && op2mode == mode_P && mymode == mode_Is))
312 if (op1mode == mode_P && op2mode == mode_P) {
313 op_is_symmetric = 1; /* ArmRoq */
314 } else if (op1mode == mode_P || op2mode == mode_P) {
315 op_is_symmetric = 0; /* ArmRoq */
321 op1mode = get_irn_mode(in[1]);
323 /* Minus: BB x float --> float */
324 op1mode == mymode && mode_is_float (op1mode) && "Minus node"
329 op1mode = get_irn_mode(in[1]);
330 op2mode = get_irn_mode(in[2]);
332 /* Mul: BB x num x num --> num */
333 mymode == op1mode && mymode == op2mode
334 && mode_is_num (op1mode) && "Mul node"
339 op1mode = get_irn_mode(in[1]);
340 op2mode = get_irn_mode(in[2]);
341 op3mode = get_irn_mode(in[3]);
343 /* Quot: BB x M x float x float --> M x X x float */
344 op1mode == mode_M && op2mode == op3mode
345 && mode_is_float(op2mode) && mymode == mode_T && "Quot node"
350 op1mode = get_irn_mode(in[1]);
351 op2mode = get_irn_mode(in[2]);
352 op3mode = get_irn_mode(in[3]);
354 /* DivMod: BB x M x num x num --> M x X x Is x Is */
355 op1mode == mode_M && op2mode == op3mode
356 && mode_is_num (op2mode) && mymode == mode_T && "DivMod node"
362 op1mode = get_irn_mode(in[1]);
363 op2mode = get_irn_mode(in[2]);
364 op3mode = get_irn_mode(in[3]);
366 /* Div or Mod: BB x M x num x num --> M x X x Is */
367 op1mode == mode_M && op2mode == op3mode &&
368 mode_is_num (op2mode) && mymode == mode_T && "Div or Mod node"
373 op1mode = get_irn_mode(in[1]);
375 /* Abs: BB x num --> num */
376 op1mode == mymode && mode_is_num (op1mode) && "Abs node"
383 op1mode = get_irn_mode(in[1]);
384 op2mode = get_irn_mode(in[2]);
386 /* And or Or or Eor: BB x int x int --> int */
387 mymode == op1mode && mymode == op2mode
388 && mode_is_int (mymode) && "And, Or or Eor node"
393 op1mode = get_irn_mode(in[1]);
395 /* Not: BB x int --> int */
397 && mode_is_int (mymode) && "Not node"
403 op1mode = get_irn_mode(in[1]);
404 op2mode = get_irn_mode(in[2]);
406 /* Cmp: BB x datab x datab --> b16 */
407 op1mode == op2mode && mode_is_data (op1mode)
408 && mymode == mode_T && "Cmp node"
415 op1mode = get_irn_mode(in[1]);
416 op2mode = get_irn_mode(in[2]);
418 /* Shl, Shr, Shrs or Rot: BB x int x Iu --> int */
419 mode_is_int (op1mode) && op2mode == mode_Iu
420 && op1mode == mymode && "Shl, Shr, Shr or Rot node"
424 op1mode = get_irn_mode(in[1]);
426 /* Conv: BB x datab1 --> datab2 */
427 mode_is_datab (op1mode)
428 && mode_is_data (mymode) && "Conv node"
432 /* Phi: BB x dataM^n --> dataM */
433 /* for some reason "<=" aborts. Is there a problem with get_store? */
434 for (i=1; i < get_irn_arity(n); i++) {
435 if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
436 assert ( get_irn_mode(in[i]) == mymode && "Phi node");
438 assert ( mode_is_dataM(mymode) && "Phi node");
441 op1mode = get_irn_mode(in[1]);
442 op2mode = get_irn_mode(in[2]);
444 /* Load: BB x M x P --> M x X x data */
445 op1mode == mode_M && op2mode == mode_P && "Load node"
447 assert ( mymode == mode_T && "Load node");
450 op1mode = get_irn_mode(in[1]);
451 op2mode = get_irn_mode(in[2]);
452 op3mode = get_irn_mode(in[3]);
454 /* Load: BB x M x P x data --> M x X */
455 op1mode == mode_M && op2mode == mode_P
456 && mode_is_data (op3mode) && "Store node"
458 assert(mymode == mode_T && "Store node");
461 op1mode = get_irn_mode(in[1]);
462 op2mode = get_irn_mode(in[2]);
464 /* Alloc: BB x M x Iu --> M x X x P */
465 op1mode == mode_M && op2mode == mode_Iu
466 && mymode == mode_T && "Alloc node"
470 op1mode = get_irn_mode(in[1]);
471 op2mode = get_irn_mode(in[2]);
472 op3mode = get_irn_mode(in[3]);
474 /* Free: BB x M x P x Iu --> M */
475 op1mode == mode_M && op2mode == mode_P && op3mode == mode_Iu
476 && mymode == mode_M && "Free node"
480 /* Sync: BB x M^n --> M */
481 for (i=1; i < get_irn_arity(n); i++) {
482 assert ( get_irn_mode(in[i]) == mode_M && "Sync node");
484 assert ( mymode == mode_M && "Sync node");
494 /*******************************************************************/
495 /* Verify the whole graph. */
496 /*******************************************************************/
499 vrfy_wrap (ir_node *node, void *env) {
503 void irg_vrfy (ir_graph *irg)
506 rem = current_ir_graph;
507 current_ir_graph = irg;
509 assert(get_irg_pinned(irg) == pinned);
511 irg_walk(irg->end, vrfy_wrap, NULL, NULL);
513 current_ir_graph = rem;