updated Header
[libfirm] / ir / opt / tropt.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Perform optimizations of the type representation.
23  * @date    20.4.2005
24  * @author  Goetz Lindenmaier
25  * @version $Id$
26  */
27 #ifndef FIRM_OPT_TROPT_H
28 #define FIRM_OPT_TROPT_H
29
30 #include "firm_types.h"
31
32 /** This is the type for a method, that returns a pointer type to
33  *  tp.  This is needed in the normalization. */
34 typedef ir_type *(*gen_pointer_type_to_func)(ir_type *tp);
35
36 /**  Insert Casts so that class type casts conform exactly with the type hierarchy.
37  *
38  *  Formulated in Java, this achieves the following:
39  *
40  *  For a class hierarchy
41  *    class A {}
42  *    class B extends A {}
43  *    class C extends B {}
44  *  we transforms a cast
45  *    (A)new C()
46  *  to
47  *    (A)((B)new C()).
48  *
49  *  The algorithm works for Casts with class types, but also for Casts
50  *  with all pointer types that point (over several indirections,
51  *  i.e. ***A) to a class type.  Normalizes all graphs.  Computes type
52  *  information (@see irtypeinfo.h) if not available.
53  *  Invalidates trout information as new casts are generated.
54  *
55  *  @param gppt_fct A function that returns a pointer type that points
56  *    to the type given as argument.  If this parameter is NULL, a default
57  *    function is used that either uses trout information or performs a O(n)
58  *    search to find an existing pointer type.  If it can not find a type,
59  *    generates a pointer type with mode_P_mach and suffix "cc_ptr_tp".
60  */
61 void normalize_irp_class_casts(gen_pointer_type_to_func gppt_fct);
62
63
64 /**  Insert Casts so that class type casts conform exactly with the type hierarchy
65  *   in given graph.
66  *
67  *   For more details see normalize_irp_class_casts().
68  *
69  *  This transformation requires that type information is computed. @see irtypeinfo.h.
70  */
71 void normalize_irg_class_casts(ir_graph *irg, gen_pointer_type_to_func gppt_fct);
72
73
74 /** Optimize casting between class types.
75  *
76  *    class A { m(); }
77  *    class B extends A { }
78  *    class C extends B {}
79  *  Performs the following transformations:
80  *    C c = (C)(B)(A)(B)new C()  --> C c = (C)(B)newC() --> C c = new C()
81  *    (Optimizing downcasts as A a = (A)(B)(new A()) --> A a = new A() can
82  *     be suppressed by setting the flag opt_suppress_downcast_optimization.
83  *     Downcasting A to B might cause an exception.  It is not clear
84  *     whether this is modeled by the Firm Cast node, as it has no exception
85  *     outputs.);
86  *  If there is inh_m() that overwrites m() in B:
87  *    ((A) new B()).m()  --> (new B()).inh_m()
88  *  Phi((A)x, (A)y)  --> (A) Phi (x, y)  if (A) is an upcast.
89  *
90  *  Computes type information if not available. @see irtypeinfo.h.
91  *  Typeinformation is valid after optimization.
92  *  Invalidates trout information.
93  */
94 void optimize_class_casts(void);
95
96 #endif /* FIRM_OPT_TROPT_H */