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 typedef struct ir_initializer_base_t {
40 ir_initializer_kind_t kind;
41 } ir_initializer_base_t;
43 typedef struct ir_initializer_compound_t {
44 ir_initializer_base_t base;
45 unsigned n_initializers;
46 ir_initializer_t *initializers[1];
47 } ir_initializer_compound_t;
49 typedef struct ir_initializer_const_t {
50 ir_initializer_base_t base;
52 } ir_initializer_const_t ;
54 typedef struct ir_initializer_tarval_t {
55 ir_initializer_base_t base;
57 } ir_initializer_tarval_t ;
59 union ir_initializer_t {
60 ir_initializer_kind_t kind;
61 ir_initializer_base_t base;
62 ir_initializer_compound_t compound;
63 ir_initializer_const_t consti;
64 ir_initializer_tarval_t tarval;
67 /** A path in a compound graph. */
68 struct compound_graph_path {
69 firm_kind kind; /**< The dynamic type tag for compound graph path. */
70 ir_type *tp; /**< The type this path belongs to. */
71 int len; /**< The length of the path. */
73 int index; /**< Array index. To compute position of array elements */
74 ir_entity *node; /**< The accessed entity. */
75 } list[1]; /**< List of entity/index tuple of length len to express the
79 /** The attributes for atomic entities. */
80 typedef struct atomic_ent_attr {
81 ir_node *value; /**< value if entity is not of variability uninitialized.
82 Only for atomic entities. */
85 /** The attributes for compound entities. */
86 typedef struct compound_ent_attr {
87 ir_node **values; /**< constant values of compound entities. Only available if
88 variability not uninitialized. Must be set for variability constant. */
89 compound_graph_path **val_paths;
90 /**< paths corresponding to constant values. Only available if
91 variability not uninitialized. Must be set for variability constant. */
94 /** A reserved value for "not yet set". */
95 #define VTABLE_NUM_NOT_SET ((unsigned)(-1))
97 /** The attributes for methods. */
98 typedef struct method_ent_attr {
99 ir_graph *irg; /**< The corresponding irg if known.
100 The ir_graph constructor automatically sets this field. */
101 unsigned irg_add_properties; /**< Additional graph properties can be
102 stored in a entity if no irg is available. */
104 unsigned vtable_number; /**< For a dynamically called method, the number assigned
105 in the virtual function table. */
107 ptr_access_kind *param_access; /**< the parameter access */
108 unsigned *param_weight; /**< The weight of method's parameters. Parameters
109 with a high weight are good candidates for procedure cloning. */
114 * An abstract data type to represent program entities.
119 firm_kind kind; /**< The dynamic type tag for entity. */
120 ident *name; /**< The name of this entity. */
121 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
122 name. If the field is read before written a default
123 mangling is applies. The name of the owner is prepended
124 to the name of the entity, separated by a underscore.
125 E.g., for a class `A' with field `a' this
126 is the ident for `A_a'. */
127 ir_type *type; /**< The type of this entity, e.g., a method type, a
128 basic type of the language or a class itself. */
129 ir_type *owner; /**< The compound type (e.g. class type) this entity belongs to. */
130 unsigned allocation:3; /**< Distinguishes static and dynamically allocated
131 entities and some further cases. */
132 unsigned visibility:3; /**< Specifies visibility to external program fragments. */
133 unsigned variability:3; /**< Specifies variability of entities content. */
134 unsigned volatility:1; /**< Specifies volatility of entities content. */
135 unsigned align:1; /**< Specifies alignment of entities content. */
136 unsigned stickyness:2; /**< Specifies whether this entity is sticky. */
137 unsigned peculiarity:3; /**< The peculiarity of this entity. */
138 unsigned address_taken:3; /**< A flag that can be set to mark address taken entities. */
139 unsigned final:1; /**< If set, this entity cannot be overridden. */
140 unsigned compiler_gen:1; /**< If set, this entity was compiler generated. */
141 unsigned backend_marked:1; /**< If set, this entity was marked by the backend for emission. */
142 unsigned has_initializer:1;
143 int offset; /**< Offset in bytes for this entity. Fixed when layout
144 of owner is determined. */
145 unsigned char offset_bit_remainder;
146 /**< If the entity is a bit field, this is the offset of
147 the start of the bit field within the byte specified
149 unsigned long visit; /**< visited counter for walks of the type information. */
150 struct dbg_info *dbi; /**< A pointer to information for debug support. */
151 void *link; /**< To store some intermediate information. */
152 ir_type *repr_class; /**< If this entity represents a class info, the associated class. */
154 /* ------------- fields for entities owned by a class type ---------------*/
156 ir_entity **overwrites; /**< A list of entities this entity overwrites. */
157 ir_entity **overwrittenby; /**< A list of entities that overwrite this entity. */
159 /* ------------- fields for atomic entities --------------- */
160 ir_node *value; /**< value if entity is not of variability uninitialized.
161 Only for atomic entities. */
163 /* ------------- fields for compound entities -------------- */
164 compound_ent_attr cmpd_attr;
165 /* ------------- fields for method entities ---------------- */
166 method_ent_attr mtd_attr;
167 /* entity initializer */
168 ir_initializer_t *initializer;
169 } attr; /**< type specific attributes */
171 /* ------------- fields for analyses ---------------*/
174 long nr; /**< A unique node number for each node to make output readable. */
175 # endif /* DEBUG_libfirm */
178 /** Initialize the entity module. */
179 void firm_init_entity(void);
182 /* ----------------------- inline functions ------------------------ */
184 _is_entity(const void *thing) {
185 return get_kind(thing) == k_entity;
188 static INLINE const char *
189 _get_entity_name(const ir_entity *ent) {
190 assert(ent && ent->kind == k_entity);
191 return get_id_str(get_entity_ident(ent));
194 static INLINE ident *
195 _get_entity_ident(const ir_entity *ent) {
196 assert(ent && ent->kind == k_entity);
201 _set_entity_ident(ir_entity *ent, ident *id) {
202 assert(ent && ent->kind == k_entity);
206 static INLINE ir_type *
207 _get_entity_owner(ir_entity *ent) {
208 assert(ent && ent->kind == k_entity);
209 return ent->owner = skip_tid(ent->owner);
212 static INLINE ident *
213 _get_entity_ld_ident(ir_entity *ent)
215 assert(ent && ent->kind == k_entity);
216 if (ent->ld_name == NULL)
217 ent->ld_name = mangle_entity(ent);
222 _set_entity_ld_ident(ir_entity *ent, ident *ld_ident) {
223 assert(ent && ent->kind == k_entity);
224 ent->ld_name = ld_ident;
227 static INLINE const char *
228 _get_entity_ld_name(ir_entity *ent) {
229 assert(ent && ent->kind == k_entity);
230 return get_id_str(get_entity_ld_ident(ent));
233 static INLINE ir_type *
234 _get_entity_type(ir_entity *ent) {
235 assert(ent && ent->kind == k_entity);
236 return ent->type = skip_tid(ent->type);
240 _set_entity_type(ir_entity *ent, ir_type *type) {
241 assert(ent && ent->kind == k_entity);
245 static INLINE ir_allocation
246 _get_entity_allocation(const ir_entity *ent) {
247 assert(ent && ent->kind == k_entity);
248 return ent->allocation;
252 _set_entity_allocation(ir_entity *ent, ir_allocation al) {
253 assert(ent && ent->kind == k_entity);
254 ent->allocation = al;
257 static INLINE ir_visibility
258 _get_entity_visibility(const ir_entity *ent) {
259 assert(ent && ent->kind == k_entity);
260 return ent->visibility;
263 static INLINE ir_variability
264 _get_entity_variability(const ir_entity *ent) {
265 assert(ent && ent->kind == k_entity);
266 return ent->variability;
269 static INLINE ir_volatility
270 _get_entity_volatility(const ir_entity *ent) {
271 assert(ent && ent->kind == k_entity);
272 return ent->volatility;
276 _set_entity_volatility(ir_entity *ent, ir_volatility vol) {
277 assert(ent && ent->kind == k_entity);
278 ent->volatility = vol;
281 static INLINE ir_align
282 _get_entity_align(const ir_entity *ent) {
283 assert(ent && ent->kind == k_entity);
288 _set_entity_align(ir_entity *ent, ir_align a) {
289 assert(ent && ent->kind == k_entity);
293 static INLINE ir_peculiarity
294 _get_entity_peculiarity(const ir_entity *ent) {
295 assert(ent && ent->kind == k_entity);
296 return ent->peculiarity;
300 * @todo Why peculiarity only for methods?
301 * Good question. Originally, there were only description and
302 * existent. The thought was, what sense does it make to
303 * describe a field? With inherited the situation changed. So
304 * I removed the assertion. GL, 28.2.05
307 _set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec) {
308 assert(ent && ent->kind == k_entity);
309 /* @@@ why peculiarity only for methods? */
310 //assert(is_Method_type(ent->type));
312 ent->peculiarity = pec;
315 static INLINE ir_stickyness
316 _get_entity_stickyness(const ir_entity *ent) {
317 assert(ent && ent->kind == k_entity);
318 return ent->stickyness;
322 _set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness) {
323 assert(ent && ent->kind == k_entity);
324 ent->stickyness = stickyness;
328 _is_entity_final(const ir_entity *ent) {
329 assert(ent && ent->kind == k_entity);
330 return (int)ent->final;
334 _set_entity_final(ir_entity *ent, int final) {
335 assert(ent && ent->kind == k_entity);
336 ent->final = final ? 1 : 0;
340 _is_entity_compiler_generated(const ir_entity *ent) {
341 assert(ent && ent->kind == k_entity);
342 return ent->compiler_gen;
346 _set_entity_compiler_generated(ir_entity *ent, int flag) {
347 assert(ent && ent->kind == k_entity);
348 ent->compiler_gen = flag ? 1 : 0;
352 _is_entity_backend_marked(const ir_entity *ent) {
353 assert(ent && ent->kind == k_entity);
354 return ent->backend_marked;
358 _set_entity_backend_marked(ir_entity *ent, int flag) {
359 assert(ent && ent->kind == k_entity);
360 ent->backend_marked = flag ? 1 : 0;
363 static INLINE ir_address_taken_state
364 _get_entity_address_taken(const ir_entity *ent) {
365 assert(ent && ent->kind == k_entity);
366 return ent->address_taken;
370 _set_entity_address_taken(ir_entity *ent, ir_address_taken_state state) {
371 assert(ent && ent->kind == k_entity);
372 assert(state == ir_address_not_taken ||
373 state == ir_address_taken_unknown ||
374 state == ir_address_taken);
375 ent->address_taken = state;
379 _get_entity_offset(const ir_entity *ent) {
380 assert(ent && ent->kind == k_entity);
385 _set_entity_offset(ir_entity *ent, int offset) {
386 assert(ent && ent->kind == k_entity);
387 ent->offset = offset;
390 static INLINE unsigned char
391 _get_entity_offset_bits_remainder(const ir_entity *ent) {
392 assert(ent && ent->kind == k_entity);
393 return ent->offset_bit_remainder;
397 _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset) {
398 assert(ent && ent->kind == k_entity);
399 ent->offset_bit_remainder = offset;
403 _get_entity_link(const ir_entity *ent) {
404 assert(ent && ent->kind == k_entity);
409 _set_entity_link(ir_entity *ent, void *l) {
410 assert(ent && ent->kind == k_entity);
414 static INLINE ir_graph *
415 _get_entity_irg(const ir_entity *ent) {
417 assert(ent && ent->kind == k_entity);
418 assert(ent == unknown_entity || is_Method_type(ent->type));
419 irg = ent->attr.mtd_attr.irg;
420 if (irg != NULL && !get_visit_pseudo_irgs() && is_pseudo_ir_graph(irg))
425 static INLINE unsigned long
426 _get_entity_visited(ir_entity *ent) {
427 assert(ent && ent->kind == k_entity);
432 _set_entity_visited(ir_entity *ent, unsigned long num) {
433 assert(ent && ent->kind == k_entity);
438 _mark_entity_visited(ir_entity *ent) {
439 assert(ent && ent->kind == k_entity);
440 ent->visit = firm_type_visited;
444 _entity_visited(ir_entity *ent) {
445 return _get_entity_visited(ent) >= firm_type_visited;
449 _entity_not_visited(ir_entity *ent) {
450 return _get_entity_visited(ent) < firm_type_visited;
453 static INLINE ir_type *
454 _get_entity_repr_class(const ir_entity *ent) {
455 assert(ent && ent->kind == k_entity);
456 return ent->repr_class;
459 static INLINE dbg_info *
460 _get_entity_dbg_info(const ir_entity *ent) {
465 _set_entity_dbg_info(ir_entity *ent, dbg_info *db) {
470 #define is_entity(thing) _is_entity(thing)
471 #define get_entity_name(ent) _get_entity_name(ent)
472 #define get_entity_ident(ent) _get_entity_ident(ent)
473 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
474 #define get_entity_owner(ent) _get_entity_owner(ent)
475 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
476 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
477 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
478 #define get_entity_type(ent) _get_entity_type(ent)
479 #define set_entity_type(ent, type) _set_entity_type(ent, type)
480 #define get_entity_allocation(ent) _get_entity_allocation(ent)
481 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
482 #define get_entity_visibility(ent) _get_entity_visibility(ent)
483 #define get_entity_variability(ent) _get_entity_variability(ent)
484 #define get_entity_volatility(ent) _get_entity_volatility(ent)
485 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
486 #define get_entity_align(ent) _get_entity_align(ent)
487 #define set_entity_align(ent, a) _set_entity_align(ent, a)
488 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
489 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
490 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
491 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
492 #define is_entity_final(ent) _is_entity_final(ent)
493 #define set_entity_final(ent, final) _set_entity_final(ent, final)
494 #define is_entity_compiler_generated(ent) _is_entity_compiler_generated(ent)
495 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
496 #define is_entity_backend_marked(ent) _is_entity_backend_marked(ent)
497 #define set_entity_backend_marked(ent, flag) _set_entity_backend_marked(ent, flag)
498 #define get_entity_address_taken(ent) _get_entity_address_taken(ent)
499 #define set_entity_address_taken(ent, flag) _set_entity_address_taken(ent, flag)
500 #define get_entity_offset(ent) _get_entity_offset(ent)
501 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
502 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
503 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
504 #define get_entity_link(ent) _get_entity_link(ent)
505 #define set_entity_link(ent, l) _set_entity_link(ent, l)
506 #define get_entity_irg(ent) _get_entity_irg(ent)
507 #define get_entity_visited(ent) _get_entity_visited(ent)
508 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
509 #define mark_entity_visited(ent) _mark_entity_visited(ent)
510 #define entity_visited(ent) _entity_visited(ent)
511 #define entity_not_visited(ent) _entity_not_visited(ent)
512 #define get_entity_repr_class(ent) _get_entity_repr_class(ent)
513 #define get_entity_dbg_info(ent) _get_entity_dbg_info(ent)
514 #define set_entity_dbg_info(ent, db) _set_entity_dbg_info(ent, db)
517 #endif /* FIRM_TR_ENTITY_T_H */