Commit 2600cf44 authored by Matthias Braun's avatar Matthias Braun
Browse files

tr: Replace copy_entity_own()/copy_entity_name() with a new clone_entity()

parent ce0541cf
......@@ -259,24 +259,13 @@ FIRM_API ir_entity *get_entity_alias(const ir_entity *alias);
FIRM_API int check_entity(const ir_entity *ent);
/**
* Copies the entity if the new_owner is different from the
* owner of the old entity, else returns the old entity.
* Create a new entity with attributes copied from an existing entity.
*
* Automatically inserts the new entity as a member of owner.
* Resets the overwrites/overwritten_by fields.
* Keeps the old atomic value.
* Does not copy the overwrites/overwritte_by, visited an dusage fields, sets
* a new name and inserts the entity into \p owner.
*/
FIRM_API ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner);
/**
* Copies the entity if the new_name is different from the
* name of the old entity, else returns the old entity.
*
* Automatically inserts the new entity as a member of owner.
* The mangled name ld_name is set to NULL.
* Overwrites relation is copied from old.
*/
FIRM_API ir_entity *copy_entity_name(ir_entity *old, ident *new_name);
FIRM_API ir_entity *clone_entity(ir_entity const *old, ident *name,
ir_type *owner);
/**
* Frees the entity.
......
......@@ -244,7 +244,8 @@ static void copy_frame_entities(ir_graph *from, ir_graph *to)
// parameter entities are already copied and the link has been set
if (!is_parameter_entity(old_ent)) {
ir_entity *new_ent = copy_entity_own(old_ent, to_frame);
ident *name = get_entity_name(old_ent);
ir_entity *new_ent = clone_entity(old_ent, name, to_frame);
set_entity_link(old_ent, new_ent);
}
}
......
......@@ -429,7 +429,8 @@ static ir_entity *clone_method(const quadruple_t *q)
/* We get a new ident for our clone method.*/
ident *const clone_ident = get_clone_ident(get_entity_ident(q->ent), q->pos, nr);
/* We get our entity for the clone method. */
ir_entity *const new_entity = copy_entity_name(q->ent, clone_ident);
ir_type *const owner = get_entity_owner(q->ent);
ir_entity *const new_entity = clone_entity(q->ent, clone_ident, owner);
/* a cloned entity is always local */
set_entity_visibility(new_entity, ir_visibility_local);
......
......@@ -168,56 +168,29 @@ static void free_entity_attrs(ir_entity *ent)
}
}
/**
* Creates a deep copy of an entity.
*/
static ir_entity *deep_entity_copy(ir_entity *old)
ir_entity *clone_entity(ir_entity const *const old, ident *const name,
ir_type *const owner)
{
ir_entity *newe = XMALLOC(ir_entity);
ir_entity *res = XMALLOC(ir_entity);
*newe = *old;
*res = *old;
/* FIXME: the initializers are NOT copied */
if (is_method_entity(old)) {
/* do NOT copy them, reanalyze. This might be the best solution */
newe->attr.mtd_attr.param_access = NULL;
newe->attr.mtd_attr.param_weight = NULL;
res->attr.mtd_attr.param_access = NULL;
res->attr.mtd_attr.param_weight = NULL;
}
newe->overwrites = NULL;
newe->overwrittenby = NULL;
newe->nr = get_irp_new_node_nr();
hook_new_entity(newe);
return newe;
}
ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner)
{
assert(old->kind == k_entity);
assert(is_compound_type(new_owner));
assert(get_type_state(new_owner) != layout_fixed);
if (old->owner == new_owner)
return old;
/* create a deep copy so we are safe of aliasing and double-freeing. */
ir_entity *newe = deep_entity_copy(old);
newe->owner = new_owner;
add_compound_member(new_owner, newe);
return newe;
}
ir_entity *copy_entity_name(ir_entity *old, ident *new_name)
{
assert(old->kind == k_entity);
if (old->name == new_name)
return old;
ir_entity *newe = deep_entity_copy(old);
newe->name = new_name;
newe->ld_name = NULL;
add_compound_member(old->owner, newe);
res->overwrites = NULL;
res->overwrittenby = NULL;
return newe;
res->nr = get_irp_new_node_nr();
res->name = name;
res->visit = 0;
res->usage = ir_usage_unknown;
res->owner = owner;
add_compound_member(owner, res);
hook_new_entity(res);
return res;
}
void free_entity(ir_entity *ent)
......
......@@ -1037,7 +1037,8 @@ ir_type *clone_frame_type(ir_type *type)
ir_type *res = new_type_frame();
for (size_t i = 0, n = get_compound_n_members(type); i < n; ++i) {
ir_entity *ent = get_compound_member(type, i);
ir_entity *nent = copy_entity_own(ent, res);
ident *name = get_entity_name(ent);
ir_entity *nent = clone_entity(ent, name, res);
set_entity_link(ent, nent);
set_entity_link(nent, ent);
}
......
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