mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-03-24 22:25:11 +00:00
tcg: Improve register allocation for matching constraints
Try harder to honor the output_pref. When we're forced to allocate a second register for the input, it does not need to use the input constraint; that will be honored by the register we allocate for the output and a move is already required. Backports commit d62816f2db439b2dd761c674f0256f21d9dd2ed0 from qemu
This commit is contained in:
parent
83a7de2566
commit
494d802781
|
@ -2749,6 +2749,8 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
|
||||||
|
|
||||||
/* satisfy input constraints */
|
/* satisfy input constraints */
|
||||||
for (k = 0; k < nb_iargs; k++) {
|
for (k = 0; k < nb_iargs; k++) {
|
||||||
|
TCGRegSet i_preferred_regs, o_preferred_regs;
|
||||||
|
|
||||||
i = def->sorted_args[nb_oargs + k];
|
i = def->sorted_args[nb_oargs + k];
|
||||||
arg = op->args[i];
|
arg = op->args[i];
|
||||||
arg_ct = &def->args_ct[i];
|
arg_ct = &def->args_ct[i];
|
||||||
|
@ -2759,17 +2761,18 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
|
||||||
/* constant is OK for instruction */
|
/* constant is OK for instruction */
|
||||||
const_args[i] = 1;
|
const_args[i] = 1;
|
||||||
new_args[i] = ts->val;
|
new_args[i] = ts->val;
|
||||||
goto iarg_end;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
temp_load(s, ts, arg_ct->u.regs, i_allocated_regs, 0);
|
i_preferred_regs = o_preferred_regs = 0;
|
||||||
|
|
||||||
if (arg_ct->ct & TCG_CT_IALIAS) {
|
if (arg_ct->ct & TCG_CT_IALIAS) {
|
||||||
|
o_preferred_regs = op->output_pref[arg_ct->alias_index];
|
||||||
if (ts->fixed_reg) {
|
if (ts->fixed_reg) {
|
||||||
/* if fixed register, we must allocate a new register
|
/* if fixed register, we must allocate a new register
|
||||||
if the alias is not the same register */
|
if the alias is not the same register */
|
||||||
if (arg != op->args[arg_ct->alias_index])
|
if (arg != op->args[arg_ct->alias_index]) {
|
||||||
goto allocate_in_reg;
|
goto allocate_in_reg;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* if the input is aliased to an output and if it is
|
/* if the input is aliased to an output and if it is
|
||||||
not dead after the instruction, we must allocate
|
not dead after the instruction, we must allocate
|
||||||
|
@ -2777,33 +2780,42 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
|
||||||
if (!IS_DEAD_ARG(i)) {
|
if (!IS_DEAD_ARG(i)) {
|
||||||
goto allocate_in_reg;
|
goto allocate_in_reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if the current register has already been allocated
|
/* check if the current register has already been allocated
|
||||||
for another input aliased to an output */
|
for another input aliased to an output */
|
||||||
int k2, i2;
|
if (ts->val_type == TEMP_VAL_REG) {
|
||||||
for (k2 = 0 ; k2 < k ; k2++) {
|
int k2, i2;
|
||||||
i2 = def->sorted_args[nb_oargs + k2];
|
reg = ts->reg;
|
||||||
if ((def->args_ct[i2].ct & TCG_CT_IALIAS) &&
|
for (k2 = 0 ; k2 < k ; k2++) {
|
||||||
(new_args[i2] == ts->reg)) {
|
i2 = def->sorted_args[nb_oargs + k2];
|
||||||
goto allocate_in_reg;
|
if ((def->args_ct[i2].ct & TCG_CT_IALIAS) &&
|
||||||
|
reg == new_args[i2]) {
|
||||||
|
goto allocate_in_reg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
i_preferred_regs = o_preferred_regs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
temp_load(s, ts, arg_ct->u.regs, i_allocated_regs, i_preferred_regs);
|
||||||
reg = ts->reg;
|
reg = ts->reg;
|
||||||
|
|
||||||
if (tcg_regset_test_reg(arg_ct->u.regs, reg)) {
|
if (tcg_regset_test_reg(arg_ct->u.regs, reg)) {
|
||||||
/* nothing to do : the constraint is satisfied */
|
/* nothing to do : the constraint is satisfied */
|
||||||
} else {
|
} else {
|
||||||
allocate_in_reg:
|
allocate_in_reg:
|
||||||
/* allocate a new register matching the constraint
|
/* allocate a new register matching the constraint
|
||||||
and move the temporary register into it */
|
and move the temporary register into it */
|
||||||
|
temp_load(s, ts, s->tcg_target_available_regs[ts->type],
|
||||||
|
i_allocated_regs, 0);
|
||||||
reg = tcg_reg_alloc(s, arg_ct->u.regs, i_allocated_regs,
|
reg = tcg_reg_alloc(s, arg_ct->u.regs, i_allocated_regs,
|
||||||
0, ts->indirect_base);
|
o_preferred_regs, ts->indirect_base);
|
||||||
tcg_out_mov(s, ts->type, reg, ts->reg);
|
tcg_out_mov(s, ts->type, reg, ts->reg);
|
||||||
}
|
}
|
||||||
new_args[i] = reg;
|
new_args[i] = reg;
|
||||||
const_args[i] = 0;
|
const_args[i] = 0;
|
||||||
tcg_regset_set_reg(i_allocated_regs, reg);
|
tcg_regset_set_reg(i_allocated_regs, reg);
|
||||||
iarg_end: ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mark dead temporaries and free the associated registers */
|
/* mark dead temporaries and free the associated registers */
|
||||||
|
|
Loading…
Reference in a new issue