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 compound entities. */
75 typedef struct compound_ent_attr {
76 ir_node **values; /**< constant values of compound entities. */
77 compound_graph_path **val_paths;
78 /**< paths corresponding to constant values. */
81 /** A reserved value for "not yet set". */
82 #define VTABLE_NUM_NOT_SET ((unsigned)(-1))
84 /** The attributes for methods. */
85 typedef struct method_ent_attr {
86 ir_graph *irg; /**< The corresponding irg if known.
87 The ir_graph constructor automatically sets this field. */
88 unsigned irg_add_properties; /**< Additional graph properties can be
89 stored in a entity if no irg is available. */
91 unsigned vtable_number; /**< For a dynamically called method, the number assigned
92 in the virtual function table. */
94 ptr_access_kind *param_access; /**< the parameter access */
95 unsigned *param_weight; /**< The weight of method's parameters. Parameters
96 with a high weight are good candidates for procedure cloning. */
99 /** additional attributes for code entities */
100 typedef struct code_ent_attr {
101 ir_label_t label; /** label of the basic block */
106 * An abstract data type to represent program entities.
111 firm_kind kind; /**< The dynamic type tag for entity. */
112 ident *name; /**< The name of this entity. */
113 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
114 name. If the field is read before written a default
115 mangling is applies. The name of the owner is prepended
116 to the name of the entity, separated by a underscore.
117 E.g., for a class `A' with field `a' this
118 is the ident for `A_a'. */
119 ir_type *type; /**< The type of this entity, e.g., a method type, a
120 basic type of the language or a class itself. */
121 ir_type *owner; /**< The compound type (e.g. class type) this entity belongs to. */
122 unsigned linkage:10; /**< Specifies linkage type */
123 unsigned volatility:1; /**< Specifies volatility of entities content.*/
124 unsigned aligned:1; /**< Specifies alignment of entities content. */
125 unsigned usage:4; /**< flag indicating usage types of this entity,
126 see ir_entity_usage. */
127 unsigned compiler_gen:1; /**< If set, this entity was compiler generated.
129 unsigned backend_marked:1; /**< If set, this entity was marked by the
130 backend for emission. */
131 unsigned visibility:3; /**< @deprecated */
132 unsigned allocation:3; /**< @deprecated */
133 unsigned peculiarity:3; /**< @deprecated */
134 unsigned final:1; /**< @deprecated */
135 int offset; /**< Offset in bytes for this entity. Fixed
136 when layout of owner is determined. */
137 unsigned alignment; /**< entity alignment in bytes */
138 unsigned char offset_bit_remainder;
139 /**< If the entity is a bit field, this is the
140 offset of the start of the bit field
141 within the byte specified by offset. */
142 ir_visited_t visit; /**< visited counter for walks of the type
144 struct dbg_info *dbi; /**< A pointer to information for debug support.
146 void *link; /**< To store some intermediate information. */
147 ir_type *repr_class; /**< If this entity represents a class info, the
150 /* ------------- fields for entities owned by a class type ---------------*/
152 ir_entity **overwrites; /**< A list of entities this entity overwrites.
154 ir_entity **overwrittenby; /**< A list of entities that overwrite this
157 /* ------------- fields for atomic entities --------------- */
158 ir_initializer_t *initializer; /**< entity initializer */
160 /* ------------- fields for compound entities -------------- */
161 compound_ent_attr cmpd_attr;
162 /* ------------- fields for method entities ---------------- */
163 method_ent_attr mtd_attr;
164 /* fields for code entities */
165 code_ent_attr code_attr;
166 } attr; /**< type specific attributes */
168 /* ------------- fields for analyses ---------------*/
171 long nr; /**< A unique node number for each node to make output
176 /** Initialize the entity module. */
177 void firm_init_entity(void);
179 /* ----------------------- inline functions ------------------------ */
181 _is_entity(const void *thing) {
182 return get_kind(thing) == k_entity;
185 static inline const char *
186 _get_entity_name(const ir_entity *ent) {
187 assert(ent && ent->kind == k_entity);
188 return get_id_str(get_entity_ident(ent));
191 static inline ident *
192 _get_entity_ident(const ir_entity *ent) {
193 assert(ent && ent->kind == k_entity);
198 _set_entity_ident(ir_entity *ent, ident *id) {
199 assert(ent && ent->kind == k_entity);
203 static inline ir_type *
204 _get_entity_owner(const ir_entity *ent) {
205 assert(ent && ent->kind == k_entity);
209 static inline ident *
210 _get_entity_ld_ident(const ir_entity *ent)
212 assert(ent && ent->kind == k_entity);
213 if (ent->ld_name == NULL)
219 _set_entity_ld_ident(ir_entity *ent, ident *ld_ident) {
220 assert(ent && ent->kind == k_entity);
221 ent->ld_name = ld_ident;
224 static inline const char *
225 _get_entity_ld_name(const ir_entity *ent) {
226 assert(ent && ent->kind == k_entity);
227 return get_id_str(get_entity_ld_ident(ent));
230 static inline ir_type *
231 _get_entity_type(const ir_entity *ent) {
232 assert(ent && ent->kind == k_entity);
237 _set_entity_type(ir_entity *ent, ir_type *type) {
238 assert(ent && ent->kind == k_entity);
242 static inline ir_linkage
243 _get_entity_linkage(const ir_entity *ent) {
244 assert(ent && ent->kind == k_entity);
248 static inline ir_volatility
249 _get_entity_volatility(const ir_entity *ent) {
250 assert(ent && ent->kind == k_entity);
251 return ent->volatility;
255 _set_entity_volatility(ir_entity *ent, ir_volatility vol) {
256 assert(ent && ent->kind == k_entity);
257 ent->volatility = vol;
260 static inline unsigned
261 _get_entity_alignment(const ir_entity *ent) {
262 assert(ent && ent->kind == k_entity);
263 return ent->alignment;
267 _set_entity_alignment(ir_entity *ent, unsigned alignment) {
268 assert(ent && ent->kind == k_entity);
269 ent->alignment = alignment;
272 static inline ir_align
273 _get_entity_aligned(const ir_entity *ent) {
274 assert(ent && ent->kind == k_entity);
279 _set_entity_aligned(ir_entity *ent, ir_align a) {
280 assert(ent && ent->kind == k_entity);
285 _is_entity_compiler_generated(const ir_entity *ent) {
286 assert(ent && ent->kind == k_entity);
287 return ent->compiler_gen;
291 _set_entity_compiler_generated(ir_entity *ent, int flag) {
292 assert(ent && ent->kind == k_entity);
293 ent->compiler_gen = flag ? 1 : 0;
297 _is_entity_backend_marked(const ir_entity *ent) {
298 assert(ent && ent->kind == k_entity);
299 return ent->backend_marked;
303 _set_entity_backend_marked(ir_entity *ent, int flag) {
304 assert(ent && ent->kind == k_entity);
305 ent->backend_marked = flag ? 1 : 0;
308 static inline ir_entity_usage
309 _get_entity_usage(const ir_entity *ent) {
310 assert(ent && ent->kind == k_entity);
315 _set_entity_usage(ir_entity *ent, ir_entity_usage state) {
316 assert(ent && ent->kind == k_entity);
321 _get_entity_offset(const ir_entity *ent) {
322 assert(ent && ent->kind == k_entity);
327 _set_entity_offset(ir_entity *ent, int offset) {
328 assert(ent && ent->kind == k_entity);
329 ent->offset = offset;
332 static inline unsigned char
333 _get_entity_offset_bits_remainder(const ir_entity *ent) {
334 assert(ent && ent->kind == k_entity);
335 return ent->offset_bit_remainder;
339 _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset) {
340 assert(ent && ent->kind == k_entity);
341 ent->offset_bit_remainder = offset;
345 _get_entity_link(const ir_entity *ent) {
346 assert(ent && ent->kind == k_entity);
351 _set_entity_link(ir_entity *ent, void *l) {
352 assert(ent && ent->kind == k_entity);
356 static inline ir_graph *
357 _get_entity_irg(const ir_entity *ent) {
359 assert(ent && ent->kind == k_entity);
360 if (!is_Method_type(ent->type) || ent == unknown_entity) {
364 irg = ent->attr.mtd_attr.irg;
365 if (irg != NULL && !get_visit_pseudo_irgs() && is_pseudo_ir_graph(irg))
370 static inline ir_visited_t _get_entity_visited(const ir_entity *ent)
372 assert(ent && ent->kind == k_entity);
376 static inline void _set_entity_visited(ir_entity *ent, ir_visited_t num)
378 assert(ent && ent->kind == k_entity);
382 static inline void _mark_entity_visited(ir_entity *ent)
384 assert(ent && ent->kind == k_entity);
385 ent->visit = firm_type_visited;
388 static inline int _entity_visited(const ir_entity *ent)
390 return _get_entity_visited(ent) >= firm_type_visited;
393 static inline int _entity_not_visited(const ir_entity *ent)
395 return _get_entity_visited(ent) < firm_type_visited;
398 static inline ir_type *_get_entity_repr_class(const ir_entity *ent)
400 assert(ent && ent->kind == k_entity);
401 return ent->repr_class;
404 static inline dbg_info *_get_entity_dbg_info(const ir_entity *ent)
409 static inline void _set_entity_dbg_info(ir_entity *ent, dbg_info *db)
414 int is_entity_final(const ir_entity *entity);
416 #define is_entity(thing) _is_entity(thing)
417 #define get_entity_name(ent) _get_entity_name(ent)
418 #define get_entity_ident(ent) _get_entity_ident(ent)
419 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
420 #define get_entity_owner(ent) _get_entity_owner(ent)
421 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
422 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
423 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
424 #define get_entity_type(ent) _get_entity_type(ent)
425 #define set_entity_type(ent, type) _set_entity_type(ent, type)
426 #define get_entity_linkage(ent) _get_entity_linkage(ent)
427 #define get_entity_volatility(ent) _get_entity_volatility(ent)
428 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
429 #define set_entity_alignment(ent, alignment) _set_entity_alignment(ent, alignment)
430 #define get_entity_alignment(ent) _get_entity_alignment(ent)
431 #define get_entity_align(ent) _get_entity_align(ent)
432 #define set_entity_align(ent, a) _set_entity_align(ent, a)
433 #define is_entity_compiler_generated(ent) _is_entity_compiler_generated(ent)
434 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
435 #define is_entity_backend_marked(ent) _is_entity_backend_marked(ent)
436 #define set_entity_backend_marked(ent, flag) _set_entity_backend_marked(ent, flag)
437 #define get_entity_usage(ent) _get_entity_usage(ent)
438 #define set_entity_usage(ent, flags) _set_entity_usage(ent, flags)
439 #define get_entity_offset(ent) _get_entity_offset(ent)
440 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
441 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
442 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
443 #define get_entity_link(ent) _get_entity_link(ent)
444 #define set_entity_link(ent, l) _set_entity_link(ent, l)
445 #define get_entity_irg(ent) _get_entity_irg(ent)
446 #define get_entity_visited(ent) _get_entity_visited(ent)
447 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
448 #define mark_entity_visited(ent) _mark_entity_visited(ent)
449 #define entity_visited(ent) _entity_visited(ent)
450 #define entity_not_visited(ent) _entity_not_visited(ent)
451 #define get_entity_repr_class(ent) _get_entity_repr_class(ent)
452 #define get_entity_dbg_info(ent) _get_entity_dbg_info(ent)
453 #define set_entity_dbg_info(ent, db) _set_entity_dbg_info(ent, db)