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
31 #include "firm_common_t.h"
32 #include "firm_config.h"
37 #include "pseudo_irg.h"
39 /** A path in a compound graph. */
40 struct compound_graph_path {
41 firm_kind kind; /**< The dynamic type tag for compound graph path. */
42 ir_type *tp; /**< The type this path belongs to. */
43 int len; /**< The length of the path. */
45 int index; /**< Array index. To compute position of array elements */
46 ir_entity *node; /**< The accessed entity. */
47 } list[1]; /**< List of entity/index tuple of length len to express the
51 /** The attributes for atomic entities. */
52 typedef struct atomic_ent_attr {
53 ir_node *value; /**< value if entity is not of variability uninitialized.
54 Only for atomic entities. */
57 /** The attributes for compound entities. */
58 typedef struct compound_ent_attr {
59 ir_node **values; /**< constant values of compound entities. Only available if
60 variability not uninitialized. Must be set for variability constant. */
61 compound_graph_path **val_paths;
62 /**< paths corresponding to constant values. Only available if
63 variability not uninitialized. Must be set for variability constant. */
66 /** A reserved value for "not yet set". */
67 #define VTABLE_NUM_NOT_SET ((unsigned)(-1))
69 /** The attributes for methods. */
70 typedef struct method_ent_attr {
71 ir_graph *irg; /**< The corresponding irg if known.
72 The ir_graph constructor automatically sets this field. */
73 unsigned irg_add_properties; /**< Additional graph properties can be
74 stored in a entity if no irg is available. */
76 unsigned vtable_number; /**< For a dynamically called method, the number assigned
77 in the virtual function table. */
79 ptr_access_kind *param_access; /**< the parameter access */
80 float *param_weight; /**< The weight of method's parameters. Parameters
81 with a high weight are good for procedure cloning. */
82 ir_img_section section; /**< The code section where this method should be placed */
87 * An abstract data type to represent program entities.
92 firm_kind kind; /**< The dynamic type tag for entity. */
93 ident *name; /**< The name of this entity. */
94 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
95 name. If the field is read before written a default
96 mangling is applies. The name of the owner is prepended
97 to the name of the entity, separated by a underscore.
98 E.g., for a class `A' with field `a' this
99 is the ident for `A_a'. */
100 ir_type *type; /**< The type of this entity, e.g., a method type, a
101 basic type of the language or a class itself. */
102 ir_type *owner; /**< The compound type (e.g. class type) this entity belongs to. */
103 ir_allocation allocation:3; /**< Distinguishes static and dynamically allocated
104 entities and some further cases. */
105 ir_visibility visibility:3; /**< Specifies visibility to external program fragments. */
106 ir_variability variability:3; /**< Specifies variability of entities content. */
107 ir_volatility volatility:2; /**< Specifies volatility of entities content. */
108 ir_stickyness stickyness:2; /**< Specifies whether this entity is sticky. */
109 ir_peculiarity peculiarity:3; /**< The peculiarity of this entity. */
110 ir_address_taken_state address_taken:3; /**< A flag that can be set to mark address taken entities. */
111 unsigned final:1; /**< If set, this entity cannot be overridden. */
112 unsigned compiler_gen:1; /**< If set, this entity was compiler generated. */
113 int offset; /**< Offset in bytes for this entity. Fixed when layout
114 of owner is determined. */
115 unsigned char offset_bit_remainder;
116 /**< If the entity is a bit field, this is the offset of
117 the start of the bit field within the byte specified
119 unsigned long visit; /**< visited counter for walks of the type information. */
120 struct dbg_info *dbi; /**< A pointer to information for debug support. */
121 void *link; /**< To store some intermediate information. */
122 ir_type *repr_class; /**< If this entity represents a class info, the associated class. */
124 /* ------------- fields for entities owned by a class type ---------------*/
126 ir_entity **overwrites; /**< A list of entities this entity overwrites. */
127 ir_entity **overwrittenby; /**< A list of entities that overwrite this entity. */
129 /* ------------- fields for atomic entities --------------- */
130 ir_node *value; /**< value if entity is not of variability uninitialized.
131 Only for atomic entities. */
133 /* ------------- fields for compound entities -------------- */
134 compound_ent_attr cmpd_attr;
135 /* ------------- fields for method entities ---------------- */
136 method_ent_attr mtd_attr;
137 } attr; /**< type specific attributes */
139 /* ------------- fields for analyses ---------------*/
142 long nr; /**< A unique node number for each node to make output readable. */
143 # endif /* DEBUG_libfirm */
146 /** Initialize the entity module. */
147 void firm_init_entity(void);
150 /* ----------------------- inline functions ------------------------ */
152 _is_entity(const void *thing) {
153 return get_kind(thing) == k_entity;
156 static INLINE const char *
157 _get_entity_name(const ir_entity *ent) {
158 assert(ent && ent->kind == k_entity);
159 return get_id_str(get_entity_ident(ent));
162 static INLINE ident *
163 _get_entity_ident(const ir_entity *ent) {
164 assert(ent && ent->kind == k_entity);
169 _set_entity_ident(ir_entity *ent, ident *id) {
170 assert(ent && ent->kind == k_entity);
174 static INLINE ir_type *
175 _get_entity_owner(ir_entity *ent) {
176 assert(ent && ent->kind == k_entity);
177 return ent->owner = skip_tid(ent->owner);
180 static INLINE ident *
181 _get_entity_ld_ident(ir_entity *ent)
183 assert(ent && ent->kind == k_entity);
184 if (ent->ld_name == NULL)
185 ent->ld_name = mangle_entity(ent);
190 _set_entity_ld_ident(ir_entity *ent, ident *ld_ident) {
191 assert(ent && ent->kind == k_entity);
192 ent->ld_name = ld_ident;
195 static INLINE const char *
196 _get_entity_ld_name(ir_entity *ent) {
197 assert(ent && ent->kind == k_entity);
198 return get_id_str(get_entity_ld_ident(ent));
201 static INLINE ir_type *
202 _get_entity_type(ir_entity *ent) {
203 assert(ent && ent->kind == k_entity);
204 return ent->type = skip_tid(ent->type);
208 _set_entity_type(ir_entity *ent, ir_type *type) {
209 assert(ent && ent->kind == k_entity);
213 static INLINE ir_allocation
214 _get_entity_allocation(const ir_entity *ent) {
215 assert(ent && ent->kind == k_entity);
216 return ent->allocation;
220 _set_entity_allocation(ir_entity *ent, ir_allocation al) {
221 assert(ent && ent->kind == k_entity);
222 ent->allocation = al;
225 static INLINE ir_visibility
226 _get_entity_visibility(const ir_entity *ent) {
227 assert(ent && ent->kind == k_entity);
228 return ent->visibility;
231 static INLINE ir_variability
232 _get_entity_variability(const ir_entity *ent) {
233 assert(ent && ent->kind == k_entity);
234 return ent->variability;
237 static INLINE ir_volatility
238 _get_entity_volatility(const ir_entity *ent) {
239 assert(ent && ent->kind == k_entity);
240 return ent->volatility;
244 _set_entity_volatility(ir_entity *ent, ir_volatility vol) {
245 assert(ent && ent->kind == k_entity);
246 ent->volatility = vol;
249 static INLINE ir_peculiarity
250 _get_entity_peculiarity(const ir_entity *ent) {
251 assert(ent && ent->kind == k_entity);
252 return ent->peculiarity;
256 * @todo Why peculiarity only for methods?
257 * Good question. Originally, there were only description and
258 * existent. The thought was, what sense does it make to
259 * describe a field? With inherited the situation changed. So
260 * I removed the assertion. GL, 28.2.05
263 _set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec) {
264 assert(ent && ent->kind == k_entity);
265 /* @@@ why peculiarity only for methods? */
266 //assert(is_Method_type(ent->type));
268 ent->peculiarity = pec;
271 static INLINE ir_stickyness
272 _get_entity_stickyness(const ir_entity *ent) {
273 assert(ent && ent->kind == k_entity);
274 return ent->stickyness;
278 _set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness) {
279 assert(ent && ent->kind == k_entity);
280 ent->stickyness = stickyness;
284 _is_entity_final(const ir_entity *ent) {
285 assert(ent && ent->kind == k_entity);
286 return (int)ent->final;
290 _set_entity_final(ir_entity *ent, int final) {
291 assert(ent && ent->kind == k_entity);
292 ent->final = final ? 1 : 0;
296 _is_entity_compiler_generated(const ir_entity *ent) {
297 assert(ent && ent->kind == k_entity);
298 return ent->compiler_gen;
302 _set_entity_compiler_generated(ir_entity *ent, int flag) {
303 assert(ent && ent->kind == k_entity);
304 ent->compiler_gen = flag ? 1 : 0;
307 static INLINE ir_address_taken_state
308 _get_entity_address_taken(const ir_entity *ent) {
309 assert(ent && ent->kind == k_entity);
310 return ent->address_taken;
314 _set_entity_address_taken(ir_entity *ent, ir_address_taken_state state) {
315 assert(ent && ent->kind == k_entity);
316 assert(ir_address_not_taken <= state && state <= ir_address_taken);
317 ent->address_taken = state;
321 _get_entity_offset(const ir_entity *ent) {
322 assert(ent && ent->kind == k_entity);
327 _set_entity_offset(ir_entity *ent, int offset) {
328 assert(ent && ent->kind == k_entity);
329 ent->offset = offset;
332 static INLINE unsigned char
333 _get_entity_offset_bits_remainder(const ir_entity *ent) {
334 assert(ent && ent->kind == k_entity);
335 return ent->offset_bit_remainder;
339 _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset) {
340 assert(ent && ent->kind == k_entity);
341 ent->offset_bit_remainder = offset;
345 _get_entity_link(const ir_entity *ent) {
346 assert(ent && ent->kind == k_entity);
351 _set_entity_link(ir_entity *ent, void *l) {
352 assert(ent && ent->kind == k_entity);
356 static INLINE ir_graph *
357 _get_entity_irg(const ir_entity *ent) {
358 assert(ent && ent->kind == k_entity);
359 assert(ent == unknown_entity || is_Method_type(ent->type));
360 if (!get_visit_pseudo_irgs() && ent->attr.mtd_attr.irg
361 && is_pseudo_ir_graph(ent->attr.mtd_attr.irg))
363 return ent->attr.mtd_attr.irg;
366 static INLINE unsigned long
367 _get_entity_visited(ir_entity *ent) {
368 assert(ent && ent->kind == k_entity);
373 _set_entity_visited(ir_entity *ent, unsigned long num) {
374 assert(ent && ent->kind == k_entity);
379 _mark_entity_visited(ir_entity *ent) {
380 assert(ent && ent->kind == k_entity);
381 ent->visit = firm_type_visited;
385 _entity_visited(ir_entity *ent) {
386 return _get_entity_visited(ent) >= firm_type_visited;
390 _entity_not_visited(ir_entity *ent) {
391 return _get_entity_visited(ent) < firm_type_visited;
394 static INLINE ir_type *
395 _get_entity_repr_class(const ir_entity *ent) {
396 assert(ent && ent->kind == k_entity);
397 return ent->repr_class;
400 #define is_entity(thing) _is_entity(thing)
401 #define get_entity_name(ent) _get_entity_name(ent)
402 #define get_entity_ident(ent) _get_entity_ident(ent)
403 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
404 #define get_entity_owner(ent) _get_entity_owner(ent)
405 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
406 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
407 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
408 #define get_entity_type(ent) _get_entity_type(ent)
409 #define set_entity_type(ent, type) _set_entity_type(ent, type)
410 #define get_entity_allocation(ent) _get_entity_allocation(ent)
411 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
412 #define get_entity_visibility(ent) _get_entity_visibility(ent)
413 #define get_entity_variability(ent) _get_entity_variability(ent)
414 #define get_entity_volatility(ent) _get_entity_volatility(ent)
415 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
416 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
417 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
418 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
419 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
420 #define is_entity_final(ent) _is_entity_final(ent)
421 #define set_entity_final(ent, final) _set_entity_final(ent, final)
422 #define is_entity_compiler_generated(ent) _is_entity_compiler_generated(ent)
423 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
424 #define get_entity_address_taken(ent) _get_entity_address_taken(ent)
425 #define set_entity_address_taken(ent, flag) _set_entity_address_taken(ent, flag)
426 #define get_entity_offset(ent) _get_entity_offset(ent)
427 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
428 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
429 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
430 #define get_entity_link(ent) _get_entity_link(ent)
431 #define set_entity_link(ent, l) _set_entity_link(ent, l)
432 #define get_entity_irg(ent) _get_entity_irg(ent)
433 #define get_entity_visited(ent) _get_entity_visited(ent)
434 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
435 #define mark_entity_visited(ent) _mark_entity_visited(ent)
436 #define entity_visited(ent) _entity_visited(ent)
437 #define entity_not_visited(ent) _entity_not_visited(ent)
438 #define get_entity_repr_class(ent) _get_entity_repr_class(ent)
441 #endif /* FIRM_TR_ENTITY_T_H */