6 * File name: ir/opt/tropt.h
7 * Purpose: Optimize the type representation.
8 * Author: Goetz Lindenmaier
12 * Copyright: (c) 2005 Universität Karlsruhe
13 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 * Perform optimizations of the type representation.
27 /** This is the type for a method, that returns a pointer type to
28 * tp. This is needed in the normalization. */
29 typedef type *(*gen_pointer_type_to_func)(type *tp);
31 /** Insert Casts so that class type casts conform exactly with the type hierarchy.
33 * Formulated in Java, this achieves the following:
35 * For a class hierarchy
37 * class B extends A {}
38 * class C extends B {}
39 * we transforms a cast
44 * The algorithm works for Casts with class types, but also for Casts
45 * with all pointer types that point (over several indirections,
46 * i.e. ***A) to a class type. Normalizes all graphs. Computes type
47 * information (@see irtypeinfo.h) if not available.
48 * Invalidates trout information as new casts are generated.
50 * @param gppt_fct A function that returns a pointer type that points
51 * to the type given as argument. If this parameter is NULL, a default
52 * function is used that either uses trout information or performs a O(n)
53 * search to find an existing pointer type. If it can not find a type,
54 * generates a pointer type with mode_P_mach and suffix "cc_ptr_tp".
56 void normalize_irp_class_casts(gen_pointer_type_to_func gppt_fct);
59 /** Insert Casts so that class type casts conform exactly with the type hierarchy
62 * For more details see @normalize_irp_class_casts().
64 * This transformation requires that type information is computed. @see irtypeinfo.h.
66 void normalize_irg_class_casts(ir_graph *irg, gen_pointer_type_to_func gppt_fct);
69 /** Optimize casting between class types.
72 * class B extends A { }
73 * class C extends B {}
74 * Performs the following transformations:
75 * C c = (C)(B)(A)(B)new C() --> C c = (C)(B)newC() --> C c = new C()
76 * (Optimizing downcasts as A a = (A)(B)(new A()) --> A a = new A() can
77 * be suppressed by setting flag opt_suppress_downcast_optimization.
78 * Downcasting A to B might cause an exception. It is not clear
79 * whether this is modeled by the Firm Cast node, as it has no exception
81 * If there is inh_m() that overwrites m() in B:
82 * ((A) new B()).m() --> (new B()).inh_m()
83 * Phi((A)x, (A)y) --> (A) Phi (x, y) if (A) is an upcast.
85 * Computes type information if not available. @see irtypeinfo.h.
86 * Typeinformation is valid after optimization.
87 * Invalidates trout information.
89 void optimize_class_casts(void);
91 #endif /* _TROPT_H_ */