Commit 575706a7 authored by Matthias Braun's avatar Matthias Braun
Browse files

ia32: Introduce immediate types for TLS and determine variants at code selection time

parent 8db545f0
......@@ -174,24 +174,27 @@ static void emit_register(const arch_register_t *reg, ir_mode *mode)
be_emit_string(name);
}
static void ia32_emit_entity(x86_imm32_t const *const imm)
static void ia32_emit_relocation(x86_imm32_t const *const imm)
{
assert(imm->kind != X86_IMM_VALUE);
ir_entity *entity = imm->entity;
be_gas_emit_entity(entity);
if (is_tls_entity(entity)) {
if (!entity_has_definition(entity)) {
be_emit_cstring("@INDNTPOFF");
} else {
be_emit_cstring("@NTPOFF");
}
}
if (imm->kind == X86_IMM_PICBASE_REL) {
switch (imm->kind) {
case X86_IMM_ADDR:
return;
case X86_IMM_TLS_IE:
be_emit_cstring("INDNTPOFF");
return;
case X86_IMM_TLS_LE:
be_emit_cstring("NTPOFF");
return;
case X86_IMM_PICBASE_REL:
be_emit_char('-');
be_emit_string(pic_base_label);
return;
case X86_IMM_VALUE:
break;
}
panic("Unexpected immediate kind");
}
static void emit_ia32_immediate(bool const prefix, x86_imm32_t const *const imm)
......@@ -202,7 +205,7 @@ static void emit_ia32_immediate(bool const prefix, x86_imm32_t const *const imm)
int32_t const offset = imm->offset;
if (entity != NULL) {
assert(imm->kind != X86_IMM_VALUE);
ia32_emit_entity(imm);
ia32_emit_relocation(imm);
if (offset != 0)
be_emit_irprintf("%+"PRId32, offset);
} else {
......@@ -373,7 +376,7 @@ static void ia32_emit_am(ir_node const *const node)
if (entity) {
assert(attr->am_imm.kind != X86_IMM_VALUE);
const ia32_attr_t *attr = get_ia32_attr_const(node);
ia32_emit_entity(&attr->am_imm);
ia32_emit_relocation(&attr->am_imm);
if (offset != 0)
be_emit_irprintf("%+"PRId32, offset);
} else if (offset != 0 || (!base && !idx)) {
......
......@@ -275,11 +275,17 @@ ir_node *ia32_create_Immediate_full(ir_graph *const irg,
return immediate;
}
static void adjust_pic(x86_imm32_t *imm)
static void adjust_relocation(x86_imm32_t *imm)
{
if (be_options.pic && imm->kind == X86_IMM_ADDR &&
get_entity_type(imm->entity) != get_code_type())
if (imm->kind != X86_IMM_ADDR)
return;
ir_entity *entity = imm->entity;
if (be_options.pic && get_entity_type(entity) != get_code_type()) {
imm->kind = X86_IMM_PICBASE_REL;
} else if (is_tls_entity(entity)) {
imm->kind = entity_has_definition(entity) ? X86_IMM_TLS_LE
: X86_IMM_TLS_IE;
}
}
static ir_node *try_create_Immediate(const ir_node *node, char const constraint)
......@@ -287,7 +293,7 @@ static ir_node *try_create_Immediate(const ir_node *node, char const constraint)
x86_imm32_t immediate;
if (!x86_match_immediate(&immediate, node, constraint))
return NULL;
adjust_pic(&immediate);
adjust_relocation(&immediate);
ir_graph *const irg = get_irn_irg(node);
return ia32_create_Immediate_full(irg, &immediate);
......@@ -482,7 +488,7 @@ static ir_node *gen_Address(ir_node *node)
.kind = X86_IMM_ADDR,
.entity = entity,
};
adjust_pic(&imm);
adjust_relocation(&imm);
ir_node *cnst;
if (is_tls_entity(entity)) {
......@@ -804,7 +810,7 @@ static void ia32_create_address_mode(x86_address_t *addr, ir_node *ptr,
x86_create_am_flags_t flags)
{
x86_create_address_mode(addr, ptr, flags);
adjust_pic(&addr->imm);
adjust_relocation(&addr->imm);
}
static void build_address_ptr(x86_address_t *addr, ir_node *ptr, ir_node *mem)
......@@ -835,7 +841,7 @@ static void build_address(ia32_address_mode_t *am, ir_node *node,
.kind = X86_IMM_ADDR,
.entity = entity,
};
adjust_pic(&addr->imm);
adjust_relocation(&addr->imm);
addr->tls_segment = false;
addr->use_frame = false;
am->ls_mode = get_type_mode(get_entity_type(entity));
......
......@@ -21,6 +21,8 @@ typedef enum x86_immediate_kind_t {
X86_IMM_VALUE, /**< no relocation, just a value */
X86_IMM_ADDR, /**< "normal" absolute addresses to a symbol */
X86_IMM_PICBASE_REL, /**< relative to pic base address */
X86_IMM_TLS_IE, /**< thread local storage, initial exec */
X86_IMM_TLS_LE, /**< thread local storage, load exec */
} x86_immediate_kind_t;
typedef struct x86_imm32_t {
......
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