2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Perform optimizations of the type representation.
24 * @author Goetz Lindenmaier
27 #ifndef FIRM_OPT_TROPT_H
28 #define FIRM_OPT_TROPT_H
30 #include "firm_types.h"
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);
36 /** Insert Casts so that class type casts conform exactly with the type hierarchy.
38 * Formulated in Java, this achieves the following:
40 * For a class hierarchy
42 * class B extends A {}
43 * class C extends B {}
44 * we transforms a cast
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.
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".
61 void normalize_irp_class_casts(gen_pointer_type_to_func gppt_fct);
64 /** Insert Casts so that class type casts conform exactly with the type hierarchy
67 * For more details see normalize_irp_class_casts().
69 * This transformation requires that type information is computed. @see irtypeinfo.h.
71 void normalize_irg_class_casts(ir_graph *irg, gen_pointer_type_to_func gppt_fct);
74 /** Optimize casting between class types.
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
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.
90 * Computes type information if not available. @see irtypeinfo.h.
91 * Typeinformation is valid after optimization.
92 * Invalidates trout information.
94 void optimize_class_casts(void);
96 #endif /* FIRM_OPT_TROPT_H */