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.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
42 #include "irgraph_t.h"
43 #include "callgraph.h"
45 #include "compound_path.h"
47 /*-----------------------------------------------------------------*/
49 /*-----------------------------------------------------------------*/
51 ir_entity *unknown_entity = NULL;
53 ir_entity *get_unknown_entity(void) { return unknown_entity; }
55 /** The name of the unknown entity. */
56 #define UNKNOWN_ENTITY_NAME "unknown_entity"
58 /*-----------------------------------------------------------------*/
60 /*-----------------------------------------------------------------*/
62 static ir_entity *intern_new_entity(ir_type *owner, ir_entity_kind kind,
63 ident *name, ir_type *type, dbg_info *dbgi)
67 res = XMALLOCZ(ir_entity);
75 res->entity_kind = kind;
76 res->volatility = volatility_non_volatile;
77 res->aligned = align_is_aligned;
78 res->usage = ir_usage_unknown;
79 res->compiler_gen = 0;
80 res->visibility = ir_visibility_default;
82 res->offset_bit_remainder = 0;
85 res->repr_class = NULL;
87 res->nr = get_irp_new_node_nr();
90 /* Remember entity in its owner. */
92 add_compound_member(owner, res);
95 set_entity_dbg_info(res, dbgi);
100 ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *type,
105 if (is_Method_type(type)) {
106 ir_graph *irg = get_const_code_irg();
108 ir_mode *mode = is_Method_type(type) ? mode_P_code : mode_P_data;
109 res = intern_new_entity(owner, IR_ENTITY_METHOD, name, type, db);
111 set_atomic_ent_value(res, new_r_SymConst(irg, mode, sym, symconst_addr_ent));
112 res->linkage = IR_LINKAGE_CONSTANT;
113 res->attr.mtd_attr.irg_add_properties = mtp_property_inherited;
114 res->attr.mtd_attr.vtable_number = IR_VTABLE_NUM_NOT_SET;
115 res->attr.mtd_attr.param_access = NULL;
116 res->attr.mtd_attr.param_weight = NULL;
117 res->attr.mtd_attr.irg = NULL;
118 } else if (owner != NULL
119 && (is_compound_type(owner) && !(owner->flags & tf_segment))) {
120 res = intern_new_entity(owner, IR_ENTITY_COMPOUND_MEMBER, name, type, db);
121 res->attr.cmpd_attr.values = NULL;
122 res->attr.cmpd_attr.val_paths = NULL;
124 res = intern_new_entity(owner, IR_ENTITY_NORMAL, name, type, db);
127 hook_new_entity(res);
131 ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
133 return new_d_entity(owner, name, type, NULL);
136 static ident *make_parameter_entity_name(size_t pos)
139 snprintf(buf, sizeof(buf), "parameter.%lu", (unsigned long) pos);
140 return new_id_from_str(buf);
143 ir_entity *new_d_parameter_entity(ir_type *owner, size_t pos, ir_type *type,
146 ident *name = make_parameter_entity_name(pos);
148 = intern_new_entity(owner, IR_ENTITY_PARAMETER, name, type, dbgi);
149 res->attr.parameter.number = pos;
150 hook_new_entity(res);
154 ir_entity *new_parameter_entity(ir_type *owner, size_t pos, ir_type *type)
156 return new_d_parameter_entity(owner, pos, type, NULL);
159 ir_entity *new_d_label_entity(ir_label_t label, dbg_info *dbgi)
161 ident *name = id_unique("label_%u");
162 ir_type *global_type = get_glob_type();
164 = intern_new_entity(global_type, IR_ENTITY_LABEL, name, firm_code_type,
166 res->attr.code_attr.label = label;
167 hook_new_entity(res);
171 ir_entity *new_label_entity(ir_label_t label)
173 return new_d_label_entity(label, NULL);
177 * Free entity attributes.
179 * @param ent the entity
181 static void free_entity_attrs(ir_entity *ent)
183 if (ent->overwrites != NULL) {
184 DEL_ARR_F(ent->overwrites);
185 ent->overwrites = NULL;
187 if (ent->overwrittenby != NULL) {
188 DEL_ARR_F(ent->overwrittenby);
189 ent->overwrittenby = NULL;
192 if (ent->initializer != NULL) {
193 /* TODO: free initializers */
194 } else if (entity_has_compound_ent_values(ent)) {
195 /* can't free compound graph path as it might be used
197 ent->attr.cmpd_attr.val_paths = NULL;
199 if (ent->entity_kind == IR_ENTITY_COMPOUND_MEMBER) {
200 ent->attr.cmpd_attr.values = NULL;
201 } else if (ent->entity_kind == IR_ENTITY_METHOD) {
202 if (ent->attr.mtd_attr.param_access) {
203 DEL_ARR_F(ent->attr.mtd_attr.param_access);
204 ent->attr.mtd_attr.param_access = NULL;
206 if (ent->attr.mtd_attr.param_weight) {
207 DEL_ARR_F(ent->attr.mtd_attr.param_weight);
208 ent->attr.mtd_attr.param_weight = NULL;
214 * Creates a deep copy of an entity.
216 static ir_entity *deep_entity_copy(ir_entity *old)
218 ir_entity *newe = XMALLOC(ir_entity);
221 if (old->initializer != NULL) {
222 /* FIXME: the initializers are NOT copied */
223 } else if (entity_has_compound_ent_values(old)) {
224 newe->attr.cmpd_attr.values = NULL;
225 newe->attr.cmpd_attr.val_paths = NULL;
226 if (old->attr.cmpd_attr.values)
227 newe->attr.cmpd_attr.values = DUP_ARR_F(ir_node *, old->attr.cmpd_attr.values);
229 /* FIXME: the compound graph paths are NOT copied */
230 if (old->attr.cmpd_attr.val_paths)
231 newe->attr.cmpd_attr.val_paths = DUP_ARR_F(compound_graph_path *, old->attr.cmpd_attr.val_paths);
232 } else if (is_method_entity(old)) {
233 /* do NOT copy them, reanalyze. This might be the best solution */
234 newe->attr.mtd_attr.param_access = NULL;
235 newe->attr.mtd_attr.param_weight = NULL;
237 newe->overwrites = NULL;
238 newe->overwrittenby = NULL;
241 newe->nr = get_irp_new_node_nr();
243 hook_new_entity(newe);
248 * Copies the entity if the new_owner is different from the
249 * owner of the old entity, else returns the old entity.
251 ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner)
254 assert(is_entity(old));
255 assert(is_compound_type(new_owner));
256 assert(get_type_state(new_owner) != layout_fixed);
258 if (old->owner == new_owner)
261 /* create a deep copy so we are safe of aliasing and double-freeing. */
262 newe = deep_entity_copy(old);
263 newe->owner = new_owner;
264 add_compound_member(new_owner, newe);
269 ir_entity *copy_entity_name(ir_entity *old, ident *new_name)
272 assert(old && old->kind == k_entity);
274 if (old->name == new_name)
277 newe = deep_entity_copy(old);
278 newe->name = new_name;
279 newe->ld_name = NULL;
280 add_compound_member(old->owner, newe);
285 void free_entity(ir_entity *ent)
287 if (ent->owner != NULL && !is_Array_type(ent->owner))
288 remove_compound_member(ent->owner, ent);
290 assert(ent && ent->kind == k_entity);
291 free_entity_attrs(ent);
296 /* Outputs a unique number for this node */
297 long get_entity_nr(const ir_entity *ent)
299 assert(ent && ent->kind == k_entity);
303 return (long)PTR_TO_INT(ent);
307 const char *(get_entity_name)(const ir_entity *ent)
309 return _get_entity_name(ent);
312 ident *(get_entity_ident)(const ir_entity *ent)
314 return _get_entity_ident(ent);
317 void (set_entity_ident)(ir_entity *ent, ident *id)
319 _set_entity_ident(ent, id);
322 ir_type *(get_entity_owner)(const ir_entity *ent)
324 return _get_entity_owner(ent);
327 void set_entity_owner(ir_entity *ent, ir_type *owner)
329 assert(is_entity(ent));
330 assert(is_compound_type(owner));
332 remove_compound_member(ent->owner, ent);
333 add_compound_member(owner, ent);
337 ident *(get_entity_ld_ident)(const ir_entity *ent)
339 return _get_entity_ld_ident(ent);
342 void (set_entity_ld_ident)(ir_entity *ent, ident *ld_ident)
344 _set_entity_ld_ident(ent, ld_ident);
347 const char *(get_entity_ld_name)(const ir_entity *ent)
349 return _get_entity_ld_name(ent);
352 int entity_has_ld_ident(const ir_entity *entity)
354 return entity->ld_name != NULL;
357 ir_type *(get_entity_type)(const ir_entity *ent)
359 return _get_entity_type(ent);
362 void set_entity_type(ir_entity *ent, ir_type *type)
364 switch (ent->entity_kind) {
365 case IR_ENTITY_METHOD:
366 assert(is_Method_type(type));
368 case IR_ENTITY_NORMAL:
369 assert(!is_Method_type(type));
371 case IR_ENTITY_LABEL:
372 assert(type == firm_code_type);
374 case IR_ENTITY_COMPOUND_MEMBER:
380 ir_volatility (get_entity_volatility)(const ir_entity *ent)
382 return _get_entity_volatility(ent);
385 void (set_entity_volatility)(ir_entity *ent, ir_volatility vol)
387 _set_entity_volatility(ent, vol);
390 /* Return the name of the volatility. */
391 const char *get_volatility_name(ir_volatility var)
393 #define X(a) case a: return #a
395 X(volatility_non_volatile);
396 X(volatility_is_volatile);
397 default: return "BAD VALUE";
402 ir_align (get_entity_aligned)(const ir_entity *ent)
404 return _get_entity_aligned(ent);
407 void (set_entity_aligned)(ir_entity *ent, ir_align a)
409 _set_entity_aligned(ent, a);
412 unsigned (get_entity_alignment)(const ir_entity *ent)
414 return _get_entity_alignment(ent);
417 void (set_entity_alignment)(ir_entity *ent, unsigned alignment)
419 _set_entity_alignment(ent, alignment);
422 /* Return the name of the alignment. */
423 const char *get_align_name(ir_align a)
425 #define X(a) case a: return #a
427 X(align_non_aligned);
429 default: return "BAD VALUE";
434 void set_entity_label(ir_entity *ent, ir_label_t label)
436 assert(ent->entity_kind == IR_ENTITY_LABEL);
437 ent->attr.code_attr.label = label;
440 ir_label_t get_entity_label(const ir_entity *ent)
442 assert(ent->entity_kind == IR_ENTITY_LABEL);
443 return ent->attr.code_attr.label;
446 static void verify_visibility(const ir_entity *entity)
448 if (get_entity_visibility(entity) == ir_visibility_external
449 && !is_method_entity(entity)) {
450 assert(!entity_has_definition(entity));
454 void set_entity_visibility(ir_entity *entity, ir_visibility visibility)
456 entity->visibility = visibility;
457 verify_visibility(entity);
460 ir_visibility get_entity_visibility(const ir_entity *entity)
462 return (ir_visibility)entity->visibility;
465 void set_entity_linkage(ir_entity *entity, ir_linkage linkage)
467 entity->linkage = linkage;
470 ir_linkage (get_entity_linkage)(const ir_entity *entity)
472 return get_entity_linkage(entity);
475 void add_entity_linkage(ir_entity *entity, ir_linkage linkage)
477 entity->linkage |= linkage;
480 void remove_entity_linkage(ir_entity *entity, ir_linkage linkage)
482 entity->linkage &= ~linkage;
485 /* Checks if an entity is compiler generated */
486 int (is_entity_compiler_generated)(const ir_entity *ent)
488 return _is_entity_compiler_generated(ent);
491 /* Sets/resets the compiler generated flag */
492 void (set_entity_compiler_generated)(ir_entity *ent, int flag)
494 _set_entity_compiler_generated(ent, flag);
497 ir_entity_usage (get_entity_usage)(const ir_entity *ent)
499 return _get_entity_usage(ent);
502 void (set_entity_usage)(ir_entity *ent, ir_entity_usage flags)
504 _set_entity_usage(ent, flags);
507 /* Set has no effect for existent entities of type method. */
508 ir_node *get_atomic_ent_value(ir_entity *entity)
510 ir_initializer_t *initializer = get_entity_initializer(entity);
512 assert(entity && is_atomic_entity(entity));
513 if (initializer == NULL) {
514 ir_type *type = get_entity_type(entity);
515 return new_r_Unknown(get_const_code_irg(), get_type_mode(type));
518 switch (get_initializer_kind(initializer)) {
519 case IR_INITIALIZER_NULL: {
520 ir_type *type = get_entity_type(entity);
521 ir_mode *mode = get_type_mode(type);
522 return new_r_Const(get_const_code_irg(), get_mode_null(mode));
524 case IR_INITIALIZER_TARVAL: {
525 ir_tarval *tv = get_initializer_tarval_value(initializer);
526 return new_r_Const(get_const_code_irg(), tv);
528 case IR_INITIALIZER_CONST:
529 return get_initializer_const_value(initializer);
530 case IR_INITIALIZER_COMPOUND:
531 panic("compound initializer in atomic entity not allowed (%+F)", entity);
534 panic("invalid initializer kind in get_atomic_ent_value(%+F)", entity);
537 void set_atomic_ent_value(ir_entity *entity, ir_node *val)
539 ir_initializer_t *initializer;
541 assert(is_atomic_entity(entity));
543 assert(is_Dummy(val) || get_irn_mode(val) == get_type_mode(entity->type));
544 initializer = create_initializer_const(val);
545 entity->initializer = initializer;
548 /* Returns true if the the node is representable as code on
550 int is_irn_const_expression(ir_node *n)
552 /* we are in danger iff an exception will arise. TODO: be more precisely,
553 * for instance Div. will NOT rise if divisor != 0
555 if (is_binop(n) && !is_fragile_op(n))
556 return is_irn_const_expression(get_binop_left(n)) && is_irn_const_expression(get_binop_right(n));
558 switch (get_irn_opcode(n)) {
565 return is_irn_const_expression(get_irn_n(n, 0));
573 * Copies a firm subgraph that complies to the restrictions for
574 * constant expressions to block.
576 ir_node *copy_const_value(dbg_info *dbg, ir_node *n, ir_node *block)
578 ir_graph *irg = get_irn_irg(block);
582 /* @@@ GL I think we should implement this using the routines from irgopt for
583 dead node elimination/inlineing. */
586 switch (get_irn_opcode(n)) {
588 nn = new_rd_Const(dbg, irg, get_Const_tarval(n));
591 nn = new_rd_SymConst(dbg, irg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n));
594 nn = new_rd_Add(dbg, block,
595 copy_const_value(dbg, get_Add_left(n), block),
596 copy_const_value(dbg, get_Add_right(n), block), m);
599 nn = new_rd_Sub(dbg, block,
600 copy_const_value(dbg, get_Sub_left(n), block),
601 copy_const_value(dbg, get_Sub_right(n), block), m);
604 nn = new_rd_Mul(dbg, block,
605 copy_const_value(dbg, get_Mul_left(n), block),
606 copy_const_value(dbg, get_Mul_right(n), block), m);
609 nn = new_rd_And(dbg, block,
610 copy_const_value(dbg, get_And_left(n), block),
611 copy_const_value(dbg, get_And_right(n), block), m);
614 nn = new_rd_Or(dbg, block,
615 copy_const_value(dbg, get_Or_left(n), block),
616 copy_const_value(dbg, get_Or_right(n), block), m);
619 nn = new_rd_Eor(dbg, block,
620 copy_const_value(dbg, get_Eor_left(n), block),
621 copy_const_value(dbg, get_Eor_right(n), block), m);
624 nn = new_rd_Cast(dbg, block,
625 copy_const_value(dbg, get_Cast_op(n), block),
629 nn = new_rd_Conv(dbg, block,
630 copy_const_value(dbg, get_Conv_op(n), block), m);
633 nn = new_r_Unknown(irg, m); break;
635 panic("opcode invalid or not implemented");
640 /** Return the name of the initializer kind. */
641 const char *get_initializer_kind_name(ir_initializer_kind_t ini)
643 #define X(a) case a: return #a
645 X(IR_INITIALIZER_CONST);
646 X(IR_INITIALIZER_TARVAL);
647 X(IR_INITIALIZER_NULL);
648 X(IR_INITIALIZER_COMPOUND);
649 default: return "BAD VALUE";
654 static ir_initializer_t null_initializer = { IR_INITIALIZER_NULL };
656 ir_initializer_t *get_initializer_null(void)
658 return &null_initializer;
661 ir_initializer_t *create_initializer_const(ir_node *value)
663 struct obstack *obst = get_irg_obstack(get_const_code_irg());
665 ir_initializer_t *initializer
666 = (ir_initializer_t*)OALLOC(obst, ir_initializer_const_t);
667 initializer->kind = IR_INITIALIZER_CONST;
668 initializer->consti.value = value;
673 ir_initializer_t *create_initializer_tarval(ir_tarval *tv)
675 struct obstack *obst = get_irg_obstack(get_const_code_irg());
677 ir_initializer_t *initializer
678 = (ir_initializer_t*)OALLOC(obst, ir_initializer_tarval_t);
679 initializer->kind = IR_INITIALIZER_TARVAL;
680 initializer->tarval.value = tv;
685 ir_initializer_t *create_initializer_compound(size_t n_entries)
687 struct obstack *obst = get_irg_obstack(get_const_code_irg());
690 size_t size = sizeof(ir_initializer_compound_t)
691 + n_entries * sizeof(ir_initializer_t*)
692 - sizeof(ir_initializer_t*);
694 ir_initializer_t *initializer
695 = (ir_initializer_t*)obstack_alloc(obst, size);
696 initializer->kind = IR_INITIALIZER_COMPOUND;
697 initializer->compound.n_initializers = n_entries;
699 for (i = 0; i < n_entries; ++i) {
700 initializer->compound.initializers[i] = get_initializer_null();
706 ir_node *get_initializer_const_value(const ir_initializer_t *initializer)
708 assert(initializer->kind == IR_INITIALIZER_CONST);
709 return skip_Id(initializer->consti.value);
712 ir_tarval *get_initializer_tarval_value(const ir_initializer_t *initializer)
714 assert(initializer->kind == IR_INITIALIZER_TARVAL);
715 return initializer->tarval.value;
718 size_t get_initializer_compound_n_entries(const ir_initializer_t *initializer)
720 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
721 return initializer->compound.n_initializers;
724 void set_initializer_compound_value(ir_initializer_t *initializer,
725 size_t index, ir_initializer_t *value)
727 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
728 assert(index < initializer->compound.n_initializers);
730 initializer->compound.initializers[index] = value;
733 ir_initializer_t *get_initializer_compound_value(
734 const ir_initializer_t *initializer, size_t index)
736 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
737 assert(index < initializer->compound.n_initializers);
739 return initializer->compound.initializers[index];
742 ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer)
744 return initializer->kind;
747 static void check_entity_initializer(ir_entity *entity)
750 ir_initializer_t *initializer = entity->initializer;
751 ir_type *entity_tp = get_entity_type(entity);
752 switch (initializer->kind) {
753 case IR_INITIALIZER_COMPOUND:
754 assert(is_compound_type(entity_tp) || is_Array_type(entity_tp));
756 case IR_INITIALIZER_CONST:
757 /* methods are initialized by a SymConst */
758 assert(is_atomic_type(entity_tp) || is_Method_type(entity_tp));
760 case IR_INITIALIZER_TARVAL:
761 assert(is_atomic_type(entity_tp));
763 case IR_INITIALIZER_NULL:
769 void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer)
771 entity->initializer = initializer;
772 check_entity_initializer(entity);
775 int has_entity_initializer(const ir_entity *entity)
777 return entity->initializer != NULL;
780 ir_initializer_t *get_entity_initializer(const ir_entity *entity)
782 return entity->initializer;
785 int (get_entity_offset)(const ir_entity *ent)
787 return _get_entity_offset(ent);
790 void (set_entity_offset)(ir_entity *ent, int offset)
792 _set_entity_offset(ent, offset);
795 unsigned char (get_entity_offset_bits_remainder)(const ir_entity *ent)
797 return _get_entity_offset_bits_remainder(ent);
800 void (set_entity_offset_bits_remainder)(ir_entity *ent, unsigned char offset)
802 _set_entity_offset_bits_remainder(ent, offset);
805 void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
807 if (ent->overwrites == NULL) {
808 ent->overwrites = NEW_ARR_F(ir_entity*, 0);
810 ARR_APP1(ir_entity *, ent->overwrites, overwritten);
811 if (overwritten->overwrittenby == NULL) {
812 overwritten->overwrittenby = NEW_ARR_F(ir_entity*, 0);
814 ARR_APP1(ir_entity *, overwritten->overwrittenby, ent);
817 size_t get_entity_n_overwrites(const ir_entity *ent)
819 if (ent->overwrites == NULL)
821 return ARR_LEN(ent->overwrites);
824 size_t get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten)
827 size_t n = get_entity_n_overwrites(ent);
828 for (i = 0; i < n; ++i) {
829 if (get_entity_overwrites(ent, i) == overwritten)
835 ir_entity *get_entity_overwrites(const ir_entity *ent, size_t pos)
837 assert(pos < get_entity_n_overwrites(ent));
838 return ent->overwrites[pos];
841 void set_entity_overwrites(ir_entity *ent, size_t pos, ir_entity *overwritten)
843 assert(pos < get_entity_n_overwrites(ent));
844 ent->overwrites[pos] = overwritten;
847 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
850 size_t n = get_entity_n_overwrites(ent);
851 for (i = 0; i < n; ++i) {
852 if (ent->overwrites[i] == overwritten) {
853 for (; i < n - 1; i++)
854 ent->overwrites[i] = ent->overwrites[i+1];
855 ARR_SETLEN(ir_entity*, ent->overwrites, n - 1);
862 size_t get_entity_n_overwrittenby(const ir_entity *ent)
864 if (ent->overwrittenby == NULL)
866 return ARR_LEN(ent->overwrittenby);
869 size_t get_entity_overwrittenby_index(const ir_entity *ent,
870 ir_entity *overwrites)
873 size_t n = get_entity_n_overwrittenby(ent);
874 for (i = 0; i < n; ++i) {
875 if (get_entity_overwrittenby(ent, i) == overwrites)
881 ir_entity *get_entity_overwrittenby(const ir_entity *ent, size_t pos)
883 assert(pos < get_entity_n_overwrittenby(ent));
884 return ent->overwrittenby[pos];
887 void set_entity_overwrittenby(ir_entity *ent, size_t pos, ir_entity *overwrites)
889 assert(pos < get_entity_n_overwrittenby(ent));
890 ent->overwrittenby[pos] = overwrites;
893 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites)
896 size_t n = get_entity_n_overwrittenby(ent);
897 for (i = 0; i < n; ++i) {
898 if (ent->overwrittenby[i] == overwrites) {
899 for (; i < n - 1; ++i)
900 ent->overwrittenby[i] = ent->overwrittenby[i+1];
901 ARR_SETLEN(ir_entity*, ent->overwrittenby, n - 1);
907 void *(get_entity_link)(const ir_entity *ent)
909 return _get_entity_link(ent);
912 void (set_entity_link)(ir_entity *ent, void *l)
914 _set_entity_link(ent, l);
917 ir_graph *(get_entity_irg)(const ir_entity *ent)
919 return _get_entity_irg(ent);
922 void set_entity_irg(ir_entity *ent, ir_graph *irg)
924 assert(is_method_entity(ent));
925 assert(get_entity_peculiarity(ent) == peculiarity_existent);
926 ent->attr.mtd_attr.irg = irg;
929 int (is_parameter_entity)(const ir_entity *entity)
931 return _is_parameter_entity(entity);
934 size_t (get_entity_parameter_number)(const ir_entity *entity)
936 return _get_entity_parameter_number(entity);
939 void set_entity_parameter_number(ir_entity *entity, size_t n)
941 assert(is_parameter_entity(entity));
942 entity->attr.parameter.number = n;
945 unsigned get_entity_vtable_number(const ir_entity *ent)
947 assert(is_method_entity((ir_entity *)ent));
948 return ent->attr.mtd_attr.vtable_number;
951 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number)
953 assert(is_method_entity(ent));
954 ent->attr.mtd_attr.vtable_number = vtable_number;
957 int (is_entity)(const void *thing)
959 return _is_entity(thing);
962 int is_atomic_entity(const ir_entity *ent)
964 ir_type *t = get_entity_type(ent);
965 const tp_op *op = get_type_tpop(t);
966 return (op == type_primitive || op == type_pointer ||
967 op == type_enumeration || op == type_method);
970 int is_compound_entity(const ir_entity *ent)
972 ir_type *t = get_entity_type(ent);
973 const tp_op *op = get_type_tpop(t);
974 return (op == type_class || op == type_struct ||
975 op == type_array || op == type_union);
978 int is_method_entity(const ir_entity *ent)
980 ir_type *t = get_entity_type(ent);
981 return is_Method_type(t);
984 ir_visited_t (get_entity_visited)(const ir_entity *ent)
986 return _get_entity_visited(ent);
989 void (set_entity_visited)(ir_entity *ent, ir_visited_t num)
991 _set_entity_visited(ent, num);
994 void (mark_entity_visited)(ir_entity *ent)
996 _mark_entity_visited(ent);
999 int (entity_visited)(const ir_entity *ent)
1001 return _entity_visited(ent);
1004 int (entity_not_visited)(const ir_entity *ent)
1006 return _entity_not_visited(ent);
1009 mtp_additional_properties get_entity_additional_properties(const ir_entity *ent)
1013 assert(is_method_entity(ent));
1015 /* first check, if the graph has additional properties */
1016 irg = get_entity_irg(ent);
1019 return get_irg_additional_properties(irg);
1021 if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited)
1022 return get_method_additional_properties(get_entity_type(ent));
1024 return ent->attr.mtd_attr.irg_add_properties;
1027 void set_entity_additional_properties(ir_entity *ent, mtp_additional_properties property_mask)
1031 assert(is_method_entity(ent));
1033 /* first check, if the graph exists */
1034 irg = get_entity_irg(ent);
1036 set_irg_additional_properties(irg, property_mask);
1038 /* do not allow to set the mtp_property_inherited flag or
1039 * the automatic inheritance of flags will not work */
1040 ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
1044 void add_entity_additional_properties(ir_entity *ent, mtp_additional_properties properties)
1048 assert(is_method_entity(ent));
1050 /* first check, if the graph exists */
1051 irg = get_entity_irg(ent);
1053 add_irg_additional_properties(irg, properties);
1055 mtp_additional_properties mask = ent->attr.mtd_attr.irg_add_properties;
1057 if (mask & mtp_property_inherited)
1058 mask = get_method_additional_properties(get_entity_type(ent));
1060 /* do not allow to set the mtp_property_inherited flag or
1061 * the automatic inheritance of flags will not work */
1062 ent->attr.mtd_attr.irg_add_properties = mask | (properties & ~mtp_property_inherited);
1066 /* Returns the class type that this type info entity represents or NULL
1067 if ent is no type info entity. */
1068 ir_type *(get_entity_repr_class)(const ir_entity *ent)
1070 return _get_entity_repr_class(ent);
1073 dbg_info *(get_entity_dbg_info)(const ir_entity *ent)
1075 return _get_entity_dbg_info(ent);
1078 void (set_entity_dbg_info)(ir_entity *ent, dbg_info *db)
1080 _set_entity_dbg_info(ent, db);
1083 int entity_is_externally_visible(const ir_entity *entity)
1085 return get_entity_visibility(entity) != ir_visibility_local
1086 || (get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER);
1089 int entity_has_definition(const ir_entity *entity)
1091 return entity->initializer != NULL
1092 || get_entity_irg(entity) != NULL
1093 || entity_has_compound_ent_values(entity);
1096 void ir_init_entity(void)
1098 assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
1099 assert(!unknown_entity && "Call firm_init_entity() only once!");
1101 unknown_entity = new_d_entity(NULL, new_id_from_str(UNKNOWN_ENTITY_NAME),
1102 firm_unknown_type, NULL);
1103 set_entity_visibility(unknown_entity, ir_visibility_external);
1104 set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
1107 void ir_finish_entity(void)
1109 if (unknown_entity != NULL) {
1110 free_entity(unknown_entity);
1111 unknown_entity = NULL;
1115 ir_allocation get_entity_allocation(const ir_entity *entity)
1117 return (ir_allocation)entity->allocation;
1120 void set_entity_allocation(ir_entity *entity, ir_allocation allocation)
1122 entity->allocation = allocation;
1125 ir_peculiarity get_entity_peculiarity(const ir_entity *entity)
1127 return (ir_peculiarity)entity->peculiarity;
1130 void set_entity_peculiarity(ir_entity *entity, ir_peculiarity peculiarity)
1132 entity->peculiarity = peculiarity;
1135 void set_entity_final(ir_entity *entity, int final)
1137 entity->final = final;
1140 int is_entity_final(const ir_entity *entity)
1142 return entity->final;