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 if ((mode == mode_P) && is_compound_type(get_method_param_type(mt, proj)))
115 /* value argument */ break;
116 assert(mode == get_type_mode(get_method_param_type(mt, proj)) &&
117 "Mode of Proj from Start doesn't match mode of param type.");
120 assert (proj >= 0 && mode_is_data(mode) &&
121 "wrong Proj from Proj from Call");
122 mt = get_Call_type(pred);
123 assert(proj < get_method_n_ress(mt) &&
124 "More Projs for results than results in type.");
125 if ((mode == mode_P) && is_compound_type(get_method_res_type(mt, proj)))
126 /* value result */ break;
127 assert(mode == get_type_mode(get_method_res_type(mt, proj)) &&
128 "Mode of Proj from Call doesn't match mode of result type.");
150 irn_vrfy (ir_node *n)
154 ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
155 int op_is_symmetric = 1; /* 0: asymmetric
156 1: operands have identical modes
157 2: modes of operands == mode of this node */
158 type *mt; /* A method type */
162 opcode = get_irn_opcode (n);
164 if (opcode != iro_Phi && opcode != iro_Block)
165 for (i = 0; i < get_irn_arity(n); i++)
166 if (get_irn_opcode(get_irn_n(n, i)) == iro_Bad
167 || get_irn_opcode(get_irn_n(n, i)) == iro_Unknown)
170 mymode = get_irn_mode (n);
177 /* Start: BB --> X x M x P x data1 x ... x datan */
178 mymode == mode_T && "Start node"
184 mymode == mode_X && "Jmp node"
190 mymode == mode_X && "Jmp node"
194 op1mode = get_irn_mode(in[1]);
196 /* Cond: BB x b --> X x X */
198 /* Cond: BB x Iu --> X^n */
199 || op1mode == mode_Iu) && "Cond node"
201 assert (mymode == mode_T);
204 op1mode = get_irn_mode(in[1]);
205 /* Return: BB x M x data1 x ... x datan --> X */
206 /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
207 assert ( op1mode == mode_M && "Return node" ); /* operand M */
208 for (i=2; i < get_irn_arity(n); i++) {
209 assert ( mode_is_data(get_irn_mode(in[i])) && "Return node"); /* operand datai */
211 assert ( mymode == mode_X ); /* result X */
212 /* Compare returned results with result types of method type */
213 mt = get_entity_type(get_irg_ent(current_ir_graph));
214 assert(get_Return_n_ress(n) == get_method_n_ress(mt) &&
215 "Number of results for Return doesn't match number of results in type.");
216 for (i = 0; i < get_Return_n_ress(n); i++)
217 assert((get_irn_mode(get_Return_res(n, i))
218 == get_type_mode(get_method_res_type(mt, i))) &&
219 "Mode of result for Return doesn't match mode of result type.");
223 op1mode = get_irn_mode(in[1]);
224 op2mode = get_irn_mode(in[2]);
226 /* Sel: BB x M x P --> X x M */
227 op1mode == mode_M && op2mode == mode_P
228 && mymode == mode_T && "Raise node"
233 /* Const: BB --> data */
234 (mode_is_data (mymode) ||
235 mymode == mode_b) /* we want boolean constants for static evaluation */
236 && "Const node" /* of Cmp. */
241 /* SymConst: BB --> Iu or
243 ((mymode == mode_Iu) || (mymode == mode_P)) && "SymConst node"
247 op1mode = get_irn_mode(in[1]);
248 op2mode = get_irn_mode(in[2]);
250 /* Sel: BB x M x P x Iu^n --> P */
251 op1mode == mode_M && op2mode == mode_P
252 && mymode == mode_P && "Sel node"
254 for (i=3; i < get_irn_arity(n); i++) {
255 assert (get_irn_mode(in[i]) == mode_Iu && "Sel node"); }
258 assert (mode_T == mymode);
259 assert (mode_is_data (op1mode));
262 op1mode = get_irn_mode(in[1]);
263 op2mode = get_irn_mode(in[2]);
264 /* Call: BB x M x P x data1 x ... x datan
265 --> M x datan+1 x ... x data n+m */
266 assert ( op1mode == mode_M && op2mode == mode_P && "Call node"); /* operand M x P */
267 for (i=3; i < get_irn_arity(n); i++) {
268 assert ( mode_is_data(get_irn_mode(in[i])) && "Call node"); /* operand datai */
270 assert ( mymode == mode_T ); /* result T */
271 /* Compare arguments of node with those of type */
272 mt = get_Call_type(n);
274 if(get_method_variadicity(mt) == variadic)
276 assert(get_Call_n_params(n) >= get_method_n_params(mt) &&
277 "Number of args for Call doesn't match number of args in " \
282 assert(get_Call_n_params(n) == get_method_n_params(mt) &&
283 "Number of args for Call doesn't match number of args in " \
284 "non variadic type.");
287 for (i = 0; i < get_method_n_params(mt); i++)
288 assert((get_irn_mode(get_Call_param(n, i))
289 == get_type_mode(get_method_param_type(mt, i))) &&
290 "Mode of arg for Call doesn't match mode of arg type.");
293 op1mode = get_irn_mode(in[1]);
294 op2mode = get_irn_mode(in[2]);
296 /* common Add: BB x num x num --> num */
297 ((mymode == op1mode && mymode == op2mode
298 && (mode_is_num(mymode) || mymode == mode_P))
299 || /* Pointer Add: BB x P x Is --> P */
300 (op1mode == mode_P && op2mode == mode_Is && mymode == mode_P)
301 || /* Pointer Add: BB x Is x P --> P */
302 (op1mode == mode_Is && op2mode == mode_P && mymode == mode_P))
305 if (op1mode == mode_P || op2mode == mode_P) {
306 /* BB x P x Is --> P or BB x Is x P --> P */
307 op_is_symmetric = 0; /* ArmRoq */
309 /* BB x num x num --> num */
314 op1mode = get_irn_mode(in[1]);
315 op2mode = get_irn_mode(in[2]);
317 /* common Sub: BB x num x num --> num */
318 ((mymode ==op1mode && mymode == op2mode
319 && mode_is_num(op1mode))
320 || /* Pointer Sub: BB x P x Is --> P */
321 (op1mode == mode_P && op2mode == mode_Is && mymode == mode_P)
322 || /* Pointer Sub: BB x Is x P --> P */
323 (op1mode == mode_Is && op2mode == mode_P && mymode == mode_P)
324 || /* Pointer Sub: BB x P x P --> Is */
325 (op1mode == mode_P && op2mode == mode_P && mymode == mode_Is))
328 if (op1mode == mode_P && op2mode == mode_P) {
329 op_is_symmetric = 1; /* ArmRoq */
330 } else if (op1mode == mode_P || op2mode == mode_P) {
331 op_is_symmetric = 0; /* ArmRoq */
337 op1mode = get_irn_mode(in[1]);
339 /* Minus: BB x float --> float */
340 op1mode == mymode && mode_is_float (op1mode) && "Minus node"
345 op1mode = get_irn_mode(in[1]);
346 op2mode = get_irn_mode(in[2]);
348 /* Mul: BB x num x num --> num */
349 mymode == op1mode && mymode == op2mode
350 && mode_is_num (op1mode) && "Mul node"
355 op1mode = get_irn_mode(in[1]);
356 op2mode = get_irn_mode(in[2]);
357 op3mode = get_irn_mode(in[3]);
359 /* Quot: BB x M x float x float --> M x X x float */
360 op1mode == mode_M && op2mode == op3mode
361 && mode_is_float(op2mode) && mymode == mode_T && "Quot node"
366 op1mode = get_irn_mode(in[1]);
367 op2mode = get_irn_mode(in[2]);
368 op3mode = get_irn_mode(in[3]);
370 /* DivMod: BB x M x num x num --> M x X x Is x Is */
371 op1mode == mode_M && op2mode == op3mode
372 && mode_is_num (op2mode) && mymode == mode_T && "DivMod node"
378 op1mode = get_irn_mode(in[1]);
379 op2mode = get_irn_mode(in[2]);
380 op3mode = get_irn_mode(in[3]);
382 /* Div or Mod: BB x M x num x num --> M x X x Is */
383 op1mode == mode_M && op2mode == op3mode &&
384 mode_is_num (op2mode) && mymode == mode_T && "Div or Mod node"
389 op1mode = get_irn_mode(in[1]);
391 /* Abs: BB x num --> num */
392 op1mode == mymode && mode_is_num (op1mode) && "Abs node"
399 op1mode = get_irn_mode(in[1]);
400 op2mode = get_irn_mode(in[2]);
402 /* And or Or or Eor: BB x int x int --> int */
403 mymode == op1mode && mymode == op2mode
404 && mode_is_int (mymode) && "And, Or or Eor node"
409 op1mode = get_irn_mode(in[1]);
411 /* Not: BB x int --> int */
413 && mode_is_int (mymode) && "Not node"
419 op1mode = get_irn_mode(in[1]);
420 op2mode = get_irn_mode(in[2]);
422 /* Cmp: BB x datab x datab --> b16 */
423 op1mode == op2mode && mode_is_data (op1mode)
424 && mymode == mode_T && "Cmp node"
431 op1mode = get_irn_mode(in[1]);
432 op2mode = get_irn_mode(in[2]);
434 /* Shl, Shr, Shrs or Rot: BB x int x Iu --> int */
435 mode_is_int (op1mode) && op2mode == mode_Iu
436 && op1mode == mymode && "Shl, Shr, Shr or Rot node"
440 op1mode = get_irn_mode(in[1]);
442 /* Conv: BB x datab1 --> datab2 */
443 mode_is_datab (op1mode)
444 && mode_is_data (mymode) && "Conv node"
448 /* Phi: BB x dataM^n --> dataM */
449 /* for some reason "<=" aborts. Is there a problem with get_store? */
450 for (i=1; i < get_irn_arity(n); i++) {
451 if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
452 assert ( get_irn_mode(in[i]) == mymode && "Phi node");
454 assert ( mode_is_dataM(mymode) && "Phi node");
457 op1mode = get_irn_mode(in[1]);
458 op2mode = get_irn_mode(in[2]);
460 /* Load: BB x M x P --> M x X x data */
461 op1mode == mode_M && op2mode == mode_P && "Load node"
463 assert ( mymode == mode_T && "Load node");
466 op1mode = get_irn_mode(in[1]);
467 op2mode = get_irn_mode(in[2]);
468 op3mode = get_irn_mode(in[3]);
470 /* Load: BB x M x P x data --> M x X */
471 op1mode == mode_M && op2mode == mode_P
472 && mode_is_data (op3mode) && "Store node"
474 assert(mymode == mode_T && "Store node");
477 op1mode = get_irn_mode(in[1]);
478 op2mode = get_irn_mode(in[2]);
480 /* Alloc: BB x M x Iu --> M x X x P */
481 op1mode == mode_M && op2mode == mode_Iu
482 && mymode == mode_T && "Alloc node"
486 op1mode = get_irn_mode(in[1]);
487 op2mode = get_irn_mode(in[2]);
488 op3mode = get_irn_mode(in[3]);
490 /* Free: BB x M x P x Iu --> M */
491 op1mode == mode_M && op2mode == mode_P && op3mode == mode_Iu
492 && mymode == mode_M && "Free node"
496 /* Sync: BB x M^n --> M */
497 for (i=1; i < get_irn_arity(n); i++) {
498 assert ( get_irn_mode(in[i]) == mode_M && "Sync node");
500 assert ( mymode == mode_M && "Sync node");
510 /*******************************************************************/
511 /* Verify the whole graph. */
512 /*******************************************************************/
515 vrfy_wrap (ir_node *node, void *env) {
519 void irg_vrfy (ir_graph *irg)
522 rem = current_ir_graph;
523 current_ir_graph = irg;
525 assert(get_irg_pinned(irg) == pinned);
527 irg_walk(irg->end, vrfy_wrap, NULL, NULL);
529 current_ir_graph = rem;