From e26e575fb98ad809bc9c161a347cecbe0f4caf90 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Wed, 30 Jun 2004 12:17:46 +0000 Subject: [PATCH] entity offset is now in bits make basic functions inline [r3255] --- ir/tr/entity.c | 197 ++++++++++++++++++------------------- ir/tr/entity.h | 28 +++--- ir/tr/entity_t.h | 247 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 331 insertions(+), 141 deletions(-) diff --git a/ir/tr/entity.c b/ir/tr/entity.c index 81390ff8e..7cca358b8 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -219,15 +219,13 @@ get_entity_nr(entity *ent) { } const char * -get_entity_name (entity *ent) { - assert(ent && ent->kind == k_entity); - return get_id_str(get_entity_ident(ent)); +(get_entity_name)(entity *ent) { + return __get_entity_name(ent); } ident * -get_entity_ident (entity *ent) { - assert(ent && ent->kind == k_entity); - return ent->name; +(get_entity_ident)(entity *ent) { + return get_entity_ident(ent); } /* @@ -236,9 +234,8 @@ void set_entity_ld_ident (entity *, ident *ld_ident); */ type * -get_entity_owner (entity *ent) { - assert(ent && ent->kind == k_entity); - return ent->owner = skip_tid(ent->owner); +(get_entity_owner)(entity *ent) { + return __get_entity_owner(ent); } void @@ -258,54 +255,38 @@ assert_legal_owner_of_ent(type *owner) { } ident * -get_entity_ld_ident (entity *ent) -{ - assert(ent && ent->kind == k_entity); - if (ent->ld_name == NULL) - ent->ld_name = mangle_entity (ent); - return ent->ld_name; +(get_entity_ld_ident)(entity *ent) { + return __get_entity_ld_ident(ent); } void -set_entity_ld_ident (entity *ent, ident *ld_ident) { - assert(ent && ent->kind == k_entity); - ent->ld_name = ld_ident; +(set_entity_ld_ident)(entity *ent, ident *ld_ident) { + __set_entity_ld_ident(ent, ld_ident); } const char * -get_entity_ld_name (entity *ent) { - assert(ent && ent->kind == k_entity); - return get_id_str(get_entity_ld_ident(ent)); +(get_entity_ld_name)(entity *ent) { + return __get_entity_ld_name(ent); } -/* -char *get_entity_ld_name (entity *); -void set_entity_ld_name (entity *, char *ld_name); -*/ - type * -get_entity_type (entity *ent) { - assert(ent && ent->kind == k_entity); - return ent->type = skip_tid(ent->type); +(get_entity_type)(entity *ent) { + return __get_entity_type(ent); } void -set_entity_type (entity *ent, type *type) { - assert(ent && ent->kind == k_entity); - ent->type = type; +(set_entity_type)(entity *ent, type *type) { + __set_entity_type(ent, type); } - ent_allocation -get_entity_allocation (entity *ent) { - assert(ent && ent->kind == k_entity); - return ent->allocation; +(get_entity_allocation)(entity *ent) { + return __get_entity_allocation(ent); } void -set_entity_allocation (entity *ent, ent_allocation al) { - assert(ent && ent->kind == k_entity); - ent->allocation = al; +(set_entity_allocation)(entity *ent, ent_allocation al) { + __set_entity_allocation(ent, al); } /* return the name of the visibility */ @@ -324,9 +305,8 @@ const char *get_allocation_name(ent_allocation all) ent_visibility -get_entity_visibility (entity *ent) { - assert(ent && ent->kind == k_entity); - return ent->visibility; +(get_entity_visibility)(entity *ent) { + return __get_entity_visibility(ent); } void @@ -354,9 +334,8 @@ const char *get_visibility_name(ent_visibility vis) } ent_variability -get_entity_variability (entity *ent) { - assert(ent && ent->kind == k_entity); - return ent->variability; +(get_entity_variability)(entity *ent) { + return __get_entity_variability(ent); } void @@ -397,15 +376,13 @@ const char *get_variability_name(ent_variability var) } ent_volatility -get_entity_volatility (entity *ent) { - assert(ent && ent->kind == k_entity); - return ent->volatility; +(get_entity_volatility)(entity *ent) { + return __get_entity_volatility(ent); } void -set_entity_volatility (entity *ent, ent_volatility vol) { - assert(ent && ent->kind == k_entity); - ent->volatility = vol; +(set_entity_volatility)(entity *ent, ent_volatility vol) { + __set_entity_volatility(ent, vol); } /* return the name of the volatility */ @@ -421,17 +398,13 @@ const char *get_volatility_name(ent_volatility var) } peculiarity -get_entity_peculiarity (entity *ent) { - assert(ent && ent->kind == k_entity); - return ent->peculiarity; +(get_entity_peculiarity)(entity *ent) { + return __get_entity_peculiarity(ent); } void -set_entity_peculiarity (entity *ent, peculiarity pec) { - assert(ent && ent->kind == k_entity); - /* @@@ why peculiarity only for methods? */ - assert(is_method_type(ent->type)); - ent->peculiarity = pec; +(set_entity_peculiarity)(entity *ent, peculiarity pec) { + __set_entity_peculiarity(ent, pec); } /* return the name of the peculiarity */ @@ -447,20 +420,16 @@ const char *get_peculiarity_name(peculiarity var) #undef X } -/** Get the entity's stickyness */ -ent_stickyness get_entity_stickyness (entity *ent) -{ - assert (ent && is_entity (ent)); - - return (ent->stickyness); +/* Get the entity's stickyness */ +ent_stickyness +(get_entity_stickyness)(entity *ent) { + return __get_entity_stickyness(ent); } -/** Set the entity's stickyness */ -void set_entity_stickyness (entity *ent, ent_stickyness stickyness) -{ - assert (ent && is_entity (ent)); - - ent->stickyness = stickyness; +/* Set the entity's stickyness */ +void +(set_entity_stickyness)(entity *ent, ent_stickyness stickyness) { + __set_entity_stickyness(ent, stickyness); } /* Set has no effect for existent entities of type method. */ @@ -492,8 +461,13 @@ int is_irn_const_expression(ir_node *n) { case iro_Unknown: return true; break; case iro_Add: - if (is_irn_const_expression(get_Add_left(n))) - return is_irn_const_expression(get_Add_right(n)); + case iro_Sub: + case iro_Mul: + case iro_And: + case iro_Or: + case iro_Eor: + if (is_irn_const_expression(get_binop_left(n))) + return is_irn_const_expression(get_binop_right(n)); case iro_Conv: case iro_Cast: return is_irn_const_expression(get_irn_n(n, 0)); @@ -518,6 +492,21 @@ ir_node *copy_const_value(ir_node *n) { case iro_Add: nn = new_Add(copy_const_value(get_Add_left(n)), copy_const_value(get_Add_right(n)), m); break; + case iro_Sub: + nn = new_Sub(copy_const_value(get_Sub_left(n)), + copy_const_value(get_Sub_right(n)), m); break; + case iro_Mul: + nn = new_Mul(copy_const_value(get_Mul_left(n)), + copy_const_value(get_Mul_right(n)), m); break; + case iro_And: + nn = new_And(copy_const_value(get_And_left(n)), + copy_const_value(get_And_right(n)), m); break; + case iro_Or: + nn = new_Or(copy_const_value(get_Or_left(n)), + copy_const_value(get_Or_right(n)), m); break; + case iro_Eor: + nn = new_Eor(copy_const_value(get_Eor_left(n)), + copy_const_value(get_Eor_right(n)), m); break; case iro_Cast: nn = new_Cast(copy_const_value(get_Cast_op(n)), get_Cast_type(n)); break; case iro_Conv: @@ -721,28 +710,36 @@ set_array_entity_values(entity *ent, tarval **values, int num_vals) { } int -get_entity_offset (entity *ent) { - assert(ent && ent->kind == k_entity); - return ent->offset; +(get_entity_offset_bytes)(entity *ent) { + return __get_entity_offset_bytes(ent); +} + +int +(get_entity_offset_bits)(entity *ent) { + return __get_entity_offset_bits(ent); } void -set_entity_offset (entity *ent, int offset) { - assert(ent && ent->kind == k_entity); - ent->offset = offset; +(set_entity_offset_bytes)(entity *ent, int offset) { + __set_entity_offset_bytes(ent, offset); } void -add_entity_overwrites (entity *ent, entity *overwritten) { +(set_entity_offset_bits)(entity *ent, int offset) { + __set_entity_offset_bits(ent, offset); +} + +void +add_entity_overwrites(entity *ent, entity *overwritten) { assert(ent && is_class_type(get_entity_owner(ent))); - ARR_APP1 (entity *, ent->overwrites, overwritten); - ARR_APP1 (entity *, overwritten->overwrittenby, ent); + ARR_APP1(entity *, ent->overwrites, overwritten); + ARR_APP1(entity *, overwritten->overwrittenby, ent); } int -get_entity_n_overwrites (entity *ent) { +get_entity_n_overwrites(entity *ent) { assert(ent && is_class_type(get_entity_owner(ent))); - return (ARR_LEN (ent->overwrites)); + return (ARR_LEN(ent->overwrites)); } int @@ -832,22 +829,18 @@ void remove_entity_overwrittenby(entity *ent, entity *overwrites) { /* A link to store intermediate information */ void * -get_entity_link(entity *ent) { - assert(ent && ent->kind == k_entity); - return ent->link; +(get_entity_link)(entity *ent) { + return __get_entity_link(ent); } void -set_entity_link(entity *ent, void *l) { - assert(ent && ent->kind == k_entity); - ent->link = l; +(set_entity_link)(entity *ent, void *l) { + __set_entity_link(ent, l); } ir_graph * -get_entity_irg(entity *ent) { - assert(ent && ent->kind == k_entity); - assert(is_method_type(ent->type)); - return ent->irg; +(get_entity_irg)(entity *ent) { + return __get_entity_irg(ent); } void @@ -863,12 +856,9 @@ set_entity_irg(entity *ent, ir_graph *irg) { ent->irg = irg; } -int is_entity (void *thing) { - assert(thing); - if (get_kind(thing) == k_entity) - return 1; - else - return 0; +int +(is_entity)(void *thing) { + return __is_entity(thing); } int is_atomic_entity(entity *ent) { @@ -885,7 +875,8 @@ int is_compound_entity(entity *ent) { is_array_type(t) || is_union_type(t)); } -/* @@@ not implemnted!!! */ +/** + * @todo not implemnted!!! */ bool equal_entity(entity *ent1, entity *ent2) { printf(" calling unimplemented equal entity!!! \n"); return true; @@ -1025,7 +1016,7 @@ void dump_entity (entity *ent) { for (i = 0; i < get_compound_ent_n_values(ent); ++i) { compound_graph_path *path = get_compound_ent_value_path(ent, i); entity *ent0 = get_compound_graph_path_node(path, 0); - printf("\n %2d %s", get_entity_offset(ent0), get_entity_name(ent0)); + printf("\n %3d %s", get_entity_offset_bits(ent0), get_entity_name(ent0)); for (j = 1; j < get_compound_graph_path_length(path); ++j) printf(".%s", get_entity_name(get_compound_graph_path_node(path, j))); printf("\t = "); @@ -1042,7 +1033,7 @@ void dump_entity (entity *ent) { printf("\n peculiarity: %s", get_peculiarity_string(get_entity_peculiarity(ent))); printf("\n ld_name: %s", ent->ld_name ? get_entity_ld_name(ent) : "no yet set"); - printf("\n offset: %d", get_entity_offset(ent)); + printf("\n offset: %d", get_entity_offset_bits(ent)); if (is_method_type(get_entity_type(ent))) { if (get_entity_irg(ent)) /* can be null */ { printf ("\n irg = %ld", get_irg_graph_nr(get_entity_irg(ent))); } diff --git a/ir/tr/entity.h b/ir/tr/entity.h index 368f55562..f6f4cfaea 100644 --- a/ir/tr/entity.h +++ b/ir/tr/entity.h @@ -45,9 +45,9 @@ * - type *type: The type of this entity, e.g., a method type, a * basic type of the language or a class itself. * - type *owner: The class this entity belongs to. In case of local -* variables the method they are defined in. -* - int offset: Offset in byte for this entity. Fixed when layout -* of owner is determined. +* variables the method they are defined in. +* - int offset: Offset in bits for this entity. Fixed when layout +* of owner is determined. * - ir_graph *irg: If (type == method_type) this is the corresponding irg. * The ir_graph constructor automatically sets this field. * If (type != method_type) access of this field will cause @@ -95,7 +95,7 @@ typedef struct ir_graph ir_graph; * @param variability A flag indicating the variability of this entity (values: * uninitialized, initalized, part_constant, constant) * @param volatility @@@ - * @param offset The offset of the entity within the compound object. Only set + * @param offset The offset of the entity within the compound object in bits. Only set * if the owner in the state "layout_fixed". * @param overwrites A list of entities overwritten by this entity. This list is only * existent if the owner of this entity is a class. The members in @@ -295,23 +295,29 @@ const char *get_volatility_name(ent_volatility var); /** This enumeration flags the stickyness of an entity. */ typedef enum { stickyness_unsticky, /**< The entity can be removed from - the program, unles contraindicated + the program, unless contraindicated by other attributes */ stickyness_sticky /**< The entity must remain in the program in any case */ } ent_stickyness; /** Get the entity's stickyness */ -ent_stickyness get_entity_stickyness (entity *ent); +ent_stickyness get_entity_stickyness(entity *ent); /** Set the entity's stickyness */ -void set_entity_stickyness (entity *ent, ent_stickyness stickyness); +void set_entity_stickyness(entity *ent, ent_stickyness stickyness); -/** Returns the offset of an entity (in a compound). Only set if layout = fixed. */ -int get_entity_offset (entity *ent); +/** Returns the offset of an entity (in a compound) in bytes. Only set if layout = fixed. */ +int get_entity_offset_bytes(entity *ent); -/** Sets the offset of an entity (in a compound). */ -void set_entity_offset (entity *ent, int offset); +/** Returns the offset of an entity (in a compound) in bits. Only set if layout = fixed. */ +int get_entity_offset_bits(entity *ent); + +/** Sets the offset of an entity (in a compound) in bytes. */ +void set_entity_offset_bytes(entity *ent, int offset); + +/** Sets the offset of an entity (in a compound) in bits. */ +void set_entity_offset_bits(entity *ent, int offset); /** Returns the stored intermediate information. */ void* get_entity_link(entity *ent); diff --git a/ir/tr/entity_t.h b/ir/tr/entity_t.h index a5f39b6f4..3d5a38f1e 100644 --- a/ir/tr/entity_t.h +++ b/ir/tr/entity_t.h @@ -11,35 +11,36 @@ */ /** -* @file entity_t.h -* -* entity.h: entities represent all program known objects. -* -* @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier -* -* An entity is the representation of program known objects in Firm. -* The primary concept of entities is to represent members of complex -* types, i.e., fields and methods of classes. As not all programming -* language model all variables and methods as members of some class, -* the concept of entities is extended to cover also local and global -* variables, and arbitrary procedures. -* -* An entity always specifies the type of the object it represents and -* the type of the object it is a part of, the owner of the entity. -* Originally this is the type of the class of which the entity is a -* member. -* The owner of local variables is the procedure they are defined in. -* The owner of global variables and procedures visible in the whole -* program is a universally defined class type "GlobalType". The owner -* of procedures defined in the scope of an other procedure is the -* enclosing procedure. -*/ - + * @file entity_t.h + * + * entity.h: entities represent all program known objects. + * + * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier + * + * An entity is the representation of program known objects in Firm. + * The primary concept of entities is to represent members of complex + * types, i.e., fields and methods of classes. As not all programming + * language model all variables and methods as members of some class, + * the concept of entities is extended to cover also local and global + * variables, and arbitrary procedures. + * + * An entity always specifies the type of the object it represents and + * the type of the object it is a part of, the owner of the entity. + * Originally this is the type of the class of which the entity is a + * member. + * The owner of local variables is the procedure they are defined in. + * The owner of global variables and procedures visible in the whole + * program is a universally defined class type "GlobalType". The owner + * of procedures defined in the scope of an other procedure is the + * enclosing procedure. + */ # ifndef _ENTITY_T_H_ # define _ENTITY_T_H_ # include "entity.h" +# include "typegmod.h" +# include "mangle.h" /** A path in a compund graph. */ struct compound_graph_path { @@ -69,8 +70,8 @@ struct entity { 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 byte for this entity. Fixed when layout - of owner is determined. */ + int offset; /**< Offset in bits for this entity. Fixed when layout + of owner is determined. */ void *link; /**< To store some intermediate information */ unsigned long visit; /**< visited counter for walks of the type information */ struct dbg_info* dbi; /**< A pointer to information for debug support. */ @@ -101,6 +102,198 @@ struct entity { #endif }; -INLINE long get_entity_nr(entity *ent); +/* ----------------------- inline functions ------------------------ */ +static INLINE int +__is_entity(void *thing) { + return get_kind(thing) == k_entity; +} + +static INLINE const char * +__get_entity_name(entity *ent) { + assert(ent && ent->kind == k_entity); + return get_id_str(get_entity_ident(ent)); +} + +static INLINE ident * +__get_entity_ident(entity *ent) { + assert(ent && ent->kind == k_entity); + return ent->name; +} + +static INLINE type * +__get_entity_owner(entity *ent) { + assert(ent && ent->kind == k_entity); + return ent->owner = skip_tid(ent->owner); +} + +static INLINE ident * +__get_entity_ld_ident(entity *ent) +{ + assert(ent && ent->kind == k_entity); + if (ent->ld_name == NULL) + ent->ld_name = mangle_entity(ent); + return ent->ld_name; +} + +static INLINE void +__set_entity_ld_ident(entity *ent, ident *ld_ident) { + assert(ent && ent->kind == k_entity); + ent->ld_name = ld_ident; +} + +static INLINE const char * +__get_entity_ld_name(entity *ent) { + assert(ent && ent->kind == k_entity); + return get_id_str(get_entity_ld_ident(ent)); +} + +static INLINE type * +__get_entity_type(entity *ent) { + assert(ent && ent->kind == k_entity); + return ent->type = skip_tid(ent->type); +} + +static INLINE void +__set_entity_type(entity *ent, type *type) { + assert(ent && ent->kind == k_entity); + ent->type = type; +} + +static INLINE ent_allocation +__get_entity_allocation(entity *ent) { + assert(ent && ent->kind == k_entity); + return ent->allocation; +} + +static INLINE void +__set_entity_allocation(entity *ent, ent_allocation al) { + assert(ent && ent->kind == k_entity); + ent->allocation = al; +} + +static INLINE ent_visibility +__get_entity_visibility(entity *ent) { + assert(ent && ent->kind == k_entity); + return ent->visibility; +} + +static INLINE ent_variability +__get_entity_variability(entity *ent) { + assert(ent && ent->kind == k_entity); + return ent->variability; +} + +static INLINE ent_volatility +__get_entity_volatility(entity *ent) { + assert(ent && ent->kind == k_entity); + return ent->volatility; +} + +static INLINE void +__set_entity_volatility(entity *ent, ent_volatility vol) { + assert(ent && ent->kind == k_entity); + ent->volatility = vol; +} + +static INLINE peculiarity +__get_entity_peculiarity(entity *ent) { + assert(ent && ent->kind == k_entity); + return ent->peculiarity; +} + +/** + * @todo why peculiarity only for methods + */ +static INLINE void +__set_entity_peculiarity(entity *ent, peculiarity pec) { + assert(ent && ent->kind == k_entity); + /* @@@ why peculiarity only for methods? */ + assert(is_method_type(ent->type)); + ent->peculiarity = pec; +} + +static INLINE ent_stickyness +__get_entity_stickyness(entity *ent) { + assert(ent && ent->kind == k_entity); + return ent->stickyness; +} + +static INLINE void +__set_entity_stickyness(entity *ent, ent_stickyness stickyness) +{ + assert(ent && ent->kind == k_entity); + ent->stickyness = stickyness; +} + +static INLINE int +__get_entity_offset_bits(entity *ent) { + assert(ent && ent->kind == k_entity); + return ent->offset; +} + +static INLINE int +__get_entity_offset_bytes(entity *ent) { + int bits = __get_entity_offset_bits(ent); + + if (bits & 7) return -1; + return bits >> 3; +} + +static INLINE void +__set_entity_offset_bits(entity *ent, int offset) { + assert(ent && ent->kind == k_entity); + ent->offset = offset; +} + +static INLINE void +__set_entity_offset_bytes(entity *ent, int offset) { + __set_entity_offset_bits(ent, offset * 8); +} + +static INLINE void * +__get_entity_link(entity *ent) { + assert(ent && ent->kind == k_entity); + return ent->link; +} + +static INLINE void +__set_entity_link(entity *ent, void *l) { + assert(ent && ent->kind == k_entity); + ent->link = l; +} + +static INLINE ir_graph * +__get_entity_irg(entity *ent) { + assert(ent && ent->kind == k_entity); + assert(is_method_type(ent->type)); + return ent->irg; +} + +#define is_entity(thing) __is_entity(thing) +#define get_entity_name(ent) __get_entity_name(ent) +#define get_entity_ident(ent) __get_entity_ident(ent) +#define get_entity_owner(ent) __get_entity_owner(ent) +#define get_entity_ld_ident(ent) __get_entity_ld_ident(ent) +#define set_entity_ld_ident(ent, ld_ident) __set_entity_ld_ident(ent, ld_ident) +#define get_entity_ld_name(ent) __get_entity_ld_name(ent) +#define get_entity_type(ent) __get_entity_type(ent) +#define set_entity_type(ent, type) __set_entity_type(ent, type) +#define get_entity_allocation(ent) __get_entity_allocation(ent) +#define set_entity_allocation(ent, al) __set_entity_allocation(ent, al) +#define get_entity_visibility(ent) __get_entity_visibility(ent) +#define get_entity_variability(ent) __get_entity_variability(ent) +#define get_entity_volatility(ent) __get_entity_volatility(ent) +#define set_entity_volatility(ent, vol) __set_entity_volatility(ent, vol) +#define get_entity_peculiarity(ent) __get_entity_peculiarity(ent) +#define set_entity_peculiarity(ent, pec) __set_entity_peculiarity(ent, pec) +#define get_entity_stickyness(ent) __get_entity_stickyness(ent) +#define set_entity_stickyness(ent, stickyness) __set_entity_stickyness(ent, stickyness) +#define get_entity_offset_bits(ent) __get_entity_offset_bits(ent) +#define get_entity_offset_bytes(ent) __get_entity_offset_bytes(ent) +#define set_entity_offset_bits(ent, offset) __set_entity_offset_bits(ent, offset) +#define set_entity_offset_bytes(ent, offset) __set_entity_offset_bytes(ent, offset) +#define get_entity_link(ent) __get_entity_link(ent) +#define set_entity_link(ent, l) __set_entity_link(ent, l) +#define get_entity_irg(ent) __get_entity_irg(ent) # endif /* _ENTITY_T_H_ */ -- 2.20.1