Commit 07c77ebb authored by Matthias Braun's avatar Matthias Braun
Browse files

ir_visibility cleanup

This commit removes the strange differentiation between
ir_visibility_external and ir_visibility_default. We now only have
ir_visibility_external for all symbols visible across compilation units.
You may or may not attach graphs/initializers to them.
parent 6cbc6739
......@@ -91,10 +91,12 @@
*/
typedef enum {
/**
* The entity is visible outside the compilation unit, but it is defined
* here.
* The entity is visible across compilation units. It might have an
* initializer/graph.
* Note that variables with visibility_external but not initializer are
* not "uninitialized" but considered to be in another compilation unit.
*/
ir_visibility_default,
ir_visibility_external,
/**
* The entity is local to the compilation unit.
* A local entity is not visible in other compilation units.
......@@ -103,18 +105,13 @@ typedef enum {
*/
ir_visibility_local,
/**
* The entity is defined outside the compilation unit but potentially used
* here.
*/
ir_visibility_external,
/**
* This has the same semantic as visibility_local. Additionally the symbol is
* completely hidden from the linker (it only appears in the assembly).
* This has the same semantic as visibility_local. Additionally the symbol
* is completely hidden from the linker (it only appears in the assembly).
* While visibility_local is probably still visible to debuggers,
* visibility_private symbols aren't and probably won't appear in the object
* files
*/
ir_visibility_private
ir_visibility_private,
} ir_visibility;
/**
......
......@@ -356,8 +356,7 @@ void be_dwarf_callframe_spilloffset(const arch_register_t *reg, int offset)
static bool is_extern_entity(const ir_entity *entity)
{
ir_visited_t visibility = get_entity_visibility(entity);
return visibility == ir_visibility_default
|| visibility == ir_visibility_external;
return visibility == ir_visibility_external;
}
static void emit_entity_label(const ir_entity *entity)
......
......@@ -421,15 +421,8 @@ static int entity_is_string_const(const ir_entity *ent)
static bool entity_is_null(const ir_entity *entity)
{
if (entity->initializer != NULL) {
return initializer_is_null(entity->initializer);
} else if (entity_has_compound_ent_values(entity)) {
/* I'm too lazy to implement this case as compound graph paths will be
* remove anyway in the future */
return false;
}
/* uninitialized, NULL is fine */
return true;
ir_initializer_t *initializer = get_entity_initializer(entity);
return initializer == NULL || initializer_is_null(initializer);
}
static bool is_comdat(const ir_entity *entity)
......@@ -450,7 +443,7 @@ static be_gas_section_t determine_basic_section(const ir_entity *entity)
if (linkage & IR_LINKAGE_CONSTANT) {
/* mach-o is the only one with a cstring section */
if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O
&& entity_is_string_const(entity))
&& entity_is_string_const(entity))
return GAS_SECTION_CSTRING;
return GAS_SECTION_RODATA;
......@@ -514,7 +507,8 @@ static void emit_visibility(const ir_entity *entity)
if (get_entity_linkage(entity) & IR_LINKAGE_WEAK) {
emit_weak(entity);
/* Note: .weak seems to imply .globl so no need to output .globl */
} else if (get_entity_visibility(entity) == ir_visibility_default) {
} else if (get_entity_visibility(entity) == ir_visibility_external
&& entity_has_definition(entity)) {
be_emit_cstring("\t.globl ");
be_gas_emit_entity(entity);
be_emit_char('\n');
......@@ -1612,24 +1606,19 @@ static void emit_global(be_gas_decl_env_t *env, const ir_entity *entity)
case ir_visibility_private:
emit_local_common(entity);
return;
case ir_visibility_default:
case ir_visibility_external:
if (linkage & IR_LINKAGE_MERGE) {
emit_common(entity);
return;
}
break;
case ir_visibility_external:
if (linkage & IR_LINKAGE_MERGE)
panic("merge link semantic not supported for extern entities");
break;
}
}
emit_visibility(entity);
if (visibility == ir_visibility_external) {
/* nothing to do for externally defined values */
/* nothing left to do without an initializer */
if (!entity_has_definition(entity))
return;
}
if (!is_po2(alignment))
panic("alignment not a power of 2");
......@@ -1665,6 +1654,7 @@ static void emit_global(be_gas_decl_env_t *env, const ir_entity *entity)
}
if (entity_is_null(entity)) {
/* we should use .space for stuff in the bss segment */
unsigned size = get_type_size_bytes(type);
if (size > 0) {
be_emit_irprintf("\t.space %u, 0\n", get_type_size_bytes(type));
......
......@@ -223,7 +223,7 @@ static void ia32_emit_entity(ir_entity *entity, int no_pic_adjust)
be_gas_emit_entity(entity);
if (get_entity_owner(entity) == get_tls_type()) {
if (get_entity_visibility(entity) == ir_visibility_external) {
if (!entity_has_definition(entity)) {
be_emit_cstring("@INDNTPOFF");
} else {
be_emit_cstring("@NTPOFF");
......
......@@ -226,7 +226,6 @@ static void symtbl_init(void)
INSERT(tt_visibility, "local", ir_visibility_local);
INSERT(tt_visibility, "external", ir_visibility_external);
INSERT(tt_visibility, "default", ir_visibility_default);
INSERT(tt_visibility, "private", ir_visibility_private);
INSERT(tt_throws, "throw", true);
......@@ -324,7 +323,6 @@ static const char *get_visibility_name(ir_visibility visibility)
switch (visibility) {
case ir_visibility_local: return "local";
case ir_visibility_external: return "external";
case ir_visibility_default: return "default";
case ir_visibility_private: return "private";
}
panic("INVALID_VISIBILITY");
......@@ -1901,7 +1899,7 @@ static void read_entity(read_env_t *env, ir_entity_kind kind)
long entnr = read_long(env);
ident *name = NULL;
ident *ld_name = NULL;
ir_visibility visibility = ir_visibility_default;
ir_visibility visibility = ir_visibility_external;
ir_linkage linkage = IR_LINKAGE_DEFAULT;
ir_type *owner = NULL;
ir_entity *entity = NULL;
......
......@@ -122,7 +122,7 @@ static void visit_segment(ir_type *segment)
for (i = 0; i < n_entities; ++i) {
ir_entity *entity = get_compound_member(segment, i);
if (get_entity_visibility(entity) != ir_visibility_default
if (get_entity_visibility(entity) != ir_visibility_external
&& !(get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER))
continue;
......
......@@ -72,7 +72,7 @@ static ir_entity *intern_new_entity(ir_type *owner, ir_entity_kind kind,
res->aligned = align_is_aligned;
res->usage = ir_usage_unknown;
res->compiler_gen = 0;
res->visibility = ir_visibility_default;
res->visibility = ir_visibility_external;
res->offset = -1;
res->offset_bit_remainder = 0;
res->alignment = 0;
......
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