From a81745f32dde0f7b195eaaaed101451d3a3fec7a Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Fri, 19 May 2006 02:26:04 +0000 Subject: [PATCH] placed method and compound entities into private attributes add vtable_number attribute to method entities is_method_entity() added [r7771] --- ir/tr/entity.c | 138 ++++++++++++++++++++++++++--------------------- ir/tr/entity_t.h | 126 ++++++++++++++++++++++++------------------- 2 files changed, 150 insertions(+), 114 deletions(-) diff --git a/ir/tr/entity.c b/ir/tr/entity.c index 6000f3999..c1761a7c6 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -123,15 +123,21 @@ new_rd_entity (dbg_info *db, ir_type *owner, ident *name, ir_type *type) res->value = new_SymConst(sym, symconst_addr_ent); current_ir_graph = rem; res->variability = variability_constant; - res->irg_add_properties = mtp_property_inherited; - res->param_access = NULL; - res->param_weight = NULL; + res->attr.mtd_attr.irg_add_properties = mtp_property_inherited; + res->attr.mtd_attr.vtable_number = VTABLE_NUM_NOT_SET; + res->attr.mtd_attr.param_access = NULL; + res->attr.mtd_attr.param_weight = NULL; + res->attr.mtd_attr.irg = NULL; + } + else if (is_compound_type(type)) { + res->variability = variability_uninitialized; + res->value = NULL; + res->attr.cmpd_attr.values = NULL; + res->attr.cmpd_attr.val_paths = NULL; } else { res->variability = variability_uninitialized; res->value = NULL; - res->values = NULL; - res->val_paths = NULL; } if (is_Class_type(owner)) { @@ -141,7 +147,6 @@ new_rd_entity (dbg_info *db, ir_type *owner, ident *name, ir_type *type) res->overwrites = NULL; res->overwrittenby = NULL; } - res->irg = NULL; #ifdef DEBUG_libfirm res->nr = get_irp_new_node_nr(); @@ -171,9 +176,11 @@ new_entity (ir_type *owner, ident *name, ir_type *type) { return new_d_entity(owner, name, type, NULL); } - - - +/** + * Free entity attributes. + * + * @param ent the entity + */ static void free_entity_attrs(entity *ent) { int i; if (get_type_tpop(get_entity_owner(ent)) == type_class) { @@ -183,25 +190,28 @@ static void free_entity_attrs(entity *ent) { assert(ent->overwrites == NULL); assert(ent->overwrittenby == NULL); } - /* if (ent->values) DEL_ARR_F(ent->values); *//* @@@ warum nich? */ - if (ent->val_paths) { - if (is_compound_entity(ent)) + if (is_compound_entity(ent)) { + if (ent->attr.cmpd_attr.val_paths) { for (i = 0; i < get_compound_ent_n_values(ent); i++) - if (ent->val_paths[i]) ; - /* free_compound_graph_path(ent->val_paths[i]) ; * @@@ warum nich? */ - /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */ - /* DEL_ARR_F(ent->val_paths); */ - } - ent->val_paths = NULL; - ent->values = NULL; - - if (ent->param_access) { - DEL_ARR_F(ent->param_access); - ent->param_access = NULL; + if (ent->attr.cmpd_attr.val_paths[i]) { + /* free_compound_graph_path(ent->attr.cmpd_attr.val_paths[i]) ; * @@@ warum nich? */ + /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */ + /* DEL_ARR_F(ent->attr.cmpd_attr.val_paths); */ + } + ent->attr.cmpd_attr.val_paths = NULL; + } + /* if (ent->attr.cmpd_attr.values) DEL_ARR_F(ent->attr.cmpd_attr.values); *//* @@@ warum nich? */ + ent->attr.cmpd_attr.values = NULL; } - if (ent->param_weight) { - DEL_ARR_F(ent->param_weight); - ent->param_weight = NULL; + else if (is_method_entity(ent)) { + if (ent->attr.mtd_attr.param_access) { + DEL_ARR_F(ent->attr.mtd_attr.param_access); + ent->attr.mtd_attr.param_access = NULL; + } + if (ent->attr.mtd_attr.param_weight) { + DEL_ARR_F(ent->attr.mtd_attr.param_weight); + ent->attr.mtd_attr.param_weight = NULL; + } } } @@ -396,8 +406,8 @@ set_entity_variability (entity *ent, ent_variability var) if ((is_compound_type(ent->type)) && (ent->variability == variability_uninitialized) && (var != variability_uninitialized)) { /* Allocate data structures for constant values */ - ent->values = NEW_ARR_F(ir_node *, 0); - ent->val_paths = NEW_ARR_F(compound_graph_path *, 0); + ent->attr.cmpd_attr.values = NEW_ARR_F(ir_node *, 0); + ent->attr.cmpd_attr.val_paths = NEW_ARR_F(compound_graph_path *, 0); } if ((is_atomic_type(ent->type)) && (ent->variability == variability_uninitialized) && (var != variability_uninitialized)) { @@ -408,13 +418,13 @@ set_entity_variability (entity *ent, ent_variability var) if ((is_compound_type(ent->type)) && (var == variability_uninitialized) && (ent->variability != variability_uninitialized)) { /* Free data structures for constant values */ - DEL_ARR_F(ent->values); ent->values = NULL; - DEL_ARR_F(ent->val_paths); ent->val_paths = NULL; + DEL_ARR_F(ent->attr.cmpd_attr.values); ent->attr.cmpd_attr.values = NULL; + DEL_ARR_F(ent->attr.cmpd_attr.val_paths); ent->attr.cmpd_attr.val_paths = NULL; } ent->variability = var; } -/* return the name of the variablity */ +/* return the name of the variability */ const char *get_variability_name(ent_variability var) { #define X(a) case a: return #a @@ -673,33 +683,33 @@ set_compound_graph_path_array_index(compound_graph_path *gr, int pos, int index) void add_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path) { assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized)); - ARR_APP1 (ir_node *, ent->values, val); - ARR_APP1 (compound_graph_path *, ent->val_paths, path); + ARR_APP1 (ir_node *, ent->attr.cmpd_attr.values, val); + ARR_APP1 (compound_graph_path *, ent->attr.cmpd_attr.val_paths, path); } void set_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path, int pos) { assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized)); - ent->values[pos] = val; - ent->val_paths[pos] = path; + ent->attr.cmpd_attr.values[pos] = val; + ent->attr.cmpd_attr.val_paths[pos] = path; } int get_compound_ent_n_values(entity *ent) { assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized)); - return (ARR_LEN (ent->values)); + return (ARR_LEN (ent->attr.cmpd_attr.values)); } ir_node * get_compound_ent_value(entity *ent, int pos) { assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized)); - return ent->values[pos]; + return ent->attr.cmpd_attr.values[pos]; } compound_graph_path * get_compound_ent_value_path(entity *ent, int pos) { assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized)); - return ent->val_paths[pos]; + return ent->attr.cmpd_attr.val_paths[pos]; } /** @@ -778,15 +788,15 @@ void remove_compound_ent_value(entity *ent, entity *value_ent) { int i; assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized)); - for (i = 0; i < (ARR_LEN (ent->val_paths)); i++) { - compound_graph_path *path = ent->val_paths[i]; + for (i = 0; i < (ARR_LEN (ent->attr.cmpd_attr.val_paths)); i++) { + compound_graph_path *path = ent->attr.cmpd_attr.val_paths[i]; if (path->list[path->len-1].node == value_ent) { - for(; i < (ARR_LEN (ent->val_paths))-1; i++) { - ent->val_paths[i] = ent->val_paths[i+1]; - ent->values[i] = ent->values[i+1]; + for(; i < (ARR_LEN (ent->attr.cmpd_attr.val_paths))-1; i++) { + ent->attr.cmpd_attr.val_paths[i] = ent->attr.cmpd_attr.val_paths[i+1]; + ent->attr.cmpd_attr.values[i] = ent->attr.cmpd_attr.values[i+1]; } - ARR_SETLEN(entity*, ent->val_paths, ARR_LEN(ent->val_paths) - 1); - ARR_SETLEN(ir_node*, ent->values, ARR_LEN(ent->values) - 1); + ARR_SETLEN(entity*, ent->attr.cmpd_attr.val_paths, ARR_LEN(ent->attr.cmpd_attr.val_paths) - 1); + ARR_SETLEN(ir_node*, ent->attr.cmpd_attr.values, ARR_LEN(ent->attr.cmpd_attr.values) - 1); break; } } @@ -1100,10 +1110,10 @@ void sort_compound_ent_values(entity *ent) { } free(permutation); - DEL_ARR_F(ent->values); - ent->values = my_values; - DEL_ARR_F(ent->val_paths); - ent->val_paths = my_paths; + DEL_ARR_F(ent->attr.cmpd_attr.values); + ent->attr.cmpd_attr.values = my_values; + DEL_ARR_F(ent->attr.cmpd_attr.val_paths); + ent->attr.cmpd_attr.val_paths = my_paths; } int @@ -1253,7 +1263,7 @@ set_entity_irg(entity *ent, ir_graph *irg) { && (ent -> visibility == visibility_external_allocated)) || (!irg && ent->peculiarity == peculiarity_description) || (!irg && ent->peculiarity == peculiarity_inherited)); - ent->irg = irg; + ent->attr.mtd_attr.irg = irg; } int @@ -1275,6 +1285,12 @@ int is_compound_entity(entity *ent) { is_Array_type(t) || is_Union_type(t)); } +int is_method_entity(entity *ent) { + ir_type *t = get_entity_type(ent); + assert(ent && ent->kind == k_entity); + return (is_Method_type(t)); +} + /** * @todo not implemented!!! */ int equal_entity(entity *ent1, entity *ent2) { @@ -1308,7 +1324,7 @@ int (entity_not_visited)(entity *ent) { unsigned get_entity_additional_properties(entity *ent) { ir_graph *irg; - assert(is_Method_type(get_entity_type(ent))); + assert(is_method_entity(ent)); /* first check, if the graph has additional properties */ irg = get_entity_irg(ent); @@ -1316,10 +1332,10 @@ unsigned get_entity_additional_properties(entity *ent) { if (irg) return get_irg_additional_properties(irg); - if (ent->irg_add_properties & mtp_property_inherited) + if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited) return get_method_additional_properties(get_entity_type(ent)); - return ent->irg_add_properties; + return ent->attr.mtd_attr.irg_add_properties; } /* Sets the mask of the additional graph properties. */ @@ -1327,7 +1343,7 @@ void set_entity_additional_properties(entity *ent, unsigned property_mask) { ir_graph *irg; - assert(is_Method_type(get_entity_type(ent))); + assert(is_method_entity(ent)); /* first check, if the graph exists */ irg = get_entity_irg(ent); @@ -1336,7 +1352,7 @@ void set_entity_additional_properties(entity *ent, unsigned property_mask) else { /* do not allow to set the mtp_property_inherited flag or * the automatic inheritance of flags will not work */ - ent->irg_add_properties = property_mask & ~mtp_property_inherited; + ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited; } } @@ -1345,35 +1361,37 @@ void set_entity_additional_property(entity *ent, mtp_additional_property flag) { ir_graph *irg; - assert(is_Method_type(get_entity_type(ent))); + assert(is_method_entity(ent)); /* first check, if the graph exists */ irg = get_entity_irg(ent); if (irg) set_irg_additional_property(irg, flag); else { - unsigned mask = ent->irg_add_properties; + unsigned mask = ent->attr.mtd_attr.irg_add_properties; if (mask & mtp_property_inherited) mask = get_method_additional_properties(get_entity_type(ent)); /* do not allow to set the mtp_property_inherited flag or * the automatic inheritance of flags will not work */ - ent->irg_add_properties = mask | (flag & ~mtp_property_inherited); + ent->attr.mtd_attr.irg_add_properties = mask | (flag & ~mtp_property_inherited); } } +/* Initialize entity module. */ void firm_init_entity(void) { symconst_symbol sym; assert(firm_unknown_type && "Call init_type() before firm_init_entity()!"); assert(!unknown_entity && "Call firm_init_entity() only once!"); + unknown_entity = new_rd_entity(NULL, firm_unknown_type, new_id_from_str(UNKNOWN_ENTITY_NAME), firm_unknown_type); set_entity_visibility(unknown_entity, visibility_external_allocated); set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity)); - sym.entity_p = unknown_entity; - current_ir_graph = get_const_code_irg(); + current_ir_graph = get_const_code_irg(); + sym.entity_p = unknown_entity; unknown_entity->value = new_SymConst(sym, symconst_addr_ent); } diff --git a/ir/tr/entity_t.h b/ir/tr/entity_t.h index edd167dad..fe454c82f 100644 --- a/ir/tr/entity_t.h +++ b/ir/tr/entity_t.h @@ -35,8 +35,8 @@ * enclosing procedure. */ -# ifndef _ENTITY_T_H_ -# define _ENTITY_T_H_ +#ifndef _FIRM_TR_ENTITY_T_H_ +#define _FIRM_TR_ENTITY_T_H_ #include "firm_common_t.h" #include "firm_config.h" @@ -55,73 +55,90 @@ struct compound_graph_path { struct tuple { int index; /**< Array index. To compute position of array elements */ entity *node; /**< entity */ - } list[1]; /**< List of entitiy/index tuple of length len to express the + } list[1]; /**< List of entity/index tuple of length len to express the access path. */ }; -/** the type of an entity */ -struct entity { - firm_kind kind; /**< dynamic type tag for entity. */ - ident *name; /**< name of this entity */ - ident *ld_name; /**< Unique name of this entity, i.e., the mangled - name. If the field is read before written a default - mangling is applies. The name of the owner is prepended - to the name of the entity, separated by a underscore. - E.g., for a class `A' with field `a' this - is the ident for `A_a'. */ - ir_type *type; /**< The type of this entity, e.g., a method type, a - basic type of the language or a class itself */ - ir_type *owner; /**< The compound type (e.g. class type) this entity belongs to. */ - ent_allocation allocation; /**< Distinguishes static and dynamically allocated - entities and some further cases. */ - visibility visibility; /**< Specifies visibility to external program - fragments */ - ent_variability variability; /**< Specifies variability of entities content */ - ent_volatility volatility; /**< Specifies volatility of entities content */ - ent_stickyness stickyness; /**< Specifies whether this entity is sticky */ - int offset; /**< Offset in bits for this entity. Fixed when layout - of owner is determined. */ - peculiarity peculiarity; /**< peculiarity of this entity */ - unsigned long visit; /**< visited counter for walks of the type information */ - struct dbg_info *dbi; /**< A pointer to information for debug support. */ - void *link; /**< To store some intermediate information */ - - /* ------------- fields for atomic entities ---------------*/ - +/** attributes for atomic entities */ +typedef struct atomic_ent_attr { ir_node *value; /**< value if entity is not of variability uninitialized. Only for atomic entities. */ +} atomic_ent_attr; - /* ------------- fields for compound entities ---------------*/ - +/** attributes for compound entities */ +typedef struct compound_ent_attr { ir_node **values; /**< constant values of compound entities. Only available if - variability not uninitialized. Must be set for variability constant - */ + variability not uninitialized. Must be set for variability constant. */ compound_graph_path **val_paths; /**< paths corresponding to constant values. Only available if - variability not uninitialized. Must be set for variability constant */ + variability not uninitialized. Must be set for variability constant. */ +} compound_ent_attr; + +/** a reserved value for "not yet set" */ +#define VTABLE_NUM_NOT_SET ((unsigned)(-1)) + +/** attributes for methods */ +typedef struct method_ent_attr { + ir_graph *irg; /**< The corresponding irg if known. + The ir_graph constructor automatically sets this field. */ + unsigned irg_add_properties; /**< Additional graph properties can be + stored in a entity if no irg is available. */ + + unsigned vtable_number; /**< For a dynamically called method, the number assigned + in the virtual function table. */ + + ptr_access_kind *param_access; /**< the parameter access */ + float *param_weight; /**< The weight of method's parameters. Parameters + with a high weight are good for procedure cloning. */ +} method_ent_attr; + + +/** the type of an entity */ +struct entity { + firm_kind kind; /**< The dynamic type tag for entity. */ + ident *name; /**< The name of this entity. */ + ident *ld_name; /**< Unique name of this entity, i.e., the mangled + name. If the field is read before written a default + mangling is applies. The name of the owner is prepended + to the name of the entity, separated by a underscore. + E.g., for a class `A' with field `a' this + is the ident for `A_a'. */ + ir_type *type; /**< The type of this entity, e.g., a method type, a + basic type of the language or a class itself. */ + ir_type *owner; /**< The compound type (e.g. class type) this entity belongs to. */ + ent_allocation allocation; /**< Distinguishes static and dynamically allocated + entities and some further cases. */ + visibility visibility; /**< Specifies visibility to external program + fragments. */ + ent_variability variability; /**< Specifies variability of entities content. */ + ent_volatility volatility; /**< Specifies volatility of entities content. */ + ent_stickyness stickyness; /**< Specifies whether this entity is sticky. */ + int offset; /**< Offset in bits for this entity. Fixed when layout + of owner is determined. */ + peculiarity peculiarity; /**< The peculiarity of this entity. */ + unsigned long visit; /**< visited counter for walks of the type information. */ + struct dbg_info *dbi; /**< A pointer to information for debug support. */ + void *link; /**< To store some intermediate information. */ /* ------------- fields for entities owned by a class type ---------------*/ entity **overwrites; /**< A list of entities this entity overwrites. */ entity **overwrittenby; /**< A list of entities that overwrite this entity. */ - /* ------------- fields for methods ---------------*/ - - ir_graph *irg; /**< If (type == method_type) this is the corresponding irg. - The ir_graph constructor automatically sets this field. - Yes, it must be here. */ - unsigned irg_add_properties; /**< Additional graph properties can be - stored in a entity if no irg is available. */ - - ptr_access_kind *param_access; /**< the parameter access */ - float *param_weight; /**< The weight of method's parameters. Parameters - with a high weight are good for procedure cloning.*/ + /* ------------- fields for atomic entities --------------- */ + ir_node *value; /**< value if entity is not of variability uninitialized. + Only for atomic entities. */ + union { + /* ------------- fields for compound entities -------------- */ + compound_ent_attr cmpd_attr; + /* ------------- fields for method entities ---------------- */ + method_ent_attr mtd_attr; + } attr; /**< type specific attributes */ /* ------------- fields for analyses ---------------*/ - #ifdef DEBUG_libfirm - long nr; /**< a unique node number for each node to make output - readable. */ + long nr; /**< A unique node number for each node to make output + readable. */ # endif /* DEBUG_libfirm */ }; @@ -298,9 +315,10 @@ static INLINE ir_graph * _get_entity_irg(const entity *ent) { assert(ent && ent->kind == k_entity); assert(ent == unknown_entity || is_Method_type(ent->type)); - if (!get_visit_pseudo_irgs() && ent->irg && is_pseudo_ir_graph(ent->irg)) + if (!get_visit_pseudo_irgs() && ent->attr.mtd_attr.irg + && is_pseudo_ir_graph(ent->attr.mtd_attr.irg)) return NULL; - return ent->irg; + return ent->attr.mtd_attr.irg; } static INLINE unsigned long @@ -363,4 +381,4 @@ _entity_not_visited(entity *ent) { #define entity_visited(ent) _entity_visited(ent) #define entity_not_visited(ent) _entity_not_visited(ent) -# endif /* _ENTITY_T_H_ */ +#endif /* _FIRM_TR_ENTITY_T_H_ */ -- 2.20.1