2 * Copyright (C) 1995-2008 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 unsigned allocation:3; /**< Distinguishes static and dynamically allocated
104 entities and some further cases. */
105 unsigned visibility:3; /**< Specifies visibility to external program fragments. */
106 unsigned variability:3; /**< Specifies variability of entities content. */
107 unsigned volatility:1; /**< Specifies volatility of entities content. */
108 unsigned align:1; /**< Specifies alignment of entities content. */
109 unsigned stickyness:2; /**< Specifies whether this entity is sticky. */
110 unsigned peculiarity:3; /**< The peculiarity of this entity. */
111 unsigned address_taken:3; /**< A flag that can be set to mark address taken entities. */
112 unsigned final:1; /**< If set, this entity cannot be overridden. */
113 unsigned compiler_gen:1; /**< If set, this entity was compiler generated. */
114 unsigned backend_marked:1; /**< If set, this entity was marked by the backend for emission. */
115 int offset; /**< Offset in bytes for this entity. Fixed when layout
116 of owner is determined. */
117 unsigned char offset_bit_remainder;
118 /**< If the entity is a bit field, this is the offset of
119 the start of the bit field within the byte specified
121 unsigned long visit; /**< visited counter for walks of the type information. */
122 struct dbg_info *dbi; /**< A pointer to information for debug support. */
123 void *link; /**< To store some intermediate information. */
124 ir_type *repr_class; /**< If this entity represents a class info, the associated class. */
126 /* ------------- fields for entities owned by a class type ---------------*/
128 ir_entity **overwrites; /**< A list of entities this entity overwrites. */
129 ir_entity **overwrittenby; /**< A list of entities that overwrite this entity. */
131 /* ------------- fields for atomic entities --------------- */
132 ir_node *value; /**< value if entity is not of variability uninitialized.
133 Only for atomic entities. */
135 /* ------------- fields for compound entities -------------- */
136 compound_ent_attr cmpd_attr;
137 /* ------------- fields for method entities ---------------- */
138 method_ent_attr mtd_attr;
139 } attr; /**< type specific attributes */
141 /* ------------- fields for analyses ---------------*/
144 long nr; /**< A unique node number for each node to make output readable. */
145 # endif /* DEBUG_libfirm */
148 /** Initialize the entity module. */
149 void firm_init_entity(void);
152 /* ----------------------- inline functions ------------------------ */
154 _is_entity(const void *thing) {
155 return get_kind(thing) == k_entity;
158 static INLINE const char *
159 _get_entity_name(const ir_entity *ent) {
160 assert(ent && ent->kind == k_entity);
161 return get_id_str(get_entity_ident(ent));
164 static INLINE ident *
165 _get_entity_ident(const ir_entity *ent) {
166 assert(ent && ent->kind == k_entity);
171 _set_entity_ident(ir_entity *ent, ident *id) {
172 assert(ent && ent->kind == k_entity);
176 static INLINE ir_type *
177 _get_entity_owner(ir_entity *ent) {
178 assert(ent && ent->kind == k_entity);
179 return ent->owner = skip_tid(ent->owner);
182 static INLINE ident *
183 _get_entity_ld_ident(ir_entity *ent)
185 assert(ent && ent->kind == k_entity);
186 if (ent->ld_name == NULL)
187 ent->ld_name = mangle_entity(ent);
192 _set_entity_ld_ident(ir_entity *ent, ident *ld_ident) {
193 assert(ent && ent->kind == k_entity);
194 ent->ld_name = ld_ident;
197 static INLINE const char *
198 _get_entity_ld_name(ir_entity *ent) {
199 assert(ent && ent->kind == k_entity);
200 return get_id_str(get_entity_ld_ident(ent));
203 static INLINE ir_type *
204 _get_entity_type(ir_entity *ent) {
205 assert(ent && ent->kind == k_entity);
206 return ent->type = skip_tid(ent->type);
210 _set_entity_type(ir_entity *ent, ir_type *type) {
211 assert(ent && ent->kind == k_entity);
215 static INLINE ir_allocation
216 _get_entity_allocation(const ir_entity *ent) {
217 assert(ent && ent->kind == k_entity);
218 return ent->allocation;
222 _set_entity_allocation(ir_entity *ent, ir_allocation al) {
223 assert(ent && ent->kind == k_entity);
224 ent->allocation = al;
227 static INLINE ir_visibility
228 _get_entity_visibility(const ir_entity *ent) {
229 assert(ent && ent->kind == k_entity);
230 return ent->visibility;
233 static INLINE ir_variability
234 _get_entity_variability(const ir_entity *ent) {
235 assert(ent && ent->kind == k_entity);
236 return ent->variability;
239 static INLINE ir_volatility
240 _get_entity_volatility(const ir_entity *ent) {
241 assert(ent && ent->kind == k_entity);
242 return ent->volatility;
246 _set_entity_volatility(ir_entity *ent, ir_volatility vol) {
247 assert(ent && ent->kind == k_entity);
248 ent->volatility = vol;
251 static INLINE ir_align
252 _get_entity_align(const ir_entity *ent) {
253 assert(ent && ent->kind == k_entity);
258 _set_entity_align(ir_entity *ent, ir_align a) {
259 assert(ent && ent->kind == k_entity);
263 static INLINE ir_peculiarity
264 _get_entity_peculiarity(const ir_entity *ent) {
265 assert(ent && ent->kind == k_entity);
266 return ent->peculiarity;
270 * @todo Why peculiarity only for methods?
271 * Good question. Originally, there were only description and
272 * existent. The thought was, what sense does it make to
273 * describe a field? With inherited the situation changed. So
274 * I removed the assertion. GL, 28.2.05
277 _set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec) {
278 assert(ent && ent->kind == k_entity);
279 /* @@@ why peculiarity only for methods? */
280 //assert(is_Method_type(ent->type));
282 ent->peculiarity = pec;
285 static INLINE ir_stickyness
286 _get_entity_stickyness(const ir_entity *ent) {
287 assert(ent && ent->kind == k_entity);
288 return ent->stickyness;
292 _set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness) {
293 assert(ent && ent->kind == k_entity);
294 ent->stickyness = stickyness;
298 _is_entity_final(const ir_entity *ent) {
299 assert(ent && ent->kind == k_entity);
300 return (int)ent->final;
304 _set_entity_final(ir_entity *ent, int final) {
305 assert(ent && ent->kind == k_entity);
306 ent->final = final ? 1 : 0;
310 _is_entity_compiler_generated(const ir_entity *ent) {
311 assert(ent && ent->kind == k_entity);
312 return ent->compiler_gen;
316 _set_entity_compiler_generated(ir_entity *ent, int flag) {
317 assert(ent && ent->kind == k_entity);
318 ent->compiler_gen = flag ? 1 : 0;
322 _is_entity_backend_marked(const ir_entity *ent) {
323 assert(ent && ent->kind == k_entity);
324 return ent->backend_marked;
328 _set_entity_backend_marked(ir_entity *ent, int flag) {
329 assert(ent && ent->kind == k_entity);
330 ent->backend_marked = flag ? 1 : 0;
333 static INLINE ir_address_taken_state
334 _get_entity_address_taken(const ir_entity *ent) {
335 assert(ent && ent->kind == k_entity);
336 return ent->address_taken;
340 _set_entity_address_taken(ir_entity *ent, ir_address_taken_state state) {
341 assert(ent && ent->kind == k_entity);
342 assert(state == ir_address_not_taken ||
343 state == ir_address_taken_unknown ||
344 state == ir_address_taken);
345 ent->address_taken = state;
349 _get_entity_offset(const ir_entity *ent) {
350 assert(ent && ent->kind == k_entity);
355 _set_entity_offset(ir_entity *ent, int offset) {
356 assert(ent && ent->kind == k_entity);
357 ent->offset = offset;
360 static INLINE unsigned char
361 _get_entity_offset_bits_remainder(const ir_entity *ent) {
362 assert(ent && ent->kind == k_entity);
363 return ent->offset_bit_remainder;
367 _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset) {
368 assert(ent && ent->kind == k_entity);
369 ent->offset_bit_remainder = offset;
373 _get_entity_link(const ir_entity *ent) {
374 assert(ent && ent->kind == k_entity);
379 _set_entity_link(ir_entity *ent, void *l) {
380 assert(ent && ent->kind == k_entity);
384 static INLINE ir_graph *
385 _get_entity_irg(const ir_entity *ent) {
387 assert(ent && ent->kind == k_entity);
388 assert(ent == unknown_entity || is_Method_type(ent->type));
389 irg = ent->attr.mtd_attr.irg;
390 if (irg != NULL && !get_visit_pseudo_irgs() && is_pseudo_ir_graph(irg))
395 static INLINE unsigned long
396 _get_entity_visited(ir_entity *ent) {
397 assert(ent && ent->kind == k_entity);
402 _set_entity_visited(ir_entity *ent, unsigned long num) {
403 assert(ent && ent->kind == k_entity);
408 _mark_entity_visited(ir_entity *ent) {
409 assert(ent && ent->kind == k_entity);
410 ent->visit = firm_type_visited;
414 _entity_visited(ir_entity *ent) {
415 return _get_entity_visited(ent) >= firm_type_visited;
419 _entity_not_visited(ir_entity *ent) {
420 return _get_entity_visited(ent) < firm_type_visited;
423 static INLINE ir_type *
424 _get_entity_repr_class(const ir_entity *ent) {
425 assert(ent && ent->kind == k_entity);
426 return ent->repr_class;
429 static INLINE dbg_info *
430 _get_entity_dbg_info(const ir_entity *ent) {
435 _set_entity_dbg_info(ir_entity *ent, dbg_info *db) {
440 #define is_entity(thing) _is_entity(thing)
441 #define get_entity_name(ent) _get_entity_name(ent)
442 #define get_entity_ident(ent) _get_entity_ident(ent)
443 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
444 #define get_entity_owner(ent) _get_entity_owner(ent)
445 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
446 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
447 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
448 #define get_entity_type(ent) _get_entity_type(ent)
449 #define set_entity_type(ent, type) _set_entity_type(ent, type)
450 #define get_entity_allocation(ent) _get_entity_allocation(ent)
451 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
452 #define get_entity_visibility(ent) _get_entity_visibility(ent)
453 #define get_entity_variability(ent) _get_entity_variability(ent)
454 #define get_entity_volatility(ent) _get_entity_volatility(ent)
455 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
456 #define get_entity_align(ent) _get_entity_align(ent)
457 #define set_entity_align(ent, a) _set_entity_align(ent, a)
458 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
459 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
460 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
461 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
462 #define is_entity_final(ent) _is_entity_final(ent)
463 #define set_entity_final(ent, final) _set_entity_final(ent, final)
464 #define is_entity_compiler_generated(ent) _is_entity_compiler_generated(ent)
465 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
466 #define is_entity_backend_marked(ent) _is_entity_backend_marked(ent)
467 #define set_entity_backend_marked(ent, flag) _set_entity_backend_marked(ent, flag)
468 #define get_entity_address_taken(ent) _get_entity_address_taken(ent)
469 #define set_entity_address_taken(ent, flag) _set_entity_address_taken(ent, flag)
470 #define get_entity_offset(ent) _get_entity_offset(ent)
471 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
472 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
473 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
474 #define get_entity_link(ent) _get_entity_link(ent)
475 #define set_entity_link(ent, l) _set_entity_link(ent, l)
476 #define get_entity_irg(ent) _get_entity_irg(ent)
477 #define get_entity_visited(ent) _get_entity_visited(ent)
478 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
479 #define mark_entity_visited(ent) _mark_entity_visited(ent)
480 #define entity_visited(ent) _entity_visited(ent)
481 #define entity_not_visited(ent) _entity_not_visited(ent)
482 #define get_entity_repr_class(ent) _get_entity_repr_class(ent)
483 #define get_entity_dbg_info(ent) _get_entity_dbg_info(ent)
484 #define set_entity_dbg_info(ent, db) _set_entity_dbg_info(ent, db)
487 #endif /* FIRM_TR_ENTITY_T_H */