Remove the obsolete .cvsignore files.
[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 "firm_types.h"
23
24 /** This is the type for a method, that returns a pointer type to
25  *  tp.  This is needed in the normalization. */
26 typedef ir_type *(*gen_pointer_type_to_func)(ir_type *tp);
27
28 /**  Insert Casts so that class type casts conform exactly with the type hierarchy.
29  *
30  *  Formulated in Java, this achieves the following:
31  *
32  *  For a class hierarchy
33  *    class A {}
34  *    class B extends A {}
35  *    class C extends B {}
36  *  we transforms a cast
37  *    (A)new C()
38  *  to
39  *    (A)((B)new C()).
40  *
41  *  The algorithm works for Casts with class types, but also for Casts
42  *  with all pointer types that point (over several indirections,
43  *  i.e. ***A) to a class type.  Normalizes all graphs.  Computes type
44  *  information (@see irtypeinfo.h) if not available.
45  *  Invalidates trout information as new casts are generated.
46  *
47  *  @param gppt_fct A function that returns a pointer type that points
48  *    to the type given as argument.  If this parameter is NULL, a default
49  *    function is used that either uses trout information or performs a O(n)
50  *    search to find an existing pointer type.  If it can not find a type,
51  *    generates a pointer type with mode_P_mach and suffix "cc_ptr_tp".
52  */
53 void normalize_irp_class_casts(gen_pointer_type_to_func gppt_fct);
54
55
56 /**  Insert Casts so that class type casts conform exactly with the type hierarchy
57  *   in given graph.
58  *
59  *   For more details see normalize_irp_class_casts().
60  *
61  *  This transformation requires that type information is computed. @see irtypeinfo.h.
62  */
63 void normalize_irg_class_casts(ir_graph *irg, gen_pointer_type_to_func gppt_fct);
64
65
66 /** Optimize casting between class types.
67  *
68  *    class A { m(); }
69  *    class B extends A { }
70  *    class C extends B {}
71  *  Performs the following transformations:
72  *    C c = (C)(B)(A)(B)new C()  --> C c = (C)(B)newC() --> C c = new C()
73  *    (Optimizing downcasts as A a = (A)(B)(new A()) --> A a = new A() can
74  *     be suppressed by setting the flag opt_suppress_downcast_optimization.
75  *     Downcasting A to B might cause an exception.  It is not clear
76  *     whether this is modeled by the Firm Cast node, as it has no exception
77  *     outputs.);
78  *  If there is inh_m() that overwrites m() in B:
79  *    ((A) new B()).m()  --> (new B()).inh_m()
80  *  Phi((A)x, (A)y)  --> (A) Phi (x, y)  if (A) is an upcast.
81  *
82  *  Computes type information if not available. @see irtypeinfo.h.
83  *  Typeinformation is valid after optimization.
84  *  Invalidates trout information.
85  */
86 void optimize_class_casts(void);
87
88 #endif /* _TROPT_H_ */