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
22 * @brief Representation of all program known entities -- private header.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
26 #ifndef FIRM_TR_ENTITY_T_H
27 #define FIRM_TR_ENTITY_T_H
29 #include "firm_common_t.h"
30 #include "firm_config.h"
36 #include "pseudo_irg.h"
38 /** A path in a compound graph. */
39 struct compound_graph_path {
40 firm_kind kind; /**< The dynamic type tag for compound graph path. */
41 ir_type *tp; /**< The type this path belongs to. */
42 int len; /**< The length of the path. */
44 int index; /**< Array index. To compute position of array elements */
45 ir_entity *node; /**< The accessed entity. */
46 } list[1]; /**< List of entity/index tuple of length len to express the
50 /** The attributes for atomic entities. */
51 typedef struct atomic_ent_attr {
52 ir_node *value; /**< value if entity is not of variability uninitialized.
53 Only for atomic entities. */
56 /** The attributes for compound entities. */
57 typedef struct compound_ent_attr {
58 ir_node **values; /**< constant values of compound entities. Only available if
59 variability not uninitialized. Must be set for variability constant. */
60 compound_graph_path **val_paths;
61 /**< paths corresponding to constant values. Only available if
62 variability not uninitialized. Must be set for variability constant. */
65 /** A reserved value for "not yet set". */
66 #define VTABLE_NUM_NOT_SET ((unsigned)(-1))
68 /** The attributes for methods. */
69 typedef struct method_ent_attr {
70 ir_graph *irg; /**< The corresponding irg if known.
71 The ir_graph constructor automatically sets this field. */
72 unsigned irg_add_properties; /**< Additional graph properties can be
73 stored in a entity if no irg is available. */
75 unsigned vtable_number; /**< For a dynamically called method, the number assigned
76 in the virtual function table. */
78 ptr_access_kind *param_access; /**< the parameter access */
79 float *param_weight; /**< The weight of method's parameters. Parameters
80 with a high weight are good for procedure cloning. */
81 ir_img_section section; /**< The code section where this method should be placed */
86 * An abstract data type to represent program entities.
91 firm_kind kind; /**< The dynamic type tag for entity. */
92 ident *name; /**< The name of this entity. */
93 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
94 name. If the field is read before written a default
95 mangling is applies. The name of the owner is prepended
96 to the name of the entity, separated by a underscore.
97 E.g., for a class `A' with field `a' this
98 is the ident for `A_a'. */
99 ir_type *type; /**< The type of this entity, e.g., a method type, a
100 basic type of the language or a class itself. */
101 ir_type *owner; /**< The compound type (e.g. class type) this entity belongs to. */
102 ir_allocation allocation:3; /**< Distinguishes static and dynamically allocated
103 entities and some further cases. */
104 ir_visibility visibility:3; /**< Specifies visibility to external program fragments. */
105 ir_variability variability:3; /**< Specifies variability of entities content. */
106 ir_volatility volatility:2; /**< Specifies volatility of entities content. */
107 ir_stickyness stickyness:2; /**< Specifies whether this entity is sticky. */
108 ir_peculiarity peculiarity:3; /**< The peculiarity of this entity. */
109 ir_address_taken_state address_taken:3; /**< A flag that can be set to mark address taken entities. */
110 unsigned final:1; /**< If set, this entity cannot be overridden. */
111 unsigned compiler_gen:1; /**< If set, this entity was compiler generated. */
112 int offset; /**< Offset in bytes for this entity. Fixed when layout
113 of owner is determined. */
114 unsigned char offset_bit_remainder;
115 /**< If the entity is a bit field, this is the offset of
116 the start of the bit field within the byte specified
118 unsigned long visit; /**< visited counter for walks of the type information. */
119 struct dbg_info *dbi; /**< A pointer to information for debug support. */
120 void *link; /**< To store some intermediate information. */
121 ir_type *repr_class; /**< If this entity represents a class info, the associated class. */
123 /* ------------- fields for entities owned by a class type ---------------*/
125 ir_entity **overwrites; /**< A list of entities this entity overwrites. */
126 ir_entity **overwrittenby; /**< A list of entities that overwrite this entity. */
128 /* ------------- fields for atomic entities --------------- */
129 ir_node *value; /**< value if entity is not of variability uninitialized.
130 Only for atomic entities. */
132 /* ------------- fields for compound entities -------------- */
133 compound_ent_attr cmpd_attr;
134 /* ------------- fields for method entities ---------------- */
135 method_ent_attr mtd_attr;
136 } attr; /**< type specific attributes */
138 /* ------------- fields for analyses ---------------*/
141 long nr; /**< A unique node number for each node to make output readable. */
142 # endif /* DEBUG_libfirm */
145 /** Initialize the entity module. */
146 void firm_init_entity(void);
149 /* ----------------------- inline functions ------------------------ */
151 _is_entity(const void *thing) {
152 return get_kind(thing) == k_entity;
155 static INLINE const char *
156 _get_entity_name(const ir_entity *ent) {
157 assert(ent && ent->kind == k_entity);
158 return get_id_str(get_entity_ident(ent));
161 static INLINE ident *
162 _get_entity_ident(const ir_entity *ent) {
163 assert(ent && ent->kind == k_entity);
168 _set_entity_ident(ir_entity *ent, ident *id) {
169 assert(ent && ent->kind == k_entity);
173 static INLINE ir_type *
174 _get_entity_owner(ir_entity *ent) {
175 assert(ent && ent->kind == k_entity);
176 return ent->owner = skip_tid(ent->owner);
179 static INLINE ident *
180 _get_entity_ld_ident(ir_entity *ent)
182 assert(ent && ent->kind == k_entity);
183 if (ent->ld_name == NULL)
184 ent->ld_name = mangle_entity(ent);
189 _set_entity_ld_ident(ir_entity *ent, ident *ld_ident) {
190 assert(ent && ent->kind == k_entity);
191 ent->ld_name = ld_ident;
194 static INLINE const char *
195 _get_entity_ld_name(ir_entity *ent) {
196 assert(ent && ent->kind == k_entity);
197 return get_id_str(get_entity_ld_ident(ent));
200 static INLINE ir_type *
201 _get_entity_type(ir_entity *ent) {
202 assert(ent && ent->kind == k_entity);
203 return ent->type = skip_tid(ent->type);
207 _set_entity_type(ir_entity *ent, ir_type *type) {
208 assert(ent && ent->kind == k_entity);
212 static INLINE ir_allocation
213 _get_entity_allocation(const ir_entity *ent) {
214 assert(ent && ent->kind == k_entity);
215 return ent->allocation;
219 _set_entity_allocation(ir_entity *ent, ir_allocation al) {
220 assert(ent && ent->kind == k_entity);
221 ent->allocation = al;
224 static INLINE ir_visibility
225 _get_entity_visibility(const ir_entity *ent) {
226 assert(ent && ent->kind == k_entity);
227 return ent->visibility;
230 static INLINE ir_variability
231 _get_entity_variability(const ir_entity *ent) {
232 assert(ent && ent->kind == k_entity);
233 return ent->variability;
236 static INLINE ir_volatility
237 _get_entity_volatility(const ir_entity *ent) {
238 assert(ent && ent->kind == k_entity);
239 return ent->volatility;
243 _set_entity_volatility(ir_entity *ent, ir_volatility vol) {
244 assert(ent && ent->kind == k_entity);
245 ent->volatility = vol;
248 static INLINE ir_peculiarity
249 _get_entity_peculiarity(const ir_entity *ent) {
250 assert(ent && ent->kind == k_entity);
251 return ent->peculiarity;
255 * @todo Why peculiarity only for methods?
256 * Good question. Originally, there were only description and
257 * existent. The thought was, what sense does it make to
258 * describe a field? With inherited the situation changed. So
259 * I removed the assertion. GL, 28.2.05
262 _set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec) {
263 assert(ent && ent->kind == k_entity);
264 /* @@@ why peculiarity only for methods? */
265 //assert(is_Method_type(ent->type));
267 ent->peculiarity = pec;
270 static INLINE ir_stickyness
271 _get_entity_stickyness(const ir_entity *ent) {
272 assert(ent && ent->kind == k_entity);
273 return ent->stickyness;
277 _set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness) {
278 assert(ent && ent->kind == k_entity);
279 ent->stickyness = stickyness;
283 _is_entity_final(const ir_entity *ent) {
284 assert(ent && ent->kind == k_entity);
285 return (int)ent->final;
289 _set_entity_final(ir_entity *ent, int final) {
290 assert(ent && ent->kind == k_entity);
291 ent->final = final ? 1 : 0;
295 _is_entity_compiler_generated(const ir_entity *ent) {
296 assert(ent && ent->kind == k_entity);
297 return ent->compiler_gen;
301 _set_entity_compiler_generated(ir_entity *ent, int flag) {
302 assert(ent && ent->kind == k_entity);
303 ent->compiler_gen = flag ? 1 : 0;
306 static INLINE ir_address_taken_state
307 _get_entity_address_taken(const ir_entity *ent) {
308 assert(ent && ent->kind == k_entity);
309 return ent->address_taken;
313 _set_entity_address_taken(ir_entity *ent, ir_address_taken_state state) {
314 assert(ent && ent->kind == k_entity);
315 assert(ir_address_not_taken <= state && state <= ir_address_taken);
316 ent->address_taken = state;
320 _get_entity_offset(const ir_entity *ent) {
321 assert(ent && ent->kind == k_entity);
326 _set_entity_offset(ir_entity *ent, int offset) {
327 assert(ent && ent->kind == k_entity);
328 ent->offset = offset;
331 static INLINE unsigned char
332 _get_entity_offset_bits_remainder(const ir_entity *ent) {
333 assert(ent && ent->kind == k_entity);
334 return ent->offset_bit_remainder;
338 _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset) {
339 assert(ent && ent->kind == k_entity);
340 ent->offset_bit_remainder = offset;
344 _get_entity_link(const ir_entity *ent) {
345 assert(ent && ent->kind == k_entity);
350 _set_entity_link(ir_entity *ent, void *l) {
351 assert(ent && ent->kind == k_entity);
355 static INLINE ir_graph *
356 _get_entity_irg(const ir_entity *ent) {
357 assert(ent && ent->kind == k_entity);
358 assert(ent == unknown_entity || is_Method_type(ent->type));
359 if (!get_visit_pseudo_irgs() && ent->attr.mtd_attr.irg
360 && is_pseudo_ir_graph(ent->attr.mtd_attr.irg))
362 return ent->attr.mtd_attr.irg;
365 static INLINE unsigned long
366 _get_entity_visited(ir_entity *ent) {
367 assert(ent && ent->kind == k_entity);
372 _set_entity_visited(ir_entity *ent, unsigned long num) {
373 assert(ent && ent->kind == k_entity);
378 _mark_entity_visited(ir_entity *ent) {
379 assert(ent && ent->kind == k_entity);
380 ent->visit = firm_type_visited;
384 _entity_visited(ir_entity *ent) {
385 return _get_entity_visited(ent) >= firm_type_visited;
389 _entity_not_visited(ir_entity *ent) {
390 return _get_entity_visited(ent) < firm_type_visited;
393 static INLINE ir_type *
394 _get_entity_repr_class(const ir_entity *ent) {
395 assert(ent && ent->kind == k_entity);
396 return ent->repr_class;
399 #define is_entity(thing) _is_entity(thing)
400 #define get_entity_name(ent) _get_entity_name(ent)
401 #define get_entity_ident(ent) _get_entity_ident(ent)
402 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
403 #define get_entity_owner(ent) _get_entity_owner(ent)
404 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
405 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
406 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
407 #define get_entity_type(ent) _get_entity_type(ent)
408 #define set_entity_type(ent, type) _set_entity_type(ent, type)
409 #define get_entity_allocation(ent) _get_entity_allocation(ent)
410 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
411 #define get_entity_visibility(ent) _get_entity_visibility(ent)
412 #define get_entity_variability(ent) _get_entity_variability(ent)
413 #define get_entity_volatility(ent) _get_entity_volatility(ent)
414 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
415 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
416 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
417 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
418 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
419 #define is_entity_final(ent) _is_entity_final(ent)
420 #define set_entity_final(ent, final) _set_entity_final(ent, final)
421 #define is_entity_compiler_generated(ent) _is_entity_compiler_generated(ent)
422 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
423 #define get_entity_address_taken(ent) _get_entity_address_taken(ent)
424 #define set_entity_address_taken(ent, flag) _set_entity_address_taken(ent, flag)
425 #define get_entity_offset(ent) _get_entity_offset(ent)
426 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
427 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
428 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
429 #define get_entity_link(ent) _get_entity_link(ent)
430 #define set_entity_link(ent, l) _set_entity_link(ent, l)
431 #define get_entity_irg(ent) _get_entity_irg(ent)
432 #define get_entity_visited(ent) _get_entity_visited(ent)
433 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
434 #define mark_entity_visited(ent) _mark_entity_visited(ent)
435 #define entity_visited(ent) _entity_visited(ent)
436 #define entity_not_visited(ent) _entity_not_visited(ent)
437 #define get_entity_repr_class(ent) _get_entity_repr_class(ent)
440 #endif /* FIRM_TR_ENTITY_T_H */