From 07c77ebb4b165865ecdfc45a048ac55dea14d84e Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 3 May 2012 20:43:05 +0200 Subject: [PATCH] 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. --- include/libfirm/typerep.h | 19 ++++++++----------- ir/be/bedwarf.c | 3 +-- ir/be/begnuas.c | 28 +++++++++------------------- ir/be/ia32/ia32_emitter.c | 2 +- ir/ir/irio.c | 4 +--- ir/opt/garbage_collect.c | 2 +- ir/tr/entity.c | 2 +- 7 files changed, 22 insertions(+), 38 deletions(-) diff --git a/include/libfirm/typerep.h b/include/libfirm/typerep.h index 55e4f8ab3..45db4bf32 100644 --- a/include/libfirm/typerep.h +++ b/include/libfirm/typerep.h @@ -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; /** diff --git a/ir/be/bedwarf.c b/ir/be/bedwarf.c index c9f4e46d6..fe892e72d 100644 --- a/ir/be/bedwarf.c +++ b/ir/be/bedwarf.c @@ -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) diff --git a/ir/be/begnuas.c b/ir/be/begnuas.c index 02d301280..0904d6475 100644 --- a/ir/be/begnuas.c +++ b/ir/be/begnuas.c @@ -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)); diff --git a/ir/be/ia32/ia32_emitter.c b/ir/be/ia32/ia32_emitter.c index d5c4e87e1..9449772ba 100644 --- a/ir/be/ia32/ia32_emitter.c +++ b/ir/be/ia32/ia32_emitter.c @@ -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"); diff --git a/ir/ir/irio.c b/ir/ir/irio.c index 0f88eee82..ea90cad3f 100644 --- a/ir/ir/irio.c +++ b/ir/ir/irio.c @@ -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; diff --git a/ir/opt/garbage_collect.c b/ir/opt/garbage_collect.c index 963c4fcf0..7fc81ec8b 100644 --- a/ir/opt/garbage_collect.c +++ b/ir/opt/garbage_collect.c @@ -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; diff --git a/ir/tr/entity.c b/ir/tr/entity.c index 4382d268e..e8e0de788 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -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; -- 2.20.1