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.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
43 #include "irgraph_t.h"
44 #include "callgraph.h"
46 #include "compound_path.h"
48 /*-----------------------------------------------------------------*/
50 /*-----------------------------------------------------------------*/
52 ir_entity *unknown_entity = NULL;
54 ir_entity *get_unknown_entity(void) { return unknown_entity; }
56 /** The name of the unknown entity. */
57 #define UNKNOWN_ENTITY_NAME "unknown_entity"
59 /*-----------------------------------------------------------------*/
61 /*-----------------------------------------------------------------*/
63 ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *type,
68 assert(!id_contains_char(name, ' ') && "entity name should not contain spaces");
70 res = XMALLOCZ(ir_entity);
78 res->volatility = volatility_non_volatile;
79 res->aligned = align_is_aligned;
80 res->usage = ir_usage_unknown;
81 res->compiler_gen = 0;
82 res->visibility = ir_visibility_default;
84 res->offset_bit_remainder = 0;
87 res->repr_class = NULL;
89 if (is_Method_type(type)) {
90 ir_graph *irg = get_const_code_irg();
92 ir_mode *mode = is_Method_type(type) ? mode_P_code : mode_P_data;
94 set_atomic_ent_value(res, new_r_SymConst(irg, mode, sym, symconst_addr_ent));
95 res->linkage = IR_LINKAGE_CONSTANT;
96 res->attr.mtd_attr.irg_add_properties = mtp_property_inherited;
97 res->attr.mtd_attr.vtable_number = IR_VTABLE_NUM_NOT_SET;
98 res->attr.mtd_attr.param_access = NULL;
99 res->attr.mtd_attr.param_weight = NULL;
100 res->attr.mtd_attr.irg = NULL;
101 } else if (is_compound_type(type)) {
102 res->attr.cmpd_attr.values = NULL;
103 res->attr.cmpd_attr.val_paths = NULL;
104 } else if (is_code_type(type)) {
105 res->attr.code_attr.label = (ir_label_t) -1;
108 /* Remember entity in it's owner. */
110 add_compound_member(owner, res);
113 res->nr = get_irp_new_node_nr();
117 set_entity_dbg_info(res, db);
119 hook_new_entity(res);
124 ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
126 return new_d_entity(owner, name, type, NULL);
130 * Free entity attributes.
132 * @param ent the entity
134 static void free_entity_attrs(ir_entity *ent)
136 if (ent->overwrites != NULL) {
137 DEL_ARR_F(ent->overwrites);
138 ent->overwrites = NULL;
140 if (ent->overwrittenby != NULL) {
141 DEL_ARR_F(ent->overwrittenby);
142 ent->overwrittenby = NULL;
145 if (ent->initializer != NULL) {
146 /* TODO: free initializers */
147 } else if (entity_has_compound_ent_values(ent)) {
148 /* can't free compound graph path as it might be used
150 ent->attr.cmpd_attr.val_paths = NULL;
152 if (is_compound_entity(ent)) {
153 ent->attr.cmpd_attr.values = NULL;
154 } else if (is_method_entity(ent)) {
155 if (ent->attr.mtd_attr.param_access) {
156 DEL_ARR_F(ent->attr.mtd_attr.param_access);
157 ent->attr.mtd_attr.param_access = NULL;
159 if (ent->attr.mtd_attr.param_weight) {
160 DEL_ARR_F(ent->attr.mtd_attr.param_weight);
161 ent->attr.mtd_attr.param_weight = NULL;
167 * Creates a deep copy of an entity.
169 static ir_entity *deep_entity_copy(ir_entity *old)
171 ir_entity *newe = XMALLOC(ir_entity);
174 if (old->initializer != NULL) {
175 /* FIXME: the initializers are NOT copied */
176 } else if (entity_has_compound_ent_values(old)) {
177 newe->attr.cmpd_attr.values = NULL;
178 newe->attr.cmpd_attr.val_paths = NULL;
179 if (old->attr.cmpd_attr.values)
180 newe->attr.cmpd_attr.values = DUP_ARR_F(ir_node *, old->attr.cmpd_attr.values);
182 /* FIXME: the compound graph paths are NOT copied */
183 if (old->attr.cmpd_attr.val_paths)
184 newe->attr.cmpd_attr.val_paths = DUP_ARR_F(compound_graph_path *, old->attr.cmpd_attr.val_paths);
185 } else if (is_method_entity(old)) {
186 /* do NOT copy them, reanalyze. This might be the best solution */
187 newe->attr.mtd_attr.param_access = NULL;
188 newe->attr.mtd_attr.param_weight = NULL;
190 newe->overwrites = NULL;
191 newe->overwrittenby = NULL;
194 newe->nr = get_irp_new_node_nr();
200 * Copies the entity if the new_owner is different from the
201 * owner of the old entity, else returns the old entity.
203 ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner)
206 assert(is_entity(old));
207 assert(is_compound_type(new_owner));
208 assert(get_type_state(new_owner) != layout_fixed);
210 if (old->owner == new_owner)
213 /* create a deep copy so we are safe of aliasing and double-freeing. */
214 newe = deep_entity_copy(old);
215 newe->owner = new_owner;
216 add_compound_member(new_owner, newe);
221 ir_entity *copy_entity_name(ir_entity *old, ident *new_name)
224 assert(old && old->kind == k_entity);
226 if (old->name == new_name)
229 newe = deep_entity_copy(old);
230 newe->name = new_name;
231 newe->ld_name = NULL;
232 add_compound_member(old->owner, newe);
237 void free_entity(ir_entity *ent)
239 if (ent->owner != NULL && !is_Array_type(ent->owner))
240 remove_compound_member(ent->owner, ent);
242 assert(ent && ent->kind == k_entity);
243 free_entity_attrs(ent);
248 /* Outputs a unique number for this node */
249 long get_entity_nr(const ir_entity *ent)
251 assert(ent && ent->kind == k_entity);
255 return (long)PTR_TO_INT(ent);
259 const char *(get_entity_name)(const ir_entity *ent)
261 return _get_entity_name(ent);
264 ident *(get_entity_ident)(const ir_entity *ent)
266 return _get_entity_ident(ent);
269 void (set_entity_ident)(ir_entity *ent, ident *id)
271 _set_entity_ident(ent, id);
274 ir_type *(get_entity_owner)(const ir_entity *ent)
276 return _get_entity_owner(ent);
279 void set_entity_owner(ir_entity *ent, ir_type *owner)
281 assert(is_entity(ent));
282 assert(is_compound_type(owner));
284 remove_compound_member(ent->owner, ent);
285 add_compound_member(owner, ent);
289 ident *(get_entity_ld_ident)(const ir_entity *ent)
291 return _get_entity_ld_ident(ent);
294 void (set_entity_ld_ident)(ir_entity *ent, ident *ld_ident)
296 _set_entity_ld_ident(ent, ld_ident);
299 const char *(get_entity_ld_name)(const ir_entity *ent)
301 return _get_entity_ld_name(ent);
304 ir_type *(get_entity_type)(const ir_entity *ent)
306 return _get_entity_type(ent);
309 void (set_entity_type)(ir_entity *ent, ir_type *type)
311 _set_entity_type(ent, type);
314 ir_volatility (get_entity_volatility)(const ir_entity *ent)
316 return _get_entity_volatility(ent);
319 void (set_entity_volatility)(ir_entity *ent, ir_volatility vol)
321 _set_entity_volatility(ent, vol);
324 /* Return the name of the volatility. */
325 const char *get_volatility_name(ir_volatility var)
327 #define X(a) case a: return #a
329 X(volatility_non_volatile);
330 X(volatility_is_volatile);
331 default: return "BAD VALUE";
336 ir_align (get_entity_aligned)(const ir_entity *ent)
338 return _get_entity_aligned(ent);
341 void (set_entity_aligned)(ir_entity *ent, ir_align a)
343 _set_entity_aligned(ent, a);
346 unsigned (get_entity_alignment)(const ir_entity *ent)
348 return _get_entity_alignment(ent);
351 void (set_entity_alignment)(ir_entity *ent, unsigned alignment)
353 _set_entity_alignment(ent, alignment);
356 /* Return the name of the alignment. */
357 const char *get_align_name(ir_align a)
359 #define X(a) case a: return #a
361 X(align_non_aligned);
363 default: return "BAD VALUE";
368 void set_entity_label(ir_entity *ent, ir_label_t label)
370 ent->attr.code_attr.label = label;
373 ir_label_t get_entity_label(const ir_entity *ent)
375 return ent->attr.code_attr.label;
378 static void verify_visibility(const ir_entity *entity)
380 if (get_entity_visibility(entity) == ir_visibility_external
381 && !is_method_entity(entity)) {
382 assert(!entity_has_definition(entity));
386 void set_entity_visibility(ir_entity *entity, ir_visibility visibility)
388 entity->visibility = visibility;
389 verify_visibility(entity);
392 ir_visibility get_entity_visibility(const ir_entity *entity)
394 return (ir_visibility)entity->visibility;
397 void set_entity_linkage(ir_entity *entity, ir_linkage linkage)
399 entity->linkage = linkage;
402 ir_linkage (get_entity_linkage)(const ir_entity *entity)
404 return get_entity_linkage(entity);
407 void add_entity_linkage(ir_entity *entity, ir_linkage linkage)
409 entity->linkage |= linkage;
412 void remove_entity_linkage(ir_entity *entity, ir_linkage linkage)
414 entity->linkage &= ~linkage;
417 /* Checks if an entity is compiler generated */
418 int (is_entity_compiler_generated)(const ir_entity *ent)
420 return _is_entity_compiler_generated(ent);
423 /* Sets/resets the compiler generated flag */
424 void (set_entity_compiler_generated)(ir_entity *ent, int flag)
426 _set_entity_compiler_generated(ent, flag);
429 ir_entity_usage (get_entity_usage)(const ir_entity *ent)
431 return _get_entity_usage(ent);
434 void (set_entity_usage)(ir_entity *ent, ir_entity_usage flags)
436 _set_entity_usage(ent, flags);
439 /* Set has no effect for existent entities of type method. */
440 ir_node *get_atomic_ent_value(ir_entity *entity)
442 ir_initializer_t *initializer = get_entity_initializer(entity);
444 assert(entity && is_atomic_entity(entity));
445 if (initializer == NULL) {
446 ir_type *type = get_entity_type(entity);
447 return new_r_Unknown(get_const_code_irg(), get_type_mode(type));
450 switch (get_initializer_kind(initializer)) {
451 case IR_INITIALIZER_NULL: {
452 ir_type *type = get_entity_type(entity);
453 ir_mode *mode = get_type_mode(type);
454 return new_r_Const(get_const_code_irg(), get_mode_null(mode));
456 case IR_INITIALIZER_TARVAL: {
457 ir_tarval *tv = get_initializer_tarval_value(initializer);
458 return new_r_Const(get_const_code_irg(), tv);
460 case IR_INITIALIZER_CONST:
461 return get_initializer_const_value(initializer);
462 case IR_INITIALIZER_COMPOUND:
463 panic("compound initializer in atomic entity not allowed (%+F)", entity);
466 panic("invalid initializer kind in get_atomic_ent_value(%+F)", entity);
469 void set_atomic_ent_value(ir_entity *entity, ir_node *val)
471 ir_initializer_t *initializer;
473 assert(is_atomic_entity(entity));
475 assert(is_Dummy(val) || get_irn_mode(val) == get_type_mode(entity->type));
476 initializer = create_initializer_const(val);
477 entity->initializer = initializer;
480 /* Returns true if the the node is representable as code on
482 int is_irn_const_expression(ir_node *n)
486 /* we are in danger iff an exception will arise. TODO: be more precisely,
487 * for instance Div. will NOT rise if divisor != 0
489 if (is_binop(n) && !is_fragile_op(n))
490 return is_irn_const_expression(get_binop_left(n)) && is_irn_const_expression(get_binop_right(n));
493 switch (get_irn_opcode(n)) {
500 return is_irn_const_expression(get_irn_n(n, 0));
508 * Copies a firm subgraph that complies to the restrictions for
509 * constant expressions to block.
511 ir_node *copy_const_value(dbg_info *dbg, ir_node *n, ir_node *block)
513 ir_graph *irg = get_irn_irg(block);
517 /* @@@ GL I think we should implement this using the routines from irgopt for
518 dead node elimination/inlineing. */
521 switch (get_irn_opcode(n)) {
523 nn = new_rd_Const(dbg, irg, get_Const_tarval(n));
526 nn = new_rd_SymConst(dbg, irg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n));
529 nn = new_rd_Add(dbg, block,
530 copy_const_value(dbg, get_Add_left(n), block),
531 copy_const_value(dbg, get_Add_right(n), block), m);
534 nn = new_rd_Sub(dbg, block,
535 copy_const_value(dbg, get_Sub_left(n), block),
536 copy_const_value(dbg, get_Sub_right(n), block), m);
539 nn = new_rd_Mul(dbg, block,
540 copy_const_value(dbg, get_Mul_left(n), block),
541 copy_const_value(dbg, get_Mul_right(n), block), m);
544 nn = new_rd_And(dbg, block,
545 copy_const_value(dbg, get_And_left(n), block),
546 copy_const_value(dbg, get_And_right(n), block), m);
549 nn = new_rd_Or(dbg, block,
550 copy_const_value(dbg, get_Or_left(n), block),
551 copy_const_value(dbg, get_Or_right(n), block), m);
554 nn = new_rd_Eor(dbg, block,
555 copy_const_value(dbg, get_Eor_left(n), block),
556 copy_const_value(dbg, get_Eor_right(n), block), m);
559 nn = new_rd_Cast(dbg, block,
560 copy_const_value(dbg, get_Cast_op(n), block),
564 nn = new_rd_Conv(dbg, block,
565 copy_const_value(dbg, get_Conv_op(n), block), m);
568 nn = new_r_Unknown(irg, m); break;
570 panic("opcode invalid or not implemented");
575 /** Return the name of the initializer kind. */
576 const char *get_initializer_kind_name(ir_initializer_kind_t ini)
578 #define X(a) case a: return #a
580 X(IR_INITIALIZER_CONST);
581 X(IR_INITIALIZER_TARVAL);
582 X(IR_INITIALIZER_NULL);
583 X(IR_INITIALIZER_COMPOUND);
584 default: return "BAD VALUE";
589 static ir_initializer_t null_initializer = { IR_INITIALIZER_NULL };
591 ir_initializer_t *get_initializer_null(void)
593 return &null_initializer;
596 ir_initializer_t *create_initializer_const(ir_node *value)
598 struct obstack *obst = get_irg_obstack(get_const_code_irg());
600 ir_initializer_t *initializer
601 = (ir_initializer_t*)OALLOC(obst, ir_initializer_const_t);
602 initializer->kind = IR_INITIALIZER_CONST;
603 initializer->consti.value = value;
608 ir_initializer_t *create_initializer_tarval(ir_tarval *tv)
610 struct obstack *obst = get_irg_obstack(get_const_code_irg());
612 ir_initializer_t *initializer
613 = (ir_initializer_t*)OALLOC(obst, ir_initializer_tarval_t);
614 initializer->kind = IR_INITIALIZER_TARVAL;
615 initializer->tarval.value = tv;
620 ir_initializer_t *create_initializer_compound(unsigned n_entries)
622 struct obstack *obst = get_irg_obstack(get_const_code_irg());
625 size_t size = sizeof(ir_initializer_compound_t)
626 + (n_entries-1) * sizeof(ir_initializer_t*);
628 ir_initializer_t *initializer
629 = (ir_initializer_t*)obstack_alloc(obst, size);
630 initializer->kind = IR_INITIALIZER_COMPOUND;
631 initializer->compound.n_initializers = n_entries;
633 for (i = 0; i < n_entries; ++i) {
634 initializer->compound.initializers[i] = get_initializer_null();
640 ir_node *get_initializer_const_value(const ir_initializer_t *initializer)
642 assert(initializer->kind == IR_INITIALIZER_CONST);
643 return skip_Id(initializer->consti.value);
646 ir_tarval *get_initializer_tarval_value(const ir_initializer_t *initializer)
648 assert(initializer->kind == IR_INITIALIZER_TARVAL);
649 return initializer->tarval.value;
652 unsigned get_initializer_compound_n_entries(const ir_initializer_t *initializer)
654 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
655 return initializer->compound.n_initializers;
658 void set_initializer_compound_value(ir_initializer_t *initializer,
659 unsigned index, ir_initializer_t *value)
661 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
662 assert(index < initializer->compound.n_initializers);
664 initializer->compound.initializers[index] = value;
667 ir_initializer_t *get_initializer_compound_value(
668 const ir_initializer_t *initializer, unsigned index)
670 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
671 assert(index < initializer->compound.n_initializers);
673 return initializer->compound.initializers[index];
676 ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer)
678 return initializer->kind;
681 static void check_entity_initializer(ir_entity *entity)
684 ir_initializer_t *initializer = entity->initializer;
685 ir_type *entity_tp = get_entity_type(entity);
686 switch (initializer->kind) {
687 case IR_INITIALIZER_COMPOUND:
688 assert(is_compound_type(entity_tp) || is_Array_type(entity_tp));
690 case IR_INITIALIZER_CONST:
691 /* methods are initialized by a SymConst */
692 assert(is_atomic_type(entity_tp) || is_Method_type(entity_tp));
694 case IR_INITIALIZER_TARVAL:
695 assert(is_atomic_type(entity_tp));
697 case IR_INITIALIZER_NULL:
703 void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer)
705 entity->initializer = initializer;
706 check_entity_initializer(entity);
709 int has_entity_initializer(const ir_entity *entity)
711 return entity->initializer != NULL;
714 ir_initializer_t *get_entity_initializer(const ir_entity *entity)
716 return entity->initializer;
719 int (get_entity_offset)(const ir_entity *ent)
721 return _get_entity_offset(ent);
724 void (set_entity_offset)(ir_entity *ent, int offset)
726 _set_entity_offset(ent, offset);
729 unsigned char (get_entity_offset_bits_remainder)(const ir_entity *ent)
731 return _get_entity_offset_bits_remainder(ent);
734 void (set_entity_offset_bits_remainder)(ir_entity *ent, unsigned char offset)
736 _set_entity_offset_bits_remainder(ent, offset);
739 void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
741 if (ent->overwrites == NULL) {
742 ent->overwrites = NEW_ARR_F(ir_entity*, 0);
744 ARR_APP1(ir_entity *, ent->overwrites, overwritten);
745 if (overwritten->overwrittenby == NULL) {
746 overwritten->overwrittenby = NEW_ARR_F(ir_entity*, 0);
748 ARR_APP1(ir_entity *, overwritten->overwrittenby, ent);
751 int get_entity_n_overwrites(const ir_entity *ent)
753 if (ent->overwrites == NULL)
755 return ARR_LEN(ent->overwrites);
758 int get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten)
761 n = get_entity_n_overwrites(ent);
762 for (i = 0; i < n; ++i) {
763 if (get_entity_overwrites(ent, i) == overwritten)
769 ir_entity *get_entity_overwrites(const ir_entity *ent, int pos)
771 assert(pos < get_entity_n_overwrites(ent));
772 return ent->overwrites[pos];
775 void set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten)
777 assert(pos < get_entity_n_overwrites(ent));
778 ent->overwrites[pos] = overwritten;
781 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
784 n = get_entity_n_overwrites(ent);
785 for (i = 0; i < n; ++i) {
786 if (ent->overwrites[i] == overwritten) {
787 for (; i < n - 1; i++)
788 ent->overwrites[i] = ent->overwrites[i+1];
789 ARR_SETLEN(ir_entity*, ent->overwrites, n - 1);
796 int get_entity_n_overwrittenby(const ir_entity *ent)
798 if (ent->overwrittenby == NULL)
800 return ARR_LEN(ent->overwrittenby);
803 int get_entity_overwrittenby_index(const ir_entity *ent, ir_entity *overwrites)
806 n = get_entity_n_overwrittenby(ent);
807 for (i = 0; i < n; ++i) {
808 if (get_entity_overwrittenby(ent, i) == overwrites)
814 ir_entity *get_entity_overwrittenby(const ir_entity *ent, int pos)
816 assert(pos < get_entity_n_overwrittenby(ent));
817 return ent->overwrittenby[pos];
820 void set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites)
822 assert(pos < get_entity_n_overwrittenby(ent));
823 ent->overwrittenby[pos] = overwrites;
826 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites)
830 n = get_entity_n_overwrittenby(ent);
831 for (i = 0; i < n; ++i) {
832 if (ent->overwrittenby[i] == overwrites) {
833 for (; i < n - 1; ++i)
834 ent->overwrittenby[i] = ent->overwrittenby[i+1];
835 ARR_SETLEN(ir_entity*, ent->overwrittenby, n - 1);
841 void *(get_entity_link)(const ir_entity *ent)
843 return _get_entity_link(ent);
846 void (set_entity_link)(ir_entity *ent, void *l)
848 _set_entity_link(ent, l);
851 ir_graph *(get_entity_irg)(const ir_entity *ent)
853 return _get_entity_irg(ent);
856 void set_entity_irg(ir_entity *ent, ir_graph *irg)
858 assert(is_method_entity(ent));
859 assert(get_entity_peculiarity(ent) == peculiarity_existent);
860 ent->attr.mtd_attr.irg = irg;
863 unsigned get_entity_vtable_number(const ir_entity *ent)
865 assert(is_method_entity((ir_entity *)ent));
866 return ent->attr.mtd_attr.vtable_number;
869 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number)
871 assert(is_method_entity(ent));
872 ent->attr.mtd_attr.vtable_number = vtable_number;
875 int (is_entity)(const void *thing)
877 return _is_entity(thing);
880 int is_atomic_entity(const ir_entity *ent)
882 ir_type *t = get_entity_type(ent);
883 const tp_op *op = get_type_tpop(t);
884 return (op == type_primitive || op == type_pointer ||
885 op == type_enumeration || op == type_method);
888 int is_compound_entity(const ir_entity *ent)
890 ir_type *t = get_entity_type(ent);
891 const tp_op *op = get_type_tpop(t);
892 return (op == type_class || op == type_struct ||
893 op == type_array || op == type_union);
896 int is_method_entity(const ir_entity *ent)
898 ir_type *t = get_entity_type(ent);
899 return is_Method_type(t);
902 ir_visited_t (get_entity_visited)(const ir_entity *ent)
904 return _get_entity_visited(ent);
907 void (set_entity_visited)(ir_entity *ent, ir_visited_t num)
909 _set_entity_visited(ent, num);
912 void (mark_entity_visited)(ir_entity *ent)
914 _mark_entity_visited(ent);
917 int (entity_visited)(const ir_entity *ent)
919 return _entity_visited(ent);
922 int (entity_not_visited)(const ir_entity *ent)
924 return _entity_not_visited(ent);
927 mtp_additional_properties get_entity_additional_properties(const ir_entity *ent)
931 assert(is_method_entity(ent));
933 /* first check, if the graph has additional properties */
934 irg = get_entity_irg(ent);
937 return get_irg_additional_properties(irg);
939 if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited)
940 return get_method_additional_properties(get_entity_type(ent));
942 return ent->attr.mtd_attr.irg_add_properties;
945 void set_entity_additional_properties(ir_entity *ent, mtp_additional_properties property_mask)
949 assert(is_method_entity(ent));
951 /* first check, if the graph exists */
952 irg = get_entity_irg(ent);
954 set_irg_additional_properties(irg, property_mask);
956 /* do not allow to set the mtp_property_inherited flag or
957 * the automatic inheritance of flags will not work */
958 ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
962 void add_entity_additional_properties(ir_entity *ent, mtp_additional_properties properties)
966 assert(is_method_entity(ent));
968 /* first check, if the graph exists */
969 irg = get_entity_irg(ent);
971 add_irg_additional_properties(irg, properties);
973 mtp_additional_properties mask = ent->attr.mtd_attr.irg_add_properties;
975 if (mask & mtp_property_inherited)
976 mask = get_method_additional_properties(get_entity_type(ent));
978 /* do not allow to set the mtp_property_inherited flag or
979 * the automatic inheritance of flags will not work */
980 ent->attr.mtd_attr.irg_add_properties = mask | (properties & ~mtp_property_inherited);
984 /* Returns the class type that this type info entity represents or NULL
985 if ent is no type info entity. */
986 ir_type *(get_entity_repr_class)(const ir_entity *ent)
988 return _get_entity_repr_class(ent);
991 dbg_info *(get_entity_dbg_info)(const ir_entity *ent)
993 return _get_entity_dbg_info(ent);
996 void (set_entity_dbg_info)(ir_entity *ent, dbg_info *db)
998 _set_entity_dbg_info(ent, db);
1001 int entity_is_externally_visible(const ir_entity *entity)
1003 return get_entity_visibility(entity) != ir_visibility_local
1004 || (get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER);
1007 int entity_has_definition(const ir_entity *entity)
1009 return entity->initializer != NULL
1010 || get_entity_irg(entity) != NULL
1011 || entity_has_compound_ent_values(entity);
1014 void ir_init_entity(void)
1016 assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
1017 assert(!unknown_entity && "Call firm_init_entity() only once!");
1019 unknown_entity = new_d_entity(NULL, new_id_from_str(UNKNOWN_ENTITY_NAME),
1020 firm_unknown_type, NULL);
1021 set_entity_visibility(unknown_entity, ir_visibility_external);
1022 set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
1025 void ir_finish_entity(void)
1027 if (unknown_entity != NULL) {
1028 free_entity(unknown_entity);
1029 unknown_entity = NULL;
1033 ir_allocation get_entity_allocation(const ir_entity *entity)
1035 return (ir_allocation)entity->allocation;
1038 void set_entity_allocation(ir_entity *entity, ir_allocation allocation)
1040 entity->allocation = allocation;
1043 ir_peculiarity get_entity_peculiarity(const ir_entity *entity)
1045 return (ir_peculiarity)entity->peculiarity;
1048 void set_entity_peculiarity(ir_entity *entity, ir_peculiarity peculiarity)
1050 entity->peculiarity = peculiarity;
1053 void set_entity_final(ir_entity *entity, int final)
1055 entity->final = final;
1058 int is_entity_final(const ir_entity *entity)
1060 return entity->final;