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