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, ir_graph *irg) {
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(irg));
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_irg (ir_node *n, ir_graph *irg)
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 if (! interprocedural_view) {
164 * do NOT check placement in interprocedural view, as we don't always know
165 * the "right" graph ...
167 assert(node_is_in_irgs_storage(irg, n) && "Node is not stored on proper IR graph!");
170 opcode = get_irn_opcode (n);
172 if (opcode != iro_Phi && opcode != iro_Block)
173 for (i = 0; i < get_irn_arity(n); i++) {
174 opcode1 = get_irn_opcode(get_irn_n(n, i));
175 if (opcode1 == iro_Bad || opcode1 == iro_Unknown)
179 mymode = get_irn_mode (n);
186 /* Start: BB --> X x M x P x data1 x ... x datan */
187 mymode == mode_T && "Start node"
193 mymode == mode_X && "Jmp node"
199 mymode == mode_X && "Jmp node"
203 op1mode = get_irn_mode(in[1]);
205 /* Cond: BB x b --> X x X */
207 /* Cond: BB x Iu --> X^n */
208 || op1mode == mode_Iu) && "Cond node"
210 assert (mymode == mode_T);
213 op1mode = get_irn_mode(in[1]);
214 /* Return: BB x M x data1 x ... x datan --> X */
215 /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
216 assert ( op1mode == mode_M && "Return node" ); /* operand M */
217 for (i=2; i < get_irn_arity(n); i++) {
218 assert ( mode_is_data(get_irn_mode(in[i])) && "Return node"); /* operand datai */
220 assert ( mymode == mode_X ); /* result X */
221 /* Compare returned results with result types of method type */
222 mt = get_entity_type(get_irg_ent(irg));
223 assert(get_Return_n_ress(n) == get_method_n_ress(mt) &&
224 "Number of results for Return doesn't match number of results in type.");
225 for (i = 0; i < get_Return_n_ress(n); i++)
226 assert((get_irn_mode(get_Return_res(n, i))
227 == get_type_mode(get_method_res_type(mt, i))) &&
228 "Mode of result for Return doesn't match mode of result type.");
232 op1mode = get_irn_mode(in[1]);
233 op2mode = get_irn_mode(in[2]);
235 /* Sel: BB x M x P --> X x M */
236 op1mode == mode_M && op2mode == mode_P
237 && mymode == mode_T && "Raise node"
242 /* Const: BB --> data */
243 (mode_is_data (mymode) ||
244 mymode == mode_b) /* we want boolean constants for static evaluation */
245 && "Const node" /* of Cmp. */
250 /* SymConst: BB --> Iu or
252 ((mymode == mode_Iu) || (mymode == mode_P)) && "SymConst node"
256 op1mode = get_irn_mode(in[1]);
257 op2mode = get_irn_mode(in[2]);
259 /* Sel: BB x M x P x Iu^n --> P */
260 op1mode == mode_M && op2mode == mode_P
261 && mymode == mode_P && "Sel node"
263 for (i=3; i < get_irn_arity(n); i++) {
264 assert (get_irn_mode(in[i]) == mode_Iu && "Sel node"); }
267 assert (mode_T == mymode);
268 assert (mode_is_data (op1mode));
271 op1mode = get_irn_mode(in[1]);
272 op2mode = get_irn_mode(in[2]);
273 /* Call: BB x M x P x data1 x ... x datan
274 --> M x datan+1 x ... x data n+m */
275 assert ( op1mode == mode_M && op2mode == mode_P && "Call node"); /* operand M x P */
276 for (i=3; i < get_irn_arity(n); i++) {
277 assert ( mode_is_data(get_irn_mode(in[i])) && "Call node"); /* operand datai */
279 assert ( mymode == mode_T ); /* result T */
280 /* Compare arguments of node with those of type */
281 mt = get_Call_type(n);
283 if(get_method_variadicity(mt) == variadic)
285 assert(get_Call_n_params(n) >= get_method_n_params(mt) &&
286 "Number of args for Call doesn't match number of args in " \
291 assert(get_Call_n_params(n) == get_method_n_params(mt) &&
292 "Number of args for Call doesn't match number of args in " \
293 "non variadic type.");
296 for (i = 0; i < get_method_n_params(mt); i++)
297 assert((get_irn_mode(get_Call_param(n, i))
298 == get_type_mode(get_method_param_type(mt, i))) &&
299 "Mode of arg for Call doesn't match mode of arg type.");
302 op1mode = get_irn_mode(in[1]);
303 op2mode = get_irn_mode(in[2]);
305 /* common Add: BB x num x num --> num */
306 ((mymode == op1mode && mymode == op2mode
307 && (mode_is_num(mymode) || mymode == mode_P))
308 || /* Pointer Add: BB x P x Is --> P */
309 (op1mode == mode_P && op2mode == mode_Is && mymode == mode_P)
310 || /* Pointer Add: BB x Is x P --> P */
311 (op1mode == mode_Is && op2mode == mode_P && mymode == mode_P))
314 if (op1mode == mode_P || op2mode == mode_P) {
315 /* BB x P x Is --> P or BB x Is x P --> P */
316 op_is_symmetric = 0; /* ArmRoq */
318 /* BB x num x num --> num */
323 op1mode = get_irn_mode(in[1]);
324 op2mode = get_irn_mode(in[2]);
326 /* common Sub: BB x num x num --> num */
327 ((mymode ==op1mode && mymode == op2mode
328 && mode_is_num(op1mode))
329 || /* Pointer Sub: BB x P x Is --> P */
330 (op1mode == mode_P && op2mode == mode_Is && mymode == mode_P)
331 || /* Pointer Sub: BB x Is x P --> P */
332 (op1mode == mode_Is && op2mode == mode_P && mymode == mode_P)
333 || /* Pointer Sub: BB x P x P --> Is */
334 (op1mode == mode_P && op2mode == mode_P && mymode == mode_Is))
337 if (op1mode == mode_P && op2mode == mode_P) {
338 op_is_symmetric = 1; /* ArmRoq */
339 } else if (op1mode == mode_P || op2mode == mode_P) {
340 op_is_symmetric = 0; /* ArmRoq */
346 op1mode = get_irn_mode(in[1]);
348 /* Minus: BB x float --> float */
349 op1mode == mymode && mode_is_float (op1mode) && "Minus node"
354 op1mode = get_irn_mode(in[1]);
355 op2mode = get_irn_mode(in[2]);
357 /* Mul: BB x num x num --> num */
358 mymode == op1mode && mymode == op2mode
359 && mode_is_num (op1mode) && "Mul node"
364 op1mode = get_irn_mode(in[1]);
365 op2mode = get_irn_mode(in[2]);
366 op3mode = get_irn_mode(in[3]);
368 /* Quot: BB x M x float x float --> M x X x float */
369 op1mode == mode_M && op2mode == op3mode
370 && mode_is_float(op2mode) && mymode == mode_T && "Quot node"
375 op1mode = get_irn_mode(in[1]);
376 op2mode = get_irn_mode(in[2]);
377 op3mode = get_irn_mode(in[3]);
379 /* DivMod: BB x M x num x num --> M x X x Is x Is */
380 op1mode == mode_M && op2mode == op3mode
381 && mode_is_num (op2mode) && mymode == mode_T && "DivMod node"
387 op1mode = get_irn_mode(in[1]);
388 op2mode = get_irn_mode(in[2]);
389 op3mode = get_irn_mode(in[3]);
391 /* Div or Mod: BB x M x num x num --> M x X x Is */
392 op1mode == mode_M && op2mode == op3mode &&
393 mode_is_num (op2mode) && mymode == mode_T && "Div or Mod node"
398 op1mode = get_irn_mode(in[1]);
400 /* Abs: BB x num --> num */
401 op1mode == mymode && mode_is_num (op1mode) && "Abs node"
408 op1mode = get_irn_mode(in[1]);
409 op2mode = get_irn_mode(in[2]);
411 /* And or Or or Eor: BB x int x int --> int */
412 mymode == op1mode && mymode == op2mode
413 && mode_is_int (mymode) && "And, Or or Eor node"
418 op1mode = get_irn_mode(in[1]);
420 /* Not: BB x int --> int */
422 && mode_is_int (mymode) && "Not node"
428 op1mode = get_irn_mode(in[1]);
429 op2mode = get_irn_mode(in[2]);
431 /* Cmp: BB x datab x datab --> b16 */
432 op1mode == op2mode && mode_is_data (op1mode)
433 && mymode == mode_T && "Cmp node"
440 op1mode = get_irn_mode(in[1]);
441 op2mode = get_irn_mode(in[2]);
443 /* Shl, Shr, Shrs or Rot: BB x int x Iu --> int */
444 mode_is_int (op1mode) && op2mode == mode_Iu
445 && op1mode == mymode && "Shl, Shr, Shr or Rot node"
449 op1mode = get_irn_mode(in[1]);
451 /* Conv: BB x datab1 --> datab2 */
452 mode_is_datab (op1mode)
453 && mode_is_data (mymode) && "Conv node"
457 /* Phi: BB x dataM^n --> dataM */
458 /* for some reason "<=" aborts. Is there a problem with get_store? */
459 for (i=1; i < get_irn_arity(n); i++) {
460 if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
461 assert ( get_irn_mode(in[i]) == mymode && "Phi node");
463 assert ( mode_is_dataM(mymode) && "Phi node");
466 op1mode = get_irn_mode(in[1]);
467 op2mode = get_irn_mode(in[2]);
469 /* Load: BB x M x P --> M x X x data */
470 op1mode == mode_M && op2mode == mode_P && "Load node"
472 assert ( mymode == mode_T && "Load node");
475 op1mode = get_irn_mode(in[1]);
476 op2mode = get_irn_mode(in[2]);
477 op3mode = get_irn_mode(in[3]);
479 /* Load: BB x M x P x data --> M x X */
480 op1mode == mode_M && op2mode == mode_P
481 && mode_is_data (op3mode) && "Store node"
483 assert(mymode == mode_T && "Store node");
486 op1mode = get_irn_mode(in[1]);
487 op2mode = get_irn_mode(in[2]);
489 /* Alloc: BB x M x Iu --> M x X x P */
490 op1mode == mode_M && op2mode == mode_Iu
491 && mymode == mode_T && "Alloc node"
495 op1mode = get_irn_mode(in[1]);
496 op2mode = get_irn_mode(in[2]);
497 op3mode = get_irn_mode(in[3]);
499 /* Free: BB x M x P x Iu --> M */
500 op1mode == mode_M && op2mode == mode_P && op3mode == mode_Iu
501 && mymode == mode_M && "Free node"
505 /* Sync: BB x M^n --> M */
506 for (i=1; i < get_irn_arity(n); i++) {
507 assert ( get_irn_mode(in[i]) == mode_M && "Sync node");
509 assert ( mymode == mode_M && "Sync node");
512 vrfy_Proj_proj(n, irg);
519 irn_vrfy (ir_node *n)
521 irn_vrfy_irg(n, current_ir_graph);
524 /*******************************************************************/
525 /* Verify the whole graph. */
526 /*******************************************************************/
529 vrfy_wrap (ir_node *node, void *env) {
533 void irg_vrfy (ir_graph *irg)
536 rem = current_ir_graph;
537 current_ir_graph = irg;
539 assert(get_irg_pinned(irg) == pinned);
541 irg_walk(irg->end, vrfy_wrap, NULL, NULL);
543 current_ir_graph = rem;