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 unsigned backend_marked:1; /**< If set, this entity was marked by the backend for emission. */
114 int offset; /**< Offset in bytes for this entity. Fixed when layout
115 of owner is determined. */
116 unsigned char offset_bit_remainder;
117 /**< If the entity is a bit field, this is the offset of
118 the start of the bit field within the byte specified
120 unsigned long visit; /**< visited counter for walks of the type information. */
121 struct dbg_info *dbi; /**< A pointer to information for debug support. */
122 void *link; /**< To store some intermediate information. */
123 ir_type *repr_class; /**< If this entity represents a class info, the associated class. */
125 /* ------------- fields for entities owned by a class type ---------------*/
127 ir_entity **overwrites; /**< A list of entities this entity overwrites. */
128 ir_entity **overwrittenby; /**< A list of entities that overwrite this entity. */
130 /* ------------- fields for atomic entities --------------- */
131 ir_node *value; /**< value if entity is not of variability uninitialized.
132 Only for atomic entities. */
134 /* ------------- fields for compound entities -------------- */
135 compound_ent_attr cmpd_attr;
136 /* ------------- fields for method entities ---------------- */
137 method_ent_attr mtd_attr;
138 } attr; /**< type specific attributes */
140 /* ------------- fields for analyses ---------------*/
143 long nr; /**< A unique node number for each node to make output readable. */
144 # endif /* DEBUG_libfirm */
147 /** Initialize the entity module. */
148 void firm_init_entity(void);
151 /* ----------------------- inline functions ------------------------ */
153 _is_entity(const void *thing) {
154 return get_kind(thing) == k_entity;
157 static INLINE const char *
158 _get_entity_name(const ir_entity *ent) {
159 assert(ent && ent->kind == k_entity);
160 return get_id_str(get_entity_ident(ent));
163 static INLINE ident *
164 _get_entity_ident(const ir_entity *ent) {
165 assert(ent && ent->kind == k_entity);
170 _set_entity_ident(ir_entity *ent, ident *id) {
171 assert(ent && ent->kind == k_entity);
175 static INLINE ir_type *
176 _get_entity_owner(ir_entity *ent) {
177 assert(ent && ent->kind == k_entity);
178 return ent->owner = skip_tid(ent->owner);
181 static INLINE ident *
182 _get_entity_ld_ident(ir_entity *ent)
184 assert(ent && ent->kind == k_entity);
185 if (ent->ld_name == NULL)
186 ent->ld_name = mangle_entity(ent);
191 _set_entity_ld_ident(ir_entity *ent, ident *ld_ident) {
192 assert(ent && ent->kind == k_entity);
193 ent->ld_name = ld_ident;
196 static INLINE const char *
197 _get_entity_ld_name(ir_entity *ent) {
198 assert(ent && ent->kind == k_entity);
199 return get_id_str(get_entity_ld_ident(ent));
202 static INLINE ir_type *
203 _get_entity_type(ir_entity *ent) {
204 assert(ent && ent->kind == k_entity);
205 return ent->type = skip_tid(ent->type);
209 _set_entity_type(ir_entity *ent, ir_type *type) {
210 assert(ent && ent->kind == k_entity);
214 static INLINE ir_allocation
215 _get_entity_allocation(const ir_entity *ent) {
216 assert(ent && ent->kind == k_entity);
217 return ent->allocation;
221 _set_entity_allocation(ir_entity *ent, ir_allocation al) {
222 assert(ent && ent->kind == k_entity);
223 ent->allocation = al;
226 static INLINE ir_visibility
227 _get_entity_visibility(const ir_entity *ent) {
228 assert(ent && ent->kind == k_entity);
229 return ent->visibility;
232 static INLINE ir_variability
233 _get_entity_variability(const ir_entity *ent) {
234 assert(ent && ent->kind == k_entity);
235 return ent->variability;
238 static INLINE ir_volatility
239 _get_entity_volatility(const ir_entity *ent) {
240 assert(ent && ent->kind == k_entity);
241 return ent->volatility;
245 _set_entity_volatility(ir_entity *ent, ir_volatility vol) {
246 assert(ent && ent->kind == k_entity);
247 ent->volatility = vol;
250 static INLINE ir_peculiarity
251 _get_entity_peculiarity(const ir_entity *ent) {
252 assert(ent && ent->kind == k_entity);
253 return ent->peculiarity;
257 * @todo Why peculiarity only for methods?
258 * Good question. Originally, there were only description and
259 * existent. The thought was, what sense does it make to
260 * describe a field? With inherited the situation changed. So
261 * I removed the assertion. GL, 28.2.05
264 _set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec) {
265 assert(ent && ent->kind == k_entity);
266 /* @@@ why peculiarity only for methods? */
267 //assert(is_Method_type(ent->type));
269 ent->peculiarity = pec;
272 static INLINE ir_stickyness
273 _get_entity_stickyness(const ir_entity *ent) {
274 assert(ent && ent->kind == k_entity);
275 return ent->stickyness;
279 _set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness) {
280 assert(ent && ent->kind == k_entity);
281 ent->stickyness = stickyness;
285 _is_entity_final(const ir_entity *ent) {
286 assert(ent && ent->kind == k_entity);
287 return (int)ent->final;
291 _set_entity_final(ir_entity *ent, int final) {
292 assert(ent && ent->kind == k_entity);
293 ent->final = final ? 1 : 0;
297 _is_entity_compiler_generated(const ir_entity *ent) {
298 assert(ent && ent->kind == k_entity);
299 return ent->compiler_gen;
303 _set_entity_compiler_generated(ir_entity *ent, int flag) {
304 assert(ent && ent->kind == k_entity);
305 ent->compiler_gen = flag ? 1 : 0;
309 _is_entity_backend_marked(const ir_entity *ent) {
310 assert(ent && ent->kind == k_entity);
311 return ent->backend_marked;
315 _set_entity_backend_marked(ir_entity *ent, int flag) {
316 assert(ent && ent->kind == k_entity);
317 ent->backend_marked = flag ? 1 : 0;
320 static INLINE ir_address_taken_state
321 _get_entity_address_taken(const ir_entity *ent) {
322 assert(ent && ent->kind == k_entity);
323 return ent->address_taken;
327 _set_entity_address_taken(ir_entity *ent, ir_address_taken_state state) {
328 assert(ent && ent->kind == k_entity);
329 assert(state == ir_address_not_taken ||
330 state == ir_address_taken_unknown ||
331 state == ir_address_taken);
332 ent->address_taken = state;
336 _get_entity_offset(const ir_entity *ent) {
337 assert(ent && ent->kind == k_entity);
342 _set_entity_offset(ir_entity *ent, int offset) {
343 assert(ent && ent->kind == k_entity);
344 ent->offset = offset;
347 static INLINE unsigned char
348 _get_entity_offset_bits_remainder(const ir_entity *ent) {
349 assert(ent && ent->kind == k_entity);
350 return ent->offset_bit_remainder;
354 _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset) {
355 assert(ent && ent->kind == k_entity);
356 ent->offset_bit_remainder = offset;
360 _get_entity_link(const ir_entity *ent) {
361 assert(ent && ent->kind == k_entity);
366 _set_entity_link(ir_entity *ent, void *l) {
367 assert(ent && ent->kind == k_entity);
371 static INLINE ir_graph *
372 _get_entity_irg(const ir_entity *ent) {
373 assert(ent && ent->kind == k_entity);
374 assert(ent == unknown_entity || is_Method_type(ent->type));
375 if (!get_visit_pseudo_irgs() && ent->attr.mtd_attr.irg
376 && is_pseudo_ir_graph(ent->attr.mtd_attr.irg))
378 return ent->attr.mtd_attr.irg;
381 static INLINE unsigned long
382 _get_entity_visited(ir_entity *ent) {
383 assert(ent && ent->kind == k_entity);
388 _set_entity_visited(ir_entity *ent, unsigned long num) {
389 assert(ent && ent->kind == k_entity);
394 _mark_entity_visited(ir_entity *ent) {
395 assert(ent && ent->kind == k_entity);
396 ent->visit = firm_type_visited;
400 _entity_visited(ir_entity *ent) {
401 return _get_entity_visited(ent) >= firm_type_visited;
405 _entity_not_visited(ir_entity *ent) {
406 return _get_entity_visited(ent) < firm_type_visited;
409 static INLINE ir_type *
410 _get_entity_repr_class(const ir_entity *ent) {
411 assert(ent && ent->kind == k_entity);
412 return ent->repr_class;
415 static INLINE dbg_info *
416 _get_entity_dbg_info(const ir_entity *ent) {
421 _set_entity_dbg_info(ir_entity *ent, dbg_info *db) {
426 #define is_entity(thing) _is_entity(thing)
427 #define get_entity_name(ent) _get_entity_name(ent)
428 #define get_entity_ident(ent) _get_entity_ident(ent)
429 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
430 #define get_entity_owner(ent) _get_entity_owner(ent)
431 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
432 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
433 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
434 #define get_entity_type(ent) _get_entity_type(ent)
435 #define set_entity_type(ent, type) _set_entity_type(ent, type)
436 #define get_entity_allocation(ent) _get_entity_allocation(ent)
437 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
438 #define get_entity_visibility(ent) _get_entity_visibility(ent)
439 #define get_entity_variability(ent) _get_entity_variability(ent)
440 #define get_entity_volatility(ent) _get_entity_volatility(ent)
441 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
442 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
443 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
444 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
445 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
446 #define is_entity_final(ent) _is_entity_final(ent)
447 #define set_entity_final(ent, final) _set_entity_final(ent, final)
448 #define is_entity_compiler_generated(ent) _is_entity_compiler_generated(ent)
449 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
450 #define is_entity_backend_marked(ent) _is_entity_backend_marked(ent)
451 #define set_entity_backend_marked(ent, flag) _set_entity_backend_marked(ent, flag)
452 #define get_entity_address_taken(ent) _get_entity_address_taken(ent)
453 #define set_entity_address_taken(ent, flag) _set_entity_address_taken(ent, flag)
454 #define get_entity_offset(ent) _get_entity_offset(ent)
455 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
456 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
457 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
458 #define get_entity_link(ent) _get_entity_link(ent)
459 #define set_entity_link(ent, l) _set_entity_link(ent, l)
460 #define get_entity_irg(ent) _get_entity_irg(ent)
461 #define get_entity_visited(ent) _get_entity_visited(ent)
462 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
463 #define mark_entity_visited(ent) _mark_entity_visited(ent)
464 #define entity_visited(ent) _entity_visited(ent)
465 #define entity_not_visited(ent) _entity_not_visited(ent)
466 #define get_entity_repr_class(ent) _get_entity_repr_class(ent)
467 #define get_entity_dbg_info(ent) _get_entity_dbg_info(ent)
468 #define set_entity_dbg_info(ent, db) _set_entity_dbg_info(ent, db)
471 #endif /* FIRM_TR_ENTITY_T_H */