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
24 * File name: ir/opt/tropt.h
25 * Purpose: Optimize the type representation.
26 * Author: Goetz Lindenmaier
30 * Copyright: (c) 2005 Universität Karlsruhe
32 * Perform optimizations of the type representation.
40 #include "firm_types.h"
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);
46 /** Insert Casts so that class type casts conform exactly with the type hierarchy.
48 * Formulated in Java, this achieves the following:
50 * For a class hierarchy
52 * class B extends A {}
53 * class C extends B {}
54 * we transforms a cast
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.
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".
71 void normalize_irp_class_casts(gen_pointer_type_to_func gppt_fct);
74 /** Insert Casts so that class type casts conform exactly with the type hierarchy
77 * For more details see normalize_irp_class_casts().
79 * This transformation requires that type information is computed. @see irtypeinfo.h.
81 void normalize_irg_class_casts(ir_graph *irg, gen_pointer_type_to_func gppt_fct);
84 /** Optimize casting between class types.
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
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.
100 * Computes type information if not available. @see irtypeinfo.h.
101 * Typeinformation is valid after optimization.
102 * Invalidates trout information.
104 void optimize_class_casts(void);
106 #endif /* _TROPT_H_ */