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.
26 /** This is the type for a method, that returns a pointer type to
27 * tp. This is needed in the normalization. */
28 typedef type *(*gen_pointer_type_to_func)(type *tp);
30 /** Insert Casts so that class type casts conform exactly with the type hierarchy.
32 * Formulated in Java, this achieves the following:
34 * For a class hierarchy
36 * class B extends A {}
37 * class C extends B {}
38 * we transforms a cast
43 * The algorithm works for Casts with class types, but also for Casts
44 * with all pointer types that point (over several indirections,
45 * i.e. ***A) to a class type. Normalizes all graphs. Computes type
46 * information (@see irtypeinfo.h) if not available.
47 * Invalidates trout information as new casts are generated.
49 * @param gppt_fct A function that returns a pointer type that points
50 * to the type given as argument. If this parameter is NULL, a default
51 * function is used that either uses trout information or performs a O(n)
52 * search to find an existing pointer type. If it can not find a type,
53 * generates a pointer type with mode_P_mach and suffix "cc_ptr_tp".
55 void normalize_irp_class_casts(gen_pointer_type_to_func gppt_fct);
58 /** Insert Casts so that class type casts conform exactly with the type hierarchy
61 * For more details see normalize_irp_class_casts().
63 * This transformation requires that type information is computed. @see irtypeinfo.h.
65 void normalize_irg_class_casts(ir_graph *irg, gen_pointer_type_to_func gppt_fct);
68 /** Optimize casting between class types.
71 * class B extends A { }
72 * class C extends B {}
73 * Performs the following transformations:
74 * C c = (C)(B)(A)(B)new C() --> C c = (C)(B)newC() --> C c = new C()
75 * (Optimizing downcasts as A a = (A)(B)(new A()) --> A a = new A() can
76 * be suppressed by setting the flag opt_suppress_downcast_optimization.
77 * Downcasting A to B might cause an exception. It is not clear
78 * whether this is modeled by the Firm Cast node, as it has no exception
80 * If there is inh_m() that overwrites m() in B:
81 * ((A) new B()).m() --> (new B()).inh_m()
82 * Phi((A)x, (A)y) --> (A) Phi (x, y) if (A) is an upcast.
84 * Computes type information if not available. @see irtypeinfo.h.
85 * Typeinformation is valid after optimization.
86 * Invalidates trout information.
88 void optimize_class_casts(void);
90 #endif /* _TROPT_H_ */