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,
69 assert(!id_contains_char(name, ' ') && "entity name should not contain spaces");
71 res = XMALLOCZ(ir_entity);
79 res->volatility = volatility_non_volatile;
80 res->aligned = align_is_aligned;
81 res->usage = ir_usage_unknown;
82 res->compiler_gen = 0;
83 res->visibility = ir_visibility_default;
85 res->offset_bit_remainder = 0;
88 res->repr_class = NULL;
90 if (is_Method_type(type)) {
92 ir_mode *mode = is_Method_type(type) ? mode_P_code : mode_P_data;
94 rem = current_ir_graph;
95 current_ir_graph = get_const_code_irg();
96 set_atomic_ent_value(res, new_SymConst(mode, sym, symconst_addr_ent));
97 current_ir_graph = rem;
98 res->linkage = IR_LINKAGE_CONSTANT;
99 res->attr.mtd_attr.irg_add_properties = mtp_property_inherited;
100 res->attr.mtd_attr.vtable_number = IR_VTABLE_NUM_NOT_SET;
101 res->attr.mtd_attr.param_access = NULL;
102 res->attr.mtd_attr.param_weight = NULL;
103 res->attr.mtd_attr.irg = NULL;
104 } else if (is_compound_type(type)) {
105 res->attr.cmpd_attr.values = NULL;
106 res->attr.cmpd_attr.val_paths = NULL;
107 } else if (is_code_type(type)) {
108 res->attr.code_attr.label = (ir_label_t) -1;
111 /* Remember entity in it's owner. */
113 add_compound_member(owner, res);
116 res->nr = get_irp_new_node_nr();
120 set_entity_dbg_info(res, db);
122 hook_new_entity(res);
127 ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
129 return new_d_entity(owner, name, type, NULL);
133 * Free entity attributes.
135 * @param ent the entity
137 static void free_entity_attrs(ir_entity *ent)
139 if (ent->overwrites != NULL) {
140 DEL_ARR_F(ent->overwrites);
141 ent->overwrites = NULL;
143 if (ent->overwrittenby != NULL) {
144 DEL_ARR_F(ent->overwrittenby);
145 ent->overwrittenby = NULL;
148 if (ent->initializer != NULL) {
149 /* TODO: free initializers */
150 } else if (entity_has_compound_ent_values(ent)) {
151 /* can't free compound graph path as it might be used
153 ent->attr.cmpd_attr.val_paths = NULL;
155 if (is_compound_entity(ent)) {
156 ent->attr.cmpd_attr.values = NULL;
157 } else if (is_method_entity(ent)) {
158 if (ent->attr.mtd_attr.param_access) {
159 DEL_ARR_F(ent->attr.mtd_attr.param_access);
160 ent->attr.mtd_attr.param_access = NULL;
162 if (ent->attr.mtd_attr.param_weight) {
163 DEL_ARR_F(ent->attr.mtd_attr.param_weight);
164 ent->attr.mtd_attr.param_weight = NULL;
170 * Creates a deep copy of an entity.
172 static ir_entity *deep_entity_copy(ir_entity *old)
174 ir_entity *newe = XMALLOC(ir_entity);
177 if (old->initializer != NULL) {
178 /* FIXME: the initializers are NOT copied */
179 } else if (entity_has_compound_ent_values(old)) {
180 newe->attr.cmpd_attr.values = NULL;
181 newe->attr.cmpd_attr.val_paths = NULL;
182 if (old->attr.cmpd_attr.values)
183 newe->attr.cmpd_attr.values = DUP_ARR_F(ir_node *, old->attr.cmpd_attr.values);
185 /* FIXME: the compound graph paths are NOT copied */
186 if (old->attr.cmpd_attr.val_paths)
187 newe->attr.cmpd_attr.val_paths = DUP_ARR_F(compound_graph_path *, old->attr.cmpd_attr.val_paths);
188 } else if (is_method_entity(old)) {
189 /* do NOT copy them, reanalyze. This might be the best solution */
190 newe->attr.mtd_attr.param_access = NULL;
191 newe->attr.mtd_attr.param_weight = NULL;
193 newe->overwrites = NULL;
194 newe->overwrittenby = NULL;
197 newe->nr = get_irp_new_node_nr();
203 * Copies the entity if the new_owner is different from the
204 * owner of the old entity, else returns the old entity.
206 ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner)
209 assert(is_entity(old));
210 assert(is_compound_type(new_owner));
211 assert(get_type_state(new_owner) != layout_fixed);
213 if (old->owner == new_owner)
216 /* create a deep copy so we are safe of aliasing and double-freeing. */
217 newe = deep_entity_copy(old);
218 newe->owner = new_owner;
219 add_compound_member(new_owner, newe);
224 ir_entity *copy_entity_name(ir_entity *old, ident *new_name)
227 assert(old && old->kind == k_entity);
229 if (old->name == new_name)
232 newe = deep_entity_copy(old);
233 newe->name = new_name;
234 newe->ld_name = NULL;
235 add_compound_member(old->owner, newe);
240 void free_entity(ir_entity *ent)
242 if (ent->owner != NULL && !is_Array_type(ent->owner))
243 remove_compound_member(ent->owner, ent);
245 assert(ent && ent->kind == k_entity);
246 free_entity_attrs(ent);
251 /* Outputs a unique number for this node */
252 long get_entity_nr(const ir_entity *ent)
254 assert(ent && ent->kind == k_entity);
258 return (long)PTR_TO_INT(ent);
262 const char *(get_entity_name)(const ir_entity *ent)
264 return _get_entity_name(ent);
267 ident *(get_entity_ident)(const ir_entity *ent)
269 return _get_entity_ident(ent);
272 void (set_entity_ident)(ir_entity *ent, ident *id)
274 _set_entity_ident(ent, id);
277 ir_type *(get_entity_owner)(const ir_entity *ent)
279 return _get_entity_owner(ent);
282 void set_entity_owner(ir_entity *ent, ir_type *owner)
284 assert(is_entity(ent));
285 assert(is_compound_type(owner));
287 remove_compound_member(ent->owner, ent);
288 add_compound_member(owner, ent);
292 ident *(get_entity_ld_ident)(const ir_entity *ent)
294 return _get_entity_ld_ident(ent);
297 void (set_entity_ld_ident)(ir_entity *ent, ident *ld_ident)
299 _set_entity_ld_ident(ent, ld_ident);
302 const char *(get_entity_ld_name)(const ir_entity *ent)
304 return _get_entity_ld_name(ent);
307 ir_type *(get_entity_type)(const ir_entity *ent)
309 return _get_entity_type(ent);
312 void (set_entity_type)(ir_entity *ent, ir_type *type)
314 _set_entity_type(ent, type);
317 ir_volatility (get_entity_volatility)(const ir_entity *ent)
319 return _get_entity_volatility(ent);
322 void (set_entity_volatility)(ir_entity *ent, ir_volatility vol)
324 _set_entity_volatility(ent, vol);
327 /* Return the name of the volatility. */
328 const char *get_volatility_name(ir_volatility var)
330 #define X(a) case a: return #a
332 X(volatility_non_volatile);
333 X(volatility_is_volatile);
334 default: return "BAD VALUE";
339 ir_align (get_entity_aligned)(const ir_entity *ent)
341 return _get_entity_aligned(ent);
344 void (set_entity_aligned)(ir_entity *ent, ir_align a)
346 _set_entity_aligned(ent, a);
349 unsigned (get_entity_alignment)(const ir_entity *ent)
351 return _get_entity_alignment(ent);
354 void (set_entity_alignment)(ir_entity *ent, unsigned alignment)
356 _set_entity_alignment(ent, alignment);
359 /* Return the name of the alignment. */
360 const char *get_align_name(ir_align a)
362 #define X(a) case a: return #a
364 X(align_non_aligned);
366 default: return "BAD VALUE";
371 void set_entity_label(ir_entity *ent, ir_label_t label)
373 ent->attr.code_attr.label = label;
376 ir_label_t get_entity_label(const ir_entity *ent)
378 return ent->attr.code_attr.label;
381 static void verify_visibility(const ir_entity *entity)
383 if (get_entity_visibility(entity) == ir_visibility_external
384 && !is_method_entity(entity)) {
385 assert(!entity_has_definition(entity));
389 void set_entity_visibility(ir_entity *entity, ir_visibility visibility)
391 entity->visibility = visibility;
392 verify_visibility(entity);
395 ir_visibility get_entity_visibility(const ir_entity *entity)
397 return entity->visibility;
400 void set_entity_linkage(ir_entity *entity, ir_linkage linkage)
402 entity->linkage = linkage;
405 ir_linkage (get_entity_linkage)(const ir_entity *entity)
407 return get_entity_linkage(entity);
410 void add_entity_linkage(ir_entity *entity, ir_linkage linkage)
412 entity->linkage |= linkage;
415 void remove_entity_linkage(ir_entity *entity, ir_linkage linkage)
417 entity->linkage &= ~linkage;
420 /* Checks if an entity is compiler generated */
421 int (is_entity_compiler_generated)(const ir_entity *ent)
423 return _is_entity_compiler_generated(ent);
426 /* Sets/resets the compiler generated flag */
427 void (set_entity_compiler_generated)(ir_entity *ent, int flag)
429 _set_entity_compiler_generated(ent, flag);
432 ir_entity_usage (get_entity_usage)(const ir_entity *ent)
434 return _get_entity_usage(ent);
437 void (set_entity_usage)(ir_entity *ent, ir_entity_usage flags)
439 _set_entity_usage(ent, flags);
442 /* Set has no effect for existent entities of type method. */
443 ir_node *get_atomic_ent_value(ir_entity *entity)
445 ir_initializer_t *initializer = get_entity_initializer(entity);
447 assert(entity && is_atomic_entity(entity));
448 if (initializer == NULL) {
449 ir_type *type = get_entity_type(entity);
450 return new_r_Unknown(get_const_code_irg(), get_type_mode(type));
453 switch (get_initializer_kind(initializer)) {
454 case IR_INITIALIZER_NULL: {
455 ir_type *type = get_entity_type(entity);
456 ir_mode *mode = get_type_mode(type);
457 return new_r_Const(get_const_code_irg(), get_mode_null(mode));
459 case IR_INITIALIZER_TARVAL: {
460 tarval *tv = get_initializer_tarval_value(initializer);
461 return new_r_Const(get_const_code_irg(), tv);
463 case IR_INITIALIZER_CONST:
464 return get_initializer_const_value(initializer);
465 case IR_INITIALIZER_COMPOUND:
466 panic("compound initializer in atomic entity not allowed (%+F)", entity);
469 panic("invalid initializer kind in get_atomic_ent_value(%+F)", entity);
472 void set_atomic_ent_value(ir_entity *entity, ir_node *val)
474 ir_initializer_t *initializer;
476 assert(is_atomic_entity(entity));
478 assert(is_Dummy(val) || get_irn_mode(val) == get_type_mode(entity->type));
479 initializer = create_initializer_const(val);
480 entity->initializer = initializer;
483 /* Returns true if the the node is representable as code on
485 int is_irn_const_expression(ir_node *n)
489 /* we are in danger iff an exception will arise. TODO: be more precisely,
490 * for instance Div. will NOT rise if divisor != 0
492 if (is_binop(n) && !is_fragile_op(n))
493 return is_irn_const_expression(get_binop_left(n)) && is_irn_const_expression(get_binop_right(n));
496 switch (get_irn_opcode(n)) {
503 return is_irn_const_expression(get_irn_n(n, 0));
511 * Copies a firm subgraph that complies to the restrictions for
512 * constant expressions to current_block in current_ir_graph.
514 ir_node *copy_const_value(dbg_info *dbg, ir_node *n)
519 /* @@@ GL I think we should implement this using the routines from irgopt for
520 dead node elimination/inlineing. */
523 switch (get_irn_opcode(n)) {
525 nn = new_d_Const_type(dbg, get_Const_tarval(n), get_Const_type(n));
528 nn = new_d_SymConst_type(dbg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n),
529 get_SymConst_value_type(n));
532 nn = new_d_Add(dbg, copy_const_value(dbg, get_Add_left(n)),
533 copy_const_value(dbg, get_Add_right(n)), m); break;
535 nn = new_d_Sub(dbg, copy_const_value(dbg, get_Sub_left(n)),
536 copy_const_value(dbg, get_Sub_right(n)), m); break;
538 nn = new_d_Mul(dbg, copy_const_value(dbg, get_Mul_left(n)),
539 copy_const_value(dbg, get_Mul_right(n)), m); break;
541 nn = new_d_And(dbg, copy_const_value(dbg, get_And_left(n)),
542 copy_const_value(dbg, get_And_right(n)), m); break;
544 nn = new_d_Or(dbg, copy_const_value(dbg, get_Or_left(n)),
545 copy_const_value(dbg, get_Or_right(n)), m); break;
547 nn = new_d_Eor(dbg, copy_const_value(dbg, get_Eor_left(n)),
548 copy_const_value(dbg, get_Eor_right(n)), m); break;
550 nn = new_d_Cast(dbg, copy_const_value(dbg, get_Cast_op(n)), get_Cast_type(n)); break;
552 nn = new_d_Conv(dbg, copy_const_value(dbg, get_Conv_op(n)), m); break;
554 nn = new_Unknown(m); break;
556 panic("opcode invalid or not implemented");
561 /** Return the name of the initializer kind. */
562 const char *get_initializer_kind_name(ir_initializer_kind_t ini)
564 #define X(a) case a: return #a
566 X(IR_INITIALIZER_CONST);
567 X(IR_INITIALIZER_TARVAL);
568 X(IR_INITIALIZER_NULL);
569 X(IR_INITIALIZER_COMPOUND);
570 default: return "BAD VALUE";
575 static ir_initializer_t null_initializer = { IR_INITIALIZER_NULL };
577 ir_initializer_t *get_initializer_null(void)
579 return &null_initializer;
582 ir_initializer_t *create_initializer_const(ir_node *value)
584 struct obstack *obst = get_irg_obstack(get_const_code_irg());
586 ir_initializer_t *initializer
587 = obstack_alloc(obst, sizeof(ir_initializer_const_t));
588 initializer->kind = IR_INITIALIZER_CONST;
589 initializer->consti.value = value;
594 ir_initializer_t *create_initializer_tarval(tarval *tv)
596 struct obstack *obst = get_irg_obstack(get_const_code_irg());
598 ir_initializer_t *initializer
599 = obstack_alloc(obst, sizeof(ir_initializer_tarval_t));
600 initializer->kind = IR_INITIALIZER_TARVAL;
601 initializer->tarval.value = tv;
606 ir_initializer_t *create_initializer_compound(unsigned n_entries)
608 struct obstack *obst = get_irg_obstack(get_const_code_irg());
611 size_t size = sizeof(ir_initializer_compound_t)
612 + (n_entries-1) * sizeof(ir_initializer_t*);
614 ir_initializer_t *initializer = obstack_alloc(obst, size);
615 initializer->kind = IR_INITIALIZER_COMPOUND;
616 initializer->compound.n_initializers = n_entries;
618 for (i = 0; i < n_entries; ++i) {
619 initializer->compound.initializers[i] = get_initializer_null();
625 ir_node *get_initializer_const_value(const ir_initializer_t *initializer)
627 assert(initializer->kind == IR_INITIALIZER_CONST);
628 return skip_Id(initializer->consti.value);
631 tarval *get_initializer_tarval_value(const ir_initializer_t *initializer)
633 assert(initializer->kind == IR_INITIALIZER_TARVAL);
634 return initializer->tarval.value;
637 unsigned get_initializer_compound_n_entries(const ir_initializer_t *initializer)
639 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
640 return initializer->compound.n_initializers;
643 void set_initializer_compound_value(ir_initializer_t *initializer,
644 unsigned index, ir_initializer_t *value)
646 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
647 assert(index < initializer->compound.n_initializers);
649 initializer->compound.initializers[index] = value;
652 ir_initializer_t *get_initializer_compound_value(
653 const ir_initializer_t *initializer, unsigned index)
655 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
656 assert(index < initializer->compound.n_initializers);
658 return initializer->compound.initializers[index];
661 ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer)
663 return initializer->kind;
666 static void check_entity_initializer(ir_entity *entity)
669 ir_initializer_t *initializer = entity->initializer;
670 ir_type *entity_tp = get_entity_type(entity);
671 switch (initializer->kind) {
672 case IR_INITIALIZER_COMPOUND:
673 assert(is_compound_type(entity_tp) || is_Array_type(entity_tp));
675 case IR_INITIALIZER_CONST:
676 /* methods are initialized by a SymConst */
677 assert(is_atomic_type(entity_tp) || is_Method_type(entity_tp));
679 case IR_INITIALIZER_TARVAL:
680 assert(is_atomic_type(entity_tp));
682 case IR_INITIALIZER_NULL:
688 void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer)
690 entity->initializer = initializer;
691 check_entity_initializer(entity);
694 int has_entity_initializer(const ir_entity *entity)
696 return entity->initializer != NULL;
699 ir_initializer_t *get_entity_initializer(const ir_entity *entity)
701 return entity->initializer;
704 int (get_entity_offset)(const ir_entity *ent)
706 return _get_entity_offset(ent);
709 void (set_entity_offset)(ir_entity *ent, int offset)
711 _set_entity_offset(ent, offset);
714 unsigned char (get_entity_offset_bits_remainder)(const ir_entity *ent)
716 return _get_entity_offset_bits_remainder(ent);
719 void (set_entity_offset_bits_remainder)(ir_entity *ent, unsigned char offset)
721 _set_entity_offset_bits_remainder(ent, offset);
724 void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
726 if (ent->overwrites == NULL) {
727 ent->overwrites = NEW_ARR_F(ir_entity*, 0);
729 ARR_APP1(ir_entity *, ent->overwrites, overwritten);
730 if (overwritten->overwrittenby == NULL) {
731 overwritten->overwrittenby = NEW_ARR_F(ir_entity*, 0);
733 ARR_APP1(ir_entity *, overwritten->overwrittenby, ent);
736 int get_entity_n_overwrites(const ir_entity *ent)
738 if (ent->overwrites == NULL)
740 return ARR_LEN(ent->overwrites);
743 int get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten)
746 n = get_entity_n_overwrites(ent);
747 for (i = 0; i < n; ++i) {
748 if (get_entity_overwrites(ent, i) == overwritten)
754 ir_entity *get_entity_overwrites(const ir_entity *ent, int pos)
756 assert(pos < get_entity_n_overwrites(ent));
757 return ent->overwrites[pos];
760 void set_entity_overwrites(ir_entity *ent, int pos, ir_entity *overwritten)
762 assert(pos < get_entity_n_overwrites(ent));
763 ent->overwrites[pos] = overwritten;
766 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
769 n = get_entity_n_overwrites(ent);
770 for (i = 0; i < n; ++i) {
771 if (ent->overwrites[i] == overwritten) {
772 for (; i < n - 1; i++)
773 ent->overwrites[i] = ent->overwrites[i+1];
774 ARR_SETLEN(ir_entity*, ent->overwrites, n - 1);
781 int get_entity_n_overwrittenby(const ir_entity *ent)
783 if (ent->overwrittenby == NULL)
785 return ARR_LEN(ent->overwrittenby);
788 int get_entity_overwrittenby_index(const ir_entity *ent, ir_entity *overwrites)
791 n = get_entity_n_overwrittenby(ent);
792 for (i = 0; i < n; ++i) {
793 if (get_entity_overwrittenby(ent, i) == overwrites)
799 ir_entity *get_entity_overwrittenby(const ir_entity *ent, int pos)
801 assert(pos < get_entity_n_overwrittenby(ent));
802 return ent->overwrittenby[pos];
805 void set_entity_overwrittenby(ir_entity *ent, int pos, ir_entity *overwrites)
807 assert(pos < get_entity_n_overwrittenby(ent));
808 ent->overwrittenby[pos] = overwrites;
811 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites)
815 n = get_entity_n_overwrittenby(ent);
816 for (i = 0; i < n; ++i) {
817 if (ent->overwrittenby[i] == overwrites) {
818 for (; i < n - 1; ++i)
819 ent->overwrittenby[i] = ent->overwrittenby[i+1];
820 ARR_SETLEN(ir_entity*, ent->overwrittenby, n - 1);
826 void *(get_entity_link)(const ir_entity *ent)
828 return _get_entity_link(ent);
831 void (set_entity_link)(ir_entity *ent, void *l)
833 _set_entity_link(ent, l);
836 ir_graph *(get_entity_irg)(const ir_entity *ent)
838 return _get_entity_irg(ent);
841 void set_entity_irg(ir_entity *ent, ir_graph *irg)
843 assert(is_method_entity(ent));
844 assert(get_entity_peculiarity(ent) == peculiarity_existent);
845 ent->attr.mtd_attr.irg = irg;
848 unsigned get_entity_vtable_number(const ir_entity *ent)
850 assert(is_method_entity((ir_entity *)ent));
851 return ent->attr.mtd_attr.vtable_number;
854 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number)
856 assert(is_method_entity(ent));
857 ent->attr.mtd_attr.vtable_number = vtable_number;
860 int (is_entity)(const void *thing)
862 return _is_entity(thing);
865 int is_atomic_entity(const ir_entity *ent)
867 ir_type *t = get_entity_type(ent);
868 const tp_op *op = get_type_tpop(t);
869 return (op == type_primitive || op == type_pointer ||
870 op == type_enumeration || op == type_method);
873 int is_compound_entity(const ir_entity *ent)
875 ir_type *t = get_entity_type(ent);
876 const tp_op *op = get_type_tpop(t);
877 return (op == type_class || op == type_struct ||
878 op == type_array || op == type_union);
881 int is_method_entity(const ir_entity *ent)
883 ir_type *t = get_entity_type(ent);
884 return is_Method_type(t);
887 ir_visited_t (get_entity_visited)(const ir_entity *ent)
889 return _get_entity_visited(ent);
892 void (set_entity_visited)(ir_entity *ent, ir_visited_t num)
894 _set_entity_visited(ent, num);
897 void (mark_entity_visited)(ir_entity *ent)
899 _mark_entity_visited(ent);
902 int (entity_visited)(const ir_entity *ent)
904 return _entity_visited(ent);
907 int (entity_not_visited)(const ir_entity *ent)
909 return _entity_not_visited(ent);
912 unsigned get_entity_additional_properties(const ir_entity *ent)
916 assert(is_method_entity(ent));
918 /* first check, if the graph has additional properties */
919 irg = get_entity_irg(ent);
922 return get_irg_additional_properties(irg);
924 if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited)
925 return get_method_additional_properties(get_entity_type(ent));
927 return ent->attr.mtd_attr.irg_add_properties;
930 void set_entity_additional_properties(ir_entity *ent, unsigned property_mask)
934 assert(is_method_entity(ent));
936 /* first check, if the graph exists */
937 irg = get_entity_irg(ent);
939 set_irg_additional_properties(irg, property_mask);
941 /* do not allow to set the mtp_property_inherited flag or
942 * the automatic inheritance of flags will not work */
943 ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
947 void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag)
951 assert(is_method_entity(ent));
953 /* first check, if the graph exists */
954 irg = get_entity_irg(ent);
956 set_irg_additional_property(irg, flag);
958 unsigned mask = ent->attr.mtd_attr.irg_add_properties;
960 if (mask & mtp_property_inherited)
961 mask = get_method_additional_properties(get_entity_type(ent));
963 /* do not allow to set the mtp_property_inherited flag or
964 * the automatic inheritance of flags will not work */
965 ent->attr.mtd_attr.irg_add_properties = mask | (flag & ~mtp_property_inherited);
969 /* Returns the class type that this type info entity represents or NULL
970 if ent is no type info entity. */
971 ir_type *(get_entity_repr_class)(const ir_entity *ent)
973 return _get_entity_repr_class(ent);
976 dbg_info *(get_entity_dbg_info)(const ir_entity *ent)
978 return _get_entity_dbg_info(ent);
981 void (set_entity_dbg_info)(ir_entity *ent, dbg_info *db)
983 _set_entity_dbg_info(ent, db);
986 int entity_is_externally_visible(const ir_entity *entity)
988 return get_entity_visibility(entity) != ir_visibility_local
989 || (get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER);
992 int entity_has_definition(const ir_entity *entity)
994 return entity->initializer != NULL
995 || get_entity_irg(entity) != NULL
996 || entity_has_compound_ent_values(entity);
999 void ir_init_entity(void)
1001 assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
1002 assert(!unknown_entity && "Call firm_init_entity() only once!");
1004 unknown_entity = new_d_entity(NULL, new_id_from_str(UNKNOWN_ENTITY_NAME),
1005 firm_unknown_type, NULL);
1006 set_entity_visibility(unknown_entity, ir_visibility_external);
1007 set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
1010 void ir_finish_entity(void)
1012 if (unknown_entity != NULL) {
1013 free_entity(unknown_entity);
1014 unknown_entity = NULL;
1018 ir_allocation get_entity_allocation(const ir_entity *entity)
1020 return entity->allocation;
1023 void set_entity_allocation(ir_entity *entity, ir_allocation allocation)
1025 entity->allocation = allocation;
1028 ir_peculiarity get_entity_peculiarity(const ir_entity *entity)
1030 return entity->peculiarity;
1033 void set_entity_peculiarity(ir_entity *entity, ir_peculiarity peculiarity)
1035 entity->peculiarity = peculiarity;
1038 void set_entity_final(ir_entity *entity, int final)
1040 entity->final = final;
1043 int is_entity_final(const ir_entity *entity)
1045 return entity->final;