Some doxygen comments added
[libfirm] / ir / ir / irvrfy.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irvrfy.c
4  * Purpose:     Check irnodes for correctness.
5  * Author:      Christian Schaefer
6  * Modified by: Goetz Lindenmaier. Till Riedel
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16
17 # include "irprog.h"
18 # include "irgraph_t.h"
19 # include "irvrfy.h"
20 # include "irgwalk.h"
21 # include "irdump.h"
22
23 #ifdef NDEBUG
24 /*
25  * in RELEASE mode, returns ret if the expression expr evaluates to zero
26  * in ASSERT mode, asserts the expression expr (and the string string).
27  */
28 #define ASSERT_AND_RET(expr, string, ret)       if (!(expr)) return (ret)
29
30 /*
31  * in RELEASE mode, returns ret if the expression expr evaluates to zero
32  * in ASSERT mode, executes blk if the expression expr evaluates to zero and asserts expr
33  */
34 #define ASSERT_AND_RET_DBG(expr, string, ret, blk)      if (!(expr)) return (ret)
35 #else
36 #define ASSERT_AND_RET(expr, string, ret) \
37 do { \
38   if (opt_do_node_verification == NODE_VERIFICATION_ON) {\
39     if (!(expr) && current_ir_graph != get_const_code_irg()) \
40     dump_ir_block_graph(current_ir_graph, "-assert"); \
41     assert((expr) && string); } \
42   if (!(expr)) { \
43     if (opt_do_node_verification == NODE_VERIFICATION_REPORT) \
44       fprintf(stderr, #expr " : " string "\n"); \
45     bad_msg = #expr " && " string; \
46     return (ret); \
47   } \
48 } while(0)
49
50 #define ASSERT_AND_RET_DBG(expr, string, ret, blk) \
51 do { \
52   if (!(expr)) { \
53     bad_msg = #expr " && " string; \
54     if (opt_do_node_verification != NODE_VERIFICATION_ERROR_ONLY) { blk; } \
55     if (opt_do_node_verification == NODE_VERIFICATION_REPORT) \
56       fprintf(stderr, #expr " : " string "\n"); \
57     else if (opt_do_node_verification == NODE_VERIFICATION_ON) \
58       assert((expr) && string); \
59     return (ret); \
60   } \
61 } while(0)
62
63 #endif
64
65 /** if this flag is set, verify entity types in Load & Store nodes */
66 static int vrfy_entities = 0;
67
68 /* @@@ replace use of array "in" by access functions. */
69 ir_node **get_irn_in(ir_node *node);
70
71 static node_verification_t opt_do_node_verification = NODE_VERIFICATION_ON;
72 static const char *bad_msg;
73
74 /* enable verification of Load/Store entities */
75 void vrfy_enable_entity_tests(int enable)
76 {
77   vrfy_entities = enable;
78 }
79
80 /**
81  * little helper for NULL modes
82  */
83 static const char *get_mode_name_ex(ir_mode *mode)
84 {
85   if (! mode)
86     return "<no mode>";
87   return get_mode_name(mode);
88 }
89
90 void do_node_verification(node_verification_t mode)
91 {
92   opt_do_node_verification = mode;
93 }
94
95 /**
96  * Prints a failure for a Node
97  */
98 static void show_node_failure(ir_node *n)
99 {
100   fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s\n" ,
101     get_irn_node_nr(n),
102     get_irn_opname(n), get_irn_modename(n)
103   );
104 }
105
106 /**
107  * Prints a failure message for a binop
108  */
109 static void show_binop_failure(ir_node *n, const char *text)
110 {
111   ir_node *left  = get_binop_left(n);
112   ir_node *right = get_binop_right(n);
113
114   fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s(%s%s, %s%s) did not match (%s)\n",
115       get_irn_node_nr(n),
116       get_irn_opname(n), get_irn_modename(n),
117       get_irn_opname(left), get_irn_modename(left),
118       get_irn_opname(right), get_irn_modename(right),
119       text);
120 }
121
122 /**
123  * Prints a failure message for an unop
124  */
125 static void show_unop_failure(ir_node *n, const char *text)
126 {
127   ir_node *op  = get_unop_op(n);
128
129   fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s(%s%s) did not match (%s)\n",
130       get_irn_node_nr(n),
131       get_irn_opname(n), get_irn_modename(n),
132       get_irn_opname(op), get_irn_modename(op),
133       text);
134 }
135
136 /**
137  * Prints a failure message for a proj
138  */
139 static void show_proj_failure(ir_node *n)
140 {
141   ir_node *op  = get_Proj_pred(n);
142   int proj     = get_Proj_proj(n);
143
144   fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s %d(%s%s) failed\n" ,
145       get_irn_node_nr(n),
146       get_irn_opname(n), get_irn_modename(n), proj,
147       get_irn_opname(op), get_irn_modename(op));
148 }
149
150 /**
151  * Prints a failure message for a proj
152  */
153 static void show_proj_failure_ent(ir_node *n, entity *ent)
154 {
155   ir_node *op  = get_Proj_pred(n);
156   int proj     = get_Proj_proj(n);
157   ir_mode *m   = get_type_mode(get_entity_type(ent));
158
159   fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s %d(%s%s) entity %s(type %s mode %s)failed\n" ,
160       get_irn_node_nr(n),
161       get_irn_opname(n), get_irn_modename(n), proj,
162       get_irn_opname(op), get_irn_modename(op),
163       get_entity_name(ent), get_type_name(get_entity_type(ent)),
164       get_mode_name_ex(m));
165 }
166
167 /**
168  * Show a node and a graph
169  */
170 static void show_node_on_graph(ir_graph *irg, ir_node *n)
171 {
172   entity *ent = get_irg_entity(irg);
173
174   if (ent)
175     fprintf(stderr, "\nFIRM: irn_vrfy_irg() of entity %s, node %ld %s%s\n",
176       get_entity_name(ent),
177       get_irn_node_nr(n), get_irn_opname(n), get_irn_modename(n));
178   else
179     fprintf(stderr, "\nFIRM: irn_vrfy_irg() of graph %p, node %ld %s%s\n",
180       (void *)irg,
181       get_irn_node_nr(n), get_irn_opname(n), get_irn_modename(n));
182 }
183
184 /**
185  * Show call params
186  */
187 static void show_call_param(ir_node *n, type *mt)
188 {
189   int i;
190
191   fprintf(stderr, "\nFIRM: irn_vrfy_irg() Call type-check failed: %s(", get_type_name(mt));
192   for (i = 0; i < get_method_n_params(mt); ++i) {
193     fprintf(stderr, "%s ", get_mode_name_ex(get_type_mode(get_method_param_type(mt, i))));
194   }
195   fprintf(stderr, ") != CALL(");
196
197   for (i = 0; i < get_Call_n_params(n); ++i) {
198     fprintf(stderr, "%s ", get_mode_name_ex(get_irn_mode(get_Call_param(n, i))));
199   }
200   fprintf(stderr, ")\n");
201
202 }
203
204 /**
205  * Show return modes
206  */
207 static void show_return_modes(ir_graph *irg, ir_node *n, type *mt, int i)
208 {
209   entity *ent = get_irg_entity(irg);
210
211   fprintf(stderr, "\nFIRM: irn_vrfy_irg() Return node %ld in entity \"%s\" mode %s different from type mode %s\n",
212     get_irn_node_nr(n), get_entity_name(ent),
213     get_mode_name_ex(get_irn_mode(get_Return_res(n, i))),
214     get_mode_name_ex(get_type_mode(get_method_res_type(mt, i)))
215   );
216 }
217
218 /**
219  * Show return number of results
220  */
221 static void show_return_nres(ir_graph *irg, ir_node *n, type *mt)
222 {
223   entity *ent = get_irg_entity(irg);
224
225   fprintf(stderr, "\nFIRM: irn_vrfy_irg() Return node %ld in entity \"%s\" has %d results different from type %d\n",
226     get_irn_node_nr(n), get_entity_name(ent),
227     get_Return_n_ress(n), get_method_n_ress(mt));
228 }
229
230 /**
231  * Show Phi input
232  */
233 static void show_phi_failure(ir_node *phi, ir_node *pred, int pos)
234 {
235   fprintf(stderr, "\nFIRM: irn_vrfy_irg() Phi node %ld has mode %s different from predeccessor node %ld mode %s\n",
236     get_irn_node_nr(phi), get_mode_name_ex(get_irn_mode(phi)),
237     get_irn_node_nr(pred), get_mode_name_ex(get_irn_mode(pred)));
238 }
239
240 /**
241  * Show Phi inputs
242  */
243 static void show_phi_inputs(ir_node *phi, ir_node *block)
244 {
245   fprintf(stderr, "\nFIRM: irn_vrfy_irg() Phi node %ld has %d inputs, its Block %ld has %d\n",
246     get_irn_node_nr(phi),   get_irn_arity(phi),
247     get_irn_node_nr(block), get_irn_arity(block));
248 }
249
250 /* If the address is Sel or SymConst, return the entity. */
251 static entity *get_ptr_entity(ir_node *ptr) {
252   if (get_irn_op(ptr) == op_Sel) {
253     return get_Sel_entity(ptr);
254   } else if ((get_irn_op(ptr) == op_SymConst) && (get_SymConst_kind(ptr) == symconst_addr_ent)) {
255     return get_SymConst_entity(ptr);
256   }
257   return NULL;
258 }
259
260 /**
261  * verify the Proj number
262  */
263 static int
264 vrfy_Proj_proj(ir_node *p, ir_graph *irg) {
265   ir_node *pred;
266   ir_mode *mode;
267   int proj;
268
269   pred = skip_Id(get_Proj_pred(p));
270   ASSERT_AND_RET(get_irn_mode(pred) == mode_T, "mode of a 'projed' node is not Tuple", 0);
271   mode = get_irn_mode(p);
272   proj = get_Proj_proj(p);
273
274   switch (get_irn_opcode(pred)) {
275     case iro_Start:
276       ASSERT_AND_RET_DBG(
277           (
278            (proj == pn_Start_X_initial_exec && mode == mode_X) ||
279            (proj == pn_Start_M         && mode == mode_M) ||
280            (proj == pn_Start_P_frame_base && mode_is_reference(mode)) ||
281            (proj == pn_Start_P_globals && mode_is_reference(mode)) ||
282            (proj == pn_Start_T_args    && mode == mode_T) ||
283            (proj == pn_Start_P_value_arg_base && mode_is_reference(mode)) ||
284            (proj == pn_Start_P_value_arg_base && mode == mode_T)    /* FIXME: only one of those */
285           ),
286           "wrong Proj from Start", 0,
287       show_proj_failure(p);
288       );
289       break;
290
291     case iro_Cond:
292       ASSERT_AND_RET_DBG(
293         (
294           (proj >= 0 && mode == mode_X && get_irn_mode(get_Cond_selector(pred)) == mode_b) ||   /* compare */
295           (mode == mode_X && mode_is_int(get_irn_mode(get_Cond_selector(pred))))                /* switch */
296         ),
297         "wrong Proj from Cond", 0,
298         show_proj_failure(p);
299       );
300       break;
301
302     case iro_Raise:
303       ASSERT_AND_RET_DBG(
304         ((proj == pn_Raise_X && mode == mode_X) || (proj == pn_Raise_M && mode == mode_M)),
305         "wrong Proj from Raise", 0,
306     show_proj_failure(p);
307       );
308       break;
309
310     case iro_InstOf:
311       ASSERT_AND_RET_DBG(
312     (proj >= 0 && mode == mode_X),
313     "wrong Proj from InstOf", 0,
314     show_proj_failure(p);
315       );
316       break;
317
318     case iro_Call:
319       ASSERT_AND_RET_DBG(
320         ((proj == pn_Call_M_regular        && mode == mode_M) ||
321          (proj == pn_Call_X_except         && mode == mode_X) ||
322          (proj == pn_Call_T_result         && mode == mode_T) ||
323          (proj == pn_Call_M_except         && mode == mode_M) ||
324      (proj == pn_Call_P_value_res_base && mode == mode_P)),
325         "wrong Proj from Call", 0,
326         show_proj_failure(p);
327       );
328
329       break;
330
331     case iro_FuncCall:
332       ASSERT_AND_RET_DBG(
333         ((proj == pn_Call_M_regular        && mode == mode_M) ||
334          (proj == pn_Call_X_except         && mode == mode_X) ||
335          (proj == pn_Call_T_result         && mode == mode_T) ||
336          (proj == pn_Call_M_except         && mode == mode_M) ||
337      (proj == pn_Call_P_value_res_base && mode == mode_P)),
338         "wrong Proj from FuncCall", 0,
339         show_proj_failure(p);
340       );
341       break;
342
343     case iro_Quot:
344       ASSERT_AND_RET_DBG(
345         ((proj == pn_Quot_M        && mode == mode_M) ||
346          (proj == pn_Quot_X_except && mode == mode_X) ||
347          (proj == pn_Quot_res      && mode_is_float(mode))),
348         "wrong Proj from Quot", 0,
349     show_proj_failure(p);
350       );
351       break;
352
353     case iro_DivMod:
354       ASSERT_AND_RET_DBG(
355         ((proj == pn_DivMod_M        && mode == mode_M) ||
356          (proj == pn_DivMod_X_except && mode == mode_X) ||
357          (proj == pn_DivMod_res_div  && mode_is_int(mode)) ||
358          (proj == pn_DivMod_res_mod  && mode_is_int(mode))),
359         "wrong Proj from DivMod", 0,
360     show_proj_failure(p);
361       );
362       break;
363
364     case iro_Div:
365       ASSERT_AND_RET_DBG(
366         ((proj == pn_Div_M        && mode == mode_M) ||
367          (proj == pn_Div_X_except && mode == mode_X) ||
368          (proj == pn_Div_res      && mode_is_int(mode))),
369         "wrong Proj from Div or Mod", 0,
370     show_proj_failure(p);
371       );
372       break;
373
374     case iro_Mod:
375       ASSERT_AND_RET_DBG(
376         ((proj == pn_Mod_M        && mode == mode_M) ||
377          (proj == pn_Mod_X_except && mode == mode_X) ||
378          (proj == pn_Mod_res      && mode_is_int(mode))),
379         "wrong Proj from Div or Mod", 0,
380     show_proj_failure(p);
381       );
382       break;
383
384     case iro_Cmp:
385       ASSERT_AND_RET_DBG(
386         (proj >= 0 && proj <= 15 && mode == mode_b),
387         "wrong Proj from Cmp", 0,
388     show_proj_failure(p);
389       );
390       break;
391
392     case iro_Load:
393       if (proj == pn_Load_res) {
394         ir_node *ptr = get_Load_ptr(pred);
395         entity *ent = get_ptr_entity(ptr);
396
397         if (vrfy_entities && ent && get_irg_phase_state(current_ir_graph) == phase_high) {
398           /* do NOT check this for lowered phases, see comment on Store */
399           ASSERT_AND_RET_DBG(
400                              (mode == get_type_mode(get_entity_type(ent))),
401                              "wrong data Proj from Load, entity type_mode failed", 0,
402                              show_proj_failure_ent(p, ent);
403                              );
404         }
405         else {
406           ASSERT_AND_RET_DBG(
407                              mode_is_data(mode) && mode == get_Load_mode(pred),
408                              "wrong data Proj from Load", 0,
409                              show_proj_failure(p);
410                              );
411         }
412       } else {
413         ASSERT_AND_RET_DBG(
414                            ((proj == pn_Load_M        && mode == mode_M) ||
415                             (proj == pn_Load_X_except && mode == mode_X)),
416                            "wrong Proj from Load", 0,
417                            show_proj_failure(p);
418                            );
419       }
420       break;
421
422     case iro_Store:
423       ASSERT_AND_RET_DBG(
424         ((proj == pn_Store_M        && mode == mode_M) ||
425          (proj == pn_Store_X_except && mode == mode_X)),
426         "wrong Proj from Store", 0,
427         show_proj_failure(p);
428       );
429       break;
430
431     case iro_Alloc:
432       ASSERT_AND_RET_DBG(
433         (
434          (proj == pn_Alloc_M        && mode == mode_M) ||
435          (proj == pn_Alloc_X_except /* && mode == mode_X*/) ||
436          (proj == pn_Alloc_res      && mode_is_reference(mode))
437         ),
438         "wrong Proj from Alloc", 0,
439         show_proj_failure(p);
440       );
441       break;
442
443     case iro_Proj:
444       {
445         type *mt; /* A method type */
446         long nr = get_Proj_proj(pred);
447
448         pred = skip_Id(get_Proj_pred(pred));
449         ASSERT_AND_RET((get_irn_mode(pred) == mode_T), "Proj from something not a tuple", 0);
450         switch (get_irn_opcode(pred))
451         {
452           case iro_Start:
453             mt = get_entity_type(get_irg_entity(irg));
454
455         if (nr == pn_Start_T_args) {
456               ASSERT_AND_RET(
457                   (proj >= 0 && mode_is_data(mode)),
458                   "wrong Proj from Proj from Start", 0);
459               ASSERT_AND_RET(
460                 (proj < get_method_n_params(mt)),
461                 "More Projs for args than args in type", 0
462               );
463               if ((mode_is_reference(mode)) && is_compound_type(get_method_param_type(mt, proj)))
464                 /* value argument */ break;
465
466               ASSERT_AND_RET(
467                   (mode == get_type_mode(get_method_param_type(mt, proj))),
468                   "Mode of Proj from Start doesn't match mode of param type.", 0);
469             }
470         else if (nr == pn_Start_P_value_arg_base) {
471           ASSERT_AND_RET(
472                   (proj >= 0 && mode_is_reference(mode)),
473                   "wrong Proj from Proj from Start", 0
474               );
475               ASSERT_AND_RET(
476                 (proj < get_method_n_params(mt)),
477                 "More Projs for args than args in type", 0
478               );
479         }
480             break;
481
482           case iro_Call:
483             {
484               ASSERT_AND_RET(
485                   (proj >= 0 && mode_is_data(mode)),
486                   "wrong Proj from Proj from Call", 0);
487               mt = get_Call_type(pred);
488               ASSERT_AND_RET(
489                   (proj < get_method_n_ress(mt)),
490                   "More Projs for results than results in type.", 0);
491               if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
492                 /* value result */ break;
493
494               ASSERT_AND_RET(
495                   (mode == get_type_mode(get_method_res_type(mt, proj))),
496                   "Mode of Proj from Call doesn't match mode of result type.", 0);
497
498             }
499             break;
500
501           case iro_FuncCall:
502             {
503               ASSERT_AND_RET(
504                   (proj >= 0 && mode_is_data(mode)),
505                   "wrong Proj from Proj from FuncCall", 0);
506               mt = get_FuncCall_type(pred);
507               ASSERT_AND_RET(
508                   (proj < get_method_n_ress(mt)),
509                   "More Projs for results than results in type.", 0);
510               if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
511                 /* value result */ break;
512
513               ASSERT_AND_RET(
514                   (mode == get_type_mode(get_method_res_type(mt, proj))),
515                   "Mode of Proj from FuncCall doesn't match mode of result type.", 0);
516             }
517             break;
518
519           case iro_Tuple:
520             /* We don't test */
521             break;
522
523           default:
524             ASSERT_AND_RET(0, "Unknown opcode", 0);
525         }
526         break;
527
528       }
529     case iro_Tuple:
530       /* We don't test */
531       break;
532
533     case iro_CallBegin:
534       break;
535
536     case iro_EndReg:
537       break;
538
539     case iro_EndExcept:
540       break;
541
542     default:
543       ASSERT_AND_RET(0, "Unknown opcode", 0);
544   }
545
546   /* all went ok */
547   return 1;
548 }
549
550 int irn_vrfy_irg(ir_node *n, ir_graph *irg)
551 {
552   int i;
553   int opcode, opcode1;
554   ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
555   int op_is_symmetric = 1;  /*  0: asymmetric
556                                 1: operands have identical modes
557                                 2: modes of operands == mode of this node */
558   type *mt;                 /* A method type */
559   entity *ent;
560
561   ir_node **in;
562
563   if (!opt_do_node_verification) return 1;
564
565   if (! get_interprocedural_view()) {
566     /*
567      * do NOT check placement in interprocedural view, as we don't always know
568      * the "right" graph ...
569      */
570     ASSERT_AND_RET_DBG(
571                        node_is_in_irgs_storage(irg, n),
572                        "Node is not stored on proper IR graph!", 0,
573                        show_node_on_graph(irg, n);
574                        );
575   }
576
577   opcode = get_irn_opcode(n);
578
579   /* We don't want to test nodes whose predecessors are Bad,
580      as we would have to special case that for each operation. */
581   if (opcode != iro_Phi && opcode != iro_Block)
582     for (i = 0; i < get_irn_arity(n); i++) {
583       opcode1 = get_irn_opcode(get_irn_n(n, i));
584       if (opcode1 == iro_Bad)
585         return 1;
586     }
587
588   mymode = get_irn_mode(n);
589   in = get_irn_in(n);
590
591   switch (opcode) {
592
593     case iro_Block:
594       for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
595         ir_node *pred =  get_Block_cfgpred(n, i);
596         ASSERT_AND_RET(
597                        (is_Bad(pred)     ||
598                         is_Unknown(pred) ||
599                         (get_irn_mode(pred) == mode_X)
600                         ), "Block node", 0);
601       }
602       /*  End block may only have Return, Raise or fragile ops as preds. */
603       if (n == get_irg_end_block(irg))
604         for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
605           ir_node *pred =  skip_Proj(get_Block_cfgpred(n, i));
606           if (is_Proj(pred) || get_irn_op(pred) == op_Tuple)
607             break;   /*  We can not test properly.  How many tuples are there? */
608           ASSERT_AND_RET(((get_irn_op(pred) == op_Return) ||
609                           is_Bad(pred)                    ||
610                           (get_irn_op(pred) == op_Raise)  ||
611                           is_fragile_op(pred)               ),
612                          "End Block node", 0);
613         }
614       /*  irg attr must == graph we are in. */
615       if (! get_interprocedural_view()) {
616         ASSERT_AND_RET(((get_irn_irg(n) && get_irn_irg(n) == irg)), "Block node has wrong irg attribute", 0);
617       }
618
619       break;
620
621     case iro_Start:
622       ASSERT_AND_RET(
623                      /* Start: BB --> X x M x ref x data1 x ... x datan x ref */
624                      mymode == mode_T, "Start node", 0
625                      );
626       break;
627
628     case iro_Jmp:
629       ASSERT_AND_RET(
630                      /* Jmp: BB --> X */
631                      mymode == mode_X, "Jmp node", 0
632                      );
633       break;
634
635     case iro_Break:
636       ASSERT_AND_RET(
637                      /* Jmp: BB --> X */
638                      mymode == mode_X, "Jmp node", 0
639                      );
640       break;
641
642     case iro_Cond:
643       op1mode = get_irn_mode(in[1]);
644       ASSERT_AND_RET(
645                      /* Cond: BB x b --> X x X */
646                      (op1mode == mode_b ||
647                       /* Cond: BB x int --> X^n */
648                       mode_is_int(op1mode) ),  "Cond node", 0
649                      );
650       ASSERT_AND_RET(mymode == mode_T, "Cond mode is not a tuple", 0);
651       break;
652
653     case iro_Return:
654       op1mode = get_irn_mode(in[1]);
655       /* Return: BB x M x data1 x ... x datan --> X */
656       /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
657       ASSERT_AND_RET( op1mode == mode_M, "Return node", 0 );  /* operand M */
658       for (i = 2; i < get_irn_arity(n); i++) {
659         ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Return node", 0 );  /* operand datai */
660       };
661       ASSERT_AND_RET( mymode == mode_X, "Result X", 0 );   /* result X */
662       /* Compare returned results with result types of method type */
663       mt = get_entity_type(get_irg_entity(irg));
664       ASSERT_AND_RET_DBG( get_Return_n_ress(n) == get_method_n_ress(mt),
665         "Number of results for Return doesn't match number of results in type.", 0,
666       show_return_nres(irg, n, mt););
667       for (i = 0; i < get_Return_n_ress(n); i++) {
668     type *res_type = get_method_res_type(mt, i);
669
670         if (is_atomic_type(res_type)) {
671       ASSERT_AND_RET_DBG(
672         get_irn_mode(get_Return_res(n, i)) == get_type_mode(res_type),
673         "Mode of result for Return doesn't match mode of result type.", 0,
674         show_return_modes(irg, n, mt, i);
675       );
676     }
677     else {
678       ASSERT_AND_RET_DBG(
679         mode_is_reference(get_irn_mode(get_Return_res(n, i))),
680         "Mode of result for Return doesn't match mode of result type.", 0,
681         show_return_modes(irg, n, mt, i);
682       );
683     }
684       }
685       break;
686
687     case iro_Raise:
688       op1mode = get_irn_mode(in[1]);
689       op2mode = get_irn_mode(in[2]);
690       ASSERT_AND_RET(
691                      /* Sel: BB x M x ref --> X x M */
692                      op1mode == mode_M && mode_is_reference(op2mode) &&
693                      mymode == mode_T, "Raise node", 0
694                      );
695       break;
696
697     case iro_Const: {
698       ASSERT_AND_RET(
699                      /* Const: BB --> data */
700                      (mode_is_data (mymode) ||
701                       mymode == mode_b)      /* we want boolean constants for static evaluation */
702                      ,"Const node", 0        /* of Cmp. */
703                      );
704       } break;
705     case iro_SymConst:
706       if (get_SymConst_kind(n) == symconst_addr_ent) {
707         entity *ent = get_SymConst_entity(n);
708         if (is_method_type(get_entity_type(ent)) &&
709             get_irn_irg(n) != get_const_code_irg()) {
710 #if 1
711           ASSERT_AND_RET((get_entity_peculiarity(ent) != peculiarity_description),
712                          "A constant must address an existing method.", 0);
713 #endif
714         }
715       }
716       ASSERT_AND_RET(
717                      /* SymConst: BB --> int*/
718                      (mode_is_int(mymode) ||
719                       /* SymConst: BB --> ref */
720                       mode_is_reference(mymode))
721                      ,"SymConst node", 0);
722       break;
723
724     case iro_Sel:
725       op1mode = get_irn_mode(in[1]);
726       op2mode = get_irn_mode(in[2]);
727       ASSERT_AND_RET_DBG(
728                          /* Sel: BB x M x ref x int^n --> ref */
729                          (op1mode == mode_M && op2mode == mymode && mode_is_reference(mymode)),
730                          "Sel node", 0, show_node_failure(n)
731                          );
732       for (i=3; i < get_irn_arity(n); i++)
733         {
734           ASSERT_AND_RET_DBG(mode_is_int(get_irn_mode(in[i])), "Sel node", 0, show_node_failure(n));
735         }
736       ent = get_Sel_entity(n);
737       ASSERT_AND_RET_DBG(ent, "Sel node with empty entity", 0, show_node_failure(n));
738       break;
739
740     case iro_InstOf:
741       ASSERT_AND_RET(mode_T == mymode, "mode of Instof is not a tuple", 0);
742       ASSERT_AND_RET(mode_is_data(op1mode), "Instof not on data", 0);
743       break;
744
745     case iro_Call:
746       op1mode = get_irn_mode(in[1]);
747       op2mode = get_irn_mode(in[2]);
748       /* Call: BB x M x ref x data1 x ... x datan
749          --> M x datan+1 x ... x data n+m */
750       ASSERT_AND_RET( op1mode == mode_M && mode_is_reference(op2mode), "Call node", 0 );  /* operand M x ref */
751
752       mt = get_Call_type(n);
753       if(get_unknown_type() == mt) {
754         break;
755       }
756
757       for (i=3; i < get_irn_arity(n); i++) {
758         ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Call node", 0 );  /* operand datai */
759       };
760       ASSERT_AND_RET( mymode == mode_T, "Call result not a tuple", 0 );   /* result T */
761       /* Compare arguments of node with those of type */
762
763       if (get_method_variadicity(mt) == variadicity_variadic) {
764         ASSERT_AND_RET_DBG(
765                            get_Call_n_params(n) >= get_method_n_params(mt),
766                            "Number of args for Call doesn't match number of args in variadic type.",
767                            0,
768                            fprintf(stderr, "Call has %d params, method %s type %d\n",
769                                    get_Call_n_params(n), get_type_name(mt), get_method_n_params(mt));
770                            );
771       }
772       else {
773         ASSERT_AND_RET(
774                        get_Call_n_params(n) == get_method_n_params(mt),
775                        "Number of args for Call doesn't match number of args in non variadic type.",
776                        0);
777       }
778
779       for (i = 0; i < get_method_n_params(mt); i++) {
780         type *t = get_method_param_type(mt, i);
781
782         if (is_atomic_type(t)) {
783           ASSERT_AND_RET_DBG(
784                              get_irn_mode(get_Call_param(n, i)) == get_type_mode(t),
785                              "Mode of arg for Call doesn't match mode of arg type.", 0,
786                              show_call_param(n, mt);
787                              );
788         }
789         else {
790           /* call with a compound type, mode must be reference */
791           ASSERT_AND_RET_DBG(
792                              mode_is_reference(get_irn_mode(get_Call_param(n, i))),
793                              "Mode of arg for Call doesn't match mode of arg type.", 0,
794                              show_call_param(n, mt);
795                              );
796         }
797       }
798
799 #if 0
800       if (Call_has_callees(n)) {
801         for (i = 0; i < get_Call_n_callees(n); i++) {
802           ASSERT_AND_RET(is_entity(get_Call_callee(n, i)), "callee array must contain entities.", 0);
803         }
804       }
805 #endif
806       break;
807
808     case iro_Add:
809       op1mode = get_irn_mode(in[1]);
810       op2mode = get_irn_mode(in[2]);
811       ASSERT_AND_RET_DBG(
812                          (
813                           /* common Add: BB x numP x numP --> numP */
814                           (op1mode == mymode && op2mode == op1mode && mode_is_numP(mymode)) ||
815                           /* Pointer Add: BB x ref x int --> ref */
816                           (mode_is_reference(op1mode) && mode_is_int(op2mode) && op1mode == mymode) ||
817                           /* Pointer Add: BB x int x ref --> ref */
818                           (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode))
819                           ),
820                          "Add node", 0,
821                          show_binop_failure(n, "/* common Add: BB x numP x numP --> numP */ |\n"
822                                             "/* Pointer Add: BB x ref x int --> ref */   |\n"
823                                             "/* Pointer Add: BB x int x ref --> ref */");
824                          );
825       if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
826         /* BB x ref x int --> ref or BB x int x ref --> ref */
827         op_is_symmetric = 0;
828       } else {
829         /* BB x num x num --> num or BB x ref x ref */
830         op_is_symmetric = 2;
831       }
832       break;
833
834     case iro_Sub:
835       op1mode = get_irn_mode(in[1]);
836       op2mode = get_irn_mode(in[2]);
837       ASSERT_AND_RET_DBG(
838                          /* common Sub: BB x numP x numP --> numP */
839                          ((mymode ==op1mode && mymode == op2mode && mode_is_numP(op1mode)) ||
840                           /* Pointer Sub: BB x ref x int --> ref */
841                           (op1mode == mymode && mode_is_int(op2mode) && mode_is_reference(mymode)) ||
842                           /* Pointer Sub: BB x int x ref --> ref */
843                           (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode)) ||
844                           /* Pointer Sub: BB x ref x ref --> int */
845                           (op1mode == op2mode && mode_is_reference(op2mode) && mode_is_int(mymode))),
846                          "Sub node", 0,
847                          show_binop_failure(n, "/* common Sub: BB x numP x numP --> numP */ |\n"
848                                             "/* Pointer Sub: BB x ref x int --> ref */   |\n"
849                                             "/* Pointer Sub: BB x int x ref --> ref */   |\n"
850                                             "/* Pointer Sub: BB x ref x ref --> int */" );
851                          );
852       if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
853         op_is_symmetric = 0;
854       } else {
855         op_is_symmetric = 2;
856       }
857       break;
858
859     case iro_Minus:
860       op1mode = get_irn_mode(in[1]);
861       ASSERT_AND_RET_DBG(
862                          /* Minus: BB x float --> float */
863                          op1mode == mymode && mode_is_float(op1mode), "Minus node", 0,
864                          show_unop_failure(n , "/* Minus: BB x float --> float */");
865                          );
866       op_is_symmetric = 2;
867       break;
868
869     case iro_Mul:
870       op1mode = get_irn_mode(in[1]);
871       op2mode = get_irn_mode(in[2]);
872       ASSERT_AND_RET_DBG(
873                          /* Mul: BB x int1 x int1 --> int2 */
874                          ((mode_is_int(op1mode)   && op2mode == op1mode && mode_is_int(mymode)) ||
875                          /* Mul: BB x float x float --> float */
876                           (mode_is_float(op1mode) && op2mode == op1mode && mymode == op1mode)),
877                          "Mul node",0,
878                          show_binop_failure(n, "/* Mul: BB x int1 x int1 --> int2 */ |\n"
879                                                "/* Mul: BB x float x float --> float */");
880                          );
881       op_is_symmetric = 2;
882       break;
883
884     case iro_Quot:
885       op1mode = get_irn_mode(in[1]);
886       op2mode = get_irn_mode(in[2]);
887       op3mode = get_irn_mode(in[3]);
888       ASSERT_AND_RET_DBG(
889                          /* Quot: BB x M x float x float --> M x X x float */
890                          op1mode == mode_M && op2mode == op3mode &&
891                          get_mode_sort(op2mode) == irms_float_number &&
892                          mymode == mode_T,
893                          "Quot node",0,
894                          show_binop_failure(n, "/* Quot: BB x M x float x float --> M x X x float */");
895                          );
896       op_is_symmetric = 2;
897       break;
898
899     case iro_DivMod:
900       op1mode = get_irn_mode(in[1]);
901       op2mode = get_irn_mode(in[2]);
902       op3mode = get_irn_mode(in[3]);
903       ASSERT_AND_RET(
904                      /* DivMod: BB x M x int x int --> M x X x int x int */
905                      op1mode == mode_M &&
906                      mode_is_int(op2mode) &&
907                      op3mode == op2mode &&
908                      mymode == mode_T,
909                      "DivMod node", 0
910                      );
911       op_is_symmetric = 1;
912       break;
913
914     case iro_Div:
915     case iro_Mod:
916       op1mode = get_irn_mode(in[1]);
917       op2mode = get_irn_mode(in[2]);
918       op3mode = get_irn_mode(in[3]);
919       ASSERT_AND_RET(
920                      /* Div or Mod: BB x M x int x int --> M x X x int */
921                      op1mode == mode_M &&
922                      op2mode == op3mode &&
923                      mode_is_int(op2mode) &&
924                      mymode == mode_T,
925                      "Div or Mod node", 0
926                      );
927       op_is_symmetric = 1;
928       break;
929
930     case iro_Abs:
931       op1mode = get_irn_mode(in[1]);
932       ASSERT_AND_RET_DBG(
933                          /* Abs: BB x num --> num */
934                          op1mode == mymode &&
935                          mode_is_num (op1mode),
936                          "Abs node", 0,
937                          show_unop_failure(n, "/* Abs: BB x num --> num */");
938                          );
939       op_is_symmetric = 2;
940       break;
941
942     case iro_And:
943     case iro_Or:
944     case iro_Eor:
945       op1mode = get_irn_mode(in[1]);
946       op2mode = get_irn_mode(in[2]);
947       ASSERT_AND_RET_DBG(
948                          /* And or Or or Eor: BB x int x int --> int */
949                          mode_is_int(mymode) &&
950                          op2mode == op1mode &&
951                          mymode == op2mode,
952                          "And, Or or Eor node", 0,
953                          show_binop_failure(n, "/* And or Or or Eor: BB x int x int --> int */");
954                          );
955       op_is_symmetric = 2;
956       break;
957
958     case iro_Not:
959       op1mode = get_irn_mode(in[1]);
960       ASSERT_AND_RET_DBG(
961                          /* Not: BB x int --> int */
962                          mode_is_int(mymode) &&
963                          mymode == op1mode,
964                          "Not node", 0,
965                          show_unop_failure(n, "/* Not: BB x int --> int */");
966                          );
967       op_is_symmetric = 2;
968       break;
969
970
971     case iro_Cmp:
972       op1mode = get_irn_mode(in[1]);
973       op2mode = get_irn_mode(in[2]);
974       ASSERT_AND_RET_DBG(
975                          /* Cmp: BB x datab x datab --> b16 */
976                          mode_is_data (op1mode) &&
977                          op2mode == op1mode &&
978                          mymode == mode_T,
979                          "Cmp node", 0,
980                          show_binop_failure(n, "/* Cmp: BB x datab x datab --> b16 */");
981                          );
982       break;
983
984     case iro_Shl:
985     case iro_Shr:
986     case iro_Shrs:
987       op1mode = get_irn_mode(in[1]);
988       op2mode = get_irn_mode(in[2]);
989       ASSERT_AND_RET_DBG(
990                          /* Shl, Shr or Shrs: BB x int x int_u --> int */
991                          mode_is_int(op1mode) &&
992                          mode_is_int(op2mode) &&
993                          !mode_is_signed(op2mode) &&
994                          mymode == op1mode,
995                          "Shl, Shr, Shr or Rot node", 0,
996                          show_binop_failure(n, "/* Shl, Shr or Shrs: BB x int x int_u --> int */");
997                          );
998       break;
999
1000     case iro_Rot:
1001       op1mode = get_irn_mode(in[1]);
1002       op2mode = get_irn_mode(in[2]);
1003       ASSERT_AND_RET_DBG(
1004                          /* Rot: BB x int x int --> int */
1005                          mode_is_int(op1mode) &&
1006                          mode_is_int(op2mode) &&
1007                          mymode == op1mode,
1008                          "Rot node", 0,
1009                          show_binop_failure(n, "/* Rot: BB x int x int --> int */");
1010                          );
1011       break;
1012
1013     case iro_Conv:
1014       op1mode = get_irn_mode(in[1]);
1015       ASSERT_AND_RET_DBG(
1016                          /* Conv: BB x datab1 --> datab2 */
1017                          mode_is_datab(op1mode) && mode_is_data(mymode),
1018                          "Conv node", 0,
1019                          show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1020                          );
1021       break;
1022
1023     case iro_Cast:
1024       op1mode = get_irn_mode(in[1]);
1025       ASSERT_AND_RET_DBG(
1026                          /* Conv: BB x datab1 --> datab2 */
1027                          mode_is_data(op1mode) && op1mode == mymode,
1028                          "Cast node", 0,
1029                          show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1030                          );
1031       break;
1032
1033     case iro_Phi:
1034     {
1035       ir_node *block = get_nodes_block(n);
1036
1037       if (! is_Bad(block) && get_irg_phase_state(get_irn_irg(n)) != phase_building) {
1038         /* a Phi node MUST have the same number of inputs as its block */
1039         ASSERT_AND_RET_DBG(
1040           get_irn_arity(n) == get_irn_arity(block),
1041           "wrong number of inputs in Phi node", 0,
1042           show_phi_inputs(n, block);
1043         );
1044       }
1045
1046       /* Phi: BB x dataM^n --> dataM */
1047       for (i = 1; i < get_irn_arity(n); i++) {
1048         if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
1049           ASSERT_AND_RET_DBG(
1050                              get_irn_mode(in[i]) == mymode,
1051                              "Phi node", 0,
1052                              show_phi_failure(n, in[i], i);
1053                              );
1054       };
1055       ASSERT_AND_RET( mode_is_dataM(mymode), "Phi node", 0 );
1056       break;
1057     }
1058     case iro_Load:
1059       op1mode = get_irn_mode(in[1]);
1060       op2mode = get_irn_mode(in[2]);
1061       ASSERT_AND_RET(
1062                      /* Load: BB x M x ref --> M x X x data */
1063                      op1mode == mode_M && mode_is_reference(op2mode),
1064                      "Load node", 0
1065                      );
1066       ASSERT_AND_RET( mymode == mode_T, "Load node", 0 );
1067
1068       /*
1069        * jack's gen_add_firm_code:simpleSel seems to build Load (Load
1070        * (Proj (Proj))) sometimes ...
1071
1072        * interprete.c:ai_eval seems to assume that this happens, too
1073
1074        * obset.c:get_abstval_any can't deal with this if the load has
1075        * mode_T
1076        *
1077       {
1078         entity *ent = hunt_for_entity (get_Load_ptr (n), n);
1079         assert ((NULL != ent) || (mymode != mode_T));
1080       }
1081       */
1082
1083       break;
1084
1085     case iro_Store:
1086       op1mode = get_irn_mode(in[1]);
1087       op2mode = get_irn_mode(in[2]);
1088       op3mode = get_irn_mode(in[3]);
1089       ASSERT_AND_RET(
1090                      /* Load: BB x M x ref data --> M x X */
1091                      op1mode == mode_M && mode_is_reference(op2mode) && mode_is_data(op3mode),
1092                      "Store node", 0
1093                      );
1094       ASSERT_AND_RET(mymode == mode_T, "Store node", 0);
1095
1096       entity *target = get_ptr_entity(in[2]);
1097       if (vrfy_entities && target && get_irg_phase_state(current_ir_graph) == phase_high) {
1098         /*
1099          * If lowered code, any Sels that add 0 may be removed, causing
1100          * an direct access to entities of array or compound type.
1101          * Prevent this by checking the phase.
1102          */
1103         ASSERT_AND_RET( op3mode == get_type_mode(get_entity_type(target)),
1104                         "Store node", 0);
1105       }
1106
1107       break;
1108
1109     case iro_Alloc:
1110       op1mode = get_irn_mode(in[1]);
1111       op2mode = get_irn_mode(in[2]);
1112       ASSERT_AND_RET_DBG(
1113                          /* Alloc: BB x M x int_u --> M x X x ref */
1114                          op1mode == mode_M &&
1115                          mode_is_int(op2mode) &&
1116                          !mode_is_signed(op2mode) &&
1117                          mymode == mode_T,
1118                          "Alloc node", 0,
1119                          show_binop_failure(n, "/* Alloc: BB x M x int_u --> M x X x ref */");
1120                          );
1121       break;
1122
1123     case iro_Free:
1124       op1mode = get_irn_mode(in[1]);
1125       op2mode = get_irn_mode(in[2]);
1126       ASSERT_AND_RET_DBG(
1127                          /* Free: BB x M x ref --> M */
1128                          op1mode == mode_M && mode_is_reference(op2mode) &&
1129                          mymode == mode_M,
1130                          "Free node", 0,
1131                          show_binop_failure(n, "/* Free: BB x M x ref --> M */");
1132                          );
1133       break;
1134
1135     case iro_Sync:
1136       /* Sync: BB x M^n --> M */
1137       for (i=1; i < get_irn_arity(n); i++) {
1138         ASSERT_AND_RET( get_irn_mode(in[i]) == mode_M, "Sync node", 0 );
1139       };
1140       ASSERT_AND_RET( mymode == mode_M, "Sync node", 0 );
1141       break;
1142
1143     case iro_Proj:
1144       return vrfy_Proj_proj(n, irg);
1145       break;
1146
1147     case iro_Confirm:
1148       op1mode = get_irn_mode(in[1]);
1149       op2mode = get_irn_mode(in[2]);
1150       ASSERT_AND_RET_DBG(
1151                          /* Confirm: BB x T x T --> T */
1152                          op1mode == mymode &&
1153                          op2mode == mymode,
1154                          "Confirm node", 0,
1155                          show_binop_failure(n, "/* Confirm: BB x T x T --> T */");
1156                          );
1157       break;
1158
1159     default:
1160       break;
1161     }
1162
1163   /* All went ok */
1164   return 1;
1165 }
1166
1167 int irn_vrfy(ir_node *n)
1168 {
1169   int res = 1;
1170 #ifdef DEBUG_libfirm
1171   res = irn_vrfy_irg(n, current_ir_graph);
1172 #endif
1173   return res;
1174 }
1175
1176 /*-----------------------------------------------------------------*/
1177 /* Verify the whole graph.                                         */
1178 /*-----------------------------------------------------------------*/
1179
1180 /* This *is* used, except gcc doesn't notice that */
1181 static void vrfy_wrap(ir_node *node, void *env)
1182 {
1183   int *res = env;
1184
1185   *res = irn_vrfy(node);
1186 }
1187
1188 int irg_vrfy(ir_graph *irg)
1189 {
1190   int res = 1;
1191 #ifdef DEBUG_libfirm
1192   ir_graph *rem;
1193
1194   rem = current_ir_graph;
1195   current_ir_graph = irg;
1196
1197   assert(get_irg_pinned(irg) == op_pin_state_pinned);
1198
1199   irg_walk_graph(irg, vrfy_wrap, NULL, &res);
1200
1201   current_ir_graph = rem;
1202
1203   if (opt_do_node_verification == NODE_VERIFICATION_REPORT && ! res) {
1204     entity *ent = get_irg_entity(current_ir_graph);
1205
1206     if (ent)
1207       fprintf(stderr, "irg_verify: Verifying graph %s failed\n", get_entity_name(ent));
1208     else
1209       fprintf(stderr, "irg_verify: Verifying graph %p failed\n", (void *)current_ir_graph);
1210   }
1211
1212 #endif
1213   return res;
1214 }
1215
1216 int irn_vrfy_irg_dump(ir_node *n, ir_graph *irg, const char **bad_string)
1217 {
1218   int res;
1219   node_verification_t old = opt_do_node_verification;
1220
1221   bad_msg = NULL;
1222   opt_do_node_verification = NODE_VERIFICATION_ERROR_ONLY;
1223   res = irn_vrfy_irg(n, irg);
1224   opt_do_node_verification = old;
1225   *bad_string = bad_msg;
1226
1227   return res;
1228 }
1229
1230
1231 typedef struct _vrfy_bad_env_t {
1232   int flags;
1233   int res;
1234 } vrfy_bad_env_t;
1235
1236 static void check_bads(ir_node *node, void *env)
1237 {
1238   vrfy_bad_env_t *venv = env;
1239   int i, arity = get_irn_arity(node);
1240
1241   if (is_Block(node)) {
1242     if ((venv->flags & BAD_CF) == 0) {
1243
1244       /* check for Bad Block predecessor */
1245       for (i = 0; i < arity; ++i) {
1246         ir_node *pred = get_irn_n(node, i);
1247
1248         if (is_Bad(pred)) {
1249           venv->res |= BAD_CF;
1250
1251           if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1252             fprintf(stderr, "irg_vrfy_bads: Block %ld has Bad predecessor\n", get_irn_node_nr(node));
1253           }
1254           if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1255             assert(0 && "Bad CF detected");
1256           }
1257         }
1258       }
1259     }
1260   }
1261   else {
1262     if ((venv->flags & BAD_BLOCK) == 0) {
1263
1264       /* check for Bad Block */
1265       if (is_Bad(get_nodes_block(node))) {
1266         venv->res |= BAD_BLOCK;
1267
1268         if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1269           fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Block\n", get_irn_node_nr(node));
1270         }
1271         if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1272           assert(0 && "Bad CF detected");
1273         }
1274       }
1275     }
1276
1277     if ((venv->flags & TUPLE) == 0) {
1278       if (get_irn_op(node) == op_Tuple) {
1279         venv->res |= TUPLE;
1280
1281         if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1282           fprintf(stderr, "irg_vrfy_bads: node %ld is a Tuple\n", get_irn_node_nr(node));
1283         }
1284         if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1285           assert(0 && "Tuple detected");
1286         }
1287       }
1288     }
1289
1290     for (i = 0; i < arity; ++i) {
1291       ir_node *pred = get_irn_n(node, i);
1292
1293       if (is_Bad(pred)) {
1294         /* check for Phi with Bad inputs */
1295         if (is_Phi(node) && !is_Bad(get_nodes_block(node)) && is_Bad(get_irn_n(get_nodes_block(node), i))) {
1296           if (venv->flags & BAD_CF)
1297             continue;
1298           else {
1299             venv->res |= BAD_CF;
1300
1301             if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1302               fprintf(stderr, "irg_vrfy_bads: Phi %ld has Bad Input\n", get_irn_node_nr(node));
1303             }
1304             if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1305               assert(0 && "Bad CF detected");
1306             }
1307           }
1308         }
1309
1310         /* Bad node input */
1311         if ((venv->flags & BAD_DF) == 0) {
1312           venv->res |= BAD_DF;
1313
1314           if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1315             fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Input\n", get_irn_node_nr(node));
1316           }
1317           if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1318             assert(0 && "Bad NON-CF detected");
1319           }
1320         }
1321       }
1322     }
1323   }
1324 }
1325
1326 /*
1327  * verify occurance of bad nodes
1328  */
1329 int irg_vrfy_bads(ir_graph *irg, int flags)
1330 {
1331   vrfy_bad_env_t env;
1332
1333   env.flags = flags;
1334   env.res   = 0;
1335
1336   irg_walk_graph(irg, check_bads, NULL, &env);
1337
1338   return env.res;
1339 }