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