5 * File name: ir/opt/tropt.h
6 * Purpose: Optimize the type representation.
7 * Author: Goetz Lindenmaier
11 * Copyright: (c) 2005 Universität Karlsruhe
12 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
14 * Perform optimizations of the type representation.
22 #include "firm_types.h"
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);
28 /** Insert Casts so that class type casts conform exactly with the type hierarchy.
30 * Formulated in Java, this achieves the following:
32 * For a class hierarchy
34 * class B extends A {}
35 * class C extends B {}
36 * we transforms a cast
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.
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".
53 void normalize_irp_class_casts(gen_pointer_type_to_func gppt_fct);
56 /** Insert Casts so that class type casts conform exactly with the type hierarchy
59 * For more details see normalize_irp_class_casts().
61 * This transformation requires that type information is computed. @see irtypeinfo.h.
63 void normalize_irg_class_casts(ir_graph *irg, gen_pointer_type_to_func gppt_fct);
66 /** Optimize casting between class types.
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
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.
82 * Computes type information if not available. @see irtypeinfo.h.
83 * Typeinformation is valid after optimization.
84 * Invalidates trout information.
86 void optimize_class_casts(void);
88 #endif /* _TROPT_H_ */