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