removed bool type and depency from stdbool.h (not C89)
[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 = 0;
355
356       assert(get_type_visited(tp) < get_master_type_visited()-1);
357       for (j = 0; j < n_subtypes; ++j) {
358         type *stp = get_class_subtype(tp, j);
359         if (type_not_visited(stp)) {
360           has_unmarked_subtype = 1;
361           break;
362         }
363       }
364
365       /* This is a good starting point. */
366       if (!has_unmarked_subtype)
367         compute_down_closure(tp);
368     }
369   }
370
371   /* The 'up' relation */
372   inc_master_type_visited();
373   inc_master_type_visited();
374   for (i = 0; i < n_types; ++i) {
375     type *tp = get_irp_type(i);
376     if (is_Class_type(tp) && type_not_visited(tp)) { /* For others there is nothing to accumulate. */
377       int j, n_supertypes = get_class_n_supertypes(tp);
378       int has_unmarked_supertype = 0;
379
380       assert(get_type_visited(tp) < get_master_type_visited()-1);
381       for (j = 0; j < n_supertypes; ++j) {
382               type *stp = get_class_supertype(tp, j);
383         if (type_not_visited(stp)) {
384           has_unmarked_supertype = 1;
385           break;
386         }
387       }
388
389       /* This is a good starting point. */
390       if (!has_unmarked_supertype)
391         compute_up_closure(tp);
392     }
393   }
394
395   irp->inh_trans_closure_state = inh_transitive_closure_valid;
396 }
397
398 /** Free memory occupied by the transitive closure information. */
399 void free_inh_transitive_closure(void) {
400   if (tr_inh_trans_set) {
401     tr_inh_trans_tp *elt;
402     for (elt = set_first(tr_inh_trans_set); elt; elt = set_next(tr_inh_trans_set)) {
403       del_pset(elt->up);
404       del_pset(elt->down);
405     }
406     del_set(tr_inh_trans_set);
407     tr_inh_trans_set = NULL;
408   }
409   irp->inh_trans_closure_state = inh_transitive_closure_none;
410 }
411
412 /* - subtype ------------------------------------------------------------- */
413
414 type *get_class_trans_subtype_first(type *tp) {
415   assert_valid_state();
416   return pset_first(get_type_map(tp, d_down));
417 }
418
419 type *get_class_trans_subtype_next (type *tp) {
420   assert_valid_state();
421   return pset_next(get_type_map(tp, d_down));
422 }
423
424 int is_class_trans_subtype (type *tp, type *subtp) {
425   assert_valid_state();
426   return (pset_find_ptr(get_type_map(tp, d_down), subtp) != NULL);
427 }
428
429 /* - supertype ----------------------------------------------------------- */
430
431 type *get_class_trans_supertype_first(type *tp) {
432   assert_valid_state();
433   return pset_first(get_type_map(tp, d_up));
434 }
435
436 type *get_class_trans_supertype_next (type *tp) {
437   assert_valid_state();
438   return pset_next(get_type_map(tp, d_up));
439 }
440
441 /* - overwrittenby ------------------------------------------------------- */
442
443 entity *get_entity_trans_overwrittenby_first(entity *ent) {
444   assert_valid_state();
445   return pset_first(get_entity_map(ent, d_down));
446 }
447
448 entity *get_entity_trans_overwrittenby_next (entity *ent) {
449   assert_valid_state();
450   return pset_next(get_entity_map(ent, d_down));
451 }
452
453 /* - overwrites ---------------------------------------------------------- */
454
455
456 /** Iterate over all transitive overwritten entities. */
457 entity *get_entity_trans_overwrites_first(entity *ent) {
458   assert_valid_state();
459   return pset_first(get_entity_map(ent, d_up));
460 }
461
462 entity *get_entity_trans_overwrites_next (entity *ent) {
463   assert_valid_state();
464   return pset_next(get_entity_map(ent, d_up));
465 }
466
467
468
469
470
471 /* ----------------------------------------------------------------------- */
472 /* Classify pairs of types/entities in the inheritance relations.          */
473 /* ----------------------------------------------------------------------- */
474
475 /* Returns true if low is subclass of high. */
476 int is_subclass_of(type *low, type *high) {
477   int i, n_subtypes;
478   assert(is_Class_type(low) && is_Class_type(high));
479
480   if (low == high) return 1;
481
482   if (get_irp_inh_transitive_closure_state() == inh_transitive_closure_valid) {
483     pset *m = get_type_map(high, d_down);
484     return pset_find_ptr(m, low) ? 1 : 0;
485   }
486
487   /* depth first search from high downwards. */
488   n_subtypes = get_class_n_subtypes(high);
489   for (i = 0; i < n_subtypes; i++) {
490     type *stp = get_class_subtype(high, i);
491     if (low == stp) return 1;
492     if (is_subclass_of(low, stp))
493       return 1;
494   }
495   return 0;
496 }
497
498
499 /* Subclass check for pointers to classes.
500  *
501  *  Dereferences at both types the same amount of pointer types (as
502  *  many as possible).  If the remaining types are both class types
503  *  and subclasses, returns true, else false.  Can also be called with
504  *  two class types.  */
505 int is_subclass_ptr_of(type *low, type *high) {
506   while (is_Pointer_type(low) && is_Pointer_type(high)) {
507     low  = get_pointer_points_to_type(low);
508     high = get_pointer_points_to_type(high);
509   }
510
511   if (is_Class_type(low) && is_Class_type(high))
512     return is_subclass_of(low, high);
513   return 0;
514 }
515
516 int is_superclass_of(type *high, type *low) {
517   return is_subclass_of(low, high);
518 }
519
520 int is_superclass_ptr_of(type *high, type *low) {
521   return is_subclass_ptr_of(low, high);
522 }
523
524 int is_overwritten_by(entity *high, entity *low) {
525   int i, n_overwrittenby;
526   assert(is_entity(low) && is_entity(high));
527
528   if (get_irp_inh_transitive_closure_state() == inh_transitive_closure_valid) {
529     pset *m = get_entity_map(high, d_down);
530     return pset_find_ptr(m, low) ? 1 : 0;
531   }
532
533   /* depth first search from high downwards. */
534   n_overwrittenby = get_entity_n_overwrittenby(high);
535   for (i = 0; i < n_overwrittenby; i++) {
536     entity *ov = get_entity_overwrittenby(high, i);
537     if (low == ov) return 1;
538     if (is_overwritten_by(low, ov))
539       return 1;
540   }
541   return 0;
542 }
543
544
545 /** Need two routines because I want to assert the result. */
546 static entity *resolve_ent_polymorphy2 (type *dynamic_class, entity *static_ent) {
547   int i, n_overwrittenby;
548   entity *res = NULL;
549
550   if (get_entity_owner(static_ent) == dynamic_class) return static_ent;
551
552   n_overwrittenby = get_entity_n_overwrittenby(static_ent);
553   for (i = 0; i < n_overwrittenby; ++i) {
554     res = resolve_ent_polymorphy2(dynamic_class, get_entity_overwrittenby(static_ent, i));
555     if (res)
556       break;
557   }
558
559   return res;
560 }
561
562 /* Resolve polymorphy in the inheritance relation.
563  *
564  * Returns the dynamically referenced entity if the static entity and the
565  * dynamic type are given.
566  * Search downwards in overwritten tree. */
567 entity *resolve_ent_polymorphy(type *dynamic_class, entity *static_ent) {
568   entity *res;
569   assert(static_ent && is_entity(static_ent));
570
571   res = resolve_ent_polymorphy2(dynamic_class, static_ent);
572   assert(res);
573
574   return res;
575 }
576
577
578
579 /* ----------------------------------------------------------------------- */
580 /* Class cast state handling.                                              */
581 /* ----------------------------------------------------------------------- */
582
583 /* - State handling. ----------------------------------------- */
584
585 void set_irg_class_cast_state(ir_graph *irg, ir_class_cast_state s) {
586   if (get_irp_class_cast_state() > s) set_irp_class_cast_state(s);
587   irg->class_cast_state = s;
588 }
589
590 ir_class_cast_state get_irg_class_cast_state(ir_graph *irg) {
591   return irg->class_cast_state;
592 }
593
594 void set_irp_class_cast_state(ir_class_cast_state s) {
595   int i;
596   for (i = 0; i < get_irp_n_irgs(); ++i)
597     assert(get_irg_class_cast_state(get_irp_irg(i)) >= s);
598   irp->class_cast_state = s;
599 }
600
601 ir_class_cast_state get_irp_class_cast_state(void) {
602   return irp->class_cast_state;
603 }
604
605 char *get_class_cast_state_string(ir_class_cast_state s) {
606 #define X(a)    case a: return #a
607   switch(s) {
608     X(ir_class_casts_any);
609     X(ir_class_casts_transitive);
610     X(ir_class_casts_normalized);
611     X(ir_class_casts_state_max);
612   default: return "invalid class cast state";
613   }
614 #undef X
615 }
616
617 /* - State verification. ------------------------------------- */
618
619 typedef struct ccs_env {
620   ir_class_cast_state expected_state;
621   ir_class_cast_state worst_situation;
622 } ccs_env;
623
624 void verify_irn_class_cast_state(ir_node *n, void *env) {
625   ccs_env             *ccs = (ccs_env *)env;
626   ir_class_cast_state this_state = ir_class_casts_any;
627   type                *fromtype, *totype;
628   int                 ref_depth = 0;
629
630   if (get_irn_op(n) != op_Cast) return;
631
632   fromtype = get_irn_typeinfo_type(get_Cast_op(n));
633   totype   = get_Cast_type(n);
634
635   while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) {
636     totype   = get_pointer_points_to_type(totype);
637     fromtype = get_pointer_points_to_type(fromtype);
638     ref_depth++;
639   }
640
641   if (!is_Class_type(totype)) return;
642
643   if (is_subclass_of(totype, fromtype) ||
644       is_subclass_of(fromtype, totype)   ) {
645     this_state = ir_class_casts_transitive;
646     if ((get_class_supertype_index(totype, fromtype) != -1) ||
647         (get_class_supertype_index(fromtype, totype) != -1) ||
648         fromtype == totype) {
649       /*   Das ist doch alt?  Aus dem cvs aufgetaucht ...
650            if ((get_class_supertype_index(totype, fromtype) == -1) &&
651            (get_class_supertype_index(fromtype, totype) == -1) ) {  */
652       this_state = ir_class_casts_normalized;
653     }
654   }
655
656   if (!(this_state >= ccs->expected_state)) {
657     printf("  Node is "); DDMN(n);
658     printf("    totype   "); DDMT(totype);
659     printf("    fromtype "); DDMT(fromtype);
660     printf("    this_state: %s, exp. state: %s\n",
661            get_class_cast_state_string(this_state),
662            get_class_cast_state_string(ccs->expected_state));
663     assert(this_state >= ccs->expected_state &&
664            "invalid state class cast state setting in graph");
665   }
666
667   if (this_state < ccs->worst_situation)
668     ccs->worst_situation = this_state;
669 }
670
671
672 /** Verify that the graph meets requirements of state set. */
673 void verify_irg_class_cast_state(ir_graph *irg) {
674   ccs_env env;
675
676   env.expected_state  = get_irg_class_cast_state(irg);
677   env.worst_situation = ir_class_casts_normalized;
678
679   irg_walk_graph(irg, NULL, verify_irn_class_cast_state, &env);
680
681   if ((env.worst_situation > env.expected_state) && get_firm_verbosity()) {
682     printf("Note:  class cast state is set lower than reqired in graph\n       ");
683     DDMG(irg);
684     printf("       state is %s, reqired is %s\n",
685            get_class_cast_state_string(env.expected_state),
686            get_class_cast_state_string(env.worst_situation));
687   }
688 }