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"
36 #include "pseudo_irg.h"
38 typedef struct ir_initializer_base_t {
39 ir_initializer_kind_t kind;
40 } ir_initializer_base_t;
43 * An compound initializer.
45 typedef struct ir_initializer_compound_t {
46 ir_initializer_base_t base;
47 unsigned n_initializers;
48 ir_initializer_t *initializers[1];
49 } ir_initializer_compound_t;
52 * An initializer containing an ir_node,
54 typedef struct ir_initializer_const_t {
55 ir_initializer_base_t base;
57 } ir_initializer_const_t ;
60 * An initializer containing a tarval.
62 typedef struct ir_initializer_tarval_t {
63 ir_initializer_base_t base;
65 } ir_initializer_tarval_t ;
67 union ir_initializer_t {
68 ir_initializer_kind_t kind;
69 ir_initializer_base_t base;
70 ir_initializer_compound_t compound;
71 ir_initializer_const_t consti;
72 ir_initializer_tarval_t tarval;
75 /** A path in a compound graph. */
76 struct compound_graph_path {
77 firm_kind kind; /**< The dynamic type tag for compound graph path. */
78 ir_type *tp; /**< The type this path belongs to. */
79 int len; /**< The length of the path. */
81 int index; /**< Array index. To compute position of array elements */
82 ir_entity *node; /**< The accessed entity. */
83 } list[1]; /**< List of entity/index tuple of length len to express the
87 /** The attributes for atomic entities. */
88 typedef struct atomic_ent_attr {
89 ir_node *value; /**< value if entity is not of variability uninitialized.
90 Only for atomic entities. */
93 /** The attributes for compound entities. */
94 typedef struct compound_ent_attr {
95 ir_node **values; /**< constant values of compound entities. Only available if
96 variability not uninitialized. Must be set for variability constant. */
97 compound_graph_path **val_paths;
98 /**< paths corresponding to constant values. Only available if
99 variability not uninitialized. Must be set for variability constant. */
102 /** A reserved value for "not yet set". */
103 #define VTABLE_NUM_NOT_SET ((unsigned)(-1))
105 /** The attributes for methods. */
106 typedef struct method_ent_attr {
107 ir_graph *irg; /**< The corresponding irg if known.
108 The ir_graph constructor automatically sets this field. */
109 unsigned irg_add_properties; /**< Additional graph properties can be
110 stored in a entity if no irg is available. */
112 unsigned vtable_number; /**< For a dynamically called method, the number assigned
113 in the virtual function table. */
115 ptr_access_kind *param_access; /**< the parameter access */
116 unsigned *param_weight; /**< The weight of method's parameters. Parameters
117 with a high weight are good candidates for procedure cloning. */
120 /** additional attributes for code entities */
121 typedef struct code_ent_attr {
122 ir_label_t label; /** label of the basic block */
127 * An abstract data type to represent program entities.
132 firm_kind kind; /**< The dynamic type tag for entity. */
133 ident *name; /**< The name of this entity. */
134 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
135 name. If the field is read before written a default
136 mangling is applies. The name of the owner is prepended
137 to the name of the entity, separated by a underscore.
138 E.g., for a class `A' with field `a' this
139 is the ident for `A_a'. */
140 ir_type *type; /**< The type of this entity, e.g., a method type, a
141 basic type of the language or a class itself. */
142 ir_type *owner; /**< The compound type (e.g. class type) this entity belongs to. */
143 unsigned allocation:3; /**< Distinguishes static and dynamically allocated
144 entities and some further cases. */
145 unsigned visibility:3; /**< Specifies visibility to external program fragments. */
146 unsigned variability:3; /**< Specifies variability of entities content. */
147 unsigned volatility:1; /**< Specifies volatility of entities content. */
148 unsigned aligned:1; /**< Specifies alignment of entities content. */
149 unsigned stickyness:2; /**< Specifies whether this entity is sticky. */
150 unsigned peculiarity:3; /**< The peculiarity of this entity. */
151 unsigned usage:4; /**< flag indicating usage types of this entity, see ir_entity_usage. */
152 unsigned final:1; /**< If set, this entity cannot be overridden. */
153 unsigned compiler_gen:1; /**< If set, this entity was compiler generated. */
154 unsigned backend_marked:1; /**< If set, this entity was marked by the backend for emission. */
155 unsigned has_initializer:1; /**< if set, this entity is initialized by new style initializers. */
156 int offset; /**< Offset in bytes for this entity. Fixed when layout
157 of owner is determined. */
158 unsigned alignment; /**< entity alignment in bytes */
159 unsigned char offset_bit_remainder;
160 /**< If the entity is a bit field, this is the offset of
161 the start of the bit field within the byte specified
163 ir_visited_t visit; /**< visited counter for walks of the type information. */
164 struct dbg_info *dbi; /**< A pointer to information for debug support. */
165 void *link; /**< To store some intermediate information. */
166 ir_type *repr_class; /**< If this entity represents a class info, the associated class. */
168 /* ------------- fields for entities owned by a class type ---------------*/
170 ir_entity **overwrites; /**< A list of entities this entity overwrites. */
171 ir_entity **overwrittenby; /**< A list of entities that overwrite this entity. */
173 /* ------------- fields for atomic entities --------------- */
174 ir_node *value; /**< value if entity is not of variability uninitialized.
175 Only for atomic entities. */
177 /* ------------- fields for compound entities -------------- */
178 compound_ent_attr cmpd_attr;
179 /* ------------- fields for method entities ---------------- */
180 method_ent_attr mtd_attr;
181 /* fields for code entities */
182 code_ent_attr code_attr;
183 /* entity initializer */
184 ir_initializer_t *initializer;
185 } attr; /**< type specific attributes */
187 /* ------------- fields for analyses ---------------*/
190 long nr; /**< A unique node number for each node to make output readable. */
191 # endif /* DEBUG_libfirm */
194 /** Initialize the entity module. */
195 void firm_init_entity(void);
198 /* ----------------------- inline functions ------------------------ */
200 _is_entity(const void *thing) {
201 return get_kind(thing) == k_entity;
204 static inline const char *
205 _get_entity_name(const ir_entity *ent) {
206 assert(ent && ent->kind == k_entity);
207 return get_id_str(get_entity_ident(ent));
210 static inline ident *
211 _get_entity_ident(const ir_entity *ent) {
212 assert(ent && ent->kind == k_entity);
217 _set_entity_ident(ir_entity *ent, ident *id) {
218 assert(ent && ent->kind == k_entity);
222 static inline ir_type *
223 _get_entity_owner(ir_entity *ent) {
224 assert(ent && ent->kind == k_entity);
225 return ent->owner = skip_tid(ent->owner);
228 static inline ident *
229 _get_entity_ld_ident(ir_entity *ent)
231 assert(ent && ent->kind == k_entity);
232 if (ent->ld_name == NULL)
233 ent->ld_name = id_mangle_entity(ent);
238 _set_entity_ld_ident(ir_entity *ent, ident *ld_ident) {
239 assert(ent && ent->kind == k_entity);
240 ent->ld_name = ld_ident;
243 static inline const char *
244 _get_entity_ld_name(ir_entity *ent) {
245 assert(ent && ent->kind == k_entity);
246 return get_id_str(get_entity_ld_ident(ent));
249 static inline ir_type *
250 _get_entity_type(ir_entity *ent) {
251 assert(ent && ent->kind == k_entity);
252 return ent->type = skip_tid(ent->type);
256 _set_entity_type(ir_entity *ent, ir_type *type) {
257 assert(ent && ent->kind == k_entity);
261 static inline ir_allocation
262 _get_entity_allocation(const ir_entity *ent) {
263 assert(ent && ent->kind == k_entity);
264 return ent->allocation;
268 _set_entity_allocation(ir_entity *ent, ir_allocation al) {
269 assert(ent && ent->kind == k_entity);
270 ent->allocation = al;
273 static inline ir_visibility
274 _get_entity_visibility(const ir_entity *ent) {
275 assert(ent && ent->kind == k_entity);
276 return ent->visibility;
279 static inline ir_variability
280 _get_entity_variability(const ir_entity *ent) {
281 assert(ent && ent->kind == k_entity);
282 return ent->variability;
285 static inline ir_volatility
286 _get_entity_volatility(const ir_entity *ent) {
287 assert(ent && ent->kind == k_entity);
288 return ent->volatility;
292 _set_entity_volatility(ir_entity *ent, ir_volatility vol) {
293 assert(ent && ent->kind == k_entity);
294 ent->volatility = vol;
297 static inline unsigned
298 _get_entity_alignment(const ir_entity *ent) {
299 assert(ent && ent->kind == k_entity);
300 return ent->alignment;
304 _set_entity_alignment(ir_entity *ent, unsigned alignment) {
305 assert(ent && ent->kind == k_entity);
306 ent->alignment = alignment;
309 static inline ir_align
310 _get_entity_aligned(const ir_entity *ent) {
311 assert(ent && ent->kind == k_entity);
316 _set_entity_aligned(ir_entity *ent, ir_align a) {
317 assert(ent && ent->kind == k_entity);
321 static inline ir_peculiarity
322 _get_entity_peculiarity(const ir_entity *ent) {
323 assert(ent && ent->kind == k_entity);
324 return ent->peculiarity;
328 * @todo Why peculiarity only for methods?
329 * Good question. Originally, there were only description and
330 * existent. The thought was, what sense does it make to
331 * describe a field? With inherited the situation changed. So
332 * I removed the assertion. GL, 28.2.05
335 _set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec) {
336 assert(ent && ent->kind == k_entity);
337 /* @@@ why peculiarity only for methods? */
338 //assert(is_Method_type(ent->type));
340 ent->peculiarity = pec;
343 static inline ir_stickyness
344 _get_entity_stickyness(const ir_entity *ent) {
345 assert(ent && ent->kind == k_entity);
346 return ent->stickyness;
350 _set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness) {
351 assert(ent && ent->kind == k_entity);
352 ent->stickyness = stickyness;
356 _is_entity_final(const ir_entity *ent) {
357 assert(ent && ent->kind == k_entity);
358 return (int)ent->final;
362 _set_entity_final(ir_entity *ent, int final) {
363 assert(ent && ent->kind == k_entity);
364 ent->final = final ? 1 : 0;
368 _is_entity_compiler_generated(const ir_entity *ent) {
369 assert(ent && ent->kind == k_entity);
370 return ent->compiler_gen;
374 _set_entity_compiler_generated(ir_entity *ent, int flag) {
375 assert(ent && ent->kind == k_entity);
376 ent->compiler_gen = flag ? 1 : 0;
380 _is_entity_backend_marked(const ir_entity *ent) {
381 assert(ent && ent->kind == k_entity);
382 return ent->backend_marked;
386 _set_entity_backend_marked(ir_entity *ent, int flag) {
387 assert(ent && ent->kind == k_entity);
388 ent->backend_marked = flag ? 1 : 0;
391 static inline ir_entity_usage
392 _get_entity_usage(const ir_entity *ent) {
393 assert(ent && ent->kind == k_entity);
398 _set_entity_usage(ir_entity *ent, ir_entity_usage state) {
399 assert(ent && ent->kind == k_entity);
404 _get_entity_offset(const ir_entity *ent) {
405 assert(ent && ent->kind == k_entity);
410 _set_entity_offset(ir_entity *ent, int offset) {
411 assert(ent && ent->kind == k_entity);
412 ent->offset = offset;
415 static inline unsigned char
416 _get_entity_offset_bits_remainder(const ir_entity *ent) {
417 assert(ent && ent->kind == k_entity);
418 return ent->offset_bit_remainder;
422 _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset) {
423 assert(ent && ent->kind == k_entity);
424 ent->offset_bit_remainder = offset;
428 _get_entity_link(const ir_entity *ent) {
429 assert(ent && ent->kind == k_entity);
434 _set_entity_link(ir_entity *ent, void *l) {
435 assert(ent && ent->kind == k_entity);
439 static inline ir_graph *
440 _get_entity_irg(const ir_entity *ent) {
442 assert(ent && ent->kind == k_entity);
443 if (!is_Method_type(ent->type) || ent == unknown_entity) {
447 irg = ent->attr.mtd_attr.irg;
448 if (irg != NULL && !get_visit_pseudo_irgs() && is_pseudo_ir_graph(irg))
453 static inline ir_visited_t
454 _get_entity_visited(ir_entity *ent) {
455 assert(ent && ent->kind == k_entity);
460 _set_entity_visited(ir_entity *ent, ir_visited_t num) {
461 assert(ent && ent->kind == k_entity);
466 _mark_entity_visited(ir_entity *ent) {
467 assert(ent && ent->kind == k_entity);
468 ent->visit = firm_type_visited;
472 _entity_visited(ir_entity *ent) {
473 return _get_entity_visited(ent) >= firm_type_visited;
477 _entity_not_visited(ir_entity *ent) {
478 return _get_entity_visited(ent) < firm_type_visited;
481 static inline ir_type *
482 _get_entity_repr_class(const ir_entity *ent) {
483 assert(ent && ent->kind == k_entity);
484 return ent->repr_class;
487 static inline dbg_info *
488 _get_entity_dbg_info(const ir_entity *ent) {
493 _set_entity_dbg_info(ir_entity *ent, dbg_info *db) {
498 #define is_entity(thing) _is_entity(thing)
499 #define get_entity_name(ent) _get_entity_name(ent)
500 #define get_entity_ident(ent) _get_entity_ident(ent)
501 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
502 #define get_entity_owner(ent) _get_entity_owner(ent)
503 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
504 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
505 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
506 #define get_entity_type(ent) _get_entity_type(ent)
507 #define set_entity_type(ent, type) _set_entity_type(ent, type)
508 #define get_entity_allocation(ent) _get_entity_allocation(ent)
509 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
510 #define get_entity_visibility(ent) _get_entity_visibility(ent)
511 #define get_entity_variability(ent) _get_entity_variability(ent)
512 #define get_entity_volatility(ent) _get_entity_volatility(ent)
513 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
514 #define set_entity_alignment(ent, alignment) _set_entity_alignment(ent, alignment)
515 #define get_entity_alignment(ent) _get_entity_alignment(ent)
516 #define get_entity_align(ent) _get_entity_align(ent)
517 #define set_entity_align(ent, a) _set_entity_align(ent, a)
518 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
519 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
520 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
521 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
522 #define is_entity_final(ent) _is_entity_final(ent)
523 #define set_entity_final(ent, final) _set_entity_final(ent, final)
524 #define is_entity_compiler_generated(ent) _is_entity_compiler_generated(ent)
525 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
526 #define is_entity_backend_marked(ent) _is_entity_backend_marked(ent)
527 #define set_entity_backend_marked(ent, flag) _set_entity_backend_marked(ent, flag)
528 #define get_entity_usage(ent) _get_entity_usage(ent)
529 #define set_entity_usage(ent, flags) _set_entity_usage(ent, flags)
530 #define get_entity_offset(ent) _get_entity_offset(ent)
531 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
532 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
533 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
534 #define get_entity_link(ent) _get_entity_link(ent)
535 #define set_entity_link(ent, l) _set_entity_link(ent, l)
536 #define get_entity_irg(ent) _get_entity_irg(ent)
537 #define get_entity_visited(ent) _get_entity_visited(ent)
538 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
539 #define mark_entity_visited(ent) _mark_entity_visited(ent)
540 #define entity_visited(ent) _entity_visited(ent)
541 #define entity_not_visited(ent) _entity_not_visited(ent)
542 #define get_entity_repr_class(ent) _get_entity_repr_class(ent)
543 #define get_entity_dbg_info(ent) _get_entity_dbg_info(ent)
544 #define set_entity_dbg_info(ent, db) _set_entity_dbg_info(ent, db)
547 #endif /* FIRM_TR_ENTITY_T_H */