2 * Copyright (C) 1995-2011 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
25 #ifndef FIRM_TR_ENTITY_T_H
26 #define FIRM_TR_ENTITY_T_H
34 #include "compound_path.h"
36 typedef struct ir_initializer_base_t {
37 ir_initializer_kind_t kind;
38 } ir_initializer_base_t;
41 * An compound initializer.
43 typedef struct ir_initializer_compound_t {
44 ir_initializer_base_t base;
45 size_t n_initializers;
46 ir_initializer_t *initializers[1];
47 } ir_initializer_compound_t;
50 * An initializer containing an ir_node,
52 typedef struct ir_initializer_const_t {
53 ir_initializer_base_t base;
55 } ir_initializer_const_t ;
58 * An initializer containing a tarval.
60 typedef struct ir_initializer_tarval_t {
61 ir_initializer_base_t base;
63 } ir_initializer_tarval_t ;
65 union ir_initializer_t {
66 ir_initializer_kind_t kind;
67 ir_initializer_base_t base;
68 ir_initializer_compound_t compound;
69 ir_initializer_const_t consti;
70 ir_initializer_tarval_t tarval;
73 /** The attributes for compound entities. */
74 typedef struct compound_ent_attr {
75 ir_node **values; /**< constant values of compound entities. */
76 compound_graph_path **val_paths;
77 /**< paths corresponding to constant values. */
80 /** The attributes for methods. */
81 typedef struct method_ent_attr {
82 ir_graph *irg; /**< The corresponding irg if known.
83 The ir_graph constructor automatically sets this field. */
84 mtp_additional_properties irg_add_properties; /**< Additional graph properties can be
85 stored in a entity if no irg is available. */
87 unsigned vtable_number; /**< For a dynamically called method, the number assigned
88 in the virtual function table. */
90 ptr_access_kind *param_access; /**< the parameter access */
91 unsigned *param_weight; /**< The weight of method's parameters. Parameters
92 with a high weight are good candidates for procedure cloning. */
95 /** additional attributes for code entities */
96 typedef struct code_ent_attr {
97 ir_label_t label; /** label of the basic block */
100 typedef struct parameter_ent_attr {
101 /**< parameters might be compounds too */
102 compound_ent_attr cmpd_attr;
104 size_t number; /**< corresponding parameter number */
105 ir_mode *doubleword_low_mode;/**< entity is a lowered doubleword parameter,
106 so additional stores because of calling
107 convention are correctly performed.
108 Matze: This is a hack. In an ideal
109 wor^H^H^Hlibfirm we would first establish
110 calling conventions and then perform doubleword
112 } parameter_ent_attr;
114 typedef enum ir_entity_kind {
117 IR_ENTITY_COMPOUND_MEMBER,
124 * An abstract data type to represent program entities.
127 firm_kind kind; /**< The dynamic type tag for entity. */
128 ident *name; /**< The name of this entity. */
129 ident *ld_name; /**< Unique name of this entity, i.e., the mangled
130 name. May be NULL to indicate that a default
131 mangling based on the name should happen */
132 ir_type *type; /**< The type of this entity */
133 ir_type *owner; /**< The compound type (e.g. class type) this
134 entity belongs to. */
135 unsigned entity_kind:3; /**< entity kind */
136 unsigned linkage:10; /**< Specifies linkage type */
137 unsigned volatility:1; /**< Specifies volatility of entities content.*/
138 unsigned aligned:1; /**< Specifies alignment of entities content. */
139 unsigned usage:4; /**< flag indicating usage types of this entity,
140 see ir_entity_usage. */
141 unsigned compiler_gen:1; /**< If set, this entity was compiler generated.
143 unsigned visibility:3; /**< @deprecated */
144 unsigned allocation:3; /**< @deprecated */
145 unsigned peculiarity:3; /**< @deprecated */
146 unsigned final:1; /**< @deprecated */
147 unsigned offset_bit_remainder:8;
148 /**< If the entity is a bit field, this is the
149 offset of the start of the bit field
150 within the byte specified by offset. */
151 int offset; /**< Offset in bytes for this entity. Fixed
152 when layout of owner is determined. */
153 unsigned alignment; /**< entity alignment in bytes */
154 ir_visited_t visit; /**< visited counter for walks of the type
156 struct dbg_info *dbi; /**< A pointer to information for debug support. */
157 void *link; /**< To store some intermediate information. */
158 ir_type *repr_class; /**< If this entity represents a class info, the
161 ir_entity **overwrites; /**< A list of entities this entity overwrites. */
162 ir_entity **overwrittenby; /**< A list of entities that overwrite this
165 ir_initializer_t *initializer; /**< entity initializer */
167 long nr; /**< A unique node number for each node to make output
172 /* ------------- fields for compound entities -------------- */
173 compound_ent_attr cmpd_attr;
174 /* ------------- fields for method entities ---------------- */
175 method_ent_attr mtd_attr;
176 /* fields for code entities */
177 code_ent_attr code_attr;
178 /** parameter number for parameter entities */
179 parameter_ent_attr parameter;
180 } attr; /**< type specific attributes */
183 /** Initialize the entity module. */
184 void ir_init_entity(void);
185 /** Cleanup entity module */
186 void ir_finish_entity(void);
189 * Creates an entity corresponding to the start address of a basic block
190 * (the basic block is marked with a label id).
192 ir_entity *new_label_entity(ir_label_t label);
195 * Like new_label_entity() but with debug information.
197 ir_entity *new_d_label_entity(ir_label_t label, dbg_info *dbgi);
199 void set_entity_irg(ir_entity *ent, ir_graph *irg);
201 /* ----------------------- inline functions ------------------------ */
202 static inline int _is_entity(const void *thing)
204 return get_kind(thing) == k_entity;
207 static inline const char *_get_entity_name(const ir_entity *ent)
209 assert(ent && ent->kind == k_entity);
210 return get_id_str(get_entity_ident(ent));
213 static inline ident *_get_entity_ident(const ir_entity *ent)
215 assert(ent && ent->kind == k_entity);
219 static inline void _set_entity_ident(ir_entity *ent, ident *id)
221 assert(ent && ent->kind == k_entity);
225 static inline ir_type *_get_entity_owner(const ir_entity *ent)
227 assert(ent && ent->kind == k_entity);
231 static inline ident *_get_entity_ld_ident(const ir_entity *ent)
233 assert(ent && ent->kind == k_entity);
234 if (ent->ld_name == NULL)
239 static inline void _set_entity_ld_ident(ir_entity *ent, ident *ld_ident)
241 assert(ent && ent->kind == k_entity);
242 ent->ld_name = ld_ident;
245 static inline const char *_get_entity_ld_name(const ir_entity *ent)
247 assert(ent && ent->kind == k_entity);
248 return get_id_str(get_entity_ld_ident(ent));
251 static inline ir_type *_get_entity_type(const ir_entity *ent)
253 assert(ent && ent->kind == k_entity);
257 static inline ir_linkage _get_entity_linkage(const ir_entity *ent)
259 assert(ent && ent->kind == k_entity);
260 return (ir_linkage) ent->linkage;
263 static inline ir_volatility _get_entity_volatility(const ir_entity *ent)
265 assert(ent && ent->kind == k_entity);
266 return (ir_volatility) ent->volatility;
269 static inline void _set_entity_volatility(ir_entity *ent, ir_volatility vol)
271 assert(ent && ent->kind == k_entity);
272 ent->volatility = vol;
275 static inline unsigned _get_entity_alignment(const ir_entity *ent)
277 assert(ent && ent->kind == k_entity);
278 return ent->alignment;
281 static inline void _set_entity_alignment(ir_entity *ent, unsigned alignment)
283 assert(ent && ent->kind == k_entity);
284 ent->alignment = alignment;
287 static inline ir_align _get_entity_aligned(const ir_entity *ent)
289 assert(ent && ent->kind == k_entity);
290 return (ir_align) ent->aligned;
293 static inline void _set_entity_aligned(ir_entity *ent, ir_align a)
295 assert(ent && ent->kind == k_entity);
299 static inline int _is_entity_compiler_generated(const ir_entity *ent)
301 assert(ent && ent->kind == k_entity);
302 return ent->compiler_gen;
305 static inline void _set_entity_compiler_generated(ir_entity *ent, int flag)
307 assert(ent && ent->kind == k_entity);
308 ent->compiler_gen = flag ? 1 : 0;
311 static inline ir_entity_usage _get_entity_usage(const ir_entity *ent)
313 assert(ent && ent->kind == k_entity);
314 return (ir_entity_usage) ent->usage;
317 static inline void _set_entity_usage(ir_entity *ent, ir_entity_usage state)
319 assert(ent && ent->kind == k_entity);
323 static inline int _get_entity_offset(const ir_entity *ent)
325 assert(ent && ent->kind == k_entity);
329 static inline void _set_entity_offset(ir_entity *ent, int offset)
331 assert(ent && ent->kind == k_entity);
332 ent->offset = offset;
335 static inline unsigned char _get_entity_offset_bits_remainder(const ir_entity *ent)
337 assert(ent && ent->kind == k_entity);
338 return ent->offset_bit_remainder;
341 static inline void _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset)
343 assert(ent && ent->kind == k_entity);
344 ent->offset_bit_remainder = offset;
347 static inline void *_get_entity_link(const ir_entity *ent)
349 assert(ent && ent->kind == k_entity);
353 static inline void _set_entity_link(ir_entity *ent, void *l)
355 assert(ent && ent->kind == k_entity);
359 static inline ir_graph *_get_entity_irg(const ir_entity *ent)
361 assert(ent && ent->kind == k_entity);
362 if (!is_Method_type(ent->type) || ent == unknown_entity) {
366 return ent->attr.mtd_attr.irg;
369 static inline ir_visited_t _get_entity_visited(const ir_entity *ent)
371 assert(ent && ent->kind == k_entity);
375 static inline void _set_entity_visited(ir_entity *ent, ir_visited_t num)
377 assert(ent && ent->kind == k_entity);
381 static inline void _mark_entity_visited(ir_entity *ent)
383 assert(ent && ent->kind == k_entity);
384 ent->visit = firm_type_visited;
387 static inline int _entity_visited(const ir_entity *ent)
389 return _get_entity_visited(ent) >= firm_type_visited;
392 static inline int _entity_not_visited(const ir_entity *ent)
394 return _get_entity_visited(ent) < firm_type_visited;
397 static inline int _is_parameter_entity(const ir_entity *entity)
399 return entity->entity_kind == IR_ENTITY_PARAMETER;
402 static inline size_t _get_entity_parameter_number(const ir_entity *entity)
404 assert(entity->entity_kind == IR_ENTITY_PARAMETER);
405 return entity->attr.parameter.number;
408 static inline ir_type *_get_entity_repr_class(const ir_entity *ent)
410 assert(ent && ent->kind == k_entity);
411 return ent->repr_class;
414 static inline dbg_info *_get_entity_dbg_info(const ir_entity *ent)
419 static inline void _set_entity_dbg_info(ir_entity *ent, dbg_info *db)
424 #define is_entity(thing) _is_entity(thing)
425 #define get_entity_name(ent) _get_entity_name(ent)
426 #define get_entity_ident(ent) _get_entity_ident(ent)
427 #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
428 #define get_entity_owner(ent) _get_entity_owner(ent)
429 #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
430 #define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
431 #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
432 #define get_entity_type(ent) _get_entity_type(ent)
433 #define get_entity_linkage(ent) _get_entity_linkage(ent)
434 #define get_entity_volatility(ent) _get_entity_volatility(ent)
435 #define set_entity_volatility(ent, vol) _set_entity_volatility(ent, vol)
436 #define set_entity_alignment(ent, alignment) _set_entity_alignment(ent, alignment)
437 #define get_entity_alignment(ent) _get_entity_alignment(ent)
438 #define get_entity_align(ent) _get_entity_align(ent)
439 #define set_entity_align(ent, a) _set_entity_align(ent, a)
440 #define is_entity_compiler_generated(ent) _is_entity_compiler_generated(ent)
441 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
442 #define get_entity_usage(ent) _get_entity_usage(ent)
443 #define set_entity_usage(ent, flags) _set_entity_usage(ent, flags)
444 #define get_entity_offset(ent) _get_entity_offset(ent)
445 #define set_entity_offset(ent, offset) _set_entity_offset(ent, offset)
446 #define get_entity_offset_bits_remainder(ent) _get_entity_offset_bits_remainder(ent)
447 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
448 #define get_entity_link(ent) _get_entity_link(ent)
449 #define set_entity_link(ent, l) _set_entity_link(ent, l)
450 #define get_entity_irg(ent) _get_entity_irg(ent)
451 #define is_parameter_entity(ent) _is_parameter_entity(ent)
452 #define get_entity_parameter_number(ent) _get_entity_parameter_number(ent)
453 #define get_entity_visited(ent) _get_entity_visited(ent)
454 #define set_entity_visited(ent, num) _set_entity_visited(ent, num)
455 #define mark_entity_visited(ent) _mark_entity_visited(ent)
456 #define entity_visited(ent) _entity_visited(ent)
457 #define entity_not_visited(ent) _entity_not_visited(ent)
458 #define get_entity_repr_class(ent) _get_entity_repr_class(ent)
459 #define get_entity_dbg_info(ent) _get_entity_dbg_info(ent)
460 #define set_entity_dbg_info(ent, db) _set_entity_dbg_info(ent, db)