Commit b2409eda authored by Matthias Braun's avatar Matthias Braun
Browse files

further cleanup in get/set_entity_irg/additional_properties

- Only allow get_entity_irg()/set_entity_irg() for method entities now.
- Allow setting/getting of additional properties for method and alias
  entities.
- Add some missing is_method_entity() checks in cgana.
parent c9f09085
......@@ -601,8 +601,10 @@ FIRM_API int is_atomic_entity(const ir_entity *ent);
/** Returns true if the type of the entity is a class, structure,
array or union type. */
FIRM_API int is_compound_entity(const ir_entity *ent);
/** Returns true if the type of the entity is a Method type. */
/** Returns true if the entity is a method entity. */
FIRM_API int is_method_entity(const ir_entity *ent);
/** Returns true if the entity is an alias entity. */
FIRM_API int is_alias_entity(const ir_entity *ent);
/** Outputs a unique number for this entity if libfirm is compiled for
* debugging, (configure with --enable-debug) else returns the address
......@@ -630,6 +632,12 @@ FIRM_API int entity_visited(const ir_entity *ent);
* @see @ref visited_counters */
FIRM_API int entity_not_visited(const ir_entity *ent);
/** Return true if this entity can be queried for additional properties.
*
* This is possible for method and alias entities.
*/
FIRM_API int entity_has_additional_properties(const ir_entity *entity);
/**
* Returns the mask of the additional entity properties.
* The properties are automatically inherited from the irg if available
......
......@@ -123,6 +123,7 @@ static size_t collect_impls(ir_entity *method, pset *set)
*/
static ir_entity **get_impl_methods(ir_entity *method)
{
assert(is_method_entity(method));
/* Collect all method entities that can be called here */
ir_entity **arr = NULL;
pset *set = pset_new_ptr_default();
......@@ -165,8 +166,7 @@ static void sel_methods_walker(ir_node *node, void *env)
}
ir_entity *const entity = get_Sel_entity(node);
const ir_type *const entity_type = get_entity_type(entity);
if (!is_Method_type(entity_type))
if (!is_method_entity(entity))
return;
/* we may have a vtable entry and need this redirection to get the actually
* called method */
......@@ -572,7 +572,10 @@ static void callee_ana_node(ir_node *node, pset *methods)
break;
}
case iro_Sel:
case iro_Sel: {
ir_entity *entity = get_Sel_entity(node);
if (!is_method_entity(entity))
break;
/* polymorphic method */
for (size_t i = 0, n = get_Sel_n_methods(node); i < n; ++i) {
ir_entity *ent = get_Sel_method(node, i);
......@@ -583,6 +586,7 @@ static void callee_ana_node(ir_node *node, pset *methods)
}
}
break;
}
case iro_Bad:
break;
......
......@@ -393,7 +393,7 @@ static bool is_comdat(const ir_entity *entity)
static be_gas_section_t determine_basic_section(const ir_entity *entity)
{
if (is_method_entity(entity))
if (is_method_entity(entity) || is_alias_entity(entity))
return GAS_SECTION_TEXT;
ir_linkage linkage = get_entity_linkage(entity);
......@@ -405,7 +405,7 @@ static be_gas_section_t determine_basic_section(const ir_entity *entity)
return GAS_SECTION_RODATA;
}
if (entity_is_null(entity) && get_entity_kind(entity) != IR_ENTITY_ALIAS)
if (entity_is_null(entity) && !is_alias_entity(entity))
return GAS_SECTION_BSS;
return GAS_SECTION_DATA;
......
......@@ -234,11 +234,11 @@ void be_abi_fix_stack_bias(ir_graph *irg)
frame_tp = get_irg_frame_type(irg);
for (i = get_class_n_members(frame_tp) - 1; i >= 0; --i) {
ir_entity *ent = get_class_member(frame_tp, i);
ir_graph *irg = get_entity_irg(ent);
if (irg != NULL) {
if (!is_method_entity(ent))
continue;
ir_graph *irg = get_entity_irg(ent);
if (irg != NULL)
irg_walk_graph(irg, NULL, lower_outer_frame_sels, NULL);
}
}
}
......
......@@ -744,8 +744,7 @@ ir_entity *get_Call_callee(const ir_node *node)
ir_entity *entity = get_SymConst_entity(ptr);
/* some (corner case/pointless) graphs can have non-method entities as
* call pointers */
ir_type *type = get_entity_type(entity);
if (!is_Method_type(type))
if (!is_method_entity(entity) && !is_alias_entity(entity))
return NULL;
return entity;
}
......
......@@ -707,7 +707,7 @@ static mtp_additional_properties check_nothrow_or_malloc(ir_graph *irg, bool top
ir_entity *callee = get_Call_callee(res);
if (callee != NULL) {
/* a direct call */
ir_graph *callee_irg = get_entity_irg(callee);
ir_graph *callee_irg = get_entity_linktime_irg(callee);
if (callee_irg == irg) {
/* A self-recursive call. The property did not
* depend on this call. */
......
......@@ -84,9 +84,10 @@ static void visit_entity(ir_entity *entity)
visit_initializer(entity->initializer);
}
irg = get_entity_irg(entity);
if (irg != NULL) {
start_visit_node(get_irg_end(irg));
if (is_method_entity(entity)) {
irg = get_entity_irg(entity);
if (irg != NULL)
start_visit_node(get_irg_end(irg));
}
}
......
......@@ -831,8 +831,12 @@ int is_compound_entity(const ir_entity *ent)
int is_method_entity(const ir_entity *ent)
{
ir_type *t = get_entity_type(ent);
return is_Method_type(t);
return ent->entity_kind == IR_ENTITY_METHOD;
}
int is_alias_entity(const ir_entity *entity)
{
return entity->entity_kind == IR_ENTITY_ALIAS;
}
ir_visited_t (get_entity_visited)(const ir_entity *ent)
......@@ -860,32 +864,38 @@ int (entity_not_visited)(const ir_entity *ent)
return _entity_not_visited(ent);
}
int entity_has_additional_properties(const ir_entity *entity)
{
return entity->entity_kind == IR_ENTITY_METHOD
|| entity->entity_kind == IR_ENTITY_ALIAS;
}
mtp_additional_properties get_entity_additional_properties(const ir_entity *ent)
{
assert(is_method_entity(ent));
return ent->attr.mtd_attr.properties;
assert(entity_has_additional_properties(ent));
return ent->attr.properties;
}
void set_entity_additional_properties(ir_entity *ent,
mtp_additional_properties property_mask)
{
assert(is_method_entity(ent));
assert(entity_has_additional_properties(ent));
/* you mustn't set less properties than the entities type */
assert((get_method_additional_properties(get_entity_type(ent)) & ~property_mask) == 0);
/* do not allow to set the mtp_property_inherited flag or
* the automatic inheritance of flags will not work */
ent->attr.mtd_attr.properties = property_mask;
ent->attr.properties = property_mask;
}
void add_entity_additional_properties(ir_entity *ent,
mtp_additional_properties properties)
{
assert(is_method_entity(ent));
assert(entity_has_additional_properties(ent));
/* do not allow to set the mtp_property_inherited flag or
* the automatic inheritance of flags will not work */
ent->attr.mtd_attr.properties |= properties;
ent->attr.properties |= properties;
}
dbg_info *(get_entity_dbg_info)(const ir_entity *ent)
......
......@@ -97,10 +97,11 @@ union ir_initializer_t {
/** The attributes for methods. */
typedef struct method_ent_attr {
mtp_additional_properties properties; /**< Additional graph properties can
be stored in a entity if no irg
is available. Must be first. */
ir_graph *irg; /**< The corresponding irg if known.
The ir_graph constructor automatically sets this field. */
mtp_additional_properties 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. */
......@@ -137,7 +138,9 @@ typedef struct parameter_ent_attr {
} parameter_ent_attr;
typedef struct alias_ent_attr {
mtp_additional_properties properties;
mtp_additional_properties properties; /**< Additional graph properties can
be stored in a entity if no irg
is available. Must be first. */
ir_entity *aliased;
} alias_ent_attr;
......@@ -209,6 +212,8 @@ struct ir_entity {
alias_ent_attr alias;
/** got entry attributes */
got_ent_attr got;
/** additional properties shared by method+alias entities */
mtp_additional_properties properties;
} attr; /**< type specific attributes */
};
......@@ -421,19 +426,19 @@ static inline void _set_entity_link(ir_entity *ent, void *l)
static inline ir_graph *_get_entity_irg(const ir_entity *ent)
{
assert(ent->kind == k_entity);
if (!is_Method_type(ent->type) || is_unknown_entity(ent)) {
return NULL;
}
assert(ent->entity_kind == IR_ENTITY_METHOD);
return ent->attr.mtd_attr.irg;
}
static inline ir_graph *_get_entity_linktime_irg(const ir_entity *entity)
{
/** weak entities might get replaced by non-weak entities at linktime
/* weak entities might get replaced by non-weak entities at linktime
* so we can't return a definite graph. */
if (get_entity_linkage(entity) & IR_LINKAGE_WEAK)
return NULL;
/* only method entities have an irg field (alias etc. does not) */
if (entity->entity_kind != IR_ENTITY_METHOD)
return NULL;
return get_entity_irg(entity);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment