Fixes for GCC 4.0: void * and pointer to function are not compatible anymore
[libfirm] / ir / tr / tr_inheritance.c
1 /**
2  *
3  * @file tr_inheritance.c
4  *
5  * Project:     libFIRM                                                   <br>
6  * File name:   ir/tr/tr_inheritance.c                                    <br>
7  * Purpose:     Utility routines for inheritance representation           <br>
8  * Author:      Goetz Lindenmaier                                         <br>
9  * Modified by:                                                           <br>
10  * Created:                                                               <br>
11  * Copyright:   (c) 2001-2005 Universität Karlsruhe                       <br>
12  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE. <br>
13  * CVS-ID:      $Id$
14  *
15  *
16  *
17  *  @see  type.h entity.h
18  */
19
20 #include "type.h"
21 #include "entity.h"
22 #include "typewalk.h"
23 #include "irgraph_t.h"
24 #include "irprog_t.h"
25 #include "pset.h"
26 #include "set.h"
27 #include "mangle.h"
28 #include "irgwalk.h"
29 #include "irflag.h"
30 //#include ".h"
31
32
33 /* ----------------------------------------------------------------------- */
34 /* Resolve implicit inheritance.                                           */
35 /* ----------------------------------------------------------------------- */
36
37 ident *default_mangle_inherited_name(entity *super, type *clss) {
38   return mangle_u(new_id_from_str("inh"), mangle_u(get_type_ident(clss), get_entity_ident(super)));
39 }
40
41 /** Replicates all entities in all super classes that are not overwritten
42    by an entity of this class. */
43 static void copy_entities_from_superclass(type *clss, void *env)
44 {
45   int i, j, k, l;
46   int overwritten;
47   type *super, *inhenttype;
48   entity *inhent, *thisent;
49   mangle_inherited_name_func *mfunc = *(mangle_inherited_name_func **)env;
50
51   for(i = 0; i < get_class_n_supertypes(clss); i++) {
52     super = get_class_supertype(clss, i);
53     assert(is_Class_type(super) && "not a class");
54     for(j = 0; j < get_class_n_members(super); j++) {
55       inhent = get_class_member(super, j);
56       inhenttype = get_entity_type(inhent);
57       /* check whether inhent is already overwritten */
58       overwritten = 0;
59       for (k = 0; (k < get_class_n_members(clss)) && (overwritten == 0); k++) {
60         thisent = get_class_member(clss, k);
61         for(l = 0; l < get_entity_n_overwrites(thisent); l++) {
62           if(inhent == get_entity_overwrites(thisent, l)) {
63             /* overwritten - do not copy */
64             overwritten = 1;
65             break;
66           }
67         }
68       }
69       /* Inherit entity */
70       if (!overwritten) {
71         thisent = copy_entity_own(inhent, clss);
72         add_entity_overwrites(thisent, inhent);
73         if (get_entity_peculiarity(inhent) == peculiarity_existent)
74           set_entity_peculiarity(thisent, peculiarity_inherited);
75         set_entity_ld_ident(thisent, mfunc(inhent, clss));
76         if (get_entity_variability(inhent) == variability_constant) {
77           assert(is_atomic_entity(inhent) &&  /* @@@ */
78                  "Inheritance of constant, compound entities not implemented");
79           set_entity_variability(thisent, variability_constant);
80           set_atomic_ent_value(thisent, get_atomic_ent_value(inhent));
81         }
82       }
83     }
84   }
85 }
86
87 /* Resolve implicit inheritance.
88  *
89  *  Resolves the implicit inheritance supplied by firm.
90  */
91 void resolve_inheritance(mangle_inherited_name_func *mfunc) {
92   if (!mfunc)
93     mfunc = default_mangle_inherited_name;
94   class_walk_super2sub(copy_entities_from_superclass, NULL, (void *)&mfunc);
95 }
96
97
98 /* ----------------------------------------------------------------------- */
99 /* The transitive closure of the subclass/superclass and                   */
100 /* overwrites/overwrittenby relation.                                      */
101 /*                                                                         */
102 /* A walk over the ir (O(#types+#entities)) computes the transitive        */
103 /* closure.  Adding a new type/entity or changing the basic relations in   */
104 /* some other way invalidates the transitive closure, i.e., it is not      */
105 /* updated by the basic functions.                                         */
106 /*                                                                         */
107 /* All functions are named as their counterparts for the basic relations,  */
108 /* adding the infix 'trans_'.                                              */
109 /* ----------------------------------------------------------------------- */
110
111 void                        set_irp_inh_transitive_closure_state(inh_transitive_closure_state s) {
112   irp->inh_trans_closure_state = s;
113 }
114 void                        invalidate_irp_inh_transitive_closure_state(void) {
115   if (irp->inh_trans_closure_state == inh_transitive_closure_valid)
116     irp->inh_trans_closure_state = inh_transitive_closure_invalid;
117 }
118 inh_transitive_closure_state get_irp_inh_transitive_closure_state(void) {
119   return irp->inh_trans_closure_state;
120 }
121
122 static void assert_valid_state(void) {
123   assert(irp->inh_trans_closure_state == inh_transitive_closure_valid ||
124          irp->inh_trans_closure_state == inh_transitive_closure_invalid);
125 }
126
127 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
128 /* There is a set that extends each entity/type with two new               */
129 /* fields:  one for the upwards directed relation: 'up' (supertype,        */
130 /* overwrites) and one for the downwards directed relation: 'down' (sub-   */
131 /* type, overwrittenby.  These fields contain psets (and maybe later       */
132 /* arrays) listing all subtypes...                                         */
133 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
134
135 typedef struct {
136   firm_kind *kind;   /* An entity or type. */
137   pset *up;
138   pset *down;
139 } tr_inh_trans_tp;
140
141 /* We use this set for all types and entities.  */
142 static set *tr_inh_trans_set = NULL;
143
144 static int tr_inh_trans_cmp(const void *e1, const void *e2, size_t size) {
145   tr_inh_trans_tp *ef1 = (tr_inh_trans_tp *)e1;
146   tr_inh_trans_tp *ef2 = (tr_inh_trans_tp *)e2;
147   return (ef1->kind != ef2->kind);
148 }
149
150 static INLINE unsigned int tr_inh_trans_hash(void *e) {
151   void *v = (void *) ((tr_inh_trans_tp *)e)->kind;
152   return HASH_PTR(v);
153 }
154
155 typedef enum {
156   d_up,
157   d_down,
158 } dir;
159
160 /* This always completes successfully. */
161 static tr_inh_trans_tp* get_firm_kind_entry(firm_kind *k) {
162   tr_inh_trans_tp a, *found;
163   a.kind = k;
164
165   if (!tr_inh_trans_set) tr_inh_trans_set = new_set(tr_inh_trans_cmp, 128);
166
167   found = set_find(tr_inh_trans_set, &a, sizeof(a), tr_inh_trans_hash(&a));
168   if (!found) {
169     a.up   = pset_new_ptr(16);
170     a.down = pset_new_ptr(16);
171     found = set_insert(tr_inh_trans_set, &a, sizeof(a), tr_inh_trans_hash(&a));
172   }
173   return found;
174 }
175
176 static pset *get_entity_map(entity *ent, dir d) {
177   tr_inh_trans_tp *found;
178
179   assert(is_entity(ent));
180   found = get_firm_kind_entry((firm_kind *)ent);
181   return (d == d_up) ? found->up : found->down;
182 }
183 /*
184 static void  add_entity_map(entity *ent, dir d, entity *new) {
185   tr_inh_trans_tp *found;
186
187   assert(is_entity(ent) && is_entity(new));
188   tr_inh_trans_tp *found = get_firm_kind_entry((firm_kind *)ent);
189   if (d == d_up)
190     pset_insert_ptr(found->up,   new);
191   else
192     pset_insert_ptr(found->down, new);
193 }
194 */
195 static pset *get_type_map(type *tp, dir d) {
196   tr_inh_trans_tp *found;
197
198   assert(is_type(tp));
199   found = get_firm_kind_entry((firm_kind *)tp);
200   return (d == d_up) ? found->up : found->down;
201 }
202 /*
203 static void  add_type_map(type *tp, dir d, type *new) {
204   tr_inh_trans_tp *found;
205
206   assert(is_type(tp) && is_type(new));
207   found = get_firm_kind_entry((firm_kind *)tp);
208   if (d == d_up) pset_insert_ptr(found->up,   new);
209   else           pset_insert_ptr(found->down, new);
210 }
211 */
212
213
214 /**
215  * Walk over all types reachable from tp in the sub/supertype
216  * relation and compute the closure for the two downwards directed
217  * relations.
218  *
219  * The walk in the dag formed by the relation is tricky:  We must visit
220  * all subtypes before visiting the supertypes.  So we first walk down.
221  * Then we can compute the closure for this type.  Then we walk up.
222  * As we call ourselves recursive, and walk in both directions, there
223  * can be cycles.  So we have to make sure, that if we visit a node
224  * a second time (in a walk up) we do nothing.  For this we increment
225  * the master visited flag twice.
226  * If the type is marked with master_flag_visited-1 it is on the stack.
227  * If it is marked with master_flag_visited it is fully processed.
228  *
229  * Well, we still miss some candidates ... */
230 static void compute_down_closure(type *tp) {
231   pset *myset, *subset;
232   int i, n_subtypes, n_members, n_supertypes;
233   unsigned long master_visited = get_master_type_visited();
234
235   assert(is_Class_type(tp));
236
237   set_type_visited(tp, master_visited-1);
238
239   /* Recursive descend. */
240   n_subtypes = get_class_n_subtypes(tp);
241   for (i = 0; i < n_subtypes; ++i) {
242     type *stp = get_class_subtype(tp, i);
243     if (get_type_visited(stp) < master_visited-1) {
244       compute_down_closure(stp);
245     }
246   }
247
248   /* types */
249   myset = get_type_map(tp, d_down);
250   for (i = 0; i < n_subtypes; ++i) {
251     type *stp = get_class_subtype(tp, i);
252     subset = get_type_map(stp, d_down);
253     pset_insert_ptr(myset, stp);
254     pset_insert_pset_ptr(myset, subset);
255   }
256
257   /* entities */
258   n_members = get_class_n_members(tp);
259   for (i = 0; i < n_members; ++i) {
260     entity *mem = get_class_member(tp, i);
261     int j, n_overwrittenby = get_entity_n_overwrittenby(mem);
262
263     myset = get_entity_map(mem, d_down);
264     for (j = 0; j < n_overwrittenby; ++j) {
265       entity *ov = get_entity_overwrittenby(mem, j);
266       subset = get_entity_map(ov, d_down);
267       pset_insert_ptr(myset, ov);
268       pset_insert_pset_ptr(myset, subset);
269     }
270   }
271
272   mark_type_visited(tp);
273
274   /* Walk up. */
275   n_supertypes = get_class_n_supertypes(tp);
276   for (i = 0; i < n_supertypes; ++i) {
277     type *stp = get_class_supertype(tp, i);
278     if (get_type_visited(stp) < master_visited-1) {
279       compute_down_closure(stp);
280     }
281   }
282 }
283
284 static void compute_up_closure(type *tp) {
285   pset *myset, *subset;
286   int i, n_subtypes, n_members, n_supertypes;
287   unsigned long master_visited = get_master_type_visited();
288
289   assert(is_Class_type(tp));
290
291   set_type_visited(tp, master_visited-1);
292
293   /* Recursive descend. */
294   n_supertypes = get_class_n_supertypes(tp);
295   for (i = 0; i < n_supertypes; ++i) {
296     type *stp = get_class_supertype(tp, i);
297     if (get_type_visited(stp) < get_master_type_visited()-1) {
298       compute_up_closure(stp);
299     }
300   }
301
302   /* types */
303   myset = get_type_map(tp, d_up);
304   for (i = 0; i < n_supertypes; ++i) {
305     type *stp = get_class_supertype(tp, i);
306     subset = get_type_map(stp, d_up);
307     pset_insert_ptr(myset, stp);
308     pset_insert_pset_ptr(myset, subset);
309   }
310
311   /* entities */
312   n_members = get_class_n_members(tp);
313   for (i = 0; i < n_members; ++i) {
314     entity *mem = get_class_member(tp, i);
315     int j, n_overwrites = get_entity_n_overwrites(mem);
316
317     myset = get_entity_map(mem, d_up);
318     for (j = 0; j < n_overwrites; ++j) {
319       entity *ov = get_entity_overwrites(mem, j);
320       subset = get_entity_map(ov, d_up);
321       pset_insert_pset_ptr(myset, subset);
322       pset_insert_ptr(myset, ov);
323     }
324   }
325
326   mark_type_visited(tp);
327
328   /* Walk down. */
329   n_subtypes = get_class_n_subtypes(tp);
330   for (i = 0; i < n_subtypes; ++i) {
331     type *stp = get_class_subtype(tp, i);
332     if (get_type_visited(stp) < master_visited-1) {
333       compute_up_closure(stp);
334     }
335   }
336 }
337
338 /** Compute the transitive closure of the subclass/superclass and
339  *  overwrites/overwrittenby relation.
340  *
341  *  This function walks over the ir (O(#types+#entities)) to compute the
342  *  transitive closure.    */
343 void compute_inh_transitive_closure(void) {
344   int i, n_types = get_irp_n_types();
345   free_inh_transitive_closure();
346
347   /* The 'down' relation */
348   inc_master_type_visited();  /* Inc twice: one if on stack, second if values computed. */
349   inc_master_type_visited();
350   for (i = 0; i < n_types; ++i) {
351     type *tp = get_irp_type(i);
352     if (is_Class_type(tp) && type_not_visited(tp)) { /* For others there is nothing to accumulate. */
353       int j, n_subtypes = get_class_n_subtypes(tp);
354       int has_unmarked_subtype = false;
355
356       assert(get_type_visited(tp) < get_master_type_visited()-1);
357       for (j = 0; j < n_subtypes && !has_unmarked_subtype; ++j) {
358         type *stp = get_class_subtype(tp, j);
359               if (type_not_visited(stp)) has_unmarked_subtype = true;
360       }
361
362       /* This is a good starting point. */
363       if (!has_unmarked_subtype)
364         compute_down_closure(tp);
365     }
366   }
367
368   /* The 'up' relation */
369   inc_master_type_visited();
370   inc_master_type_visited();
371   for (i = 0; i < n_types; ++i) {
372     type *tp = get_irp_type(i);
373     if (is_Class_type(tp) && type_not_visited(tp)) { /* For others there is nothing to accumulate. */
374       int j, n_supertypes = get_class_n_supertypes(tp);
375       int has_unmarked_supertype = false;
376
377       assert(get_type_visited(tp) < get_master_type_visited()-1);
378       for (j = 0; j < n_supertypes && !has_unmarked_supertype; ++j) {
379               type *stp = get_class_supertype(tp, j);
380               if (type_not_visited(stp)) has_unmarked_supertype = true;
381       }
382
383       /* This is a good starting point. */
384       if (!has_unmarked_supertype)
385         compute_up_closure(tp);
386     }
387   }
388
389   irp->inh_trans_closure_state = inh_transitive_closure_valid;
390 }
391
392 /** Free memory occupied by the transitive closure information. */
393 void free_inh_transitive_closure(void) {
394   if (tr_inh_trans_set) {
395     tr_inh_trans_tp *elt;
396     for (elt = set_first(tr_inh_trans_set); elt; elt = set_next(tr_inh_trans_set)) {
397       del_pset(elt->up);
398       del_pset(elt->down);
399     }
400     del_set(tr_inh_trans_set);
401     tr_inh_trans_set = NULL;
402   }
403   irp->inh_trans_closure_state = inh_transitive_closure_none;
404 }
405
406 /* - subtype ------------------------------------------------------------- */
407
408 type *get_class_trans_subtype_first(type *tp) {
409   assert_valid_state();
410   return pset_first(get_type_map(tp, d_down));
411 }
412
413 type *get_class_trans_subtype_next (type *tp) {
414   assert_valid_state();
415   return pset_next(get_type_map(tp, d_down));
416 }
417
418 int is_class_trans_subtype (type *tp, type *subtp) {
419   assert_valid_state();
420   return (pset_find_ptr(get_type_map(tp, d_down), subtp) != NULL);
421 }
422
423 /* - supertype ----------------------------------------------------------- */
424
425 type *get_class_trans_supertype_first(type *tp) {
426   assert_valid_state();
427   return pset_first(get_type_map(tp, d_up));
428 }
429
430 type *get_class_trans_supertype_next (type *tp) {
431   assert_valid_state();
432   return pset_next(get_type_map(tp, d_up));
433 }
434
435 /* - overwrittenby ------------------------------------------------------- */
436
437 entity *get_entity_trans_overwrittenby_first(entity *ent) {
438   assert_valid_state();
439   return pset_first(get_entity_map(ent, d_down));
440 }
441
442 entity *get_entity_trans_overwrittenby_next (entity *ent) {
443   assert_valid_state();
444   return pset_next(get_entity_map(ent, d_down));
445 }
446
447 /* - overwrites ---------------------------------------------------------- */
448
449
450 /** Iterate over all transitive overwritten entities. */
451 entity *get_entity_trans_overwrites_first(entity *ent) {
452   assert_valid_state();
453   return pset_first(get_entity_map(ent, d_up));
454 }
455
456 entity *get_entity_trans_overwrites_next (entity *ent) {
457   assert_valid_state();
458   return pset_next(get_entity_map(ent, d_up));
459 }
460
461
462
463
464
465 /* ----------------------------------------------------------------------- */
466 /* Classify pairs of types/entities in the inheritance relations.          */
467 /* ----------------------------------------------------------------------- */
468
469 /* Returns true if low is subclass of high. */
470 int is_subclass_of(type *low, type *high) {
471   int i, n_subtypes;
472   assert(is_Class_type(low) && is_Class_type(high));
473
474   if (low == high) return 1;
475
476   if (get_irp_inh_transitive_closure_state() == inh_transitive_closure_valid) {
477     pset *m = get_type_map(high, d_down);
478     return pset_find_ptr(m, low) ? 1 : 0;
479   }
480
481   /* depth first search from high downwards. */
482   n_subtypes = get_class_n_subtypes(high);
483   for (i = 0; i < n_subtypes; i++) {
484     type *stp = get_class_subtype(high, i);
485     if (low == stp) return 1;
486     if (is_subclass_of(low, stp))
487       return 1;
488   }
489   return 0;
490 }
491
492
493 /* Subclass check for pointers to classes.
494  *
495  *  Dereferences at both types the same amount of pointer types (as
496  *  many as possible).  If the remaining types are both class types
497  *  and subclasses, returns true, else false.  Can also be called with
498  *  two class types.  */
499 int is_subclass_ptr_of(type *low, type *high) {
500   while (is_Pointer_type(low) && is_Pointer_type(high)) {
501     low  = get_pointer_points_to_type(low);
502     high = get_pointer_points_to_type(high);
503   }
504
505   if (is_Class_type(low) && is_Class_type(high))
506     return is_subclass_of(low, high);
507   return 0;
508 }
509
510 int is_superclass_of(type *high, type *low) {
511   return is_subclass_of(low, high);
512 }
513
514 int is_superclass_ptr_of(type *high, type *low) {
515   return is_subclass_ptr_of(low, high);
516 }
517
518 int is_overwritten_by(entity *high, entity *low) {
519   int i, n_overwrittenby;
520   assert(is_entity(low) && is_entity(high));
521
522   if (get_irp_inh_transitive_closure_state() == inh_transitive_closure_valid) {
523     pset *m = get_entity_map(high, d_down);
524     return pset_find_ptr(m, low) ? 1 : 0;
525   }
526
527   /* depth first search from high downwards. */
528   n_overwrittenby = get_entity_n_overwrittenby(high);
529   for (i = 0; i < n_overwrittenby; i++) {
530     entity *ov = get_entity_overwrittenby(high, i);
531     if (low == ov) return 1;
532     if (is_overwritten_by(low, ov))
533       return 1;
534   }
535   return 0;
536 }
537
538
539 /** Need two routines because I want to assert the result. */
540 static entity *resolve_ent_polymorphy2 (type *dynamic_class, entity *static_ent) {
541   int i, n_overwrittenby;
542   entity *res = NULL;
543
544   if (get_entity_owner(static_ent) == dynamic_class) return static_ent;
545
546   n_overwrittenby = get_entity_n_overwrittenby(static_ent);
547   for (i = 0; i < n_overwrittenby; ++i) {
548     res = resolve_ent_polymorphy2(dynamic_class, get_entity_overwrittenby(static_ent, i));
549     if (res)
550       break;
551   }
552
553   return res;
554 }
555
556 /* Resolve polymorphy in the inheritance relation.
557  *
558  * Returns the dynamically referenced entity if the static entity and the
559  * dynamic type are given.
560  * Search downwards in overwritten tree. */
561 entity *resolve_ent_polymorphy(type *dynamic_class, entity *static_ent) {
562   entity *res;
563   assert(static_ent && is_entity(static_ent));
564
565   res = resolve_ent_polymorphy2(dynamic_class, static_ent);
566   assert(res);
567
568   return res;
569 }
570
571
572
573 /* ----------------------------------------------------------------------- */
574 /* Class cast state handling.                                              */
575 /* ----------------------------------------------------------------------- */
576
577 /* - State handling. ----------------------------------------- */
578
579 void set_irg_class_cast_state(ir_graph *irg, ir_class_cast_state s) {
580   if (get_irp_class_cast_state() > s) set_irp_class_cast_state(s);
581   irg->class_cast_state = s;
582 }
583
584 ir_class_cast_state get_irg_class_cast_state(ir_graph *irg) {
585   return irg->class_cast_state;
586 }
587
588 void set_irp_class_cast_state(ir_class_cast_state s) {
589   int i;
590   for (i = 0; i < get_irp_n_irgs(); ++i)
591     assert(get_irg_class_cast_state(get_irp_irg(i)) >= s);
592   irp->class_cast_state = s;
593 }
594
595 ir_class_cast_state get_irp_class_cast_state(void) {
596   return irp->class_cast_state;
597 }
598
599 char *get_class_cast_state_string(ir_class_cast_state s) {
600 #define X(a)    case a: return #a
601   switch(s) {
602     X(ir_class_casts_any);
603     X(ir_class_casts_transitive);
604     X(ir_class_casts_normalized);
605     X(ir_class_casts_state_max);
606   default: return "invalid class cast state";
607   }
608 #undef X
609 }
610
611 /* - State verification. ------------------------------------- */
612
613 typedef struct ccs_env {
614   ir_class_cast_state expected_state;
615   ir_class_cast_state worst_situation;
616 } ccs_env;
617
618 void verify_irn_class_cast_state(ir_node *n, void *env) {
619   ccs_env             *ccs = (ccs_env *)env;
620   ir_class_cast_state this_state = ir_class_casts_any;
621   type                *fromtype, *totype;
622   int                 ref_depth = 0;
623
624   if (get_irn_op(n) != op_Cast) return;
625
626   fromtype = get_irn_typeinfo_type(get_Cast_op(n));
627   totype   = get_Cast_type(n);
628
629   while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) {
630     totype   = get_pointer_points_to_type(totype);
631     fromtype = get_pointer_points_to_type(fromtype);
632     ref_depth++;
633   }
634
635   if (!is_Class_type(totype)) return;
636
637   if (is_subclass_of(totype, fromtype) ||
638       is_subclass_of(fromtype, totype)   ) {
639     this_state = ir_class_casts_transitive;
640     if ((get_class_supertype_index(totype, fromtype) != -1) ||
641         (get_class_supertype_index(fromtype, totype) != -1) ||
642         fromtype == totype) {
643       /*   Das ist doch alt?  Aus dem cvs aufgetaucht ...
644            if ((get_class_supertype_index(totype, fromtype) == -1) &&
645            (get_class_supertype_index(fromtype, totype) == -1) ) {  */
646       this_state = ir_class_casts_normalized;
647     }
648   }
649
650   if (!(this_state >= ccs->expected_state)) {
651     printf("  Node is "); DDMN(n);
652     printf("    totype   "); DDMT(totype);
653     printf("    fromtype "); DDMT(fromtype);
654     printf("    this_state: %s, exp. state: %s\n",
655            get_class_cast_state_string(this_state),
656            get_class_cast_state_string(ccs->expected_state));
657     assert(this_state >= ccs->expected_state &&
658            "invalid state class cast state setting in graph");
659   }
660
661   if (this_state < ccs->worst_situation)
662     ccs->worst_situation = this_state;
663 }
664
665
666 /** Verify that the graph meets requirements of state set. */
667 void verify_irg_class_cast_state(ir_graph *irg) {
668   ccs_env env;
669
670   env.expected_state  = get_irg_class_cast_state(irg);
671   env.worst_situation = ir_class_casts_normalized;
672
673   irg_walk_graph(irg, NULL, verify_irn_class_cast_state, &env);
674
675   if ((env.worst_situation > env.expected_state) && get_firm_verbosity()) {
676     printf("Note:  class cast state is set lower than reqired in graph\n       ");
677     DDMG(irg);
678     printf("       state is %s, reqired is %s\n",
679            get_class_cast_state_string(env.expected_state),
680            get_class_cast_state_string(env.worst_situation));
681   }
682 }