replaced all recursive computed_value calls ba value_of()
[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 (! get_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 (! get_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
749       mt = get_Call_type(n);
750       if(get_unknown_type() == mt) {
751         break;
752       }
753
754       for (i=3; i < get_irn_arity(n); i++) {
755         ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Call node", 0 );  /* operand datai */
756       };
757       ASSERT_AND_RET( mymode == mode_T, "Call result not a tuple", 0 );   /* result T */
758       /* Compare arguments of node with those of type */
759
760       if (get_method_variadicity(mt) == variadicity_variadic) {
761         ASSERT_AND_RET_DBG(
762                            get_Call_n_params(n) >= get_method_n_params(mt),
763                            "Number of args for Call doesn't match number of args in variadic type.",
764                            0,
765                            fprintf(stderr, "Call has %d params, method %s type %d\n",
766                                    get_Call_n_params(n), get_type_name(mt), get_method_n_params(mt));
767                            );
768       }
769       else {
770         ASSERT_AND_RET(
771                        get_Call_n_params(n) == get_method_n_params(mt),
772                        "Number of args for Call doesn't match number of args in non variadic type.",
773                        0);
774       }
775
776       for (i = 0; i < get_method_n_params(mt); i++) {
777     type *t = get_method_param_type(mt, i);
778
779     if (is_atomic_type(t)) {
780       ASSERT_AND_RET_DBG(
781           get_irn_mode(get_Call_param(n, i)) == get_type_mode(t),
782           "Mode of arg for Call doesn't match mode of arg type.", 0,
783       show_call_param(n, mt);
784       );
785     }
786     else {
787       /* call with a compound type, mode must be reference */
788       ASSERT_AND_RET_DBG(
789           mode_is_reference(get_irn_mode(get_Call_param(n, i))),
790           "Mode of arg for Call doesn't match mode of arg type.", 0,
791       show_call_param(n, mt);
792       );
793     }
794       }
795       break;
796
797     case iro_Add:
798       op1mode = get_irn_mode(in[1]);
799       op2mode = get_irn_mode(in[2]);
800       ASSERT_AND_RET_DBG(
801                          (
802                           /* common Add: BB x numP x numP --> numP */
803                           (op1mode == mymode && op2mode == op1mode && mode_is_numP(mymode)) ||
804                           /* Pointer Add: BB x ref x int --> ref */
805                           (mode_is_reference(op1mode) && mode_is_int(op2mode) && op1mode == mymode) ||
806                           /* Pointer Add: BB x int x ref --> ref */
807                           (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode))
808                           ),
809                          "Add node", 0,
810                          show_binop_failure(n, "/* common Add: BB x numP x numP --> numP */ |\n"
811                                             "/* Pointer Add: BB x ref x int --> ref */   |\n"
812                                             "/* Pointer Add: BB x int x ref --> ref */");
813                          );
814       if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
815         /* BB x ref x int --> ref or BB x int x ref --> ref */
816         op_is_symmetric = 0;
817       } else {
818         /* BB x num x num --> num or BB x ref x ref */
819         op_is_symmetric = 2;
820       }
821       break;
822
823     case iro_Sub:
824       op1mode = get_irn_mode(in[1]);
825       op2mode = get_irn_mode(in[2]);
826       ASSERT_AND_RET_DBG(
827                          /* common Sub: BB x numP x numP --> numP */
828                          ((mymode ==op1mode && mymode == op2mode && mode_is_numP(op1mode)) ||
829                           /* Pointer Sub: BB x ref x int --> ref */
830                           (op1mode == mymode && mode_is_int(op2mode) && mode_is_reference(mymode)) ||
831                           /* Pointer Sub: BB x int x ref --> ref */
832                           (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode)) ||
833                           /* Pointer Sub: BB x ref x ref --> int */
834                           (op1mode == op2mode && mode_is_reference(op2mode) && mode_is_int(mymode))),
835                          "Sub node", 0,
836                          show_binop_failure(n, "/* common Sub: BB x numP x numP --> numP */ |\n"
837                                             "/* Pointer Sub: BB x ref x int --> ref */   |\n"
838                                             "/* Pointer Sub: BB x int x ref --> ref */   |\n"
839                                             "/* Pointer Sub: BB x ref x ref --> int */" );
840                          );
841       if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
842         op_is_symmetric = 0;
843       } else {
844         op_is_symmetric = 2;
845       }
846       break;
847
848     case iro_Minus:
849       op1mode = get_irn_mode(in[1]);
850       ASSERT_AND_RET_DBG(
851                          /* Minus: BB x float --> float */
852                          op1mode == mymode && mode_is_float(op1mode), "Minus node", 0,
853                          show_unop_failure(n , "/* Minus: BB x float --> float */");
854                          );
855       op_is_symmetric = 2;
856       break;
857
858     case iro_Mul:
859       op1mode = get_irn_mode(in[1]);
860       op2mode = get_irn_mode(in[2]);
861       ASSERT_AND_RET_DBG(
862                          /* Mul: BB x int1 x int1 --> int2 */
863                          ((mode_is_int(op1mode)   && op2mode == op1mode && mode_is_int(mymode)) ||
864                          /* Mul: BB x float x float --> float */
865                           (mode_is_float(op1mode) && op2mode == op1mode && mymode == op1mode)),
866                          "Mul node",0,
867                          show_binop_failure(n, "/* Mul: BB x int1 x int1 --> int2 */ |\n"
868                                                "/* Mul: BB x float x float --> float */");
869                          );
870       op_is_symmetric = 2;
871       break;
872
873     case iro_Quot:
874       op1mode = get_irn_mode(in[1]);
875       op2mode = get_irn_mode(in[2]);
876       op3mode = get_irn_mode(in[3]);
877       ASSERT_AND_RET_DBG(
878                          /* Quot: BB x M x float x float --> M x X x float */
879                          op1mode == mode_M && op2mode == op3mode &&
880                          get_mode_sort(op2mode) == irms_float_number &&
881                          mymode == mode_T,
882                          "Quot node",0,
883                          show_binop_failure(n, "/* Quot: BB x M x float x float --> M x X x float */");
884                          );
885       op_is_symmetric = 2;
886       break;
887
888     case iro_DivMod:
889       op1mode = get_irn_mode(in[1]);
890       op2mode = get_irn_mode(in[2]);
891       op3mode = get_irn_mode(in[3]);
892       ASSERT_AND_RET(
893                      /* DivMod: BB x M x int x int --> M x X x int x int */
894                      op1mode == mode_M &&
895                      mode_is_int(op2mode) &&
896                      op3mode == op2mode &&
897                      mymode == mode_T,
898                      "DivMod node", 0
899                      );
900       op_is_symmetric = 1;
901       break;
902
903     case iro_Div:
904     case iro_Mod:
905       op1mode = get_irn_mode(in[1]);
906       op2mode = get_irn_mode(in[2]);
907       op3mode = get_irn_mode(in[3]);
908       ASSERT_AND_RET(
909                      /* Div or Mod: BB x M x int x int --> M x X x int */
910                      op1mode == mode_M &&
911                      op2mode == op3mode &&
912                      mode_is_int(op2mode) &&
913                      mymode == mode_T,
914                      "Div or Mod node", 0
915                      );
916       op_is_symmetric = 1;
917       break;
918
919     case iro_Abs:
920       op1mode = get_irn_mode(in[1]);
921       ASSERT_AND_RET_DBG(
922                          /* Abs: BB x num --> num */
923                          op1mode == mymode &&
924                          mode_is_num (op1mode),
925                          "Abs node", 0,
926                          show_unop_failure(n, "/* Abs: BB x num --> num */");
927                          );
928       op_is_symmetric = 2;
929       break;
930
931     case iro_And:
932     case iro_Or:
933     case iro_Eor:
934       op1mode = get_irn_mode(in[1]);
935       op2mode = get_irn_mode(in[2]);
936       ASSERT_AND_RET_DBG(
937                          /* And or Or or Eor: BB x int x int --> int */
938                          mode_is_int(mymode) &&
939                          op2mode == op1mode &&
940                          mymode == op2mode,
941                          "And, Or or Eor node", 0,
942                          show_binop_failure(n, "/* And or Or or Eor: BB x int x int --> int */");
943                          );
944       op_is_symmetric = 2;
945       break;
946
947     case iro_Not:
948       op1mode = get_irn_mode(in[1]);
949       ASSERT_AND_RET_DBG(
950                          /* Not: BB x int --> int */
951                          mode_is_int(mymode) &&
952                          mymode == op1mode,
953                          "Not node", 0,
954                          show_unop_failure(n, "/* Not: BB x int --> int */");
955                          );
956       op_is_symmetric = 2;
957       break;
958
959
960     case iro_Cmp:
961       op1mode = get_irn_mode(in[1]);
962       op2mode = get_irn_mode(in[2]);
963       ASSERT_AND_RET_DBG(
964                          /* Cmp: BB x datab x datab --> b16 */
965                          mode_is_data (op1mode) &&
966                          op2mode == op1mode &&
967                          mymode == mode_T,
968                          "Cmp node", 0,
969                          show_binop_failure(n, "/* Cmp: BB x datab x datab --> b16 */");
970                          );
971       break;
972
973     case iro_Shl:
974     case iro_Shr:
975     case iro_Shrs:
976       op1mode = get_irn_mode(in[1]);
977       op2mode = get_irn_mode(in[2]);
978       ASSERT_AND_RET_DBG(
979                          /* Shl, Shr or Shrs: BB x int x int_u --> int */
980                          mode_is_int(op1mode) &&
981                          mode_is_int(op2mode) &&
982                          !mode_is_signed(op2mode) &&
983                          mymode == op1mode,
984                          "Shl, Shr, Shr or Rot node", 0,
985                          show_binop_failure(n, "/* Shl, Shr or Shrs: BB x int x int_u --> int */");
986                          );
987       break;
988
989     case iro_Rot:
990       op1mode = get_irn_mode(in[1]);
991       op2mode = get_irn_mode(in[2]);
992       ASSERT_AND_RET_DBG(
993                          /* Rot: BB x int x int --> int */
994                          mode_is_int(op1mode) &&
995                          mode_is_int(op2mode) &&
996                          mymode == op1mode,
997                          "Rot node", 0,
998                          show_binop_failure(n, "/* Rot: BB x int x int --> int */");
999                          );
1000       break;
1001
1002     case iro_Conv:
1003       op1mode = get_irn_mode(in[1]);
1004       ASSERT_AND_RET_DBG(
1005                          /* Conv: BB x datab1 --> datab2 */
1006                          mode_is_datab(op1mode) && mode_is_data(mymode),
1007                          "Conv node", 0,
1008                          show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1009                          );
1010       break;
1011
1012     case iro_Cast:
1013       op1mode = get_irn_mode(in[1]);
1014       ASSERT_AND_RET_DBG(
1015                          /* Conv: BB x datab1 --> datab2 */
1016                          mode_is_data(op1mode) && op1mode == mymode,
1017                          "Cast node", 0,
1018                          show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1019                          );
1020       break;
1021
1022     case iro_Phi:
1023     {
1024       ir_node *block = get_nodes_block(n);
1025
1026       if (! is_Bad(block) && get_irg_phase_state(get_irn_irg(n)) != phase_building) {
1027         /* a Phi node MUST have the same number of inputs as its block */
1028         ASSERT_AND_RET_DBG(
1029           get_irn_arity(n) == get_irn_arity(block),
1030           "wrong number of inputs in Phi node", 0,
1031           show_phi_inputs(n, block);
1032         );
1033       }
1034
1035       /* Phi: BB x dataM^n --> dataM */
1036       for (i = 1; i < get_irn_arity(n); i++) {
1037         if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
1038           ASSERT_AND_RET_DBG(
1039                              get_irn_mode(in[i]) == mymode,
1040                              "Phi node", 0,
1041                              show_phi_failure(n, in[i], i);
1042                              );
1043       };
1044       ASSERT_AND_RET( mode_is_dataM(mymode), "Phi node", 0 );
1045       break;
1046     }
1047     case iro_Load:
1048       op1mode = get_irn_mode(in[1]);
1049       op2mode = get_irn_mode(in[2]);
1050       ASSERT_AND_RET(
1051                      /* Load: BB x M x ref --> M x X x data */
1052                      op1mode == mode_M && mode_is_reference(op2mode),
1053                      "Load node", 0
1054                      );
1055       ASSERT_AND_RET( mymode == mode_T, "Load node", 0 );
1056
1057       /*
1058        * jack's gen_add_firm_code:simpleSel seems to build Load (Load
1059        * (Proj (Proj))) sometimes ...
1060
1061        * interprete.c:ai_eval seems to assume that this happens, too
1062
1063        * obset.c:get_abstval_any can't deal with this if the load has
1064        * mode_T
1065        *
1066       {
1067         entity *ent = hunt_for_entity (get_Load_ptr (n), n);
1068         assert ((NULL != ent) || (mymode != mode_T));
1069       }
1070       */
1071
1072       break;
1073
1074     case iro_Store:
1075       op1mode = get_irn_mode(in[1]);
1076       op2mode = get_irn_mode(in[2]);
1077       op3mode = get_irn_mode(in[3]);
1078       ASSERT_AND_RET(
1079                      /* Load: BB x M x ref data --> M x X */
1080                      op1mode == mode_M && mode_is_reference(op2mode) && mode_is_data(op3mode),
1081                      "Store node", 0
1082                      );
1083       ASSERT_AND_RET(mymode == mode_T, "Store node", 0);
1084
1085       entity *target = get_ptr_entity(in[2]);
1086       if (vrfy_entities && target && get_irg_phase_state(current_ir_graph) == phase_high) {
1087         /*
1088          * If lowered code, any Sels that add 0 may be removed, causing
1089          * an direct access to entities of array or compound type.
1090          * Prevent this by checking the phase.
1091          */
1092         ASSERT_AND_RET( op3mode == get_type_mode(get_entity_type(target)),
1093                         "Store node", 0);
1094       }
1095
1096       break;
1097
1098     case iro_Alloc:
1099       op1mode = get_irn_mode(in[1]);
1100       op2mode = get_irn_mode(in[2]);
1101       ASSERT_AND_RET_DBG(
1102                          /* Alloc: BB x M x int_u --> M x X x ref */
1103                          op1mode == mode_M &&
1104                          mode_is_int(op2mode) &&
1105                          !mode_is_signed(op2mode) &&
1106                          mymode == mode_T,
1107                          "Alloc node", 0,
1108                          show_binop_failure(n, "/* Alloc: BB x M x int_u --> M x X x ref */");
1109                          );
1110       break;
1111
1112     case iro_Free:
1113       op1mode = get_irn_mode(in[1]);
1114       op2mode = get_irn_mode(in[2]);
1115       ASSERT_AND_RET_DBG(
1116                          /* Free: BB x M x ref --> M */
1117                          op1mode == mode_M && mode_is_reference(op2mode) &&
1118                          mymode == mode_M,
1119                          "Free node", 0,
1120                          show_binop_failure(n, "/* Free: BB x M x ref --> M */");
1121                          );
1122       break;
1123
1124     case iro_Sync:
1125       /* Sync: BB x M^n --> M */
1126       for (i=1; i < get_irn_arity(n); i++) {
1127         ASSERT_AND_RET( get_irn_mode(in[i]) == mode_M, "Sync node", 0 );
1128       };
1129       ASSERT_AND_RET( mymode == mode_M, "Sync node", 0 );
1130       break;
1131
1132     case iro_Proj:
1133       return vrfy_Proj_proj(n, irg);
1134       break;
1135
1136     case iro_Confirm:
1137       op1mode = get_irn_mode(in[1]);
1138       op2mode = get_irn_mode(in[2]);
1139       ASSERT_AND_RET_DBG(
1140                          /* Confirm: BB x T x T --> T */
1141                          op1mode == mymode &&
1142                          op2mode == mymode,
1143                          "Confirm node", 0,
1144                          show_binop_failure(n, "/* Confirm: BB x T x T --> T */");
1145                          );
1146       break;
1147
1148     default:
1149       break;
1150     }
1151
1152   /* All went ok */
1153   return 1;
1154 }
1155
1156 int irn_vrfy(ir_node *n)
1157 {
1158   int res = 1;
1159 #ifdef DEBUG_libfirm
1160   res = irn_vrfy_irg(n, current_ir_graph);
1161 #endif
1162   return res;
1163 }
1164
1165 /*-----------------------------------------------------------------*/
1166 /* Verify the whole graph.                                         */
1167 /*-----------------------------------------------------------------*/
1168
1169 /* This *is* used, except gcc doesn't notice that */
1170 static void vrfy_wrap(ir_node *node, void *env)
1171 {
1172   int *res = env;
1173
1174   *res = irn_vrfy(node);
1175 }
1176
1177 int irg_vrfy(ir_graph *irg)
1178 {
1179   int res = 1;
1180 #ifdef DEBUG_libfirm
1181   ir_graph *rem;
1182
1183   rem = current_ir_graph;
1184   current_ir_graph = irg;
1185
1186   assert(get_irg_pinned(irg) == op_pin_state_pinned);
1187
1188   irg_walk_graph(irg, vrfy_wrap, NULL, &res);
1189
1190   current_ir_graph = rem;
1191
1192   if (opt_do_node_verification == NODE_VERIFICATION_REPORT && ! res) {
1193     entity *ent = get_irg_entity(current_ir_graph);
1194
1195     if (ent)
1196       fprintf(stderr, "irg_verify: Verifying graph %s failed\n", get_entity_name(ent));
1197     else
1198       fprintf(stderr, "irg_verify: Verifying graph %p failed\n", (void *)current_ir_graph);
1199   }
1200
1201 #endif
1202   return res;
1203 }
1204
1205 int irn_vrfy_irg_dump(ir_node *n, ir_graph *irg, const char **bad_string)
1206 {
1207   int res;
1208   node_verification_t old = opt_do_node_verification;
1209
1210   bad_msg = NULL;
1211   opt_do_node_verification = NODE_VERIFICATION_ERROR_ONLY;
1212   res = irn_vrfy_irg(n, irg);
1213   opt_do_node_verification = old;
1214   *bad_string = bad_msg;
1215
1216   return res;
1217 }
1218
1219
1220 typedef struct _vrfy_bad_env_t {
1221   int flags;
1222   int res;
1223 } vrfy_bad_env_t;
1224
1225 static void check_bads(ir_node *node, void *env)
1226 {
1227   vrfy_bad_env_t *venv = env;
1228   int i, arity = get_irn_arity(node);
1229
1230   if (is_Block(node)) {
1231     if ((venv->flags & BAD_CF) == 0) {
1232
1233       /* check for Bad Block predecessor */
1234       for (i = 0; i < arity; ++i) {
1235         ir_node *pred = get_irn_n(node, i);
1236
1237         if (is_Bad(pred)) {
1238           venv->res |= BAD_CF;
1239
1240           if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1241             fprintf(stderr, "irg_vrfy_bads: Block %ld has Bad predecessor\n", get_irn_node_nr(node));
1242           }
1243           if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1244             assert(0 && "Bad CF detected");
1245           }
1246         }
1247       }
1248     }
1249   }
1250   else {
1251     if ((venv->flags & BAD_BLOCK) == 0) {
1252
1253       /* check for Bad Block */
1254       if (is_Bad(get_nodes_block(node))) {
1255         venv->res |= BAD_BLOCK;
1256
1257         if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1258           fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Block\n", get_irn_node_nr(node));
1259         }
1260         if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1261           assert(0 && "Bad CF detected");
1262         }
1263       }
1264     }
1265
1266     if ((venv->flags & TUPLE) == 0) {
1267       if (get_irn_op(node) == op_Tuple) {
1268         venv->res |= TUPLE;
1269
1270         if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1271           fprintf(stderr, "irg_vrfy_bads: node %ld is a Tuple\n", get_irn_node_nr(node));
1272         }
1273         if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1274           assert(0 && "Tuple detected");
1275         }
1276       }
1277     }
1278
1279     for (i = 0; i < arity; ++i) {
1280       ir_node *pred = get_irn_n(node, i);
1281
1282       if (is_Bad(pred)) {
1283         /* check for Phi with Bad inputs */
1284         if (is_Phi(node) && !is_Bad(get_nodes_block(node)) && is_Bad(get_irn_n(get_nodes_block(node), i))) {
1285           if (venv->flags & BAD_CF)
1286             continue;
1287           else {
1288             venv->res |= BAD_CF;
1289
1290             if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1291               fprintf(stderr, "irg_vrfy_bads: Phi %ld has Bad Input\n", get_irn_node_nr(node));
1292             }
1293             if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1294               assert(0 && "Bad CF detected");
1295             }
1296           }
1297         }
1298
1299         /* Bad node input */
1300         if ((venv->flags & BAD_DF) == 0) {
1301           venv->res |= BAD_DF;
1302
1303           if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1304             fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Input\n", get_irn_node_nr(node));
1305           }
1306           if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1307             assert(0 && "Bad NON-CF detected");
1308           }
1309         }
1310       }
1311     }
1312   }
1313 }
1314
1315 /*
1316  * verify occurance of bad nodes
1317  */
1318 int irg_vrfy_bads(ir_graph *irg, int flags)
1319 {
1320   vrfy_bad_env_t env;
1321
1322   env.flags = flags;
1323   env.res   = 0;
1324
1325   irg_walk_graph(irg, check_bads, NULL, &env);
1326
1327   return env.res;
1328 }