Commit 73db736b authored by Christoph Mallon's avatar Christoph Mallon
Browse files

amd64, sparc: Use be_match_immediate().

This enables matching Address+Const.
parent ad4328b6
......@@ -463,12 +463,18 @@ static bool match_immediate_32(amd64_imm32_t *imm, const ir_node *op,
{
assert(mode_needs_gp_reg(get_irn_mode(op)));
assert(imm->offset == 0 && imm->entity == NULL);
if (is_Const(op)) {
ir_tarval *tv = get_Const_tarval(op);
ir_tarval *tv;
ir_entity *entity;
if (!be_match_immediate(op, &tv, &entity))
return false;
int32_t val;
if (tv) {
if (!tarval_is_long(tv))
return false;
long lval = get_tarval_long(tv);
int32_t val = (int32_t)lval;
long lval = get_tarval_long(tv);
val = (int32_t)lval;
if ((long)val != lval)
return false;
/** the immediate value is signed extended to 64bit, sometimes
......@@ -476,16 +482,18 @@ static bool match_immediate_32(amd64_imm32_t *imm, const ir_node *op,
if (!upper32_dont_care && val < 0
&& !mode_is_signed(get_tarval_mode(tv)))
return false;
imm->offset = val;
return true;
} else if (can_match_ip_relative && is_Address(op)) {
} else {
val = 0;
}
if (entity && !can_match_ip_relative) {
/* TODO: check if entity is in lower 4GB address space/relative */
ir_entity *entity = get_Address_entity(op);
imm->entity = entity;
return true;
return false;
}
/* TODO: SymConst, Add(SymConst, Const) ... */
return false;
imm->offset = val;
imm->entity = entity;
return true;
}
static ir_heights_t *heights;
......
......@@ -357,6 +357,31 @@ int sparc_is_valid_clobber(const char *clobber)
return strcmp(clobber, "memory") == 0 || strcmp(clobber, "cc") == 0;
}
static bool sparc_match_immediate(sparc_asm_operand_t *const operand, ir_node *const node, char const imm_type)
{
ir_tarval *offset;
ir_entity *entity;
if (!be_match_immediate(node, &offset, &entity))
return false;
if (entity && imm_type != 'i')
return false;
long value;
if (offset) {
value = get_tarval_long(offset);
if (imm_type == 'I' && !sparc_is_value_imm_encodeable(value))
return false;
} else {
value = 0;
}
operand->kind = ASM_OPERAND_IMMEDIATE;
operand->immediate_value = value;
operand->immediate_value_entity = entity;
return true;
}
static ir_node *gen_ASM(ir_node *node)
{
int n_inputs = get_ASM_n_inputs(node);
......@@ -451,24 +476,8 @@ static ir_node *gen_ASM(ir_node *node)
/* try to use an immediate value */
char imm_type = parsed_constraint.immediate_type;
if (imm_type == 'I') {
if (is_imm_encodeable(pred)) {
operand->kind = ASM_OPERAND_IMMEDIATE;
operand->immediate_value = get_Const_long(pred);
continue;
}
} else if (imm_type == 'i') {
/* TODO: match Add(Address,Const), ... */
if (is_Address(pred)) {
operand->kind = ASM_OPERAND_IMMEDIATE;
operand->immediate_value_entity = get_Address_entity(pred);
continue;
} else if (is_Const(pred)) {
operand->kind = ASM_OPERAND_IMMEDIATE;
operand->immediate_value = get_Const_long(pred);
continue;
}
}
if (imm_type != '\0' && sparc_match_immediate(operand, pred, imm_type))
continue;
arch_register_req_t const *const req = make_register_req(irg, &parsed_constraint, n_out_constraints, out_reg_reqs, i);
in_reg_reqs[i] = req;
......
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