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 float *param_weight; /**< The weight of method's parameters. Parameters
109 with a high weight are good for procedure cloning. */
110 ir_img_section section; /**< The code section where this method should be placed */
115 * An abstract data type to represent program entities.
120 firm_kind kind; /**< The dynamic type tag for entity. */
121 ident *name; /**< The name of this entity. */
122 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
123 name. If the field is read before written a default
124 mangling is applies. The name of the owner is prepended
125 to the name of the entity, separated by a underscore.
126 E.g., for a class `A' with field `a' this
127 is the ident for `A_a'. */
128 ir_type *type; /**< The type of this entity, e.g., a method type, a
129 basic type of the language or a class itself. */
130 ir_type *owner; /**< The compound type (e.g. class type) this entity belongs to. */
131 unsigned allocation:3; /**< Distinguishes static and dynamically allocated
132 entities and some further cases. */
133 unsigned visibility:3; /**< Specifies visibility to external program fragments. */
134 unsigned variability:3; /**< Specifies variability of entities content. */
135 unsigned volatility:1; /**< Specifies volatility of entities content. */
136 unsigned align:1; /**< Specifies alignment of entities content. */
137 unsigned stickyness:2; /**< Specifies whether this entity is sticky. */
138 unsigned peculiarity:3; /**< The peculiarity of this entity. */
139 unsigned address_taken:3; /**< A flag that can be set to mark address taken entities. */
140 unsigned final:1; /**< If set, this entity cannot be overridden. */
141 unsigned compiler_gen:1; /**< If set, this entity was compiler generated. */
142 unsigned backend_marked:1; /**< If set, this entity was marked by the backend for emission. */
143 unsigned has_initializer:1;
144 int offset; /**< Offset in bytes for this entity. Fixed when layout
145 of owner is determined. */
146 unsigned char offset_bit_remainder;
147 /**< If the entity is a bit field, this is the offset of
148 the start of the bit field within the byte specified
150 unsigned long visit; /**< visited counter for walks of the type information. */
151 struct dbg_info *dbi; /**< A pointer to information for debug support. */
152 void *link; /**< To store some intermediate information. */
153 ir_type *repr_class; /**< If this entity represents a class info, the associated class. */
155 /* ------------- fields for entities owned by a class type ---------------*/
157 ir_entity **overwrites; /**< A list of entities this entity overwrites. */
158 ir_entity **overwrittenby; /**< A list of entities that overwrite this entity. */
160 /* ------------- fields for atomic entities --------------- */
161 ir_node *value; /**< value if entity is not of variability uninitialized.
162 Only for atomic entities. */
164 /* ------------- fields for compound entities -------------- */
165 compound_ent_attr cmpd_attr;
166 /* ------------- fields for method entities ---------------- */
167 method_ent_attr mtd_attr;
168 /* entity initializer */
169 ir_initializer_t *initializer;
170 } attr; /**< type specific attributes */
172 /* ------------- fields for analyses ---------------*/
175 long nr; /**< A unique node number for each node to make output readable. */
176 # endif /* DEBUG_libfirm */
179 /** Initialize the entity module. */
180 void firm_init_entity(void);
183 /* ----------------------- inline functions ------------------------ */
185 _is_entity(const void *thing) {
186 return get_kind(thing) == k_entity;
189 static INLINE const char *
190 _get_entity_name(const ir_entity *ent) {
191 assert(ent && ent->kind == k_entity);
192 return get_id_str(get_entity_ident(ent));
195 static INLINE ident *
196 _get_entity_ident(const ir_entity *ent) {
197 assert(ent && ent->kind == k_entity);
202 _set_entity_ident(ir_entity *ent, ident *id) {
203 assert(ent && ent->kind == k_entity);
207 static INLINE ir_type *
208 _get_entity_owner(ir_entity *ent) {
209 assert(ent && ent->kind == k_entity);
210 return ent->owner = skip_tid(ent->owner);
213 static INLINE ident *
214 _get_entity_ld_ident(ir_entity *ent)
216 assert(ent && ent->kind == k_entity);
217 if (ent->ld_name == NULL)
218 ent->ld_name = mangle_entity(ent);
223 _set_entity_ld_ident(ir_entity *ent, ident *ld_ident) {
224 assert(ent && ent->kind == k_entity);
225 ent->ld_name = ld_ident;
228 static INLINE const char *
229 _get_entity_ld_name(ir_entity *ent) {
230 assert(ent && ent->kind == k_entity);
231 return get_id_str(get_entity_ld_ident(ent));
234 static INLINE ir_type *
235 _get_entity_type(ir_entity *ent) {
236 assert(ent && ent->kind == k_entity);
237 return ent->type = skip_tid(ent->type);
241 _set_entity_type(ir_entity *ent, ir_type *type) {
242 assert(ent && ent->kind == k_entity);
246 static INLINE ir_allocation
247 _get_entity_allocation(const ir_entity *ent) {
248 assert(ent && ent->kind == k_entity);
249 return ent->allocation;
253 _set_entity_allocation(ir_entity *ent, ir_allocation al) {
254 assert(ent && ent->kind == k_entity);
255 ent->allocation = al;
258 static INLINE ir_visibility
259 _get_entity_visibility(const ir_entity *ent) {
260 assert(ent && ent->kind == k_entity);
261 return ent->visibility;
264 static INLINE ir_variability
265 _get_entity_variability(const ir_entity *ent) {
266 assert(ent && ent->kind == k_entity);
267 return ent->variability;
270 static INLINE ir_volatility
271 _get_entity_volatility(const ir_entity *ent) {
272 assert(ent && ent->kind == k_entity);
273 return ent->volatility;
277 _set_entity_volatility(ir_entity *ent, ir_volatility vol) {
278 assert(ent && ent->kind == k_entity);
279 ent->volatility = vol;
282 static INLINE ir_align
283 _get_entity_align(const ir_entity *ent) {
284 assert(ent && ent->kind == k_entity);
289 _set_entity_align(ir_entity *ent, ir_align a) {
290 assert(ent && ent->kind == k_entity);
294 static INLINE ir_peculiarity
295 _get_entity_peculiarity(const ir_entity *ent) {
296 assert(ent && ent->kind == k_entity);
297 return ent->peculiarity;
301 * @todo Why peculiarity only for methods?
302 * Good question. Originally, there were only description and
303 * existent. The thought was, what sense does it make to
304 * describe a field? With inherited the situation changed. So
305 * I removed the assertion. GL, 28.2.05
308 _set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec) {
309 assert(ent && ent->kind == k_entity);
310 /* @@@ why peculiarity only for methods? */
311 //assert(is_Method_type(ent->type));
313 ent->peculiarity = pec;
316 static INLINE ir_stickyness
317 _get_entity_stickyness(const ir_entity *ent) {
318 assert(ent && ent->kind == k_entity);
319 return ent->stickyness;
323 _set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness) {
324 assert(ent && ent->kind == k_entity);
325 ent->stickyness = stickyness;
329 _is_entity_final(const ir_entity *ent) {
330 assert(ent && ent->kind == k_entity);
331 return (int)ent->final;
335 _set_entity_final(ir_entity *ent, int final) {
336 assert(ent && ent->kind == k_entity);
337 ent->final = final ? 1 : 0;
341 _is_entity_compiler_generated(const ir_entity *ent) {
342 assert(ent && ent->kind == k_entity);
343 return ent->compiler_gen;
347 _set_entity_compiler_generated(ir_entity *ent, int flag) {
348 assert(ent && ent->kind == k_entity);
349 ent->compiler_gen = flag ? 1 : 0;
353 _is_entity_backend_marked(const ir_entity *ent) {
354 assert(ent && ent->kind == k_entity);
355 return ent->backend_marked;
359 _set_entity_backend_marked(ir_entity *ent, int flag) {
360 assert(ent && ent->kind == k_entity);
361 ent->backend_marked = flag ? 1 : 0;
364 static INLINE ir_address_taken_state
365 _get_entity_address_taken(const ir_entity *ent) {
366 assert(ent && ent->kind == k_entity);
367 return ent->address_taken;
371 _set_entity_address_taken(ir_entity *ent, ir_address_taken_state state) {
372 assert(ent && ent->kind == k_entity);
373 assert(state == ir_address_not_taken ||
374 state == ir_address_taken_unknown ||
375 state == ir_address_taken);
376 ent->address_taken = state;
380 _get_entity_offset(const ir_entity *ent) {
381 assert(ent && ent->kind == k_entity);
386 _set_entity_offset(ir_entity *ent, int offset) {
387 assert(ent && ent->kind == k_entity);
388 ent->offset = offset;
391 static INLINE unsigned char
392 _get_entity_offset_bits_remainder(const ir_entity *ent) {
393 assert(ent && ent->kind == k_entity);
394 return ent->offset_bit_remainder;
398 _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset) {
399 assert(ent && ent->kind == k_entity);
400 ent->offset_bit_remainder = offset;
404 _get_entity_link(const ir_entity *ent) {
405 assert(ent && ent->kind == k_entity);
410 _set_entity_link(ir_entity *ent, void *l) {
411 assert(ent && ent->kind == k_entity);
415 static INLINE ir_graph *
416 _get_entity_irg(const ir_entity *ent) {
418 assert(ent && ent->kind == k_entity);
419 assert(ent == unknown_entity || is_Method_type(ent->type));
420 irg = ent->attr.mtd_attr.irg;
421 if (irg != NULL && !get_visit_pseudo_irgs() && is_pseudo_ir_graph(irg))
426 static INLINE unsigned long
427 _get_entity_visited(ir_entity *ent) {
428 assert(ent && ent->kind == k_entity);
433 _set_entity_visited(ir_entity *ent, unsigned long num) {
434 assert(ent && ent->kind == k_entity);
439 _mark_entity_visited(ir_entity *ent) {
440 assert(ent && ent->kind == k_entity);
441 ent->visit = firm_type_visited;
445 _entity_visited(ir_entity *ent) {
446 return _get_entity_visited(ent) >= firm_type_visited;
450 _entity_not_visited(ir_entity *ent) {
451 return _get_entity_visited(ent) < firm_type_visited;
454 static INLINE ir_type *
455 _get_entity_repr_class(const ir_entity *ent) {
456 assert(ent && ent->kind == k_entity);
457 return ent->repr_class;
460 static INLINE dbg_info *
461 _get_entity_dbg_info(const ir_entity *ent) {
466 _set_entity_dbg_info(ir_entity *ent, dbg_info *db) {
471 #define is_entity(thing) _is_entity(thing)
472 #define get_entity_name(ent) _get_entity_name(ent)
473 #define get_entity_ident(ent) _get_entity_ident(ent)
474 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
475 #define get_entity_owner(ent) _get_entity_owner(ent)
476 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
477 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
478 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
479 #define get_entity_type(ent) _get_entity_type(ent)
480 #define set_entity_type(ent, type) _set_entity_type(ent, type)
481 #define get_entity_allocation(ent) _get_entity_allocation(ent)
482 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
483 #define get_entity_visibility(ent) _get_entity_visibility(ent)
484 #define get_entity_variability(ent) _get_entity_variability(ent)
485 #define get_entity_volatility(ent) _get_entity_volatility(ent)
486 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
487 #define get_entity_align(ent) _get_entity_align(ent)
488 #define set_entity_align(ent, a) _set_entity_align(ent, a)
489 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
490 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
491 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
492 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
493 #define is_entity_final(ent) _is_entity_final(ent)
494 #define set_entity_final(ent, final) _set_entity_final(ent, final)
495 #define is_entity_compiler_generated(ent) _is_entity_compiler_generated(ent)
496 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
497 #define is_entity_backend_marked(ent) _is_entity_backend_marked(ent)
498 #define set_entity_backend_marked(ent, flag) _set_entity_backend_marked(ent, flag)
499 #define get_entity_address_taken(ent) _get_entity_address_taken(ent)
500 #define set_entity_address_taken(ent, flag) _set_entity_address_taken(ent, flag)
501 #define get_entity_offset(ent) _get_entity_offset(ent)
502 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
503 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
504 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
505 #define get_entity_link(ent) _get_entity_link(ent)
506 #define set_entity_link(ent, l) _set_entity_link(ent, l)
507 #define get_entity_irg(ent) _get_entity_irg(ent)
508 #define get_entity_visited(ent) _get_entity_visited(ent)
509 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
510 #define mark_entity_visited(ent) _mark_entity_visited(ent)
511 #define entity_visited(ent) _entity_visited(ent)
512 #define entity_not_visited(ent) _entity_not_visited(ent)
513 #define get_entity_repr_class(ent) _get_entity_repr_class(ent)
514 #define get_entity_dbg_info(ent) _get_entity_dbg_info(ent)
515 #define set_entity_dbg_info(ent, db) _set_entity_dbg_info(ent, db)
518 #endif /* FIRM_TR_ENTITY_T_H */