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
34 #include "pseudo_irg.h"
35 #include "compound_path.h"
37 typedef struct ir_initializer_base_t {
38 ir_initializer_kind_t kind;
39 } ir_initializer_base_t;
42 * An compound initializer.
44 typedef struct ir_initializer_compound_t {
45 ir_initializer_base_t base;
46 unsigned n_initializers;
47 ir_initializer_t *initializers[1];
48 } ir_initializer_compound_t;
51 * An initializer containing an ir_node,
53 typedef struct ir_initializer_const_t {
54 ir_initializer_base_t base;
56 } ir_initializer_const_t ;
59 * An initializer containing a tarval.
61 typedef struct ir_initializer_tarval_t {
62 ir_initializer_base_t base;
64 } ir_initializer_tarval_t ;
66 union ir_initializer_t {
67 ir_initializer_kind_t kind;
68 ir_initializer_base_t base;
69 ir_initializer_compound_t compound;
70 ir_initializer_const_t consti;
71 ir_initializer_tarval_t tarval;
74 /** The attributes for atomic entities. */
75 typedef struct atomic_ent_attr {
76 ir_node *value; /**< value if entity is not of variability uninitialized.
77 Only for atomic entities. */
80 /** The attributes for compound entities. */
81 typedef struct compound_ent_attr {
82 ir_node **values; /**< constant values of compound entities. Only available if
83 variability not uninitialized. Must be set for variability constant. */
84 compound_graph_path **val_paths;
85 /**< paths corresponding to constant values. Only available if
86 variability not uninitialized. Must be set for variability constant. */
89 /** A reserved value for "not yet set". */
90 #define VTABLE_NUM_NOT_SET ((unsigned)(-1))
92 /** The attributes for methods. */
93 typedef struct method_ent_attr {
94 ir_graph *irg; /**< The corresponding irg if known.
95 The ir_graph constructor automatically sets this field. */
96 unsigned irg_add_properties; /**< Additional graph properties can be
97 stored in a entity if no irg is available. */
99 unsigned vtable_number; /**< For a dynamically called method, the number assigned
100 in the virtual function table. */
102 ptr_access_kind *param_access; /**< the parameter access */
103 unsigned *param_weight; /**< The weight of method's parameters. Parameters
104 with a high weight are good candidates for procedure cloning. */
107 /** additional attributes for code entities */
108 typedef struct code_ent_attr {
109 ir_label_t label; /** label of the basic block */
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 aligned: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 usage:4; /**< flag indicating usage types of this entity, see ir_entity_usage. */
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; /**< if set, this entity is initialized by new style initializers. */
143 int offset; /**< Offset in bytes for this entity. Fixed when layout
144 of owner is determined. */
145 unsigned alignment; /**< entity alignment in bytes */
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 ir_visited_t 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 /* fields for code entities */
169 code_ent_attr code_attr;
170 /* entity initializer */
171 ir_initializer_t *initializer;
172 } attr; /**< type specific attributes */
174 /* ------------- fields for analyses ---------------*/
177 long nr; /**< A unique node number for each node to make output readable. */
178 # endif /* DEBUG_libfirm */
181 /** Initialize the entity module. */
182 void firm_init_entity(void);
185 /* ----------------------- inline functions ------------------------ */
187 _is_entity(const void *thing) {
188 return get_kind(thing) == k_entity;
191 static inline const char *
192 _get_entity_name(const ir_entity *ent) {
193 assert(ent && ent->kind == k_entity);
194 return get_id_str(get_entity_ident(ent));
197 static inline ident *
198 _get_entity_ident(const ir_entity *ent) {
199 assert(ent && ent->kind == k_entity);
204 _set_entity_ident(ir_entity *ent, ident *id) {
205 assert(ent && ent->kind == k_entity);
209 static inline ir_type *
210 _get_entity_owner(ir_entity *ent) {
211 assert(ent && ent->kind == k_entity);
215 static inline ident *
216 _get_entity_ld_ident(ir_entity *ent)
218 assert(ent && ent->kind == k_entity);
219 if (ent->ld_name == NULL)
220 ent->ld_name = id_mangle_entity(ent);
225 _set_entity_ld_ident(ir_entity *ent, ident *ld_ident) {
226 assert(ent && ent->kind == k_entity);
227 ent->ld_name = ld_ident;
230 static inline const char *
231 _get_entity_ld_name(ir_entity *ent) {
232 assert(ent && ent->kind == k_entity);
233 return get_id_str(get_entity_ld_ident(ent));
236 static inline ir_type *
237 _get_entity_type(ir_entity *ent) {
238 assert(ent && ent->kind == k_entity);
243 _set_entity_type(ir_entity *ent, ir_type *type) {
244 assert(ent && ent->kind == k_entity);
248 static inline ir_allocation
249 _get_entity_allocation(const ir_entity *ent) {
250 assert(ent && ent->kind == k_entity);
251 return ent->allocation;
255 _set_entity_allocation(ir_entity *ent, ir_allocation al) {
256 assert(ent && ent->kind == k_entity);
257 ent->allocation = al;
260 static inline ir_visibility
261 _get_entity_visibility(const ir_entity *ent) {
262 assert(ent && ent->kind == k_entity);
263 return ent->visibility;
266 static inline ir_variability
267 _get_entity_variability(const ir_entity *ent) {
268 assert(ent && ent->kind == k_entity);
269 return ent->variability;
272 static inline ir_volatility
273 _get_entity_volatility(const ir_entity *ent) {
274 assert(ent && ent->kind == k_entity);
275 return ent->volatility;
279 _set_entity_volatility(ir_entity *ent, ir_volatility vol) {
280 assert(ent && ent->kind == k_entity);
281 ent->volatility = vol;
284 static inline unsigned
285 _get_entity_alignment(const ir_entity *ent) {
286 assert(ent && ent->kind == k_entity);
287 return ent->alignment;
291 _set_entity_alignment(ir_entity *ent, unsigned alignment) {
292 assert(ent && ent->kind == k_entity);
293 ent->alignment = alignment;
296 static inline ir_align
297 _get_entity_aligned(const ir_entity *ent) {
298 assert(ent && ent->kind == k_entity);
303 _set_entity_aligned(ir_entity *ent, ir_align a) {
304 assert(ent && ent->kind == k_entity);
308 static inline ir_peculiarity
309 _get_entity_peculiarity(const ir_entity *ent) {
310 assert(ent && ent->kind == k_entity);
311 return ent->peculiarity;
315 * @todo Why peculiarity only for methods?
316 * Good question. Originally, there were only description and
317 * existent. The thought was, what sense does it make to
318 * describe a field? With inherited the situation changed. So
319 * I removed the assertion. GL, 28.2.05
322 _set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec) {
323 assert(ent && ent->kind == k_entity);
324 /* @@@ why peculiarity only for methods? */
325 //assert(is_Method_type(ent->type));
327 ent->peculiarity = pec;
330 static inline ir_stickyness
331 _get_entity_stickyness(const ir_entity *ent) {
332 assert(ent && ent->kind == k_entity);
333 return ent->stickyness;
337 _set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness) {
338 assert(ent && ent->kind == k_entity);
339 ent->stickyness = stickyness;
343 _is_entity_final(const ir_entity *ent) {
344 assert(ent && ent->kind == k_entity);
345 return (int)ent->final;
349 _set_entity_final(ir_entity *ent, int final) {
350 assert(ent && ent->kind == k_entity);
351 ent->final = final ? 1 : 0;
355 _is_entity_compiler_generated(const ir_entity *ent) {
356 assert(ent && ent->kind == k_entity);
357 return ent->compiler_gen;
361 _set_entity_compiler_generated(ir_entity *ent, int flag) {
362 assert(ent && ent->kind == k_entity);
363 ent->compiler_gen = flag ? 1 : 0;
367 _is_entity_backend_marked(const ir_entity *ent) {
368 assert(ent && ent->kind == k_entity);
369 return ent->backend_marked;
373 _set_entity_backend_marked(ir_entity *ent, int flag) {
374 assert(ent && ent->kind == k_entity);
375 ent->backend_marked = flag ? 1 : 0;
378 static inline ir_entity_usage
379 _get_entity_usage(const ir_entity *ent) {
380 assert(ent && ent->kind == k_entity);
385 _set_entity_usage(ir_entity *ent, ir_entity_usage state) {
386 assert(ent && ent->kind == k_entity);
391 _get_entity_offset(const ir_entity *ent) {
392 assert(ent && ent->kind == k_entity);
397 _set_entity_offset(ir_entity *ent, int offset) {
398 assert(ent && ent->kind == k_entity);
399 ent->offset = offset;
402 static inline unsigned char
403 _get_entity_offset_bits_remainder(const ir_entity *ent) {
404 assert(ent && ent->kind == k_entity);
405 return ent->offset_bit_remainder;
409 _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset) {
410 assert(ent && ent->kind == k_entity);
411 ent->offset_bit_remainder = offset;
415 _get_entity_link(const ir_entity *ent) {
416 assert(ent && ent->kind == k_entity);
421 _set_entity_link(ir_entity *ent, void *l) {
422 assert(ent && ent->kind == k_entity);
426 static inline ir_graph *
427 _get_entity_irg(const ir_entity *ent) {
429 assert(ent && ent->kind == k_entity);
430 if (!is_Method_type(ent->type) || ent == unknown_entity) {
434 irg = ent->attr.mtd_attr.irg;
435 if (irg != NULL && !get_visit_pseudo_irgs() && is_pseudo_ir_graph(irg))
440 static inline ir_visited_t
441 _get_entity_visited(ir_entity *ent) {
442 assert(ent && ent->kind == k_entity);
447 _set_entity_visited(ir_entity *ent, ir_visited_t num) {
448 assert(ent && ent->kind == k_entity);
453 _mark_entity_visited(ir_entity *ent) {
454 assert(ent && ent->kind == k_entity);
455 ent->visit = firm_type_visited;
459 _entity_visited(ir_entity *ent) {
460 return _get_entity_visited(ent) >= firm_type_visited;
464 _entity_not_visited(ir_entity *ent) {
465 return _get_entity_visited(ent) < firm_type_visited;
468 static inline ir_type *
469 _get_entity_repr_class(const ir_entity *ent) {
470 assert(ent && ent->kind == k_entity);
471 return ent->repr_class;
474 static inline dbg_info *
475 _get_entity_dbg_info(const ir_entity *ent) {
480 _set_entity_dbg_info(ir_entity *ent, dbg_info *db) {
485 #define is_entity(thing) _is_entity(thing)
486 #define get_entity_name(ent) _get_entity_name(ent)
487 #define get_entity_ident(ent) _get_entity_ident(ent)
488 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
489 #define get_entity_owner(ent) _get_entity_owner(ent)
490 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
491 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
492 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
493 #define get_entity_type(ent) _get_entity_type(ent)
494 #define set_entity_type(ent, type) _set_entity_type(ent, type)
495 #define get_entity_allocation(ent) _get_entity_allocation(ent)
496 #define set_entity_allocation(ent, al) _set_entity_allocation(ent, al)
497 #define get_entity_visibility(ent) _get_entity_visibility(ent)
498 #define get_entity_variability(ent) _get_entity_variability(ent)
499 #define get_entity_volatility(ent) _get_entity_volatility(ent)
500 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
501 #define set_entity_alignment(ent, alignment) _set_entity_alignment(ent, alignment)
502 #define get_entity_alignment(ent) _get_entity_alignment(ent)
503 #define get_entity_align(ent) _get_entity_align(ent)
504 #define set_entity_align(ent, a) _set_entity_align(ent, a)
505 #define get_entity_peculiarity(ent) _get_entity_peculiarity(ent)
506 #define set_entity_peculiarity(ent, pec) _set_entity_peculiarity(ent, pec)
507 #define get_entity_stickyness(ent) _get_entity_stickyness(ent)
508 #define set_entity_stickyness(ent, stickyness) _set_entity_stickyness(ent, stickyness)
509 #define is_entity_final(ent) _is_entity_final(ent)
510 #define set_entity_final(ent, final) _set_entity_final(ent, final)
511 #define is_entity_compiler_generated(ent) _is_entity_compiler_generated(ent)
512 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
513 #define is_entity_backend_marked(ent) _is_entity_backend_marked(ent)
514 #define set_entity_backend_marked(ent, flag) _set_entity_backend_marked(ent, flag)
515 #define get_entity_usage(ent) _get_entity_usage(ent)
516 #define set_entity_usage(ent, flags) _set_entity_usage(ent, flags)
517 #define get_entity_offset(ent) _get_entity_offset(ent)
518 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
519 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
520 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
521 #define get_entity_link(ent) _get_entity_link(ent)
522 #define set_entity_link(ent, l) _set_entity_link(ent, l)
523 #define get_entity_irg(ent) _get_entity_irg(ent)
524 #define get_entity_visited(ent) _get_entity_visited(ent)
525 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
526 #define mark_entity_visited(ent) _mark_entity_visited(ent)
527 #define entity_visited(ent) _entity_visited(ent)
528 #define entity_not_visited(ent) _entity_not_visited(ent)
529 #define get_entity_repr_class(ent) _get_entity_repr_class(ent)
530 #define get_entity_dbg_info(ent) _get_entity_dbg_info(ent)
531 #define set_entity_dbg_info(ent, db) _set_entity_dbg_info(ent, db)
534 #endif /* FIRM_TR_ENTITY_T_H */