mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-23 23:35:33 +00:00
tcg: Introduce temp_load
Unify all of the places that realize a temporary into a register. Backports commit 40ae5c62ebaaf7d9d3b93b88c2d32bf6342f7889 from qemu
This commit is contained in:
parent
c821ffd989
commit
292c67109a
115
qemu/tcg/tcg.c
115
qemu/tcg/tcg.c
|
@ -1775,6 +1775,35 @@ static TCGReg tcg_reg_alloc(TCGContext *s, TCGRegSet reg1, TCGRegSet reg2)
|
||||||
tcg_abort();
|
tcg_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Make sure the temporary is in a register. If needed, allocate the register
|
||||||
|
from DESIRED while avoiding ALLOCATED. */
|
||||||
|
static void temp_load(TCGContext *s, TCGTemp *ts, TCGRegSet desired_regs,
|
||||||
|
TCGRegSet allocated_regs)
|
||||||
|
{
|
||||||
|
TCGReg reg;
|
||||||
|
|
||||||
|
switch (ts->val_type) {
|
||||||
|
case TEMP_VAL_REG:
|
||||||
|
return;
|
||||||
|
case TEMP_VAL_CONST:
|
||||||
|
reg = tcg_reg_alloc(s, desired_regs, allocated_regs);
|
||||||
|
tcg_out_movi(s, ts->type, reg, ts->val);
|
||||||
|
ts->mem_coherent = 0;
|
||||||
|
break;
|
||||||
|
case TEMP_VAL_MEM:
|
||||||
|
reg = tcg_reg_alloc(s, desired_regs, allocated_regs);
|
||||||
|
tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset);
|
||||||
|
ts->mem_coherent = 1;
|
||||||
|
break;
|
||||||
|
case TEMP_VAL_DEAD:
|
||||||
|
default:
|
||||||
|
tcg_abort();
|
||||||
|
}
|
||||||
|
ts->reg = reg;
|
||||||
|
ts->val_type = TEMP_VAL_REG;
|
||||||
|
s->reg_to_temp[reg] = ts;
|
||||||
|
}
|
||||||
|
|
||||||
/* mark a temporary as dead. */
|
/* mark a temporary as dead. */
|
||||||
static inline void temp_dead(TCGContext *s, TCGTemp *ts)
|
static inline void temp_dead(TCGContext *s, TCGTemp *ts)
|
||||||
{
|
{
|
||||||
|
@ -1798,13 +1827,8 @@ static void temp_sync(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs)
|
||||||
}
|
}
|
||||||
switch (ts->val_type) {
|
switch (ts->val_type) {
|
||||||
case TEMP_VAL_CONST:
|
case TEMP_VAL_CONST:
|
||||||
ts->reg = tcg_reg_alloc(s, s->tcg_target_available_regs[ts->type],
|
temp_load(s, ts, s->tcg_target_available_regs[ts->type], allocated_regs);
|
||||||
allocated_regs);
|
/* fallthrough */
|
||||||
ts->val_type = TEMP_VAL_REG;
|
|
||||||
s->reg_to_temp[ts->reg] = ts;
|
|
||||||
ts->mem_coherent = 0;
|
|
||||||
tcg_out_movi(s, ts->type, ts->reg, ts->val);
|
|
||||||
/* fallthrough*/
|
|
||||||
case TEMP_VAL_REG:
|
case TEMP_VAL_REG:
|
||||||
tcg_reg_sync(s, ts->reg);
|
tcg_reg_sync(s, ts->reg);
|
||||||
break;
|
break;
|
||||||
|
@ -1940,17 +1964,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def,
|
||||||
we don't have to reload SOURCE the next time it is used. */
|
we don't have to reload SOURCE the next time it is used. */
|
||||||
if (((NEED_SYNC_ARG(0) || ots->fixed_reg) && ts->val_type != TEMP_VAL_REG)
|
if (((NEED_SYNC_ARG(0) || ots->fixed_reg) && ts->val_type != TEMP_VAL_REG)
|
||||||
|| ts->val_type == TEMP_VAL_MEM) {
|
|| ts->val_type == TEMP_VAL_MEM) {
|
||||||
ts->reg = tcg_reg_alloc(s, (TCGRegSet)s->tcg_target_available_regs[itype],
|
temp_load(s, ts, s->tcg_target_available_regs[itype], allocated_regs);
|
||||||
allocated_regs);
|
|
||||||
if (ts->val_type == TEMP_VAL_MEM) {
|
|
||||||
tcg_out_ld(s, itype, ts->reg, ts->mem_base->reg, ts->mem_offset);
|
|
||||||
ts->mem_coherent = 1;
|
|
||||||
} else if (ts->val_type == TEMP_VAL_CONST) {
|
|
||||||
tcg_out_movi(s, itype, ts->reg, ts->val);
|
|
||||||
ts->mem_coherent = 0;
|
|
||||||
}
|
|
||||||
s->reg_to_temp[ts->reg] = ts;
|
|
||||||
ts->val_type = TEMP_VAL_REG;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_DEAD_ARG(0) && !ots->fixed_reg) {
|
if (IS_DEAD_ARG(0) && !ots->fixed_reg) {
|
||||||
|
@ -2033,29 +2047,17 @@ static void tcg_reg_alloc_op(TCGContext *s,
|
||||||
arg = args[i];
|
arg = args[i];
|
||||||
arg_ct = &def->args_ct[i];
|
arg_ct = &def->args_ct[i];
|
||||||
ts = &s->temps[arg];
|
ts = &s->temps[arg];
|
||||||
if (ts->val_type == TEMP_VAL_MEM) {
|
|
||||||
reg = tcg_reg_alloc(s, arg_ct->u.regs, allocated_regs);
|
if (ts->val_type == TEMP_VAL_CONST
|
||||||
tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset);
|
&& tcg_target_const_match(ts->val, ts->type, arg_ct)) {
|
||||||
ts->val_type = TEMP_VAL_REG;
|
/* constant is OK for instruction */
|
||||||
ts->reg = reg;
|
const_args[i] = 1;
|
||||||
ts->mem_coherent = 1;
|
new_args[i] = ts->val;
|
||||||
s->reg_to_temp[reg] = ts;
|
goto iarg_end;
|
||||||
} else if (ts->val_type == TEMP_VAL_CONST) {
|
|
||||||
if (tcg_target_const_match(ts->val, ts->type, arg_ct)) {
|
|
||||||
/* constant is OK for instruction */
|
|
||||||
const_args[i] = 1;
|
|
||||||
new_args[i] = ts->val;
|
|
||||||
goto iarg_end;
|
|
||||||
} else {
|
|
||||||
/* need to move to a register */
|
|
||||||
reg = tcg_reg_alloc(s, arg_ct->u.regs, allocated_regs);
|
|
||||||
tcg_out_movi(s, ts->type, reg, ts->val);
|
|
||||||
ts->val_type = TEMP_VAL_REG;
|
|
||||||
ts->reg = reg;
|
|
||||||
ts->mem_coherent = 0;
|
|
||||||
s->reg_to_temp[reg] = ts;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
temp_load(s, ts, arg_ct->u.regs, allocated_regs);
|
||||||
|
|
||||||
assert(ts->val_type == TEMP_VAL_REG);
|
assert(ts->val_type == TEMP_VAL_REG);
|
||||||
if (arg_ct->ct & TCG_CT_IALIAS) {
|
if (arg_ct->ct & TCG_CT_IALIAS) {
|
||||||
if (ts->fixed_reg) {
|
if (ts->fixed_reg) {
|
||||||
|
@ -2218,23 +2220,9 @@ static void tcg_reg_alloc_call(TCGContext *s, int nb_oargs, int nb_iargs,
|
||||||
#endif
|
#endif
|
||||||
if (arg != TCG_CALL_DUMMY_ARG) {
|
if (arg != TCG_CALL_DUMMY_ARG) {
|
||||||
ts = &s->temps[arg];
|
ts = &s->temps[arg];
|
||||||
if (ts->val_type == TEMP_VAL_REG) {
|
temp_load(s, ts, s->tcg_target_available_regs[ts->type],
|
||||||
tcg_out_st(s, ts->type, ts->reg, TCG_REG_CALL_STACK, stack_offset);
|
s->reserved_regs);
|
||||||
} else if (ts->val_type == TEMP_VAL_MEM) {
|
tcg_out_st(s, ts->type, ts->reg, TCG_REG_CALL_STACK, stack_offset);
|
||||||
reg = tcg_reg_alloc(s, (TCGRegSet)s->tcg_target_available_regs[ts->type],
|
|
||||||
s->reserved_regs);
|
|
||||||
/* XXX: not correct if reading values from the stack */
|
|
||||||
tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset);
|
|
||||||
tcg_out_st(s, ts->type, reg, TCG_REG_CALL_STACK, stack_offset);
|
|
||||||
} else if (ts->val_type == TEMP_VAL_CONST) {
|
|
||||||
reg = tcg_reg_alloc(s, (TCGRegSet)s->tcg_target_available_regs[ts->type],
|
|
||||||
s->reserved_regs);
|
|
||||||
/* XXX: sign extend may be needed on some targets */
|
|
||||||
tcg_out_movi(s, ts->type, reg, ts->val);
|
|
||||||
tcg_out_st(s, ts->type, reg, TCG_REG_CALL_STACK, stack_offset);
|
|
||||||
} else {
|
|
||||||
tcg_abort();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#ifndef TCG_TARGET_STACK_GROWSUP
|
#ifndef TCG_TARGET_STACK_GROWSUP
|
||||||
stack_offset += sizeof(tcg_target_long);
|
stack_offset += sizeof(tcg_target_long);
|
||||||
|
@ -2249,18 +2237,19 @@ static void tcg_reg_alloc_call(TCGContext *s, int nb_oargs, int nb_iargs,
|
||||||
ts = &s->temps[arg];
|
ts = &s->temps[arg];
|
||||||
reg = tcg_target_call_iarg_regs[i];
|
reg = tcg_target_call_iarg_regs[i];
|
||||||
tcg_reg_free(s, reg);
|
tcg_reg_free(s, reg);
|
||||||
|
|
||||||
if (ts->val_type == TEMP_VAL_REG) {
|
if (ts->val_type == TEMP_VAL_REG) {
|
||||||
if (ts->reg != reg) {
|
if (ts->reg != reg) {
|
||||||
tcg_out_mov(s, ts->type, reg, ts->reg);
|
tcg_out_mov(s, ts->type, reg, ts->reg);
|
||||||
}
|
}
|
||||||
} else if (ts->val_type == TEMP_VAL_MEM) {
|
|
||||||
tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset);
|
|
||||||
} else if (ts->val_type == TEMP_VAL_CONST) {
|
|
||||||
/* XXX: sign extend ? */
|
|
||||||
tcg_out_movi(s, ts->type, reg, ts->val);
|
|
||||||
} else {
|
} else {
|
||||||
tcg_abort();
|
TCGRegSet arg_set;
|
||||||
|
|
||||||
|
tcg_regset_clear(arg_set);
|
||||||
|
tcg_regset_set_reg(arg_set, reg);
|
||||||
|
temp_load(s, ts, arg_set, allocated_regs);
|
||||||
}
|
}
|
||||||
|
|
||||||
tcg_regset_set_reg(allocated_regs, reg);
|
tcg_regset_set_reg(allocated_regs, reg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue