fixed classify_value() function
[libfirm] / ir / opt / tropt.h
1 /**
2  *
3  * @file irsimpeltype.h
4  *
5  * Project:     libFIRM
6  * File name:   ir/opt/tropt.h
7  * Purpose:     Optimize the type representation.
8  * Author:      Goetz Lindenmaier
9  * Modified by:
10  * Created:     20.4.2005
11  * CVS-ID:      $Id$
12  * Copyright:   (c) 2005 Universität Karlsruhe
13  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
14  *
15  * Perform optimizations of the type representation.
16  *
17  *
18  */
19
20 #ifndef _TROPT_H_
21 #define _TROPT_H_
22
23 #include "irnode.h"
24 #include "irgraph.h"
25 #include "type.h"
26
27 /** This is the type for a method, that returns a pointer type to
28  *  tp.  This is needed in the normalization. */
29 typedef type *(*gen_pointer_type_to_func)(type *tp);
30
31 /**  Insert Casts so that class type casts conform exactly with the type hierarchy.
32  *
33  *  Formulated in Java, this achieves the following:
34  *
35  *  For a class hierarchy
36  *    class A {}
37  *    class B extends A {}
38  *    class C extends B {}
39  *  we transforms a cast
40  *    (A)new C()
41  *  to
42  *    (A)((B)new C()).
43  *
44  *  The algorithm works for Casts with class types, but also for Casts
45  *  with all pointer types that point (over several indirections,
46  *  i.e. ***A) to a class type.  Normalizes all graphs.  Computes type
47  *  information (@see irtypeinfo.h) if not available.
48  *  Invalidates trout information as new casts are generated.
49  *
50  *  @param gppt_fct A function that returns a pointer type that points
51  *    to the type given as argument.  If this parameter is NULL, a default
52  *    function is used that either uses trout information or performs a O(n)
53  *    search to find an existing pointer type.  If it can not find a type,
54  *    generates a pointer type with mode_P_mach and suffix "cc_ptr_tp".
55  */
56 void normalize_irp_class_casts(gen_pointer_type_to_func gppt_fct);
57
58
59 /**  Insert Casts so that class type casts conform exactly with the type hierarchy
60  *   in given graph.
61  *
62  *   For more details see @normalize_irp_class_casts().
63  *
64  *  This transformation requires that type information is computed. @see irtypeinfo.h.
65  */
66 void normalize_irg_class_casts(ir_graph *irg, gen_pointer_type_to_func gppt_fct);
67
68
69 /** Optimize casting between class types.
70  *
71  *    class A { m(); }
72  *    class B extends A { }
73  *    class C extends B {}
74  *  Performs the following transformations:
75  *    C c = (C)(B)(A)(B)new C()  --> C c = (C)(B)newC() --> C c = new C()
76  *    (Optimizing downcasts as A a = (A)(B)(new A()) --> A a = new A() can
77  *     be suppressed by setting flag opt_suppress_downcast_optimization.
78  *     Downcasting A to B might cause an exception.  It is not clear
79  *     whether this is modeled by the Firm Cast node, as it has no exception
80  *     outputs.);
81  *  If there is inh_m() that overwrites m() in B:
82  *    ((A) new B()).m()  --> (new B()).inh_m()
83  *  Phi((A)x, (A)y)  --> (A) Phi (x, y)  if (A) is an upcast.
84  *
85  *  Computes type information if not available. @see irtypeinfo.h.
86  *  Typeinformation is valid after optimization.
87  *  Invalidates trout information.
88  */
89 void optimize_class_casts(void);
90
91 #endif /* _TROPT_H_ */