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

type: Ensure visibility/linkage are set on construction

This is done by introducing a new new_global_entity() function for
constructing globals/adding a visibility argument to new_alias_entity().
parent 859487f0
......@@ -208,6 +208,13 @@ FIRM_API int entity_has_definition(const ir_entity *entity);
*/
FIRM_API ir_entity *new_entity(ir_type *owner, ident *name, ir_type *tp);
/**
* Creates a new global entity.
*/
FIRM_API ir_entity *new_global_entity(ir_type *segment, ident *ld_name,
ir_type *type, ir_visibility visibility,
ir_linkage linkage);
/**
* Creates a new entity corresponding to a function parameter.
* This must be created on an irgs frame_type
......@@ -230,7 +237,8 @@ FIRM_API ir_entity *new_parameter_entity(ir_type *owner, size_t pos,
* @return the newly created entity
*/
FIRM_API ir_entity *new_alias_entity(ir_type *owner, ident *name,
ir_entity *alias, ir_type *type);
ir_entity *alias, ir_type *type,
ir_visibility visibility);
/**
* Sets the entity an alias entity aliases.
......
......@@ -347,9 +347,9 @@ ir_entity *create_float_const_entity(ir_tarval *const tv)
ir_type *type = mode == x86_mode_E ? x86_type_E : get_type_for_mode(mode);
ir_type *glob = get_glob_type();
entity = new_entity(glob, id_unique("C%u"), type);
set_entity_visibility(entity, ir_visibility_private);
add_entity_linkage(entity, IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
entity = new_global_entity(glob, id_unique("C%u"), type,
ir_visibility_private,
IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
ir_initializer_t *initializer = create_initializer_tarval(tv);
set_entity_initializer(entity, initializer);
......@@ -1529,9 +1529,9 @@ static ir_node *gen_Switch(ir_node *const node)
ir_type *const utype = get_unknown_type();
ir_entity *const entity
= new_entity(irp->dummy_owner, id_unique("TBL%u"), utype);
set_entity_visibility(entity, ir_visibility_private);
add_entity_linkage(entity, IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
= new_global_entity(irp->dummy_owner, id_unique("TBL%u"), utype,
ir_visibility_private,
IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
arch_register_req_t const **in_reqs;
amd64_op_mode_t op_mode;
......
......@@ -118,9 +118,9 @@ static ir_entity *make_divmod(char const *const name, ir_type *const even, ir_ty
ident *const id = new_id_from_str(name);
ir_type *const glob = get_glob_type();
ir_entity *const ent = new_entity(glob, id, mtp);
set_entity_ld_ident(ent, id);
set_entity_visibility(ent, ir_visibility_external);
ir_entity *const ent = new_global_entity(glob, id, mtp,
ir_visibility_external,
IR_LINKAGE_DEFAULT);
return ent;
}
......@@ -360,9 +360,9 @@ static ir_entity *create_64_intrinsic_fkt(ir_type *method, const ir_op *op,
}
ident *id = new_id_from_str(name);
ir_type *glob = get_glob_type();
ir_entity *result = new_entity(glob, id, method);
set_entity_ld_ident(result, id);
set_entity_visibility(result, ir_visibility_external);
ir_entity *result = new_global_entity(glob, id, method,
ir_visibility_external,
IR_LINKAGE_DEFAULT);
return result;
}
......
......@@ -1163,10 +1163,9 @@ static void ia32_select_instructions(ir_graph *irg)
if (mcount == NULL) {
ir_type *tp = new_type_method(0, 0);
ident *id = new_id_from_str("mcount");
mcount = new_entity(get_glob_type(), id, tp);
/* FIXME: enter the right ld_ident here */
set_entity_ld_ident(mcount, get_entity_ident(mcount));
set_entity_visibility(mcount, ir_visibility_external);
mcount = new_global_entity(get_glob_type(), id, tp,
ir_visibility_external,
IR_LINKAGE_DEFAULT);
}
instrument_initcall(irg, mcount);
}
......
......@@ -1238,9 +1238,8 @@ static void emit_ia32_GetEIP(const ir_node *node)
char const *const name = get_register_name_16bit(reg);
ident *const id = new_id_fmt("__x86.get_pc_thunk.%s", name);
ir_type *const tp = get_thunk_type();
thunk = new_entity(glob, id, tp);
set_entity_visibility(thunk, ir_visibility_external_private);
add_entity_linkage(thunk, IR_LINKAGE_MERGE|IR_LINKAGE_GARBAGE_COLLECT);
thunk = new_global_entity(glob, id, tp, ir_visibility_external_private,
IR_LINKAGE_MERGE|IR_LINKAGE_GARBAGE_COLLECT);
/* Note that we do not create a proper method graph, but rather cheat
* later and emit the instructions manually. This is just necessary so
* firm knows we will actually output code for this entity. */
......
......@@ -42,10 +42,9 @@ static ir_entity *create_ent(ir_entity **const dst, int value, const char *name)
set_type_alignment_bytes(type, 4);
ir_type *const glob = get_glob_type();
ident *const id = new_id_from_str(name);
ir_entity *const ent = new_entity(glob, id, type);
set_entity_ld_ident(ent, id);
set_entity_visibility(ent, ir_visibility_local);
add_entity_linkage(ent, IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
ir_entity *const ent
= new_global_entity(glob, id, type, ir_visibility_local,
IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
ir_graph *const cnst_irg = get_const_code_irg();
ir_node *const cnst = new_r_Const_long(cnst_irg, mode, value);
......
......@@ -34,12 +34,11 @@ static ir_entity *create_trampoline(be_main_env_t *be, ir_entity *method)
ident *old_id = get_entity_ld_ident(method);
ident *id = new_id_fmt("%s$stub", old_id);
ir_type *parent = be->pic_trampolines_type;
ir_entity *ent = new_entity(parent, id, type);
set_entity_ld_ident(ent, id);
ir_entity *ent = new_global_entity(parent, id, type,
ir_visibility_private,
IR_LINKAGE_DEFAULT);
/* We misuse the ident field to point to the old entity */
set_entity_ident(ent, old_id);
set_entity_visibility(ent, ir_visibility_private);
return ent;
}
......@@ -64,10 +63,10 @@ static ir_entity *create_nonlazyptr(be_main_env_t *be, ir_entity *entity)
ir_type *e_type = get_entity_type(entity);
ir_type *type = new_type_pointer(e_type);
ir_type *parent = be->pic_symbols_type;
ir_entity *ent = new_entity(parent, id, type);
set_entity_ld_ident(ent, id);
ir_entity *ent = new_global_entity(parent, id, type,
ir_visibility_private,
IR_LINKAGE_DEFAULT);
set_entity_ident(ent, old_id);
set_entity_visibility(ent, ir_visibility_private);
return ent;
}
......
......@@ -317,10 +317,10 @@ static ir_entity *create_float_const_entity(ir_tarval *tv, ident *name)
name = id_unique("C%u");
ir_type *const tp = get_prim_type(mode);
res = new_entity(get_glob_type(), name, tp);
res = new_global_entity(get_glob_type(), name, tp,
ir_visibility_private,
IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
set_entity_ld_ident(res, get_entity_ident(res));
set_entity_visibility(res, ir_visibility_private);
add_entity_linkage(res, IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
ir_initializer_t *const initializer = create_initializer_tarval(tv);
set_entity_initializer(res, initializer);
......@@ -579,11 +579,11 @@ ir_entity *ia32_gen_fp_known_const(ia32_known_const_t const kct)
ir_type *type = get_prim_type(ia32_mode_float32);
ir_type *atype = ia32_create_float_array(type);
ent = new_entity(get_glob_type(), name, atype);
ent = new_global_entity(get_glob_type(), name, atype,
ir_visibility_private,
IR_LINKAGE_CONSTANT|IR_LINKAGE_NO_IDENTITY);
set_entity_ld_ident(ent, name);
set_entity_visibility(ent, ir_visibility_private);
add_entity_linkage(ent, IR_LINKAGE_CONSTANT|IR_LINKAGE_NO_IDENTITY);
ir_initializer_t *initializer = create_initializer_compound(2);
set_initializer_compound_value(initializer, 0,
......@@ -2926,9 +2926,9 @@ static ir_node *gen_Switch(ir_node *node)
ir_type *const utype = get_unknown_type();
ir_entity *const entity
= new_entity(irp->dummy_owner, id_unique("TBL%u"), utype);
set_entity_visibility(entity, ir_visibility_private);
add_entity_linkage(entity, IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
= new_global_entity(irp->dummy_owner, id_unique("TBL%u"), utype,
ir_visibility_private,
IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
ir_graph *irg = get_irn_irg(node);
const ir_switch_table *table = get_Switch_table(node);
......@@ -3335,7 +3335,10 @@ static ir_entity *ia32_create_const_array(ir_node *c0, ir_node *c1,
ir_type *tp = get_prim_type(mode);
tp = ia32_create_float_array(tp);
ir_entity *ent = new_entity(get_glob_type(), id_unique("C%u"), tp);
ir_entity *ent
= new_global_entity(get_glob_type(), id_unique("C%u"), tp,
ir_visibility_private,
IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
set_entity_ld_ident(ent, get_entity_ident(ent));
set_entity_visibility(ent, ir_visibility_private);
......
......@@ -118,9 +118,9 @@ static ir_entity *create_64_intrinsic_fkt(ir_type *method, const ir_op *op,
}
ident *id = new_id_from_str(name);
ir_type *glob = get_glob_type();
ir_entity *result = new_entity(glob, id, method);
set_entity_ld_ident(result, id);
set_entity_visibility(result, ir_visibility_external);
ir_entity *result = new_global_entity(glob, id, method,
ir_visibility_external,
IR_LINKAGE_DEFAULT);
return result;
}
......
......@@ -1169,9 +1169,9 @@ static ir_entity *create_float_const_entity(ir_tarval *const tv)
ir_mode *mode = get_tarval_mode(tv);
ir_type *type = get_type_for_mode(mode);
ir_type *glob = get_glob_type();
entity = new_entity(glob, id_unique("C%u"), type);
set_entity_visibility(entity, ir_visibility_private);
add_entity_linkage(entity, IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
entity = new_global_entity(glob, id_unique("C%u"), type,
ir_visibility_private,
IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
ir_initializer_t *initializer = create_initializer_tarval(tv);
set_entity_initializer(entity, initializer);
......@@ -1245,9 +1245,9 @@ static ir_node *gen_Switch(ir_node *node)
ir_type *const utype = get_unknown_type();
ir_entity *const entity
= new_entity(irp->dummy_owner, id_unique("TBL%u"), utype);
set_entity_visibility(entity, ir_visibility_private);
add_entity_linkage(entity, IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
= new_global_entity(irp->dummy_owner, id_unique("TBL%u"), utype,
ir_visibility_private,
IR_LINKAGE_CONSTANT | IR_LINKAGE_NO_IDENTITY);
/* construct base address */
ir_node *table_address = make_address(dbgi, new_block, entity, 0);
......
......@@ -1795,7 +1795,7 @@ static void read_entity(read_env_t *env, ir_entity_kind kind)
switch (kind) {
case IR_ENTITY_ALIAS: {
ir_entity *aliased = read_entity_ref(env);
entity = new_alias_entity(owner, name, aliased, type);
entity = new_alias_entity(owner, name, aliased, type, visibility);
break;
}
case IR_ENTITY_NORMAL:
......
......@@ -32,20 +32,22 @@ ir_entity *get_unknown_entity(void)
}
static ir_entity *intern_new_entity(ir_type *owner, ir_entity_kind kind,
ident *name, ir_type *type)
ident *name, ir_type *type,
ir_visibility visibility)
{
assert(owner != NULL);
ir_entity *res = XMALLOCZ(ir_entity);
res->kind = k_entity;
res->name = name;
res->ld_name = name;
res->type = type;
res->owner = owner;
res->entity_kind = kind;
res->volatility = volatility_non_volatile;
res->aligned = align_is_aligned;
res->usage = ir_usage_unknown;
res->visibility = ir_visibility_external;
res->visibility = visibility;
res->nr = get_irp_new_node_nr();
/* Remember entity in its owner. */
......@@ -55,11 +57,12 @@ static ir_entity *intern_new_entity(ir_type *owner, ir_entity_kind kind,
return res;
}
ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
static ir_entity *new_entity_vis(ir_type *owner, ident *name, ir_type *type,
ir_visibility vis)
{
ir_entity *res;
if (is_Method_type(type)) {
res = intern_new_entity(owner, IR_ENTITY_METHOD, name, type);
res = intern_new_entity(owner, IR_ENTITY_METHOD, name, type, vis);
res->linkage = IR_LINKAGE_CONSTANT;
res->attr.mtd_attr.properties = get_method_additional_properties(type);
res->attr.mtd_attr.vtable_number = IR_VTABLE_NUM_NOT_SET;
......@@ -67,20 +70,37 @@ ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
res->attr.mtd_attr.param_weight = NULL;
res->attr.mtd_attr.irg = NULL;
} else if (is_compound_type(owner) && !is_segment_type(owner)) {
res = intern_new_entity(owner, IR_ENTITY_COMPOUND_MEMBER, name, type);
res = intern_new_entity(owner, IR_ENTITY_COMPOUND_MEMBER, name, type,
vis);
res->attr.compound_member.offset = -1;
} else {
res = intern_new_entity(owner, IR_ENTITY_NORMAL, name, type);
res = intern_new_entity(owner, IR_ENTITY_NORMAL, name, type, vis);
}
hook_new_entity(res);
return res;
}
ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
{
return new_entity_vis(owner, name, type, ir_visibility_external);
}
ir_entity *new_global_entity(ir_type *segment, ident *ld_name, ir_type *type,
ir_visibility visibility, ir_linkage linkage)
{
assert(is_segment_type(segment) || segment == irp->dummy_owner);
ir_entity *res = new_entity_vis(segment, ld_name, type, visibility);
add_entity_linkage(res, linkage);
hook_new_entity(res);
return res;
}
ir_entity *new_parameter_entity(ir_type *owner, size_t pos, ir_type *type)
{
ident *name = new_id_fmt("parameter.%lu", (unsigned long)pos);
ir_entity *res = intern_new_entity(owner, IR_ENTITY_PARAMETER, name, type);
ir_entity *res = intern_new_entity(owner, IR_ENTITY_PARAMETER, name, type,
ir_visibility_private);
res->attr.compound_member.offset = -1;
res->attr.parameter.number = pos;
hook_new_entity(res);
......@@ -92,16 +112,17 @@ ir_entity *new_label_entity(ir_label_t label)
ident *name = id_unique("label_%u");
ir_type *global_type = get_glob_type();
ir_entity *res = intern_new_entity(global_type, IR_ENTITY_LABEL, name,
get_code_type());
get_code_type(), ir_visibility_private);
res->attr.code_attr.label = label;
hook_new_entity(res);
return res;
}
ir_entity *new_alias_entity(ir_type *owner, ident *name, ir_entity *aliased,
ir_type *type)
ir_type *type, ir_visibility visibility)
{
ir_entity *res = intern_new_entity(owner, IR_ENTITY_ALIAS, name, type);
ir_entity *res = intern_new_entity(owner, IR_ENTITY_ALIAS, name, type,
visibility);
res->attr.alias.aliased = aliased;
hook_new_entity(res);
return res;
......@@ -258,7 +279,8 @@ void set_entity_ld_ident(ir_entity *const ent, ident *const ld_ident)
ent->ld_name = ld_ident;
if (old_ident != ld_ident) {
ir_type *owner = get_entity_owner(ent);
if (is_segment_type(owner) && !(owner->flags & tf_info)) {
if (is_segment_type(owner) && !(owner->flags & tf_info)
&& get_entity_visibility(ent) != ir_visibility_private) {
pmap *globals = irp->globals;
pmap_insert(globals, old_ident, NULL);
assert(!pmap_contains(globals, ld_ident));
......@@ -903,7 +925,7 @@ void ir_init_entity(ir_prog *irp)
ident *const id = new_id_from_str(UNKNOWN_ENTITY_NAME);
ir_type *const utype = get_unknown_type();
irp->unknown_entity = intern_new_entity(irp->dummy_owner, IR_ENTITY_UNKNOWN,
id, utype);
id, utype, ir_visibility_private);
set_entity_visibility(irp->unknown_entity, ir_visibility_external);
set_entity_ld_ident(irp->unknown_entity, id);
hook_new_entity(irp->unknown_entity);
......
......@@ -976,7 +976,8 @@ void remove_compound_member(ir_type *type, ir_entity *member)
for (; i < n - 1; ++i)
type->attr.ca.members[i] = type->attr.ca.members[i+1];
ARR_SETLEN(ir_entity*, type->attr.ca.members, n-1);
if (is_segment_type(type) && !(type->flags & tf_info)) {
if (is_segment_type(type) && !(type->flags & tf_info)
&& get_entity_visibility(member) != ir_visibility_private) {
pmap *globals = irp->globals;
pmap_insert(globals, get_entity_ld_ident(member), NULL);
}
......@@ -992,7 +993,8 @@ void add_compound_member(ir_type *type, ir_entity *entity)
assert(get_entity_type(entity) != type);
ARR_APP1(ir_entity *, type->attr.ca.members, entity);
/* Add segment members to globals map. */
if (is_segment_type(type) && !(type->flags & tf_info)) {
if (is_segment_type(type) && !(type->flags & tf_info)
&& get_entity_visibility(entity) != ir_visibility_private) {
ident *id = get_entity_ld_ident(entity);
pmap *globals = irp->globals;
/* Globals must have unique names. */
......
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