bearch: Dump the output requirement and the assigned register in the same line for...
[libfirm] / ir / tr / entity_t.h
1 /*
2  * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /*
21  * @file
22  * @brief   Representation of all program known entities -- private header.
23  * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
24  */
25 #ifndef FIRM_TR_ENTITY_T_H
26 #define FIRM_TR_ENTITY_T_H
27
28 #include <assert.h>
29 #include <stdbool.h>
30
31 #include "typerep.h"
32 #include "type_t.h"
33 #include "ident.h"
34
35 #define is_entity(thing)                         _is_entity(thing)
36 #define get_entity_name(ent)                     _get_entity_name(ent)
37 #define get_entity_ident(ent)                    _get_entity_ident(ent)
38 #define set_entity_ident(ent, id)                _set_entity_ident(ent, id)
39 #define get_entity_owner(ent)                    _get_entity_owner(ent)
40 #define get_entity_ld_ident(ent)                 _get_entity_ld_ident(ent)
41 #define set_entity_ld_ident(ent, ld_ident)       _set_entity_ld_ident(ent, ld_ident)
42 #define get_entity_ld_name(ent)                  _get_entity_ld_name(ent)
43 #define get_entity_type(ent)                     _get_entity_type(ent)
44 #define get_entity_linkage(ent)                  _get_entity_linkage(ent)
45 #define get_entity_volatility(ent)               _get_entity_volatility(ent)
46 #define set_entity_volatility(ent, vol)          _set_entity_volatility(ent, vol)
47 #define set_entity_alignment(ent, alignment)     _set_entity_alignment(ent, alignment)
48 #define get_entity_alignment(ent)                _get_entity_alignment(ent)
49 #define get_entity_align(ent)                    _get_entity_align(ent)
50 #define set_entity_align(ent, a)                 _set_entity_align(ent, a)
51 #define is_entity_compiler_generated(ent)        _is_entity_compiler_generated(ent)
52 #define set_entity_compiler_generated(ent, flag) _set_entity_compiler_generated(ent, flag)
53 #define get_entity_usage(ent)                    _get_entity_usage(ent)
54 #define set_entity_usage(ent, flags)             _set_entity_usage(ent, flags)
55 #define get_entity_offset(ent)                   _get_entity_offset(ent)
56 #define set_entity_offset(ent, offset)           _set_entity_offset(ent, offset)
57 #define get_entity_offset_bits_remainder(ent)    _get_entity_offset_bits_remainder(ent)
58 #define set_entity_offset_bits_remainder(ent, o) _set_entity_offset_bits_remainder(ent, o)
59 #define get_entity_link(ent)                     _get_entity_link(ent)
60 #define set_entity_link(ent, l)                  _set_entity_link(ent, l)
61 #define get_entity_irg(ent)                      _get_entity_irg(ent)
62 #define is_parameter_entity(ent)                 _is_parameter_entity(ent)
63 #define get_entity_parameter_number(ent)         _get_entity_parameter_number(ent)
64 #define get_entity_visited(ent)                  _get_entity_visited(ent)
65 #define set_entity_visited(ent, num)             _set_entity_visited(ent, num)
66 #define mark_entity_visited(ent)                 _mark_entity_visited(ent)
67 #define entity_visited(ent)                      _entity_visited(ent)
68 #define entity_not_visited(ent)                  _entity_not_visited(ent)
69 #define get_entity_repr_class(ent)               _get_entity_repr_class(ent)
70 #define get_entity_dbg_info(ent)                 _get_entity_dbg_info(ent)
71 #define set_entity_dbg_info(ent, db)             _set_entity_dbg_info(ent, db)
72
73 typedef struct ir_initializer_base_t {
74         ir_initializer_kind_t kind;
75 } ir_initializer_base_t;
76
77 /**
78  * An compound initializer.
79  */
80 typedef struct ir_initializer_compound_t {
81         ir_initializer_base_t  base;
82         size_t                 n_initializers;
83         ir_initializer_t      *initializers[1];
84 } ir_initializer_compound_t;
85
86 /**
87  * An initializer containing an ir_node,
88  */
89 typedef struct ir_initializer_const_t {
90         ir_initializer_base_t  base;
91         ir_node               *value;
92 } ir_initializer_const_t ;
93
94 /**
95  * An initializer containing a tarval.
96  */
97 typedef struct ir_initializer_tarval_t {
98         ir_initializer_base_t  base;
99         ir_tarval             *value;
100 } ir_initializer_tarval_t ;
101
102 union ir_initializer_t {
103         ir_initializer_kind_t      kind;
104         ir_initializer_base_t      base;
105         ir_initializer_compound_t  compound;
106         ir_initializer_const_t     consti;
107         ir_initializer_tarval_t    tarval;
108 };
109
110 /** The attributes for methods. */
111 typedef struct method_ent_attr {
112         ir_graph *irg;                 /**< The corresponding irg if known.
113                                             The ir_graph constructor automatically sets this field. */
114         mtp_additional_properties properties;   /**< Additional graph properties can be
115                                             stored in a entity if no irg is available. */
116
117         unsigned vtable_number;        /**< For a dynamically called method, the number assigned
118                                             in the virtual function table. */
119
120         ptr_access_kind *param_access; /**< the parameter access */
121         unsigned *param_weight;        /**< The weight of method's parameters. Parameters
122                                             with a high weight are good candidates for procedure cloning. */
123 } method_ent_attr;
124
125 /** additional attributes for code entities */
126 typedef struct code_ent_attr {
127         ir_label_t  label;       /** label of the basic block */
128 } code_ent_attr;
129
130 typedef struct parameter_ent_attr {
131         size_t   number; /**< corresponding parameter number */
132         ir_mode *doubleword_low_mode;/**< entity is a lowered doubleword parameter,
133                                                                 so additional stores because of calling
134                                                                 convention are correctly performed.
135                                     Matze: This is a hack. In an ideal
136                                     wor^H^H^Hlibfirm we would first establish
137                                     calling conventions and then perform doubleword
138                                     lowering...) */
139 } parameter_ent_attr;
140
141 typedef enum ir_entity_kind {
142         IR_ENTITY_NORMAL,
143         IR_ENTITY_METHOD,
144         IR_ENTITY_COMPOUND_MEMBER,
145         IR_ENTITY_PARAMETER,
146         IR_ENTITY_LABEL,
147         IR_ENTITY_UNKNOWN,
148 } ir_entity_kind;
149
150 /**
151  * An abstract data type to represent program entities.
152  */
153 struct ir_entity {
154         firm_kind kind;          /**< The dynamic type tag for entity. */
155         ident *name;             /**< The name of this entity. */
156         ident *ld_name;          /**< Unique name of this entity, i.e., the mangled
157                                       name. May be NULL to indicate that a default
158                                       mangling based on the name should happen */
159         ir_type *type;           /**< The type of this entity */
160         ir_type *owner;          /**< The compound type (e.g. class type) this
161                                                               entity belongs to. */
162         unsigned entity_kind:3;  /**< entity kind */
163         unsigned linkage:10;     /**< Specifies linkage type */
164         unsigned volatility:1;   /**< Specifies volatility of entities content.*/
165         unsigned aligned:1;      /**< Specifies alignment of entities content. */
166         unsigned usage:4;        /**< flag indicating usage types of this entity,
167                                       see ir_entity_usage. */
168         unsigned compiler_gen:1; /**< If set, this entity was compiler generated.
169                                   */
170         unsigned visibility:3;   /**< @deprecated */
171         unsigned allocation:3;   /**< @deprecated */
172         unsigned peculiarity:3;  /**< @deprecated */
173         unsigned final:1;        /**< @deprecated */
174         unsigned offset_bit_remainder:8;
175                                  /**< If the entity is a bit field, this is the
176                                       offset of the start of the bit field
177                                       within the byte specified by offset. */
178         int offset;              /**< Offset in bytes for this entity. Fixed
179                                       when layout of owner is determined. */
180         unsigned alignment;      /**< entity alignment in bytes */
181         ir_visited_t visit;      /**< visited counter for walks of the type
182                                       information. */
183         struct dbg_info *dbi;    /**< A pointer to information for debug support. */
184         void *link;              /**< To store some intermediate information. */
185         ir_type *repr_class;     /**< If this entity represents a class info, the
186                                       associated class. */
187
188         ir_entity **overwrites;  /**< A list of entities this entity overwrites. */
189         ir_entity **overwrittenby; /**< A list of entities that overwrite this
190                                         entity. */
191
192         ir_initializer_t *initializer; /**< entity initializer */
193 #ifdef DEBUG_libfirm
194         long nr;             /**< A unique node number for each node to make output
195                                   readable. */
196 #endif
197
198         union {
199                 /* ------------- fields for method entities ---------------- */
200                 method_ent_attr    mtd_attr;
201                 /* fields for code entities */
202                 code_ent_attr      code_attr;
203                 /** parameter number for parameter entities */
204                 parameter_ent_attr parameter;
205         } attr; /**< type specific attributes */
206 };
207
208 /** Initialize the entity module. */
209 void ir_init_entity(ir_prog *irp);
210 /** Cleanup entity module */
211 void ir_finish_entity(ir_prog *irp);
212
213 /**
214  * Creates an entity corresponding to the start address of a basic block
215  * (the basic block is marked with a label id).
216  */
217 ir_entity *new_label_entity(ir_label_t label);
218
219 /**
220  * Like new_label_entity() but with debug information.
221  */
222 ir_entity *new_d_label_entity(ir_label_t label, dbg_info *dbgi);
223
224 void set_entity_irg(ir_entity *ent, ir_graph *irg);
225
226 /* ----------------------- inline functions ------------------------ */
227 static inline int _is_entity(const void *thing)
228 {
229         return get_kind(thing) == k_entity;
230 }
231
232 static inline ident *_get_entity_ident(const ir_entity *ent)
233 {
234         assert(ent->kind == k_entity);
235         return ent->name;
236 }
237
238 static inline const char *_get_entity_name(const ir_entity *ent)
239 {
240         assert(ent->kind == k_entity);
241         return get_id_str(get_entity_ident(ent));
242 }
243
244 static inline void _set_entity_ident(ir_entity *ent, ident *id)
245 {
246         assert(ent->kind == k_entity);
247         ent->name = id;
248 }
249
250 static inline ir_type *_get_entity_owner(const ir_entity *ent)
251 {
252         assert(ent->kind == k_entity);
253         return ent->owner;
254 }
255
256 static inline ident *_get_entity_ld_ident(const ir_entity *ent)
257 {
258         assert(ent->kind == k_entity);
259         if (ent->ld_name == NULL)
260                 return ent->name;
261         return ent->ld_name;
262 }
263
264 static inline void _set_entity_ld_ident(ir_entity *ent, ident *ld_ident)
265 {
266         assert(ent->kind == k_entity);
267         ent->ld_name = ld_ident;
268 }
269
270 static inline const char *_get_entity_ld_name(const ir_entity *ent)
271 {
272         assert(ent->kind == k_entity);
273         return get_id_str(get_entity_ld_ident(ent));
274 }
275
276 static inline ir_type *_get_entity_type(const ir_entity *ent)
277 {
278         assert(ent->kind == k_entity);
279         return ent->type;
280 }
281
282 static inline ir_linkage _get_entity_linkage(const ir_entity *ent)
283 {
284         assert(ent->kind == k_entity);
285         return (ir_linkage) ent->linkage;
286 }
287
288 static inline ir_volatility _get_entity_volatility(const ir_entity *ent)
289 {
290         assert(ent->kind == k_entity);
291         return (ir_volatility) ent->volatility;
292 }
293
294 static inline void _set_entity_volatility(ir_entity *ent, ir_volatility vol)
295 {
296         assert(ent->kind == k_entity);
297         ent->volatility = vol;
298 }
299
300 static inline unsigned _get_entity_alignment(const ir_entity *ent)
301 {
302         assert(ent->kind == k_entity);
303         return ent->alignment;
304 }
305
306 static inline void _set_entity_alignment(ir_entity *ent, unsigned alignment)
307 {
308         assert(ent->kind == k_entity);
309         ent->alignment = alignment;
310 }
311
312 static inline ir_align _get_entity_aligned(const ir_entity *ent)
313 {
314         assert(ent->kind == k_entity);
315         return (ir_align) ent->aligned;
316 }
317
318 static inline void _set_entity_aligned(ir_entity *ent, ir_align a)
319 {
320         assert(ent->kind == k_entity);
321         ent->aligned = a;
322 }
323
324 static inline int _is_entity_compiler_generated(const ir_entity *ent)
325 {
326         assert(ent->kind == k_entity);
327         return ent->compiler_gen;
328 }
329
330 static inline void _set_entity_compiler_generated(ir_entity *ent, int flag)
331 {
332         assert(ent->kind == k_entity);
333         ent->compiler_gen = flag ? 1 : 0;
334 }
335
336 static inline ir_entity_usage _get_entity_usage(const ir_entity *ent)
337 {
338         assert(ent->kind == k_entity);
339         return (ir_entity_usage) ent->usage;
340 }
341
342 static inline void _set_entity_usage(ir_entity *ent, ir_entity_usage state)
343 {
344         assert(ent->kind == k_entity);
345         ent->usage = state;
346 }
347
348 static inline int _get_entity_offset(const ir_entity *ent)
349 {
350         assert(ent->kind == k_entity);
351         return ent->offset;
352 }
353
354 static inline void _set_entity_offset(ir_entity *ent, int offset)
355 {
356         assert(ent->kind == k_entity);
357         ent->offset = offset;
358 }
359
360 static inline unsigned char _get_entity_offset_bits_remainder(const ir_entity *ent)
361 {
362         assert(ent->kind == k_entity);
363         return ent->offset_bit_remainder;
364 }
365
366 static inline void _set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset)
367 {
368         assert(ent->kind == k_entity);
369         ent->offset_bit_remainder = offset;
370 }
371
372 static inline void *_get_entity_link(const ir_entity *ent)
373 {
374         assert(ent->kind == k_entity);
375         return ent->link;
376 }
377
378 static inline void _set_entity_link(ir_entity *ent, void *l)
379 {
380         assert(ent->kind == k_entity);
381         ent->link = l;
382 }
383
384 static inline ir_graph *_get_entity_irg(const ir_entity *ent)
385 {
386         assert(ent->kind == k_entity);
387         if (!is_Method_type(ent->type) || is_unknown_entity(ent)) {
388                 return NULL;
389         }
390
391         return ent->attr.mtd_attr.irg;
392 }
393
394 static inline ir_visited_t _get_entity_visited(const ir_entity *ent)
395 {
396         assert(ent->kind == k_entity);
397         return ent->visit;
398 }
399
400 static inline void _set_entity_visited(ir_entity *ent, ir_visited_t num)
401 {
402         assert(ent->kind == k_entity);
403         ent->visit = num;
404 }
405
406 static inline void _mark_entity_visited(ir_entity *ent)
407 {
408         assert(ent->kind == k_entity);
409         ent->visit = firm_type_visited;
410 }
411
412 static inline int _entity_visited(const ir_entity *ent)
413 {
414         return _get_entity_visited(ent) >= firm_type_visited;
415 }
416
417 static inline int _entity_not_visited(const ir_entity *ent)
418 {
419         return _get_entity_visited(ent) < firm_type_visited;
420 }
421
422 static inline int _is_parameter_entity(const ir_entity *entity)
423 {
424         return entity->entity_kind == IR_ENTITY_PARAMETER;
425 }
426
427 static inline size_t _get_entity_parameter_number(const ir_entity *entity)
428 {
429         assert(entity->entity_kind == IR_ENTITY_PARAMETER);
430         return entity->attr.parameter.number;
431 }
432
433 static inline ir_type *_get_entity_repr_class(const ir_entity *ent)
434 {
435         assert(ent->kind == k_entity);
436         return ent->repr_class;
437 }
438
439 static inline dbg_info *_get_entity_dbg_info(const ir_entity *ent)
440 {
441         return ent->dbi;
442 }
443
444 static inline void _set_entity_dbg_info(ir_entity *ent, dbg_info *db)
445 {
446         ent->dbi = db;
447 }
448
449 #endif