Commit 859487f0 authored by Matthias Braun's avatar Matthias Braun
Browse files

Introduce globals map

The map maps global symbols to the respective entities in the segment
types. This should avoid hacks in some frontends, avoids a sepcial map
for compilerlib entities and ensures that frontend and compilerlib
entities are in sync.
parent 373423a4
...@@ -184,6 +184,13 @@ FIRM_API ir_type *get_glob_type(void); ...@@ -184,6 +184,13 @@ FIRM_API ir_type *get_glob_type(void);
*/ */
FIRM_API ir_type *get_tls_type(void); FIRM_API ir_type *get_tls_type(void);
/**
* Returns global entity with name \p name.
* A global entity is an entity in one of the segment types.
* \see get_glob_type(), \see get_segment_type()
*/
FIRM_API ir_entity *ir_get_global(ident *name);
/** /**
* Returns the number of all types in the irp. * Returns the number of all types in the irp.
* @deprecated * @deprecated
......
...@@ -34,8 +34,10 @@ static ir_entity *create_trampoline(be_main_env_t *be, ir_entity *method) ...@@ -34,8 +34,10 @@ static ir_entity *create_trampoline(be_main_env_t *be, ir_entity *method)
ident *old_id = get_entity_ld_ident(method); ident *old_id = get_entity_ld_ident(method);
ident *id = new_id_fmt("%s$stub", old_id); ident *id = new_id_fmt("%s$stub", old_id);
ir_type *parent = be->pic_trampolines_type; ir_type *parent = be->pic_trampolines_type;
ir_entity *ent = new_entity(parent, old_id, type); ir_entity *ent = new_entity(parent, id, type);
set_entity_ld_ident(ent, id); set_entity_ld_ident(ent, id);
/* We misuse the ident field to point to the old entity */
set_entity_ident(ent, old_id);
set_entity_visibility(ent, ir_visibility_private); set_entity_visibility(ent, ir_visibility_private);
return ent; return ent;
...@@ -62,8 +64,9 @@ static ir_entity *create_nonlazyptr(be_main_env_t *be, ir_entity *entity) ...@@ -62,8 +64,9 @@ static ir_entity *create_nonlazyptr(be_main_env_t *be, ir_entity *entity)
ir_type *e_type = get_entity_type(entity); ir_type *e_type = get_entity_type(entity);
ir_type *type = new_type_pointer(e_type); ir_type *type = new_type_pointer(e_type);
ir_type *parent = be->pic_symbols_type; ir_type *parent = be->pic_symbols_type;
ir_entity *ent = new_entity(parent, old_id, type); ir_entity *ent = new_entity(parent, id, type);
set_entity_ld_ident(ent, id); set_entity_ld_ident(ent, id);
set_entity_ident(ent, old_id);
set_entity_visibility(ent, ir_visibility_private); set_entity_visibility(ent, ir_visibility_private);
return ent; return ent;
......
...@@ -44,7 +44,7 @@ static ir_prog *new_incomplete_ir_prog(void) ...@@ -44,7 +44,7 @@ static ir_prog *new_incomplete_ir_prog(void)
#ifndef NDEBUG #ifndef NDEBUG
res->reserved_resources = IRP_RESOURCE_NONE; res->reserved_resources = IRP_RESOURCE_NONE;
#endif #endif
res->compilerlib_entities = pmap_create(); res->globals = pmap_create();
return res; return res;
} }
...@@ -115,7 +115,8 @@ void free_ir_prog(void) ...@@ -115,7 +115,8 @@ void free_ir_prog(void)
DEL_ARR_F(irp->global_asms); DEL_ARR_F(irp->global_asms);
pmap_destroy(irp->compilerlib_entities); pmap_destroy(irp->globals);
irp->name = NULL; irp->name = NULL;
irp->const_code_irg = NULL; irp->const_code_irg = NULL;
free(irp); free(irp);
...@@ -155,6 +156,11 @@ ir_type *(get_tls_type)(void) ...@@ -155,6 +156,11 @@ ir_type *(get_tls_type)(void)
return get_tls_type_(); return get_tls_type_();
} }
ir_entity *ir_get_global(ident *name)
{
return pmap_get(ir_entity, irp->globals, name);
}
void add_irp_irg(ir_graph *irg) void add_irp_irg(ir_graph *irg)
{ {
assert(irg != NULL); assert(irg != NULL);
......
...@@ -43,6 +43,7 @@ struct ir_prog { ...@@ -43,6 +43,7 @@ struct ir_prog {
ir_graph *main_irg; /**< The entry point to the compiled program ir_graph *main_irg; /**< The entry point to the compiled program
or NULL if no point exists. */ or NULL if no point exists. */
ir_graph **graphs; /**< A list of all graphs in the ir. */ ir_graph **graphs; /**< A list of all graphs in the ir. */
pmap *globals; /**< Map identifiers to global entities. */
/** This graph holds nodes for global entity initialization expressions. /** This graph holds nodes for global entity initialization expressions.
* It is not a function. */ * It is not a function. */
ir_graph *const_code_irg; ir_graph *const_code_irg;
...@@ -70,8 +71,6 @@ struct ir_prog { ...@@ -70,8 +71,6 @@ struct ir_prog {
size_t max_irg_idx; /**< highest unused irg index */ size_t max_irg_idx; /**< highest unused irg index */
long max_node_nr; /**< Highest number unique node numbers. */ long max_node_nr; /**< Highest number unique node numbers. */
unsigned dump_nr; /**< number of program info dumps */ unsigned dump_nr; /**< number of program info dumps */
/** Maps ident* to ir_entity* of the compilerlib */
pmap *compilerlib_entities;
#ifndef NDEBUG #ifndef NDEBUG
/** Bitset for tracking used global resources. */ /** Bitset for tracking used global resources. */
irp_resources_t reserved_resources; irp_resources_t reserved_resources;
......
...@@ -9,12 +9,13 @@ ...@@ -9,12 +9,13 @@
* @date 2011-09-22 * @date 2011-09-22
* @author Manuel Mohr * @author Manuel Mohr
*/ */
#include <assert.h>
#include "iroptimize.h" #include "iroptimize.h"
#include "irprog_t.h" #include "irprog_t.h"
#include "type_t.h"
#include "typerep.h" #include "typerep.h"
#include <assert.h>
/* The default implementation does not set a different ld name. */ /* The default implementation does not set a different ld name. */
static ident *compilerlib_name_mangle_default(ident *id, ir_type *mt) static ident *compilerlib_name_mangle_default(ident *id, ir_type *mt)
{ {
...@@ -38,27 +39,17 @@ compilerlib_name_mangle_t get_compilerlib_name_mangle(void) ...@@ -38,27 +39,17 @@ compilerlib_name_mangle_t get_compilerlib_name_mangle(void)
ir_entity *create_compilerlib_entity(ident *id, ir_type *mt) ir_entity *create_compilerlib_entity(ident *id, ir_type *mt)
{ {
ir_entity *entity = pmap_get(ir_entity, irp->compilerlib_entities, id); ident *ld_name = compilerlib_mangler(id, mt);
/* Look for existing entity. */
ir_entity *entity = ir_get_global(ld_name);
if (entity != NULL) if (entity != NULL)
return entity; return entity;
/* let frontend mangle the name */ /* Create a new one */
ident *ld_name = compilerlib_mangler(id, mt);
/* search for an existing entity */
ir_type *glob = get_glob_type(); ir_type *glob = get_glob_type();
for (size_t i = 0, n_members = get_compound_n_members(glob); entity = new_entity(glob, ld_name, mt);
i < n_members; ++i) {
ir_entity *member = get_compound_member(glob, i);
if (get_entity_ld_ident(member) == ld_name) {
entity = member;
goto found;
}
}
entity = new_entity(glob, id, mt);
set_entity_ld_ident(entity, ld_name); set_entity_ld_ident(entity, ld_name);
set_entity_visibility(entity, ir_visibility_external); set_entity_visibility(entity, ir_visibility_external);
found:
pmap_insert(irp->compilerlib_entities, id, entity);
return entity; return entity;
} }
...@@ -252,9 +252,19 @@ ident *(get_entity_ld_ident)(const ir_entity *ent) ...@@ -252,9 +252,19 @@ ident *(get_entity_ld_ident)(const ir_entity *ent)
return _get_entity_ld_ident(ent); return _get_entity_ld_ident(ent);
} }
void (set_entity_ld_ident)(ir_entity *ent, ident *ld_ident) void set_entity_ld_ident(ir_entity *const ent, ident *const ld_ident)
{ {
_set_entity_ld_ident(ent, ld_ident); ident *old_ident = get_entity_ld_ident(ent);
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)) {
pmap *globals = irp->globals;
pmap_insert(globals, old_ident, NULL);
assert(!pmap_contains(globals, ld_ident));
pmap_insert(globals, ld_ident, ent);
}
}
} }
const char *(get_entity_ld_name)(const ir_entity *ent) const char *(get_entity_ld_name)(const ir_entity *ent)
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#define set_entity_ident(ent, id) _set_entity_ident(ent, id) #define set_entity_ident(ent, id) _set_entity_ident(ent, id)
#define get_entity_owner(ent) _get_entity_owner(ent) #define get_entity_owner(ent) _get_entity_owner(ent)
#define get_entity_ld_ident(ent) _get_entity_ld_ident(ent) #define get_entity_ld_ident(ent) _get_entity_ld_ident(ent)
#define set_entity_ld_ident(ent, ld_ident) _set_entity_ld_ident(ent, ld_ident)
#define get_entity_ld_name(ent) _get_entity_ld_name(ent) #define get_entity_ld_name(ent) _get_entity_ld_name(ent)
#define get_entity_type(ent) _get_entity_type(ent) #define get_entity_type(ent) _get_entity_type(ent)
#define get_entity_linkage(ent) _get_entity_linkage(ent) #define get_entity_linkage(ent) _get_entity_linkage(ent)
...@@ -259,12 +258,6 @@ static inline ident *_get_entity_ld_ident(const ir_entity *ent) ...@@ -259,12 +258,6 @@ static inline ident *_get_entity_ld_ident(const ir_entity *ent)
return ent->name; return ent->name;
} }
static inline void _set_entity_ld_ident(ir_entity *ent, ident *ld_ident)
{
assert(ent->kind == k_entity);
ent->ld_name = ld_ident;
}
static inline const char *_get_entity_ld_name(const ir_entity *ent) static inline const char *_get_entity_ld_name(const ir_entity *ent)
{ {
assert(ent->kind == k_entity); assert(ent->kind == k_entity);
......
...@@ -976,6 +976,10 @@ void remove_compound_member(ir_type *type, ir_entity *member) ...@@ -976,6 +976,10 @@ void remove_compound_member(ir_type *type, ir_entity *member)
for (; i < n - 1; ++i) for (; i < n - 1; ++i)
type->attr.ca.members[i] = type->attr.ca.members[i+1]; type->attr.ca.members[i] = type->attr.ca.members[i+1];
ARR_SETLEN(ir_entity*, type->attr.ca.members, n-1); ARR_SETLEN(ir_entity*, type->attr.ca.members, n-1);
if (is_segment_type(type) && !(type->flags & tf_info)) {
pmap *globals = irp->globals;
pmap_insert(globals, get_entity_ld_ident(member), NULL);
}
break; break;
} }
} }
...@@ -987,6 +991,14 @@ void add_compound_member(ir_type *type, ir_entity *entity) ...@@ -987,6 +991,14 @@ void add_compound_member(ir_type *type, ir_entity *entity)
/* try to detect double-add */ /* try to detect double-add */
assert(get_entity_type(entity) != type); assert(get_entity_type(entity) != type);
ARR_APP1(ir_entity *, type->attr.ca.members, entity); ARR_APP1(ir_entity *, type->attr.ca.members, entity);
/* Add segment members to globals map. */
if (is_segment_type(type) && !(type->flags & tf_info)) {
ident *id = get_entity_ld_ident(entity);
pmap *globals = irp->globals;
/* Globals must have unique names. */
assert(!pmap_contains(globals, id));
pmap_insert(globals, id, entity);
}
} }
int is_code_type(ir_type const *const type) int is_code_type(ir_type const *const type)
......
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
#define FIRM_TR_TYPE_T_H #define FIRM_TR_TYPE_T_H
#include <stdbool.h> #include <stdbool.h>
#include "typerep.h"
#include "firm_common.h"
#include "array.h" #include "array.h"
#include "firm_common.h"
#include "typerep.h"
#define get_master_type_visited() get_master_type_visited_() #define get_master_type_visited() get_master_type_visited_()
#define get_type_link(tp) get_type_link_(tp) #define get_type_link(tp) get_type_link_(tp)
...@@ -104,7 +104,7 @@ typedef enum type_flags { ...@@ -104,7 +104,7 @@ typedef enum type_flags {
tf_frame_type = 1U << 3, /**< Set if this is a frame type. */ tf_frame_type = 1U << 3, /**< Set if this is a frame type. */
tf_global_type = 1U << 4, /**< Set only for the global type */ tf_global_type = 1U << 4, /**< Set only for the global type */
tf_tls_type = 1U << 5, /**< Set only for the tls type */ tf_tls_type = 1U << 5, /**< Set only for the tls type */
tf_info = 1U << 6, /**< infos (for example constructor, destructor pointers) */ tf_info = 1U << 6, /**< infos (for example constructor, destructor pointers), all members are anonymous */
tf_variable_size = 1U << 7, /**< compound or array type may have variable size last element */ tf_variable_size = 1U << 7, /**< compound or array type may have variable size last element */
tf_lowered_dw = 1U << 8, /**< hack to identify lowered doubleword params */ tf_lowered_dw = 1U << 8, /**< hack to identify lowered doubleword params */
} type_flags; } type_flags;
......
Supports Markdown
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