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);
247 ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner)
250 assert(is_entity(old));
251 assert(is_compound_type(new_owner));
252 assert(get_type_state(new_owner) != layout_fixed);
254 if (old->owner == new_owner)
257 /* create a deep copy so we are safe of aliasing and double-freeing. */
258 newe = deep_entity_copy(old);
259 newe->owner = new_owner;
260 add_compound_member(new_owner, newe);
265 ir_entity *copy_entity_name(ir_entity *old, ident *new_name)
268 assert(old && old->kind == k_entity);
270 if (old->name == new_name)
273 newe = deep_entity_copy(old);
274 newe->name = new_name;
275 newe->ld_name = NULL;
276 add_compound_member(old->owner, newe);
281 void free_entity(ir_entity *ent)
283 if (ent->owner != NULL && !is_Array_type(ent->owner))
284 remove_compound_member(ent->owner, ent);
286 assert(ent && ent->kind == k_entity);
287 free_entity_attrs(ent);
292 long get_entity_nr(const ir_entity *ent)
294 assert(ent && ent->kind == k_entity);
298 return (long)PTR_TO_INT(ent);
302 const char *(get_entity_name)(const ir_entity *ent)
304 return _get_entity_name(ent);
307 ident *(get_entity_ident)(const ir_entity *ent)
309 return _get_entity_ident(ent);
312 void (set_entity_ident)(ir_entity *ent, ident *id)
314 _set_entity_ident(ent, id);
317 ir_type *(get_entity_owner)(const ir_entity *ent)
319 return _get_entity_owner(ent);
322 void set_entity_owner(ir_entity *ent, ir_type *owner)
324 assert(is_entity(ent));
325 assert(is_compound_type(owner));
327 remove_compound_member(ent->owner, ent);
328 add_compound_member(owner, ent);
332 ident *(get_entity_ld_ident)(const ir_entity *ent)
334 return _get_entity_ld_ident(ent);
337 void (set_entity_ld_ident)(ir_entity *ent, ident *ld_ident)
339 _set_entity_ld_ident(ent, ld_ident);
342 const char *(get_entity_ld_name)(const ir_entity *ent)
344 return _get_entity_ld_name(ent);
347 int entity_has_ld_ident(const ir_entity *entity)
349 return entity->ld_name != NULL;
352 ir_type *(get_entity_type)(const ir_entity *ent)
354 return _get_entity_type(ent);
357 void set_entity_type(ir_entity *ent, ir_type *type)
359 switch (ent->entity_kind) {
360 case IR_ENTITY_METHOD:
361 assert(is_Method_type(type));
363 case IR_ENTITY_NORMAL:
364 assert(!is_Method_type(type));
366 case IR_ENTITY_LABEL:
367 assert(type == firm_code_type);
369 case IR_ENTITY_COMPOUND_MEMBER:
375 ir_volatility (get_entity_volatility)(const ir_entity *ent)
377 return _get_entity_volatility(ent);
380 void (set_entity_volatility)(ir_entity *ent, ir_volatility vol)
382 _set_entity_volatility(ent, vol);
385 const char *get_volatility_name(ir_volatility var)
387 #define X(a) case a: return #a
389 X(volatility_non_volatile);
390 X(volatility_is_volatile);
391 default: return "BAD VALUE";
396 ir_align (get_entity_aligned)(const ir_entity *ent)
398 return _get_entity_aligned(ent);
401 void (set_entity_aligned)(ir_entity *ent, ir_align a)
403 _set_entity_aligned(ent, a);
406 unsigned (get_entity_alignment)(const ir_entity *ent)
408 return _get_entity_alignment(ent);
411 void (set_entity_alignment)(ir_entity *ent, unsigned alignment)
413 _set_entity_alignment(ent, alignment);
416 const char *get_align_name(ir_align a)
418 #define X(a) case a: return #a
420 X(align_non_aligned);
422 default: return "BAD VALUE";
427 void set_entity_label(ir_entity *ent, ir_label_t label)
429 assert(ent->entity_kind == IR_ENTITY_LABEL);
430 ent->attr.code_attr.label = label;
433 ir_label_t get_entity_label(const ir_entity *ent)
435 assert(ent->entity_kind == IR_ENTITY_LABEL);
436 return ent->attr.code_attr.label;
439 static void verify_visibility(const ir_entity *entity)
441 if (get_entity_visibility(entity) == ir_visibility_external
442 && !is_method_entity(entity)) {
443 assert(!entity_has_definition(entity));
447 void set_entity_visibility(ir_entity *entity, ir_visibility visibility)
449 entity->visibility = visibility;
450 verify_visibility(entity);
453 ir_visibility get_entity_visibility(const ir_entity *entity)
455 return (ir_visibility)entity->visibility;
458 void set_entity_linkage(ir_entity *entity, ir_linkage linkage)
460 entity->linkage = linkage;
463 ir_linkage (get_entity_linkage)(const ir_entity *entity)
465 return get_entity_linkage(entity);
468 void add_entity_linkage(ir_entity *entity, ir_linkage linkage)
470 entity->linkage |= linkage;
473 void remove_entity_linkage(ir_entity *entity, ir_linkage linkage)
475 entity->linkage &= ~linkage;
478 int (is_entity_compiler_generated)(const ir_entity *ent)
480 return _is_entity_compiler_generated(ent);
483 void (set_entity_compiler_generated)(ir_entity *ent, int flag)
485 _set_entity_compiler_generated(ent, flag);
488 ir_entity_usage (get_entity_usage)(const ir_entity *ent)
490 return _get_entity_usage(ent);
493 void (set_entity_usage)(ir_entity *ent, ir_entity_usage flags)
495 _set_entity_usage(ent, flags);
498 ir_node *get_atomic_ent_value(ir_entity *entity)
500 ir_initializer_t *initializer = get_entity_initializer(entity);
502 assert(entity && is_atomic_entity(entity));
503 if (initializer == NULL) {
504 ir_type *type = get_entity_type(entity);
505 return new_r_Unknown(get_const_code_irg(), get_type_mode(type));
508 switch (get_initializer_kind(initializer)) {
509 case IR_INITIALIZER_NULL: {
510 ir_type *type = get_entity_type(entity);
511 ir_mode *mode = get_type_mode(type);
512 return new_r_Const(get_const_code_irg(), get_mode_null(mode));
514 case IR_INITIALIZER_TARVAL: {
515 ir_tarval *tv = get_initializer_tarval_value(initializer);
516 return new_r_Const(get_const_code_irg(), tv);
518 case IR_INITIALIZER_CONST:
519 return get_initializer_const_value(initializer);
520 case IR_INITIALIZER_COMPOUND:
521 panic("compound initializer in atomic entity not allowed (%+F)", entity);
524 panic("invalid initializer kind in get_atomic_ent_value(%+F)", entity);
527 void set_atomic_ent_value(ir_entity *entity, ir_node *val)
529 ir_initializer_t *initializer;
531 assert(is_atomic_entity(entity));
533 assert(is_Dummy(val) || get_irn_mode(val) == get_type_mode(entity->type));
534 initializer = create_initializer_const(val);
535 entity->initializer = initializer;
538 int is_irn_const_expression(ir_node *n)
540 /* we are in danger iff an exception will arise. TODO: be more precisely,
541 * for instance Div. will NOT rise if divisor != 0
543 if (is_binop(n) && !is_fragile_op(n))
544 return is_irn_const_expression(get_binop_left(n)) && is_irn_const_expression(get_binop_right(n));
546 switch (get_irn_opcode(n)) {
553 return is_irn_const_expression(get_irn_n(n, 0));
560 ir_node *copy_const_value(dbg_info *dbg, ir_node *n, ir_node *block)
562 ir_graph *irg = get_irn_irg(block);
566 /* @@@ GL I think we should implement this using the routines from irgopt for
567 dead node elimination/inlineing. */
570 switch (get_irn_opcode(n)) {
572 nn = new_rd_Const(dbg, irg, get_Const_tarval(n));
575 nn = new_rd_SymConst(dbg, irg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n));
578 nn = new_rd_Add(dbg, block,
579 copy_const_value(dbg, get_Add_left(n), block),
580 copy_const_value(dbg, get_Add_right(n), block), m);
583 nn = new_rd_Sub(dbg, block,
584 copy_const_value(dbg, get_Sub_left(n), block),
585 copy_const_value(dbg, get_Sub_right(n), block), m);
588 nn = new_rd_Mul(dbg, block,
589 copy_const_value(dbg, get_Mul_left(n), block),
590 copy_const_value(dbg, get_Mul_right(n), block), m);
593 nn = new_rd_And(dbg, block,
594 copy_const_value(dbg, get_And_left(n), block),
595 copy_const_value(dbg, get_And_right(n), block), m);
598 nn = new_rd_Or(dbg, block,
599 copy_const_value(dbg, get_Or_left(n), block),
600 copy_const_value(dbg, get_Or_right(n), block), m);
603 nn = new_rd_Eor(dbg, block,
604 copy_const_value(dbg, get_Eor_left(n), block),
605 copy_const_value(dbg, get_Eor_right(n), block), m);
608 nn = new_rd_Cast(dbg, block,
609 copy_const_value(dbg, get_Cast_op(n), block),
613 nn = new_rd_Conv(dbg, block,
614 copy_const_value(dbg, get_Conv_op(n), block), m);
617 nn = new_r_Unknown(irg, m); break;
619 panic("opcode invalid or not implemented");
624 const char *get_initializer_kind_name(ir_initializer_kind_t ini)
626 #define X(a) case a: return #a
628 X(IR_INITIALIZER_CONST);
629 X(IR_INITIALIZER_TARVAL);
630 X(IR_INITIALIZER_NULL);
631 X(IR_INITIALIZER_COMPOUND);
632 default: return "BAD VALUE";
637 static ir_initializer_t null_initializer = { IR_INITIALIZER_NULL };
639 ir_initializer_t *get_initializer_null(void)
641 return &null_initializer;
644 ir_initializer_t *create_initializer_const(ir_node *value)
646 struct obstack *obst = get_irg_obstack(get_const_code_irg());
648 ir_initializer_t *initializer
649 = (ir_initializer_t*)OALLOC(obst, ir_initializer_const_t);
650 initializer->kind = IR_INITIALIZER_CONST;
651 initializer->consti.value = value;
656 ir_initializer_t *create_initializer_tarval(ir_tarval *tv)
658 struct obstack *obst = get_irg_obstack(get_const_code_irg());
660 ir_initializer_t *initializer
661 = (ir_initializer_t*)OALLOC(obst, ir_initializer_tarval_t);
662 initializer->kind = IR_INITIALIZER_TARVAL;
663 initializer->tarval.value = tv;
668 ir_initializer_t *create_initializer_compound(size_t n_entries)
670 struct obstack *obst = get_irg_obstack(get_const_code_irg());
673 size_t size = sizeof(ir_initializer_compound_t)
674 + n_entries * sizeof(ir_initializer_t*)
675 - sizeof(ir_initializer_t*);
677 ir_initializer_t *initializer
678 = (ir_initializer_t*)obstack_alloc(obst, size);
679 initializer->kind = IR_INITIALIZER_COMPOUND;
680 initializer->compound.n_initializers = n_entries;
682 for (i = 0; i < n_entries; ++i) {
683 initializer->compound.initializers[i] = get_initializer_null();
689 ir_node *get_initializer_const_value(const ir_initializer_t *initializer)
691 assert(initializer->kind == IR_INITIALIZER_CONST);
692 return skip_Id(initializer->consti.value);
695 ir_tarval *get_initializer_tarval_value(const ir_initializer_t *initializer)
697 assert(initializer->kind == IR_INITIALIZER_TARVAL);
698 return initializer->tarval.value;
701 size_t get_initializer_compound_n_entries(const ir_initializer_t *initializer)
703 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
704 return initializer->compound.n_initializers;
707 void set_initializer_compound_value(ir_initializer_t *initializer,
708 size_t index, ir_initializer_t *value)
710 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
711 assert(index < initializer->compound.n_initializers);
713 initializer->compound.initializers[index] = value;
716 ir_initializer_t *get_initializer_compound_value(
717 const ir_initializer_t *initializer, size_t index)
719 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
720 assert(index < initializer->compound.n_initializers);
722 return initializer->compound.initializers[index];
725 ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer)
727 return initializer->kind;
730 static void check_entity_initializer(ir_entity *entity)
733 ir_initializer_t *initializer = entity->initializer;
734 ir_type *entity_tp = get_entity_type(entity);
735 switch (initializer->kind) {
736 case IR_INITIALIZER_COMPOUND:
737 assert(is_compound_type(entity_tp) || is_Array_type(entity_tp));
739 case IR_INITIALIZER_CONST:
740 /* methods are initialized by a SymConst */
741 assert(is_atomic_type(entity_tp) || is_Method_type(entity_tp));
743 case IR_INITIALIZER_TARVAL:
744 assert(is_atomic_type(entity_tp));
746 case IR_INITIALIZER_NULL:
752 void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer)
754 entity->initializer = initializer;
755 check_entity_initializer(entity);
758 int has_entity_initializer(const ir_entity *entity)
760 return entity->initializer != NULL;
763 ir_initializer_t *get_entity_initializer(const ir_entity *entity)
765 return entity->initializer;
768 int (get_entity_offset)(const ir_entity *ent)
770 return _get_entity_offset(ent);
773 void (set_entity_offset)(ir_entity *ent, int offset)
775 _set_entity_offset(ent, offset);
778 unsigned char (get_entity_offset_bits_remainder)(const ir_entity *ent)
780 return _get_entity_offset_bits_remainder(ent);
783 void (set_entity_offset_bits_remainder)(ir_entity *ent, unsigned char offset)
785 _set_entity_offset_bits_remainder(ent, offset);
788 void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
790 if (ent->overwrites == NULL) {
791 ent->overwrites = NEW_ARR_F(ir_entity*, 0);
793 ARR_APP1(ir_entity *, ent->overwrites, overwritten);
794 if (overwritten->overwrittenby == NULL) {
795 overwritten->overwrittenby = NEW_ARR_F(ir_entity*, 0);
797 ARR_APP1(ir_entity *, overwritten->overwrittenby, ent);
800 size_t get_entity_n_overwrites(const ir_entity *ent)
802 if (ent->overwrites == NULL)
804 return ARR_LEN(ent->overwrites);
807 size_t get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten)
810 size_t n = get_entity_n_overwrites(ent);
811 for (i = 0; i < n; ++i) {
812 if (get_entity_overwrites(ent, i) == overwritten)
818 ir_entity *get_entity_overwrites(const ir_entity *ent, size_t pos)
820 assert(pos < get_entity_n_overwrites(ent));
821 return ent->overwrites[pos];
824 void set_entity_overwrites(ir_entity *ent, size_t pos, ir_entity *overwritten)
826 assert(pos < get_entity_n_overwrites(ent));
827 ent->overwrites[pos] = overwritten;
830 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
833 size_t n = get_entity_n_overwrites(ent);
834 for (i = 0; i < n; ++i) {
835 if (ent->overwrites[i] == overwritten) {
836 for (; i < n - 1; i++)
837 ent->overwrites[i] = ent->overwrites[i+1];
838 ARR_SETLEN(ir_entity*, ent->overwrites, n - 1);
845 size_t get_entity_n_overwrittenby(const ir_entity *ent)
847 if (ent->overwrittenby == NULL)
849 return ARR_LEN(ent->overwrittenby);
852 size_t get_entity_overwrittenby_index(const ir_entity *ent,
853 ir_entity *overwrites)
856 size_t n = get_entity_n_overwrittenby(ent);
857 for (i = 0; i < n; ++i) {
858 if (get_entity_overwrittenby(ent, i) == overwrites)
864 ir_entity *get_entity_overwrittenby(const ir_entity *ent, size_t pos)
866 assert(pos < get_entity_n_overwrittenby(ent));
867 return ent->overwrittenby[pos];
870 void set_entity_overwrittenby(ir_entity *ent, size_t pos, ir_entity *overwrites)
872 assert(pos < get_entity_n_overwrittenby(ent));
873 ent->overwrittenby[pos] = overwrites;
876 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites)
879 size_t n = get_entity_n_overwrittenby(ent);
880 for (i = 0; i < n; ++i) {
881 if (ent->overwrittenby[i] == overwrites) {
882 for (; i < n - 1; ++i)
883 ent->overwrittenby[i] = ent->overwrittenby[i+1];
884 ARR_SETLEN(ir_entity*, ent->overwrittenby, n - 1);
890 void *(get_entity_link)(const ir_entity *ent)
892 return _get_entity_link(ent);
895 void (set_entity_link)(ir_entity *ent, void *l)
897 _set_entity_link(ent, l);
900 ir_graph *(get_entity_irg)(const ir_entity *ent)
902 return _get_entity_irg(ent);
905 void set_entity_irg(ir_entity *ent, ir_graph *irg)
907 assert(is_method_entity(ent));
908 assert(get_entity_peculiarity(ent) == peculiarity_existent);
909 ent->attr.mtd_attr.irg = irg;
912 int (is_parameter_entity)(const ir_entity *entity)
914 return _is_parameter_entity(entity);
917 size_t (get_entity_parameter_number)(const ir_entity *entity)
919 return _get_entity_parameter_number(entity);
922 void set_entity_parameter_number(ir_entity *entity, size_t n)
924 assert(is_parameter_entity(entity));
925 entity->attr.parameter.number = n;
928 unsigned get_entity_vtable_number(const ir_entity *ent)
930 assert(is_method_entity((ir_entity *)ent));
931 return ent->attr.mtd_attr.vtable_number;
934 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number)
936 assert(is_method_entity(ent));
937 ent->attr.mtd_attr.vtable_number = vtable_number;
940 int (is_entity)(const void *thing)
942 return _is_entity(thing);
945 int is_atomic_entity(const ir_entity *ent)
947 ir_type *t = get_entity_type(ent);
948 const tp_op *op = get_type_tpop(t);
949 return (op == type_primitive || op == type_pointer ||
950 op == type_enumeration || op == type_method);
953 int is_compound_entity(const ir_entity *ent)
955 ir_type *t = get_entity_type(ent);
956 const tp_op *op = get_type_tpop(t);
957 return (op == type_class || op == type_struct ||
958 op == type_array || op == type_union);
961 int is_method_entity(const ir_entity *ent)
963 ir_type *t = get_entity_type(ent);
964 return is_Method_type(t);
967 ir_visited_t (get_entity_visited)(const ir_entity *ent)
969 return _get_entity_visited(ent);
972 void (set_entity_visited)(ir_entity *ent, ir_visited_t num)
974 _set_entity_visited(ent, num);
977 void (mark_entity_visited)(ir_entity *ent)
979 _mark_entity_visited(ent);
982 int (entity_visited)(const ir_entity *ent)
984 return _entity_visited(ent);
987 int (entity_not_visited)(const ir_entity *ent)
989 return _entity_not_visited(ent);
992 mtp_additional_properties get_entity_additional_properties(const ir_entity *ent)
996 assert(is_method_entity(ent));
998 /* first check, if the graph has additional properties */
999 irg = get_entity_irg(ent);
1002 return get_irg_additional_properties(irg);
1004 if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited)
1005 return get_method_additional_properties(get_entity_type(ent));
1007 return ent->attr.mtd_attr.irg_add_properties;
1010 void set_entity_additional_properties(ir_entity *ent, mtp_additional_properties property_mask)
1014 assert(is_method_entity(ent));
1016 /* first check, if the graph exists */
1017 irg = get_entity_irg(ent);
1019 set_irg_additional_properties(irg, property_mask);
1021 /* do not allow to set the mtp_property_inherited flag or
1022 * the automatic inheritance of flags will not work */
1023 ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
1027 void add_entity_additional_properties(ir_entity *ent, mtp_additional_properties properties)
1031 assert(is_method_entity(ent));
1033 /* first check, if the graph exists */
1034 irg = get_entity_irg(ent);
1036 add_irg_additional_properties(irg, properties);
1038 mtp_additional_properties mask = ent->attr.mtd_attr.irg_add_properties;
1040 if (mask & mtp_property_inherited)
1041 mask = get_method_additional_properties(get_entity_type(ent));
1043 /* do not allow to set the mtp_property_inherited flag or
1044 * the automatic inheritance of flags will not work */
1045 ent->attr.mtd_attr.irg_add_properties = mask | (properties & ~mtp_property_inherited);
1049 ir_type *(get_entity_repr_class)(const ir_entity *ent)
1051 return _get_entity_repr_class(ent);
1054 dbg_info *(get_entity_dbg_info)(const ir_entity *ent)
1056 return _get_entity_dbg_info(ent);
1059 void (set_entity_dbg_info)(ir_entity *ent, dbg_info *db)
1061 _set_entity_dbg_info(ent, db);
1064 int entity_is_externally_visible(const ir_entity *entity)
1066 return get_entity_visibility(entity) != ir_visibility_local
1067 || (get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER);
1070 int entity_has_definition(const ir_entity *entity)
1072 return entity->initializer != NULL
1073 || get_entity_irg(entity) != NULL
1074 || entity_has_compound_ent_values(entity);
1077 void ir_init_entity(void)
1079 assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
1080 assert(!unknown_entity && "Call firm_init_entity() only once!");
1082 unknown_entity = new_d_entity(NULL, new_id_from_str(UNKNOWN_ENTITY_NAME),
1083 firm_unknown_type, NULL);
1084 set_entity_visibility(unknown_entity, ir_visibility_external);
1085 set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
1088 void ir_finish_entity(void)
1090 if (unknown_entity != NULL) {
1091 free_entity(unknown_entity);
1092 unknown_entity = NULL;
1096 ir_allocation get_entity_allocation(const ir_entity *entity)
1098 return (ir_allocation)entity->allocation;
1101 void set_entity_allocation(ir_entity *entity, ir_allocation allocation)
1103 entity->allocation = allocation;
1106 ir_peculiarity get_entity_peculiarity(const ir_entity *entity)
1108 return (ir_peculiarity)entity->peculiarity;
1111 void set_entity_peculiarity(ir_entity *entity, ir_peculiarity peculiarity)
1113 entity->peculiarity = peculiarity;
1116 void set_entity_final(ir_entity *entity, int final)
1118 entity->final = final;
1121 int is_entity_final(const ir_entity *entity)
1123 return entity->final;