1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Christian Schaefer
15 # include "irgraph_t.h"
19 void vrfy_Proj_proj(ir_node *p);
26 ir_mode *mymode, *op1mode, *op2mode, *op3mode;
27 int op_is_symmetric = 1; /* 0: asymmetric
28 1: operands have identical modes
29 2: modes of operands == mode of this node */
30 type *mt; /* A method type */
34 opcode = get_irn_opcode (n);
36 if (opcode != iro_Phi && opcode != iro_Block)
37 for (i = 0; i < get_irn_arity(n); i++)
38 if (get_irn_opcode(get_irn_n(n, i)) == iro_Bad
39 || get_irn_opcode(get_irn_n(n, i)) == iro_Unknown)
42 mymode = get_irn_mode (n);
49 /* Start: BB --> X x M x P x data1 x ... x datan */
50 mymode == mode_T && "Start node"
56 mymode == mode_X && "Jmp node"
60 op1mode = get_irn_mode(in[1]);
62 /* Cond: BB x b --> X x X */
64 /* Cond: BB x Iu --> X^n */
65 || op1mode == mode_I) && "Cond node"
67 assert (mymode == mode_T);
70 op1mode = get_irn_mode(in[1]);
71 /* Return: BB x M x data1 x ... x datan --> X */
72 /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
73 assert ( op1mode == mode_M && "Return node" ); /* operand M */
74 for (i=2; i < get_irn_arity(n); i++) {
75 assert ( mode_is_data(get_irn_mode(in[i])) && "Return node"); /* operand datai */
77 assert ( mymode == mode_X ); /* result X */
78 /* Compare returned results with result types of method type */
79 mt = get_entity_type(get_irg_ent(current_ir_graph));
80 assert(get_Return_n_res(n) == get_method_n_res(mt) &&
81 "Number of results for Return doesn't match number of results in type.");
82 for (i = 0; i < get_Return_n_res(n); i++)
83 assert((get_irn_mode(get_Return_res(n, i))
84 == get_type_mode(get_method_res_type(mt, i))) &&
85 "Mode of result for Return doesn't match mode of result type.");
89 op1mode = get_irn_mode(in[1]);
90 op2mode = get_irn_mode(in[2]);
92 /* Sel: BB x M x P --> X x M */
93 op1mode == mode_M && op2mode == mode_p
94 && mymode == mode_T && "Raise node"
99 /* Const: BB --> data */
100 (mode_is_data (mymode) ||
101 mymode == mode_b) /* we want boolean constants for static evaluation */
102 && "Const node" /* of Cmp. */
107 /* SymConst: BB --> Iu or
109 ((mymode == mode_I) || (mymode == mode_p)) && "SymConst node"
113 op1mode = get_irn_mode(in[1]);
114 op2mode = get_irn_mode(in[2]);
116 /* Sel: BB x M x P x Iu^n --> P */
117 op1mode == mode_M && op2mode == mode_p
118 && mymode == mode_p && "Sel node"
120 for (i=3; i < get_irn_arity(n); i++) {
121 assert (get_irn_mode(in[i]) == mode_I && "Sel node"); }
124 assert (mode_T == mymode);
125 assert (mode_is_data (op1mode));
128 op1mode = get_irn_mode(in[1]);
129 op2mode = get_irn_mode(in[2]);
130 /* Call: BB x M x P x data1 x ... x datan
131 --> M x datan+1 x ... x data n+m */
132 assert ( op1mode == mode_M && op2mode == mode_p && "Call node"); /* operand M x P */
133 for (i=3; i < get_irn_arity(n); i++) {
134 assert ( mode_is_data(get_irn_mode(in[i])) && "Call node"); /* operand datai */
136 assert ( mymode == mode_T ); /* result T */
137 /* Compare arguments of node with those of type */
138 mt = get_Call_type(n);
139 assert(get_Call_n_params(n) == get_method_n_params(mt) &&
140 "Number of args for Call doesn't match number of args in type.");
141 for (i = 0; i < get_Call_n_params(n); i++)
142 assert((get_irn_mode(get_Call_param(n, i))
143 == get_type_mode(get_method_param_type(mt, i))) &&
144 "Mode of arg for Call doesn't match mode of arg type.");
147 op1mode = get_irn_mode(in[1]);
148 op2mode = get_irn_mode(in[2]);
150 /* common Add: BB x num x num --> num */
151 ((mymode == op1mode && mymode == op2mode
152 && mode_is_num(mymode))
153 || /* Pointer Add: BB x P x Is --> P */
154 (op1mode == mode_p && op2mode == mode_i && mymode == mode_p)
155 || /* Pointer Add: BB x Is x P --> P */
156 (op1mode == mode_i && op2mode == mode_p && mymode == mode_p))
159 if (op1mode == mode_p || op2mode == mode_p) {
160 /* BB x P x Is --> P or BB x Is x P --> P */
161 op_is_symmetric = 0; /* ArmRoq */
163 /* BB x num x num --> num */
168 op1mode = get_irn_mode(in[1]);
169 op2mode = get_irn_mode(in[2]);
171 /* common Sub: BB x num x num --> num */
172 ((mymode ==op1mode && mymode == op2mode
173 && mode_is_num(op1mode))
174 || /* Pointer Sub: BB x P x Is --> P */
175 (op1mode == mode_p && op2mode == mode_i && mymode == mode_p)
176 || /* Pointer Sub: BB x Is x P --> P */
177 (op1mode == mode_i && op2mode == mode_p && mymode == mode_p)
178 || /* Pointer Sub: BB x P x P --> Is */
179 (op1mode == mode_p && op2mode == mode_p && mymode == mode_i))
182 if (op1mode == mode_p && op2mode == mode_p) {
183 op_is_symmetric = 1; /* ArmRoq */
184 } else if (op1mode == mode_p || op2mode == mode_p) {
185 op_is_symmetric = 0; /* ArmRoq */
191 op1mode = get_irn_mode(in[1]);
193 /* Minus: BB x float --> float */
194 op1mode == mymode && mode_is_float (op1mode) && "Minus node"
199 op1mode = get_irn_mode(in[1]);
200 op2mode = get_irn_mode(in[2]);
202 /* Mul: BB x num x num --> num */
203 mymode == op1mode && mymode == op2mode
204 && mode_is_num (op1mode) && "Mul node"
209 op1mode = get_irn_mode(in[1]);
210 op2mode = get_irn_mode(in[2]);
211 op3mode = get_irn_mode(in[3]);
213 /* Quot: BB x M x float x float --> M x X x float */
214 op1mode == mode_M && op2mode == op3mode
215 && mode_is_float(op2mode) && mymode == mode_T && "Quot node"
220 op1mode = get_irn_mode(in[1]);
221 op2mode = get_irn_mode(in[2]);
222 op3mode = get_irn_mode(in[3]);
224 /* DivMod: BB x M x num x num --> M x X x Is x Is */
225 op1mode == mode_M && op2mode == op3mode
226 && mode_is_num (op2mode) && mymode == mode_T && "DivMod node"
232 op1mode = get_irn_mode(in[1]);
233 op2mode = get_irn_mode(in[2]);
234 op3mode = get_irn_mode(in[3]);
236 /* Div or Mod: BB x M x num x num --> M x X x Is */
237 op1mode == mode_M && op2mode == op3mode &&
238 mode_is_num (op2mode) && mymode == mode_T && "Div or Mod node"
243 op1mode = get_irn_mode(in[1]);
245 /* Abs: BB x num --> num */
246 op1mode == mymode && mode_is_num (op1mode) && "Abs node"
253 op1mode = get_irn_mode(in[1]);
254 op2mode = get_irn_mode(in[2]);
256 /* And or Or or Eor: BB x int x int --> int */
257 mymode == op1mode && mymode == op2mode
258 && mode_is_int (mymode) && "And, Or or Eor node"
263 op1mode = get_irn_mode(in[1]);
265 /* Not: BB x int --> int */
267 && mode_is_int (mymode) && "Not node"
273 op1mode = get_irn_mode(in[1]);
274 op2mode = get_irn_mode(in[2]);
276 /* Cmp: BB x datab x datab --> b16 */
277 op1mode == op2mode && mode_is_data (op1mode)
278 && mymode == mode_T && "Cmp node"
285 op1mode = get_irn_mode(in[1]);
286 op2mode = get_irn_mode(in[2]);
288 /* Shl, Shr, Shrs or Rot: BB x int x Iu --> int */
289 mode_is_int (op1mode) && op2mode == mode_I
290 && op1mode == mymode && "Shl, Shr, Shr or Rot node"
294 op1mode = get_irn_mode(in[1]);
296 /* Conv: BB x datab1 --> datab2 */
297 mode_is_datab (op1mode)
298 && mode_is_data (mymode) && "Conv node"
302 /* Phi: BB x dataM^n --> dataM */
303 /* for some reason "<=" aborts. Is there a problem with get_store? */
304 for (i=1; i < get_irn_arity(n); i++) {
306 assert ( get_irn_mode(in[i]) == mymode && "Phi node");
308 assert ( mode_is_dataM(mymode) && "Phi node");
311 op1mode = get_irn_mode(in[1]);
312 op2mode = get_irn_mode(in[2]);
314 /* Load: BB x M x P --> M x X x data */
315 op1mode == mode_M && op2mode == mode_p && "Load node"
317 assert ( mymode == mode_T && "Load node");
320 op1mode = get_irn_mode(in[1]);
321 op2mode = get_irn_mode(in[2]);
322 op3mode = get_irn_mode(in[3]);
324 /* Load: BB x M x P x data --> M x X */
325 op1mode == mode_M && op2mode == mode_p
326 && mode_is_data (op3mode) && "Store node"
328 assert(mymode == mode_T && "Store node");
331 op1mode = get_irn_mode(in[1]);
332 op2mode = get_irn_mode(in[2]);
334 /* Alloc: BB x M x Iu --> M x X x P */
335 op1mode == mode_M && op2mode == mode_I
336 && mymode == mode_T && "Alloc node"
340 op1mode = get_irn_mode(in[1]);
341 op2mode = get_irn_mode(in[2]);
342 op3mode = get_irn_mode(in[3]);
344 /* Free: BB x M x P x Iu --> M */
345 op1mode == mode_M && op2mode == mode_p && op3mode == mode_I
346 && mymode == mode_M && "Free node"
350 /* Sync: BB x M^n --> M */
351 for (i=1; i < get_irn_arity(n); i++) {
352 assert ( get_irn_mode(in[i]) == mode_M && "Sync node");
354 assert ( mymode == mode_M && "Sync node");
364 vrfy_Proj_proj(ir_node *p) {
369 pred = skip_nop(get_Proj_pred(p));
370 assert(get_irn_mode(pred) == mode_T);
371 mode = get_irn_mode(p);
372 proj = get_Proj_proj(p);
374 switch (get_irn_opcode(pred)) {
376 assert ((proj == 0 && mode == mode_X) ||
377 (proj == 1 && mode == mode_M) ||
378 (proj == 2 && mode == mode_p) ||
379 (proj == 3 && mode == mode_p) ||
380 (proj == 4 && mode == mode_T) &&
381 "wrong Proj from Start" );
384 assert ((proj >= 0 && mode == mode_X) &&
385 "wrong Proj from Cond");
388 assert ((proj == 0 && mode == mode_X) ||
389 (proj == 1 && mode == mode_M) &&
390 "wrong Proj from Raise" );
393 assert (((proj >= 0 && mode == mode_X) &&
394 "wrong Proj from InstOf"));
397 assert ((proj == 0 && mode == mode_M) ||
398 (proj == 1 && mode == mode_X) ||
399 (proj == 2 && mode == mode_T) ||
400 (proj == 3 && mode == mode_M) &&
401 "wrong Proj from Call" );
404 assert ((proj == 0 && mode == mode_M) ||
405 (proj == 1 && mode == mode_X) ||
406 (proj == 2 && mode_is_float(mode)) &&
407 "wrong Proj from Quot");
410 assert ((proj == 0 && mode == mode_M) ||
411 (proj == 1 && mode == mode_X) ||
412 (proj == 2 && mode == mode_i) ||
413 (proj == 3 && mode == mode_i) &&
414 "wrong Proj from DivMod" );
418 assert ((proj == 0 && mode == mode_M) ||
419 (proj == 1 && mode == mode_X) ||
420 (proj == 2 && mode == mode_i) &&
421 "wrong Proj from Div or Mod" );
424 assert ((proj >= 0 && proj <= 15 && mode == mode_b) &&
425 "wrong Proj from Cmp");
428 assert ((proj == 0 && mode == mode_M) ||
429 (proj == 1 && mode == mode_X) ||
430 (proj == 2 && mode_is_data(mode)) &&
431 "wrong Proj from Load");
434 assert ((proj == 0 && mode == mode_M) ||
435 (proj == 1 && mode == mode_X) &&
436 "wrong Proj from Store");
439 assert ((proj == 0 && mode == mode_M) ||
440 (proj == 1 /* && mode == mode_X*/) ||
441 (proj == 2 && mode == mode_p) &&
442 "wrong Proj from Alloc");
445 type *mt; /* A method type */
446 pred = skip_nop(get_Proj_pred(pred));
447 assert(get_irn_mode(pred) == mode_T);
448 switch (get_irn_opcode(pred)) {
450 assert (proj >= 0 && mode_is_data(mode) &&
451 "wrong Proj from Proj from Start");
452 mt = get_entity_type(get_irg_ent(current_ir_graph));
453 assert(proj < get_method_n_params(mt) &&
454 "More Projs for args than args in type");
455 assert(mode == get_type_mode(get_method_param_type(mt, proj)) &&
456 "Mode of Proj from Start doesn't match mode of param type.");
459 assert (proj >= 0 && mode_is_data(mode) &&
460 "wrong Proj from Proj from Call");
461 mt = get_Call_type(pred);
462 assert(proj < get_method_n_res(mt) &&
463 "More Projs for results than results in type.");
464 assert(mode == get_type_mode(get_method_res_type(mt, proj)) &&
465 "Mode of Proj from Call doesn't match mode of result type.");
487 /*******************************************************************/
488 /* Verify the whole graph. */
489 /*******************************************************************/
492 vrfy_wrap (ir_node *node, void *env) {
497 irg_vrfy (ir_graph *irg)
500 rem = current_ir_graph;
501 current_ir_graph = irg;
503 assert(get_irg_pinned(irg) == pinned);
505 irg_walk(irg->end, vrfy_wrap, NULL, NULL);
507 current_ir_graph = rem;