2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Representation of all program known entities -- private header.
9 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
11 #ifndef FIRM_TR_ENTITY_T_H
12 #define FIRM_TR_ENTITY_T_H
21 #define is_entity(thing) _is_entity(thing)
22 #define get_entity_name(ent) _get_entity_name(ent)
23 #define get_entity_ident(ent) _get_entity_ident(ent)
24 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
25 #define get_entity_owner(ent) _get_entity_owner(ent)
26 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
27 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
28 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
29 #define get_entity_type(ent) _get_entity_type(ent)
30 #define get_entity_linkage(ent) _get_entity_linkage(ent)
31 #define get_entity_volatility(ent) _get_entity_volatility(ent)
32 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
33 #define set_entity_alignment(ent, alignment) _set_entity_alignment(ent, alignment)
34 #define get_entity_alignment(ent) _get_entity_alignment(ent)
35 #define get_entity_align(ent) _get_entity_align(ent)
36 #define set_entity_align(ent, a) _set_entity_align(ent, a)
37 #define is_entity_compiler_generated(ent) _is_entity_compiler_generated(ent)
38 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
39 #define get_entity_usage(ent) _get_entity_usage(ent)
40 #define set_entity_usage(ent, flags) _set_entity_usage(ent, flags)
41 #define get_entity_offset(ent) _get_entity_offset(ent)
42 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
43 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
44 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
45 #define get_entity_link(ent) _get_entity_link(ent)
46 #define set_entity_link(ent, l) _set_entity_link(ent, l)
47 #define get_entity_irg(ent) _get_entity_irg(ent)
48 #define is_parameter_entity(ent) _is_parameter_entity(ent)
49 #define get_entity_parameter_number(ent) _get_entity_parameter_number(ent)
50 #define get_entity_visited(ent) _get_entity_visited(ent)
51 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
52 #define mark_entity_visited(ent) _mark_entity_visited(ent)
53 #define entity_visited(ent) _entity_visited(ent)
54 #define entity_not_visited(ent) _entity_not_visited(ent)
55 #define get_entity_dbg_info(ent) _get_entity_dbg_info(ent)
56 #define set_entity_dbg_info(ent, db) _set_entity_dbg_info(ent, db)
58 typedef struct ir_initializer_base_t {
59 ir_initializer_kind_t kind;
60 } ir_initializer_base_t;
63 * An compound initializer.
65 typedef struct ir_initializer_compound_t {
66 ir_initializer_base_t base;
67 size_t n_initializers;
68 ir_initializer_t *initializers[1];
69 } ir_initializer_compound_t;
72 * An initializer containing an ir_node,
74 typedef struct ir_initializer_const_t {
75 ir_initializer_base_t base;
77 } ir_initializer_const_t ;
80 * An initializer containing a tarval.
82 typedef struct ir_initializer_tarval_t {
83 ir_initializer_base_t base;
85 } ir_initializer_tarval_t ;
87 union ir_initializer_t {
88 ir_initializer_kind_t kind;
89 ir_initializer_base_t base;
90 ir_initializer_compound_t compound;
91 ir_initializer_const_t consti;
92 ir_initializer_tarval_t tarval;
95 /** The attributes for methods. */
96 typedef struct method_ent_attr {
97 ir_graph *irg; /**< The corresponding irg if known.
98 The ir_graph constructor automatically sets this field. */
99 mtp_additional_properties properties; /**< Additional graph properties can be
100 stored in a entity if no irg is available. */
102 unsigned vtable_number; /**< For a dynamically called method, the number assigned
103 in the virtual function table. */
105 ptr_access_kind *param_access; /**< the parameter access */
106 unsigned *param_weight; /**< The weight of method's parameters. Parameters
107 with a high weight are good candidates for procedure cloning. */
110 /** additional attributes for code entities */
111 typedef struct code_ent_attr {
112 ir_label_t label; /** label of the basic block */
115 typedef struct parameter_ent_attr {
116 size_t number; /**< corresponding parameter number */
117 ir_mode *doubleword_low_mode;/**< entity is a lowered doubleword parameter,
118 so additional stores because of calling
119 convention are correctly performed.
120 Matze: This is a hack. In an ideal
121 wor^H^H^Hlibfirm we would first establish
122 calling conventions and then perform doubleword
124 } parameter_ent_attr;
126 typedef enum ir_entity_kind {
129 IR_ENTITY_COMPOUND_MEMBER,
136 * An abstract data type to represent program entities.
139 firm_kind kind; /**< The dynamic type tag for entity. */
140 ident *name; /**< The name of this entity. */
141 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
142 name. May be NULL to indicate that a default
143 mangling based on the name should happen */
144 ir_type *type; /**< The type of this entity */
145 ir_type *owner; /**< The compound type (e.g. class type) this
146 entity belongs to. */
147 unsigned entity_kind:3; /**< entity kind */
148 unsigned linkage:10; /**< Specifies linkage type */
149 unsigned volatility:1; /**< Specifies volatility of entities content.*/
150 unsigned aligned:1; /**< Specifies alignment of entities content. */
151 unsigned usage:4; /**< flag indicating usage types of this entity,
152 see ir_entity_usage. */
153 unsigned compiler_gen:1; /**< If set, this entity was compiler generated.
155 unsigned visibility:3; /**< @deprecated */
156 unsigned allocation:3; /**< @deprecated */
157 unsigned peculiarity:3; /**< @deprecated */
158 unsigned final:1; /**< @deprecated */
159 unsigned offset_bit_remainder:8;
160 /**< If the entity is a bit field, this is the
161 offset of the start of the bit field
162 within the byte specified by offset. */
163 int offset; /**< Offset in bytes for this entity. Fixed
164 when layout of owner is determined. */
165 unsigned alignment; /**< entity alignment in bytes */
166 ir_visited_t visit; /**< visited counter for walks of the type
168 struct dbg_info *dbi; /**< A pointer to information for debug support. */
169 void *link; /**< To store some intermediate information. */
171 ir_entity **overwrites; /**< A list of entities this entity overwrites. */
172 ir_entity **overwrittenby; /**< A list of entities that overwrite this
175 ir_initializer_t *initializer; /**< entity initializer */
177 long nr; /**< A unique node number for each node to make output
182 /* ------------- fields for method entities ---------------- */
183 method_ent_attr mtd_attr;
184 /* fields for code entities */
185 code_ent_attr code_attr;
186 /** parameter number for parameter entities */
187 parameter_ent_attr parameter;
188 } attr; /**< type specific attributes */
191 /** Initialize the entity module. */
192 void ir_init_entity(ir_prog *irp);
193 /** Cleanup entity module */
194 void ir_finish_entity(ir_prog *irp);
197 * Creates an entity corresponding to the start address of a basic block
198 * (the basic block is marked with a label id).
200 ir_entity *new_label_entity(ir_label_t label);
203 * Like new_label_entity() but with debug information.
205 ir_entity *new_d_label_entity(ir_label_t label, dbg_info *dbgi);
207 void set_entity_irg(ir_entity *ent, ir_graph *irg);
209 /* ----------------------- inline functions ------------------------ */
210 static inline int _is_entity(const void *thing)
212 return get_kind(thing) == k_entity;
215 static inline ident *_get_entity_ident(const ir_entity *ent)
217 assert(ent->kind == k_entity);
221 static inline const char *_get_entity_name(const ir_entity *ent)
223 assert(ent->kind == k_entity);
224 return get_id_str(get_entity_ident(ent));
227 static inline void _set_entity_ident(ir_entity *ent, ident *id)
229 assert(ent->kind == k_entity);
233 static inline ir_type *_get_entity_owner(const ir_entity *ent)
235 assert(ent->kind == k_entity);
239 static inline ident *_get_entity_ld_ident(const ir_entity *ent)
241 assert(ent->kind == k_entity);
242 if (ent->ld_name == NULL)
247 static inline void _set_entity_ld_ident(ir_entity *ent, ident *ld_ident)
249 assert(ent->kind == k_entity);
250 ent->ld_name = ld_ident;
253 static inline const char *_get_entity_ld_name(const ir_entity *ent)
255 assert(ent->kind == k_entity);
256 return get_id_str(get_entity_ld_ident(ent));
259 static inline ir_type *_get_entity_type(const ir_entity *ent)
261 assert(ent->kind == k_entity);
265 static inline ir_linkage _get_entity_linkage(const ir_entity *ent)
267 assert(ent->kind == k_entity);
268 return (ir_linkage) ent->linkage;
271 static inline ir_volatility _get_entity_volatility(const ir_entity *ent)
273 assert(ent->kind == k_entity);
274 return (ir_volatility) ent->volatility;
277 static inline void _set_entity_volatility(ir_entity *ent, ir_volatility vol)
279 assert(ent->kind == k_entity);
280 ent->volatility = vol;
283 static inline unsigned _get_entity_alignment(const ir_entity *ent)
285 assert(ent->kind == k_entity);
286 return ent->alignment;
289 static inline void _set_entity_alignment(ir_entity *ent, unsigned alignment)
291 assert(ent->kind == k_entity);
292 ent->alignment = alignment;
295 static inline ir_align _get_entity_aligned(const ir_entity *ent)
297 assert(ent->kind == k_entity);
298 return (ir_align) ent->aligned;
301 static inline void _set_entity_aligned(ir_entity *ent, ir_align a)
303 assert(ent->kind == k_entity);
307 static inline int _is_entity_compiler_generated(const ir_entity *ent)
309 assert(ent->kind == k_entity);
310 return ent->compiler_gen;
313 static inline void _set_entity_compiler_generated(ir_entity *ent, int flag)
315 assert(ent->kind == k_entity);
316 ent->compiler_gen = flag ? 1 : 0;
319 static inline ir_entity_usage _get_entity_usage(const ir_entity *ent)
321 assert(ent->kind == k_entity);
322 return (ir_entity_usage) ent->usage;
325 static inline void _set_entity_usage(ir_entity *ent, ir_entity_usage state)
327 assert(ent->kind == k_entity);
331 static inline int _get_entity_offset(const ir_entity *ent)
333 assert(ent->kind == k_entity);
337 static inline void _set_entity_offset(ir_entity *ent, int offset)
339 assert(ent->kind == k_entity);
340 ent->offset = offset;
343 static inline unsigned char _get_entity_offset_bits_remainder(const ir_entity *ent)
345 assert(ent->kind == k_entity);
346 return ent->offset_bit_remainder;
349 static inline void _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset)
351 assert(ent->kind == k_entity);
352 ent->offset_bit_remainder = offset;
355 static inline void *_get_entity_link(const ir_entity *ent)
357 assert(ent->kind == k_entity);
361 static inline void _set_entity_link(ir_entity *ent, void *l)
363 assert(ent->kind == k_entity);
367 static inline ir_graph *_get_entity_irg(const ir_entity *ent)
369 assert(ent->kind == k_entity);
370 if (!is_Method_type(ent->type) || is_unknown_entity(ent)) {
374 return ent->attr.mtd_attr.irg;
377 static inline ir_visited_t _get_entity_visited(const ir_entity *ent)
379 assert(ent->kind == k_entity);
383 static inline void _set_entity_visited(ir_entity *ent, ir_visited_t num)
385 assert(ent->kind == k_entity);
389 static inline void _mark_entity_visited(ir_entity *ent)
391 assert(ent->kind == k_entity);
392 ent->visit = firm_type_visited;
395 static inline int _entity_visited(const ir_entity *ent)
397 return _get_entity_visited(ent) >= firm_type_visited;
400 static inline int _entity_not_visited(const ir_entity *ent)
402 return _get_entity_visited(ent) < firm_type_visited;
405 static inline int _is_parameter_entity(const ir_entity *entity)
407 return entity->entity_kind == IR_ENTITY_PARAMETER;
410 static inline size_t _get_entity_parameter_number(const ir_entity *entity)
412 assert(entity->entity_kind == IR_ENTITY_PARAMETER);
413 return entity->attr.parameter.number;
416 static inline dbg_info *_get_entity_dbg_info(const ir_entity *ent)
421 static inline void _set_entity_dbg_info(ir_entity *ent, dbg_info *db)