Loads do not remove any nodes from the exec after sets. Also fix a 'node leak'.
[libfirm] / ir / tr / tr_inheritance.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file tr_inheritance.h
22  * @brief   Utility routines for inheritance representation
23  * @author  Goetz Lindenmaier
24  * @version $Id$
25  * @summary
26  *
27  * This file supplies a set of utility routines for the inheritance
28  * representation.
29  *
30  * Inheritance is represented in Firm by two relations: sub/supertype
31  * between class types, overwrites/ovwerwrittenby between entities.
32  *
33  * - Classify pairs of types/entities in the inheritance relations.
34  * - Resolve implicit inheritance.
35  * - Compute the transitive closure of the subclass/superclass and
36  *   overwrites/overwrittenby relation.
37  *
38  * @see  type.h entity.h
39  */
40 #ifndef FIRM_TR_INHERITANCE_H
41 #define FIRM_TR_INHERITANCE_H
42
43 #include "firm_types.h"
44 #include "type.h"
45 #include "ident.h"
46
47 /* ----------------------------------------------------------------------- */
48 /* Classify pairs of types/entities in the inheritance relations.          */
49 /* ----------------------------------------------------------------------- */
50
51 /** Returns true if low is subclass of high.
52  *
53  *  Low is a subclass of high if low == high or if low is a subclass of
54  *  a subclass of high.  I.e, we search in all subtypes of high for low.
55  *  @@@ this can be implemented more efficient if we know the set of all
56  *  subclasses of high.  */
57 int is_SubClass_of(ir_type *low, ir_type *high);
58
59 /** Subclass check for pointers to classes.
60  *
61  *  Dereferences at both types the same amount of pointer types (as
62  *  many as possible).  If the remaining types are both class types
63  *  and subclasses, returns true, else false.  Can also be called with
64  *  two class types.  */
65 int is_SubClass_ptr_of(ir_type *low, ir_type *high);
66
67 /** Returns true if high is superclass of low.
68  *
69  *  Low is a subclass of high if low == high or if low is a subclass of
70  *  a subclass of high.  I.e, we search in all subtypes of high for low.
71  *  @@@ this can be implemented more efficient if we know the set of all
72  *  subclasses of high.  */
73 #define is_SuperClass_of(high, low) is_SubClass_of(low, high)
74
75 /** Superclass check for pointers to classes.
76  *
77  *  Dereferences at both types the same amount of pointer types (as
78  *  many as possible).  If the remaining types are both class types
79  *  and superclasses, returns true, else false.  Can also be called with
80  *  two class types.  */
81 #define is_SuperClass_ptr_of(low, high) is_SubClass_ptr_of(high, low)
82
83 /** Returns true if high is (transitive) overwritten by low.
84  *
85  *  Returns false if high == low. */
86 int is_overwritten_by(ir_entity *high, ir_entity *low);
87
88 /** Resolve polymorphism in the inheritance relation.
89  *
90  *  Returns the dynamically referenced entity if the static entity and the
91  *  dynamic type are given.
92  *  Searches downwards in overwritten tree. */
93 ir_entity *resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity* static_ent);
94
95 /* ----------------------------------------------------------------------- */
96 /* Resolve implicit inheritance.                                           */
97 /* ----------------------------------------------------------------------- */
98
99 /** Default name mangling for inherited entities.
100  *
101  *  Returns an ident that consists of the name of type followed by an
102  *  underscore and the name (not ld_name) of the entity. */
103 ident *default_mangle_inherited_name(ir_entity *ent, ir_type *clss);
104
105 /** Type of argument functions for inheritance resolver.
106  *
107  * @param ent     The entity in the super type that will be overwritten
108  *                by the newly generated entity, for which this name is
109  *                used.
110  * @param clss    The class type in which the new entity will be placed.
111  */
112 typedef ident *mangle_inherited_name_func(ir_entity *ent, ir_type *clss);
113
114 /** Resolve implicit inheritance.
115  *
116  *  Resolves the implicit inheritance supplied by firm.  Firm defines,
117  *  that each entity that is not overwritten in a subclass is
118  *  inherited to this subclass without change implicitly.  This
119  *  function generates entities that explicitly represent this
120  *  inheritance.  It generates for each entity overwriting entities in
121  *  all subclasses of the owner of the entity, if the entity is not
122  *  overwritten in that subclass.
123  *
124  *  The name of the new entity is generated with the function passed.
125  *  If the function is NULL, the default_mangle_inherited_name() is
126  *  used.
127  *
128  *  This function was moved here from firmlower 3/2005.
129  */
130 void resolve_inheritance(mangle_inherited_name_func *mfunc);
131
132
133 /* ----------------------------------------------------------------------- */
134 /* The transitive closure of the subclass/superclass and                   */
135 /* overwrites/overwrittenby relation.                                      */
136 /*                                                                         */
137 /* A walk over the ir (O(#types+#entities)) computes the transitive        */
138 /* closure.  Adding a new type/entity or changing the basic relations in   */
139 /* some other way invalidates the transitive closure, i.e., it is not      */
140 /* updated by the basic functions.                                         */
141 /*                                                                         */
142 /* The transitive edges are held in a set, not in an array as the          */
143 /* underlying relation.                                                    */
144 /*                                                                         */
145 /* Do the sets contain the node itself?  I assume NOT!                     */
146 /* ----------------------------------------------------------------------- */
147
148 /** The state of the transitive closure.
149  *
150  *  @todo: we could manage the state for each relation separately.  Invalidating
151  *  the entity relations does not mean invalidating the class relation. */
152 typedef enum {
153         inh_transitive_closure_none,       /**<  Closure is not computed, can not be accessed. */
154         inh_transitive_closure_valid,      /**<  Closure computed and valid. */
155         inh_transitive_closure_invalid,    /**<  Closure invalid, but can be accessed. */
156         inh_transitive_closure_max         /**<  Invalid value. */
157 } inh_transitive_closure_state;
158
159 void                         set_irp_inh_transitive_closure_state(inh_transitive_closure_state s);
160 void                         invalidate_irp_inh_transitive_closure_state(void);
161 inh_transitive_closure_state get_irp_inh_transitive_closure_state(void);
162
163
164 /** Compute transitive closure of the subclass/superclass and
165  * overwrites/overwrittenby relation.
166  *
167  * This function walks over the ir (O(#types+#entities)) to compute the
168  * transitive closure.    */
169 void compute_inh_transitive_closure(void);
170
171 /** Free memory occupied by the transitive closure information. */
172 void free_inh_transitive_closure(void);
173
174
175 /* - subtype ------------------------------------------------------------- */
176
177 /** Iterate over all transitive subtypes. */
178 ir_type *get_class_trans_subtype_first(ir_type *tp);
179 ir_type *get_class_trans_subtype_next (ir_type *tp);
180 int   is_class_trans_subtype (ir_type *tp, ir_type *subtp);
181
182 /* - supertype ----------------------------------------------------------- */
183
184 /** Iterate over all transitive supertypes. */
185 ir_type *get_class_trans_supertype_first(ir_type *tp);
186 ir_type *get_class_trans_supertype_next (ir_type *tp);
187
188 /* - overwrittenby ------------------------------------------------------- */
189
190 /** Iterate over all entities that transitive overwrite this entities. */
191 ir_entity *get_entity_trans_overwrittenby_first(ir_entity *ent);
192 ir_entity *get_entity_trans_overwrittenby_next (ir_entity *ent);
193
194 /* - overwrites ---------------------------------------------------------- */
195
196 /** Iterate over all transitive overwritten entities. */
197 ir_entity *get_entity_trans_overwrites_first(ir_entity *ent);
198 ir_entity *get_entity_trans_overwrites_next (ir_entity *ent);
199
200
201 /* ----------------------------------------------------------------------- */
202 /** The state of Cast operations that cast class types or pointers to class
203  *  types.
204  *
205  * The state expresses, how far Cast operations conform with the class
206  * hierarchy.
207  *
208  *   class A {}
209  *   class B1 extends A {}
210  *   class B2 extends A {}
211  *   class C  extends B1 {}
212  * normalized:  Cast operations conform with the inheritance relation.
213  *   I.e., the type of the operand of a Cast is either a super= or a sub-
214  *   type of the type casted to. Example: (A)((B2) (new C())).
215  * transitive:  Cast operations conform with the transitive inheritance
216  *   relation. Example: (A)(new C()).
217  * any:  Cast operations do not conform with the transitive inheritance
218  *   relation.  Example: (B2)(new B1())
219  *
220  *  @see: tropt.h
221  */
222 /* ----------------------------------------------------------------------- */
223
224 /** Flags for class cast state.
225  *
226  * The state in irp is always smaller or equal to the state of any
227  * irg.
228  *
229  * We rely on the ordering of the enum. */
230 typedef enum {
231         ir_class_casts_any        = 0, /**< There are class casts that do not cast in conformance with
232                                             the class hierarchy.  @@@ So far this does not happen in Firm. */
233         ir_class_casts_transitive = 1, /**< Class casts conform to transitive inheritance edges. Default. */
234         ir_class_casts_normalized = 2, /**< Class casts conform to inheritance edges. */
235         ir_class_casts_state_max
236 } ir_class_cast_state;
237 char *get_class_cast_state_string(ir_class_cast_state s);
238
239 void                set_irg_class_cast_state(ir_graph *irg, ir_class_cast_state s);
240 ir_class_cast_state get_irg_class_cast_state(ir_graph *irg);
241 void                set_irp_class_cast_state(ir_class_cast_state s);
242 ir_class_cast_state get_irp_class_cast_state(void);
243
244 /** Verify the class cast state of an irg.
245  *
246  *  Asserts if state is to high, outputs warning if state is to low
247  *  and firm verbosity is set.
248  */
249 void verify_irg_class_cast_state(ir_graph *irg);
250 #endif  /* FIRM_TR_INHERITANCE_H */