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 /** The name of the unknown entity. */
48 #define UNKNOWN_ENTITY_NAME "unknown_entity"
50 ir_entity *get_unknown_entity(void)
52 return irp->unknown_entity;
55 /*-----------------------------------------------------------------*/
57 /*-----------------------------------------------------------------*/
59 static ir_entity *intern_new_entity(ir_type *owner, ir_entity_kind kind,
60 ident *name, ir_type *type, dbg_info *dbgi)
62 ir_entity *res = XMALLOCZ(ir_entity);
70 res->entity_kind = kind;
71 res->volatility = volatility_non_volatile;
72 res->aligned = align_is_aligned;
73 res->usage = ir_usage_unknown;
74 res->compiler_gen = 0;
75 res->visibility = ir_visibility_default;
77 res->offset_bit_remainder = 0;
80 res->repr_class = NULL;
82 res->nr = get_irp_new_node_nr();
85 /* Remember entity in its owner. */
87 add_compound_member(owner, res);
90 set_entity_dbg_info(res, dbgi);
95 ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *type,
100 if (is_Method_type(type)) {
101 ir_graph *irg = get_const_code_irg();
103 ir_mode *mode = is_Method_type(type) ? mode_P_code : mode_P_data;
104 res = intern_new_entity(owner, IR_ENTITY_METHOD, name, type, db);
106 set_atomic_ent_value(res, new_r_SymConst(irg, mode, sym, symconst_addr_ent));
107 res->linkage = IR_LINKAGE_CONSTANT;
108 res->attr.mtd_attr.irg_add_properties = mtp_property_inherited;
109 res->attr.mtd_attr.vtable_number = IR_VTABLE_NUM_NOT_SET;
110 res->attr.mtd_attr.param_access = NULL;
111 res->attr.mtd_attr.param_weight = NULL;
112 res->attr.mtd_attr.irg = NULL;
113 } else if (owner != NULL
114 && (is_compound_type(owner) && !(owner->flags & tf_segment))) {
115 res = intern_new_entity(owner, IR_ENTITY_COMPOUND_MEMBER, name, type, db);
116 res->attr.cmpd_attr.values = NULL;
117 res->attr.cmpd_attr.val_paths = NULL;
119 res = intern_new_entity(owner, IR_ENTITY_NORMAL, name, type, db);
122 hook_new_entity(res);
126 ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
128 return new_d_entity(owner, name, type, NULL);
131 static ident *make_parameter_entity_name(size_t pos)
134 snprintf(buf, sizeof(buf), "parameter.%lu", (unsigned long) pos);
135 return new_id_from_str(buf);
138 ir_entity *new_d_parameter_entity(ir_type *owner, size_t pos, ir_type *type,
141 ident *name = make_parameter_entity_name(pos);
143 = intern_new_entity(owner, IR_ENTITY_PARAMETER, name, type, dbgi);
144 res->attr.parameter.number = pos;
145 hook_new_entity(res);
149 ir_entity *new_parameter_entity(ir_type *owner, size_t pos, ir_type *type)
151 return new_d_parameter_entity(owner, pos, type, NULL);
154 ir_entity *new_d_label_entity(ir_label_t label, dbg_info *dbgi)
156 ident *name = id_unique("label_%u");
157 ir_type *global_type = get_glob_type();
159 = intern_new_entity(global_type, IR_ENTITY_LABEL, name, get_code_type(),
161 res->attr.code_attr.label = label;
162 hook_new_entity(res);
166 ir_entity *new_label_entity(ir_label_t label)
168 return new_d_label_entity(label, NULL);
172 * Free entity attributes.
174 * @param ent the entity
176 static void free_entity_attrs(ir_entity *ent)
178 if (ent->overwrites != NULL) {
179 DEL_ARR_F(ent->overwrites);
180 ent->overwrites = NULL;
182 if (ent->overwrittenby != NULL) {
183 DEL_ARR_F(ent->overwrittenby);
184 ent->overwrittenby = NULL;
187 if (ent->initializer != NULL) {
188 /* TODO: free initializers */
189 } else if (entity_has_compound_ent_values(ent)) {
190 /* can't free compound graph path as it might be used
192 ent->attr.cmpd_attr.val_paths = NULL;
194 if (ent->entity_kind == IR_ENTITY_COMPOUND_MEMBER) {
195 ent->attr.cmpd_attr.values = NULL;
196 } else if (ent->entity_kind == IR_ENTITY_METHOD) {
197 if (ent->attr.mtd_attr.param_access) {
198 DEL_ARR_F(ent->attr.mtd_attr.param_access);
199 ent->attr.mtd_attr.param_access = NULL;
201 if (ent->attr.mtd_attr.param_weight) {
202 DEL_ARR_F(ent->attr.mtd_attr.param_weight);
203 ent->attr.mtd_attr.param_weight = NULL;
209 * Creates a deep copy of an entity.
211 static ir_entity *deep_entity_copy(ir_entity *old)
213 ir_entity *newe = XMALLOC(ir_entity);
216 if (old->initializer != NULL) {
217 /* FIXME: the initializers are NOT copied */
218 } else if (entity_has_compound_ent_values(old)) {
219 newe->attr.cmpd_attr.values = NULL;
220 newe->attr.cmpd_attr.val_paths = NULL;
221 if (old->attr.cmpd_attr.values)
222 newe->attr.cmpd_attr.values = DUP_ARR_F(ir_node *, old->attr.cmpd_attr.values);
224 /* FIXME: the compound graph paths are NOT copied */
225 if (old->attr.cmpd_attr.val_paths)
226 newe->attr.cmpd_attr.val_paths = DUP_ARR_F(compound_graph_path *, old->attr.cmpd_attr.val_paths);
227 } else if (is_method_entity(old)) {
228 /* do NOT copy them, reanalyze. This might be the best solution */
229 newe->attr.mtd_attr.param_access = NULL;
230 newe->attr.mtd_attr.param_weight = NULL;
232 newe->overwrites = NULL;
233 newe->overwrittenby = NULL;
236 newe->nr = get_irp_new_node_nr();
238 hook_new_entity(newe);
242 ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner)
245 assert(is_entity(old));
246 assert(is_compound_type(new_owner));
247 assert(get_type_state(new_owner) != layout_fixed);
249 if (old->owner == new_owner)
252 /* create a deep copy so we are safe of aliasing and double-freeing. */
253 newe = deep_entity_copy(old);
254 newe->owner = new_owner;
255 add_compound_member(new_owner, newe);
260 ir_entity *copy_entity_name(ir_entity *old, ident *new_name)
263 assert(old && old->kind == k_entity);
265 if (old->name == new_name)
268 newe = deep_entity_copy(old);
269 newe->name = new_name;
270 newe->ld_name = NULL;
271 add_compound_member(old->owner, newe);
276 void free_entity(ir_entity *ent)
278 if (ent->owner != NULL && !is_Array_type(ent->owner))
279 remove_compound_member(ent->owner, ent);
281 assert(ent && ent->kind == k_entity);
282 free_entity_attrs(ent);
289 long get_entity_nr(const ir_entity *ent)
291 assert(ent && ent->kind == k_entity);
295 return (long)PTR_TO_INT(ent);
299 const char *(get_entity_name)(const ir_entity *ent)
301 return _get_entity_name(ent);
304 ident *(get_entity_ident)(const ir_entity *ent)
306 return _get_entity_ident(ent);
309 void (set_entity_ident)(ir_entity *ent, ident *id)
311 _set_entity_ident(ent, id);
314 ir_type *(get_entity_owner)(const ir_entity *ent)
316 return _get_entity_owner(ent);
319 void set_entity_owner(ir_entity *ent, ir_type *owner)
321 assert(is_entity(ent));
322 assert(is_compound_type(owner));
324 remove_compound_member(ent->owner, ent);
325 add_compound_member(owner, ent);
329 ident *(get_entity_ld_ident)(const ir_entity *ent)
331 return _get_entity_ld_ident(ent);
334 void (set_entity_ld_ident)(ir_entity *ent, ident *ld_ident)
336 _set_entity_ld_ident(ent, ld_ident);
339 const char *(get_entity_ld_name)(const ir_entity *ent)
341 return _get_entity_ld_name(ent);
344 int entity_has_ld_ident(const ir_entity *entity)
346 return entity->ld_name != NULL;
349 ir_type *(get_entity_type)(const ir_entity *ent)
351 return _get_entity_type(ent);
354 void set_entity_type(ir_entity *ent, ir_type *type)
356 switch (ent->entity_kind) {
357 case IR_ENTITY_METHOD:
358 assert(is_Method_type(type));
360 case IR_ENTITY_NORMAL:
361 assert(!is_Method_type(type));
363 case IR_ENTITY_LABEL:
364 assert(type == get_code_type());
366 case IR_ENTITY_COMPOUND_MEMBER:
372 ir_volatility (get_entity_volatility)(const ir_entity *ent)
374 return _get_entity_volatility(ent);
377 void (set_entity_volatility)(ir_entity *ent, ir_volatility vol)
379 _set_entity_volatility(ent, vol);
382 const char *get_volatility_name(ir_volatility var)
384 #define X(a) case a: return #a
386 X(volatility_non_volatile);
387 X(volatility_is_volatile);
388 default: return "BAD VALUE";
393 ir_align (get_entity_aligned)(const ir_entity *ent)
395 return _get_entity_aligned(ent);
398 void (set_entity_aligned)(ir_entity *ent, ir_align a)
400 _set_entity_aligned(ent, a);
403 unsigned (get_entity_alignment)(const ir_entity *ent)
405 return _get_entity_alignment(ent);
408 void (set_entity_alignment)(ir_entity *ent, unsigned alignment)
410 _set_entity_alignment(ent, alignment);
413 const char *get_align_name(ir_align a)
415 #define X(a) case a: return #a
417 X(align_non_aligned);
419 default: return "BAD VALUE";
424 void set_entity_label(ir_entity *ent, ir_label_t label)
426 assert(ent->entity_kind == IR_ENTITY_LABEL);
427 ent->attr.code_attr.label = label;
430 ir_label_t get_entity_label(const ir_entity *ent)
432 assert(ent->entity_kind == IR_ENTITY_LABEL);
433 return ent->attr.code_attr.label;
436 static void verify_visibility(const ir_entity *entity)
438 if (get_entity_visibility(entity) == ir_visibility_external
439 && !is_method_entity(entity)) {
440 assert(!entity_has_definition(entity));
444 void set_entity_visibility(ir_entity *entity, ir_visibility visibility)
446 entity->visibility = visibility;
447 verify_visibility(entity);
450 ir_visibility get_entity_visibility(const ir_entity *entity)
452 return (ir_visibility)entity->visibility;
455 void set_entity_linkage(ir_entity *entity, ir_linkage linkage)
457 entity->linkage = linkage;
460 ir_linkage (get_entity_linkage)(const ir_entity *entity)
462 return get_entity_linkage(entity);
465 void add_entity_linkage(ir_entity *entity, ir_linkage linkage)
467 entity->linkage |= linkage;
470 void remove_entity_linkage(ir_entity *entity, ir_linkage linkage)
472 entity->linkage &= ~linkage;
475 int (is_entity_compiler_generated)(const ir_entity *ent)
477 return _is_entity_compiler_generated(ent);
480 void (set_entity_compiler_generated)(ir_entity *ent, int flag)
482 _set_entity_compiler_generated(ent, flag);
485 ir_entity_usage (get_entity_usage)(const ir_entity *ent)
487 return _get_entity_usage(ent);
490 void (set_entity_usage)(ir_entity *ent, ir_entity_usage flags)
492 _set_entity_usage(ent, flags);
495 ir_node *get_atomic_ent_value(ir_entity *entity)
497 ir_initializer_t *initializer = get_entity_initializer(entity);
499 assert(entity && is_atomic_entity(entity));
500 if (initializer == NULL) {
501 ir_type *type = get_entity_type(entity);
502 return new_r_Unknown(get_const_code_irg(), get_type_mode(type));
505 switch (get_initializer_kind(initializer)) {
506 case IR_INITIALIZER_NULL: {
507 ir_type *type = get_entity_type(entity);
508 ir_mode *mode = get_type_mode(type);
509 return new_r_Const(get_const_code_irg(), get_mode_null(mode));
511 case IR_INITIALIZER_TARVAL: {
512 ir_tarval *tv = get_initializer_tarval_value(initializer);
513 return new_r_Const(get_const_code_irg(), tv);
515 case IR_INITIALIZER_CONST:
516 return get_initializer_const_value(initializer);
517 case IR_INITIALIZER_COMPOUND:
518 panic("compound initializer in atomic entity not allowed (%+F)", entity);
521 panic("invalid initializer kind in get_atomic_ent_value(%+F)", entity);
524 void set_atomic_ent_value(ir_entity *entity, ir_node *val)
526 ir_initializer_t *initializer;
528 assert(is_atomic_entity(entity));
530 assert(is_Dummy(val) || get_irn_mode(val) == get_type_mode(entity->type));
531 initializer = create_initializer_const(val);
532 entity->initializer = initializer;
535 int is_irn_const_expression(ir_node *n)
537 /* we are in danger iff an exception will arise. TODO: be more precisely,
538 * for instance Div. will NOT rise if divisor != 0
540 if (is_binop(n) && !is_fragile_op(n))
541 return is_irn_const_expression(get_binop_left(n)) && is_irn_const_expression(get_binop_right(n));
543 switch (get_irn_opcode(n)) {
550 return is_irn_const_expression(get_irn_n(n, 0));
557 ir_node *copy_const_value(dbg_info *dbg, ir_node *n, ir_node *block)
559 ir_graph *irg = get_irn_irg(block);
563 /* @@@ GL I think we should implement this using the routines from irgopt for
564 dead node elimination/inlineing. */
567 switch (get_irn_opcode(n)) {
569 nn = new_rd_Const(dbg, irg, get_Const_tarval(n));
572 nn = new_rd_SymConst(dbg, irg, get_irn_mode(n), get_SymConst_symbol(n), get_SymConst_kind(n));
575 nn = new_rd_Add(dbg, block,
576 copy_const_value(dbg, get_Add_left(n), block),
577 copy_const_value(dbg, get_Add_right(n), block), m);
580 nn = new_rd_Sub(dbg, block,
581 copy_const_value(dbg, get_Sub_left(n), block),
582 copy_const_value(dbg, get_Sub_right(n), block), m);
585 nn = new_rd_Mul(dbg, block,
586 copy_const_value(dbg, get_Mul_left(n), block),
587 copy_const_value(dbg, get_Mul_right(n), block), m);
590 nn = new_rd_And(dbg, block,
591 copy_const_value(dbg, get_And_left(n), block),
592 copy_const_value(dbg, get_And_right(n), block), m);
595 nn = new_rd_Or(dbg, block,
596 copy_const_value(dbg, get_Or_left(n), block),
597 copy_const_value(dbg, get_Or_right(n), block), m);
600 nn = new_rd_Eor(dbg, block,
601 copy_const_value(dbg, get_Eor_left(n), block),
602 copy_const_value(dbg, get_Eor_right(n), block), m);
605 nn = new_rd_Cast(dbg, block,
606 copy_const_value(dbg, get_Cast_op(n), block),
610 nn = new_rd_Conv(dbg, block,
611 copy_const_value(dbg, get_Conv_op(n), block), m);
614 nn = new_r_Unknown(irg, m); break;
616 panic("opcode invalid or not implemented");
621 const char *get_initializer_kind_name(ir_initializer_kind_t ini)
623 #define X(a) case a: return #a
625 X(IR_INITIALIZER_CONST);
626 X(IR_INITIALIZER_TARVAL);
627 X(IR_INITIALIZER_NULL);
628 X(IR_INITIALIZER_COMPOUND);
629 default: return "BAD VALUE";
634 static ir_initializer_t null_initializer = { IR_INITIALIZER_NULL };
636 ir_initializer_t *get_initializer_null(void)
638 return &null_initializer;
641 ir_initializer_t *create_initializer_const(ir_node *value)
643 struct obstack *obst = get_irg_obstack(get_const_code_irg());
645 ir_initializer_t *initializer
646 = (ir_initializer_t*)OALLOC(obst, ir_initializer_const_t);
647 initializer->kind = IR_INITIALIZER_CONST;
648 initializer->consti.value = value;
653 ir_initializer_t *create_initializer_tarval(ir_tarval *tv)
655 struct obstack *obst = get_irg_obstack(get_const_code_irg());
657 ir_initializer_t *initializer
658 = (ir_initializer_t*)OALLOC(obst, ir_initializer_tarval_t);
659 initializer->kind = IR_INITIALIZER_TARVAL;
660 initializer->tarval.value = tv;
665 ir_initializer_t *create_initializer_compound(size_t n_entries)
667 struct obstack *obst = get_irg_obstack(get_const_code_irg());
670 size_t size = sizeof(ir_initializer_compound_t)
671 + n_entries * sizeof(ir_initializer_t*)
672 - sizeof(ir_initializer_t*);
674 ir_initializer_t *initializer
675 = (ir_initializer_t*)obstack_alloc(obst, size);
676 initializer->kind = IR_INITIALIZER_COMPOUND;
677 initializer->compound.n_initializers = n_entries;
679 for (i = 0; i < n_entries; ++i) {
680 initializer->compound.initializers[i] = get_initializer_null();
686 ir_node *get_initializer_const_value(const ir_initializer_t *initializer)
688 assert(initializer->kind == IR_INITIALIZER_CONST);
689 return skip_Id(initializer->consti.value);
692 ir_tarval *get_initializer_tarval_value(const ir_initializer_t *initializer)
694 assert(initializer->kind == IR_INITIALIZER_TARVAL);
695 return initializer->tarval.value;
698 size_t get_initializer_compound_n_entries(const ir_initializer_t *initializer)
700 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
701 return initializer->compound.n_initializers;
704 void set_initializer_compound_value(ir_initializer_t *initializer,
705 size_t index, ir_initializer_t *value)
707 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
708 assert(index < initializer->compound.n_initializers);
710 initializer->compound.initializers[index] = value;
713 ir_initializer_t *get_initializer_compound_value(
714 const ir_initializer_t *initializer, size_t index)
716 assert(initializer->kind == IR_INITIALIZER_COMPOUND);
717 assert(index < initializer->compound.n_initializers);
719 return initializer->compound.initializers[index];
722 ir_initializer_kind_t get_initializer_kind(const ir_initializer_t *initializer)
724 return initializer->kind;
727 static void check_entity_initializer(ir_entity *entity)
730 ir_initializer_t *initializer = entity->initializer;
731 ir_type *entity_tp = get_entity_type(entity);
732 switch (initializer->kind) {
733 case IR_INITIALIZER_COMPOUND:
734 assert(is_compound_type(entity_tp) || is_Array_type(entity_tp));
736 case IR_INITIALIZER_CONST:
737 /* methods are initialized by a SymConst */
738 assert(is_atomic_type(entity_tp) || is_Method_type(entity_tp));
740 case IR_INITIALIZER_TARVAL:
741 assert(is_atomic_type(entity_tp));
743 case IR_INITIALIZER_NULL:
749 void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer)
751 entity->initializer = initializer;
752 check_entity_initializer(entity);
755 int has_entity_initializer(const ir_entity *entity)
757 return entity->initializer != NULL;
760 ir_initializer_t *get_entity_initializer(const ir_entity *entity)
762 return entity->initializer;
765 int (get_entity_offset)(const ir_entity *ent)
767 return _get_entity_offset(ent);
770 void (set_entity_offset)(ir_entity *ent, int offset)
772 _set_entity_offset(ent, offset);
775 unsigned char (get_entity_offset_bits_remainder)(const ir_entity *ent)
777 return _get_entity_offset_bits_remainder(ent);
780 void (set_entity_offset_bits_remainder)(ir_entity *ent, unsigned char offset)
782 _set_entity_offset_bits_remainder(ent, offset);
785 void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
787 if (ent->overwrites == NULL) {
788 ent->overwrites = NEW_ARR_F(ir_entity*, 0);
790 ARR_APP1(ir_entity *, ent->overwrites, overwritten);
791 if (overwritten->overwrittenby == NULL) {
792 overwritten->overwrittenby = NEW_ARR_F(ir_entity*, 0);
794 ARR_APP1(ir_entity *, overwritten->overwrittenby, ent);
797 size_t get_entity_n_overwrites(const ir_entity *ent)
799 if (ent->overwrites == NULL)
801 return ARR_LEN(ent->overwrites);
804 size_t get_entity_overwrites_index(const ir_entity *ent, ir_entity *overwritten)
807 size_t n = get_entity_n_overwrites(ent);
808 for (i = 0; i < n; ++i) {
809 if (get_entity_overwrites(ent, i) == overwritten)
815 ir_entity *get_entity_overwrites(const ir_entity *ent, size_t pos)
817 assert(pos < get_entity_n_overwrites(ent));
818 return ent->overwrites[pos];
821 void set_entity_overwrites(ir_entity *ent, size_t pos, ir_entity *overwritten)
823 assert(pos < get_entity_n_overwrites(ent));
824 ent->overwrites[pos] = overwritten;
827 void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten)
830 size_t n = get_entity_n_overwrites(ent);
831 for (i = 0; i < n; ++i) {
832 if (ent->overwrites[i] == overwritten) {
833 for (; i < n - 1; i++)
834 ent->overwrites[i] = ent->overwrites[i+1];
835 ARR_SETLEN(ir_entity*, ent->overwrites, n - 1);
842 size_t get_entity_n_overwrittenby(const ir_entity *ent)
844 if (ent->overwrittenby == NULL)
846 return ARR_LEN(ent->overwrittenby);
849 size_t get_entity_overwrittenby_index(const ir_entity *ent,
850 ir_entity *overwrites)
853 size_t n = get_entity_n_overwrittenby(ent);
854 for (i = 0; i < n; ++i) {
855 if (get_entity_overwrittenby(ent, i) == overwrites)
861 ir_entity *get_entity_overwrittenby(const ir_entity *ent, size_t pos)
863 assert(pos < get_entity_n_overwrittenby(ent));
864 return ent->overwrittenby[pos];
867 void set_entity_overwrittenby(ir_entity *ent, size_t pos, ir_entity *overwrites)
869 assert(pos < get_entity_n_overwrittenby(ent));
870 ent->overwrittenby[pos] = overwrites;
873 void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites)
876 size_t n = get_entity_n_overwrittenby(ent);
877 for (i = 0; i < n; ++i) {
878 if (ent->overwrittenby[i] == overwrites) {
879 for (; i < n - 1; ++i)
880 ent->overwrittenby[i] = ent->overwrittenby[i+1];
881 ARR_SETLEN(ir_entity*, ent->overwrittenby, n - 1);
887 void *(get_entity_link)(const ir_entity *ent)
889 return _get_entity_link(ent);
892 void (set_entity_link)(ir_entity *ent, void *l)
894 _set_entity_link(ent, l);
897 ir_graph *(get_entity_irg)(const ir_entity *ent)
899 return _get_entity_irg(ent);
902 void set_entity_irg(ir_entity *ent, ir_graph *irg)
904 assert(is_method_entity(ent));
905 assert(get_entity_peculiarity(ent) == peculiarity_existent);
906 ent->attr.mtd_attr.irg = irg;
909 int (is_parameter_entity)(const ir_entity *entity)
911 return _is_parameter_entity(entity);
914 size_t (get_entity_parameter_number)(const ir_entity *entity)
916 return _get_entity_parameter_number(entity);
919 void set_entity_parameter_number(ir_entity *entity, size_t n)
921 assert(is_parameter_entity(entity));
922 entity->attr.parameter.number = n;
925 unsigned get_entity_vtable_number(const ir_entity *ent)
927 assert(is_method_entity((ir_entity *)ent));
928 return ent->attr.mtd_attr.vtable_number;
931 void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number)
933 assert(is_method_entity(ent));
934 ent->attr.mtd_attr.vtable_number = vtable_number;
937 int is_unknown_entity(const ir_entity *entity)
939 return entity->entity_kind == IR_ENTITY_UNKNOWN;
942 int (is_entity)(const void *thing)
944 return _is_entity(thing);
947 int is_atomic_entity(const ir_entity *ent)
949 ir_type *t = get_entity_type(ent);
950 const tp_op *op = get_type_tpop(t);
951 return (op == type_primitive || op == type_pointer ||
952 op == type_enumeration || op == type_method);
955 int is_compound_entity(const ir_entity *ent)
957 ir_type *t = get_entity_type(ent);
958 const tp_op *op = get_type_tpop(t);
959 return (op == type_class || op == type_struct ||
960 op == type_array || op == type_union);
963 int is_method_entity(const ir_entity *ent)
965 ir_type *t = get_entity_type(ent);
966 return is_Method_type(t);
969 ir_visited_t (get_entity_visited)(const ir_entity *ent)
971 return _get_entity_visited(ent);
974 void (set_entity_visited)(ir_entity *ent, ir_visited_t num)
976 _set_entity_visited(ent, num);
979 void (mark_entity_visited)(ir_entity *ent)
981 _mark_entity_visited(ent);
984 int (entity_visited)(const ir_entity *ent)
986 return _entity_visited(ent);
989 int (entity_not_visited)(const ir_entity *ent)
991 return _entity_not_visited(ent);
994 mtp_additional_properties get_entity_additional_properties(const ir_entity *ent)
998 assert(is_method_entity(ent));
1000 /* first check, if the graph has additional properties */
1001 irg = get_entity_irg(ent);
1004 return get_irg_additional_properties(irg);
1006 if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited)
1007 return get_method_additional_properties(get_entity_type(ent));
1009 return ent->attr.mtd_attr.irg_add_properties;
1012 void set_entity_additional_properties(ir_entity *ent, mtp_additional_properties property_mask)
1016 assert(is_method_entity(ent));
1018 /* first check, if the graph exists */
1019 irg = get_entity_irg(ent);
1021 set_irg_additional_properties(irg, property_mask);
1023 /* do not allow to set the mtp_property_inherited flag or
1024 * the automatic inheritance of flags will not work */
1025 ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
1029 void add_entity_additional_properties(ir_entity *ent, mtp_additional_properties properties)
1033 assert(is_method_entity(ent));
1035 /* first check, if the graph exists */
1036 irg = get_entity_irg(ent);
1038 add_irg_additional_properties(irg, properties);
1040 mtp_additional_properties mask = ent->attr.mtd_attr.irg_add_properties;
1042 if (mask & mtp_property_inherited)
1043 mask = get_method_additional_properties(get_entity_type(ent));
1045 /* do not allow to set the mtp_property_inherited flag or
1046 * the automatic inheritance of flags will not work */
1047 ent->attr.mtd_attr.irg_add_properties = mask | (properties & ~mtp_property_inherited);
1051 ir_type *(get_entity_repr_class)(const ir_entity *ent)
1053 return _get_entity_repr_class(ent);
1056 dbg_info *(get_entity_dbg_info)(const ir_entity *ent)
1058 return _get_entity_dbg_info(ent);
1061 void (set_entity_dbg_info)(ir_entity *ent, dbg_info *db)
1063 _set_entity_dbg_info(ent, db);
1066 int entity_is_externally_visible(const ir_entity *entity)
1068 return get_entity_visibility(entity) != ir_visibility_local
1069 || (get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER);
1072 int entity_has_definition(const ir_entity *entity)
1074 return entity->initializer != NULL
1075 || get_entity_irg(entity) != NULL
1076 || entity_has_compound_ent_values(entity);
1079 void ir_init_entity(ir_prog *irp)
1081 ident *id = new_id_from_str(UNKNOWN_ENTITY_NAME);
1082 irp->unknown_entity = intern_new_entity(NULL, IR_ENTITY_UNKNOWN, id,
1083 irp->unknown_type, NULL);
1084 set_entity_visibility(irp->unknown_entity, ir_visibility_external);
1085 set_entity_ld_ident(irp->unknown_entity, id);
1086 hook_new_entity(irp->unknown_entity);
1089 void ir_finish_entity(ir_prog *irp)
1091 free_entity(irp->unknown_entity);
1094 ir_allocation get_entity_allocation(const ir_entity *entity)
1096 return (ir_allocation)entity->allocation;
1099 void set_entity_allocation(ir_entity *entity, ir_allocation allocation)
1101 entity->allocation = allocation;
1104 ir_peculiarity get_entity_peculiarity(const ir_entity *entity)
1106 return (ir_peculiarity)entity->peculiarity;
1109 void set_entity_peculiarity(ir_entity *entity, ir_peculiarity peculiarity)
1111 entity->peculiarity = peculiarity;
1114 void set_entity_final(ir_entity *entity, int final)
1116 entity->final = final;
1119 int is_entity_final(const ir_entity *entity)
1121 return entity->final;