tcg: Propagate args to op->args in tcg.c

Backports commit efee3746fa471852daba7674b0d34f8c88be7559 from qemu
This commit is contained in:
Richard Henderson 2018-03-05 07:06:09 -05:00 committed by Lioncash
parent 845cfc2ae9
commit f1e2ea6847
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -1323,14 +1323,12 @@ void tcg_dump_ops(TCGContext *s)
for (oi = s->gen_op_buf[0].next; oi != 0; oi = op->next) { for (oi = s->gen_op_buf[0].next; oi != 0; oi = op->next) {
int i, k, nb_oargs, nb_iargs, nb_cargs; int i, k, nb_oargs, nb_iargs, nb_cargs;
const TCGOpDef *def; const TCGOpDef *def;
const TCGArg *args;
TCGOpcode c; TCGOpcode c;
int col = 0; int col = 0;
op = &s->gen_op_buf[oi]; op = &s->gen_op_buf[oi];
c = op->opc; c = op->opc;
def = &s->tcg_op_defs[c]; def = &s->tcg_op_defs[c];
args = op->args;
if (c == INDEX_op_insn_start) { if (c == INDEX_op_insn_start) {
col += qemu_log("%s ----", oi != s->gen_op_buf[0].next ? "\n" : ""); col += qemu_log("%s ----", oi != s->gen_op_buf[0].next ? "\n" : "");
@ -1339,9 +1337,9 @@ void tcg_dump_ops(TCGContext *s)
target_ulong a; target_ulong a;
#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
a = ((target_ulong)args[i * 2 + 1] << 32) | args[i * 2]; a = deposit64(op->args[i * 2], 32, 32, op->args[i * 2 + 1]);
#else #else
a = args[i]; a = op->args[i];
#endif #endif
col += qemu_log(" " TARGET_FMT_lx, a); col += qemu_log(" " TARGET_FMT_lx, a);
} }
@ -1353,14 +1351,14 @@ void tcg_dump_ops(TCGContext *s)
/* function name, flags, out args */ /* function name, flags, out args */
col += qemu_log(" %s %s,$0x%" TCG_PRIlx ",$%d", def->name, col += qemu_log(" %s %s,$0x%" TCG_PRIlx ",$%d", def->name,
tcg_find_helper(s, args[nb_oargs + nb_iargs]), tcg_find_helper(s, op->args[nb_oargs + nb_iargs]),
args[nb_oargs + nb_iargs + 1], nb_oargs); op->args[nb_oargs + nb_iargs + 1], nb_oargs);
for (i = 0; i < nb_oargs; i++) { for (i = 0; i < nb_oargs; i++) {
col += qemu_log(",%s", tcg_get_arg_str_idx(s, buf, sizeof(buf), col += qemu_log(",%s", tcg_get_arg_str_idx(s, buf, sizeof(buf),
args[i])); op->args[i]));
} }
for (i = 0; i < nb_iargs; i++) { for (i = 0; i < nb_iargs; i++) {
TCGArg arg = args[nb_oargs + i]; TCGArg arg = op->args[nb_oargs + i];
const char *t = "<dummy>"; const char *t = "<dummy>";
if (arg != TCG_CALL_DUMMY_ARG) { if (arg != TCG_CALL_DUMMY_ARG) {
t = tcg_get_arg_str_idx(s, buf, sizeof(buf), arg); t = tcg_get_arg_str_idx(s, buf, sizeof(buf), arg);
@ -1380,14 +1378,14 @@ void tcg_dump_ops(TCGContext *s)
col += qemu_log(","); col += qemu_log(",");
} }
col += qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf), col += qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf),
args[k++])); op->args[k++]));
} }
for (i = 0; i < nb_iargs; i++) { for (i = 0; i < nb_iargs; i++) {
if (k != 0) { if (k != 0) {
col += qemu_log(","); col += qemu_log(",");
} }
col += qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf), col += qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf),
args[k++])); op->args[k++]));
} }
switch (c) { switch (c) {
case INDEX_op_brcond_i32: case INDEX_op_brcond_i32:
@ -1398,10 +1396,11 @@ void tcg_dump_ops(TCGContext *s)
case INDEX_op_brcond_i64: case INDEX_op_brcond_i64:
case INDEX_op_setcond_i64: case INDEX_op_setcond_i64:
case INDEX_op_movcond_i64: case INDEX_op_movcond_i64:
if (args[k] < ARRAY_SIZE(cond_name) && cond_name[args[k]]) { if (op->args[k] < ARRAY_SIZE(cond_name)
col += qemu_log(",%s", cond_name[args[k++]]); && cond_name[op->args[k]]) {
col += qemu_log(",%s", cond_name[op->args[k++]]);
} else { } else {
col += qemu_log(",$0x%" TCG_PRIlx, args[k++]); col += qemu_log(",$0x%" TCG_PRIlx, op->args[k++]);
} }
i = 1; i = 1;
break; break;
@ -1410,7 +1409,7 @@ void tcg_dump_ops(TCGContext *s)
case INDEX_op_qemu_ld_i64: case INDEX_op_qemu_ld_i64:
case INDEX_op_qemu_st_i64: case INDEX_op_qemu_st_i64:
{ {
TCGMemOpIdx oi = args[k++]; TCGMemOpIdx oi = op->args[k++];
TCGMemOp op = get_memop(oi); TCGMemOp op = get_memop(oi);
unsigned ix = get_mmuidx(oi); unsigned ix = get_mmuidx(oi);
@ -1435,14 +1434,15 @@ void tcg_dump_ops(TCGContext *s)
case INDEX_op_brcond_i32: case INDEX_op_brcond_i32:
case INDEX_op_brcond_i64: case INDEX_op_brcond_i64:
case INDEX_op_brcond2_i32: case INDEX_op_brcond2_i32:
col += qemu_log("%s$L%d", k ? "," : "", arg_label(s, args[k])->id); col += qemu_log("%s$L%d", k ? "," : "",
arg_label(s, op->args[k])->id);
i++, k++; i++, k++;
break; break;
default: default:
break; break;
} }
for (; i < nb_cargs; i++, k++) { for (; i < nb_cargs; i++, k++) {
col += qemu_log("%s$0x%" TCG_PRIlx, k ? "," : "", args[k]); col += qemu_log("%s$0x%" TCG_PRIlx, k ? "," : "", op->args[k]);
} }
} }
if (op->life) { if (op->life) {
@ -1722,7 +1722,6 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)
TCGArg arg; TCGArg arg;
TCGOp * const op = &s->gen_op_buf[oi]; TCGOp * const op = &s->gen_op_buf[oi];
TCGArg * const args = op->args;
TCGOpcode opc = op->opc; TCGOpcode opc = op->opc;
const TCGOpDef *def = &s->tcg_op_defs[opc]; const TCGOpDef *def = &s->tcg_op_defs[opc];
@ -1735,12 +1734,12 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)
nb_oargs = op->callo; nb_oargs = op->callo;
nb_iargs = op->calli; nb_iargs = op->calli;
call_flags = args[nb_oargs + nb_iargs + 1]; call_flags = op->args[nb_oargs + nb_iargs + 1];
/* pure functions can be removed if their result is unused */ /* pure functions can be removed if their result is unused */
if (call_flags & TCG_CALL_NO_SIDE_EFFECTS) { if (call_flags & TCG_CALL_NO_SIDE_EFFECTS) {
for (i = 0; i < nb_oargs; i++) { for (i = 0; i < nb_oargs; i++) {
arg = args[i]; arg = op->args[i];
if (temp_state[arg] != TS_DEAD) { if (temp_state[arg] != TS_DEAD) {
goto do_not_remove_call; goto do_not_remove_call;
} }
@ -1751,7 +1750,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)
/* output args are dead */ /* output args are dead */
for (i = 0; i < nb_oargs; i++) { for (i = 0; i < nb_oargs; i++) {
arg = args[i]; arg = op->args[i];
if (temp_state[arg] & TS_DEAD) { if (temp_state[arg] & TS_DEAD) {
arg_life |= DEAD_ARG << i; arg_life |= DEAD_ARG << i;
} }
@ -1774,7 +1773,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)
/* record arguments that die in this helper */ /* record arguments that die in this helper */
for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) { for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) {
arg = args[i]; arg = op->args[i];
if (arg != TCG_CALL_DUMMY_ARG) { if (arg != TCG_CALL_DUMMY_ARG) {
if (temp_state[arg] & TS_DEAD) { if (temp_state[arg] & TS_DEAD) {
arg_life |= DEAD_ARG << i; arg_life |= DEAD_ARG << i;
@ -1783,7 +1782,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)
} }
/* input arguments are live for preceding opcodes */ /* input arguments are live for preceding opcodes */
for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) { for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) {
arg = args[i]; arg = op->args[i];
if (arg != TCG_CALL_DUMMY_ARG) { if (arg != TCG_CALL_DUMMY_ARG) {
temp_state[arg] &= ~TS_DEAD; temp_state[arg] &= ~TS_DEAD;
} }
@ -1795,7 +1794,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)
break; break;
case INDEX_op_discard: case INDEX_op_discard:
/* mark the temporary as dead */ /* mark the temporary as dead */
temp_state[args[0]] = TS_DEAD; temp_state[op->args[0]] = TS_DEAD;
break; break;
case INDEX_op_add2_i32: case INDEX_op_add2_i32:
@ -1816,15 +1815,15 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)
the low part. The result can be optimized to a simple the low part. The result can be optimized to a simple
add or sub. This happens often for x86_64 guest when the add or sub. This happens often for x86_64 guest when the
cpu mode is set to 32 bit. */ cpu mode is set to 32 bit. */
if (temp_state[args[1]] == TS_DEAD) { if (temp_state[op->args[1]] == TS_DEAD) {
if (temp_state[args[0]] == TS_DEAD) { if (temp_state[op->args[0]] == TS_DEAD) {
goto do_remove; goto do_remove;
} }
/* Replace the opcode and adjust the args in place, /* Replace the opcode and adjust the args in place,
leaving 3 unused args at the end. */ leaving 3 unused args at the end. */
op->opc = opc = opc_new; op->opc = opc = opc_new;
args[1] = args[2]; op->args[1] = op->args[2];
args[2] = args[4]; op->args[2] = op->args[4];
/* Fall through and mark the single-word operation live. */ /* Fall through and mark the single-word operation live. */
nb_iargs = 2; nb_iargs = 2;
nb_oargs = 1; nb_oargs = 1;
@ -1854,21 +1853,21 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)
do_mul2: do_mul2:
nb_iargs = 2; nb_iargs = 2;
nb_oargs = 2; nb_oargs = 2;
if (temp_state[args[1]] == TS_DEAD) { if (temp_state[op->args[1]] == TS_DEAD) {
if (temp_state[args[0]] == TS_DEAD) { if (temp_state[op->args[0]] == TS_DEAD) {
/* Both parts of the operation are dead. */ /* Both parts of the operation are dead. */
goto do_remove; goto do_remove;
} }
/* The high part of the operation is dead; generate the low. */ /* The high part of the operation is dead; generate the low. */
op->opc = opc = opc_new; op->opc = opc = opc_new;
args[1] = args[2]; op->args[1] = op->args[2];
args[2] = args[3]; op->args[2] = op->args[3];
} else if (temp_state[args[0]] == TS_DEAD && have_opc_new2) { } else if (temp_state[op->args[0]] == TS_DEAD && have_opc_new2) {
/* The low part of the operation is dead; generate the high. */ /* The low part of the operation is dead; generate the high. */
op->opc = opc = opc_new2; op->opc = opc = opc_new2;
args[0] = args[1]; op->args[0] = op->args[1];
args[1] = args[2]; op->args[1] = op->args[2];
args[2] = args[3]; op->args[2] = op->args[3];
} else { } else {
goto do_not_remove; goto do_not_remove;
} }
@ -1886,7 +1885,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)
implies side effects */ implies side effects */
if (!(def->flags & TCG_OPF_SIDE_EFFECTS) && nb_oargs != 0) { if (!(def->flags & TCG_OPF_SIDE_EFFECTS) && nb_oargs != 0) {
for (i = 0; i < nb_oargs; i++) { for (i = 0; i < nb_oargs; i++) {
if (temp_state[args[i]] != TS_DEAD) { if (temp_state[op->args[i]] != TS_DEAD) {
goto do_not_remove; goto do_not_remove;
} }
} }
@ -1896,7 +1895,7 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)
do_not_remove: do_not_remove:
/* output args are dead */ /* output args are dead */
for (i = 0; i < nb_oargs; i++) { for (i = 0; i < nb_oargs; i++) {
arg = args[i]; arg = op->args[i];
if (temp_state[arg] & TS_DEAD) { if (temp_state[arg] & TS_DEAD) {
arg_life |= DEAD_ARG << i; arg_life |= DEAD_ARG << i;
} }
@ -1931,14 +1930,14 @@ static void liveness_pass_1(TCGContext *s, uint8_t *temp_state)
/* record arguments that die in this opcode */ /* record arguments that die in this opcode */
for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) {
arg = args[i]; arg = op->args[i];
if (temp_state[arg] & TS_DEAD) { if (temp_state[arg] & TS_DEAD) {
arg_life |= DEAD_ARG << i; arg_life |= DEAD_ARG << i;
} }
} }
/* input arguments are live for preceding opcodes */ /* input arguments are live for preceding opcodes */
for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) {
temp_state[args[i]] &= ~TS_DEAD; temp_state[op->args[i]] &= ~TS_DEAD;
} }
} }
break; break;
@ -1973,7 +1972,6 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)
for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) { for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) {
TCGOp *op = &s->gen_op_buf[oi]; TCGOp *op = &s->gen_op_buf[oi];
TCGArg *args = op->args;
TCGOpcode opc = op->opc; TCGOpcode opc = op->opc;
const TCGOpDef *def = &s->tcg_op_defs[opc]; const TCGOpDef *def = &s->tcg_op_defs[opc];
TCGLifeData arg_life = op->life; TCGLifeData arg_life = op->life;
@ -1985,7 +1983,7 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)
if (opc == INDEX_op_call) { if (opc == INDEX_op_call) {
nb_oargs = op->callo; nb_oargs = op->callo;
nb_iargs = op->calli; nb_iargs = op->calli;
call_flags = args[nb_oargs + nb_iargs + 1]; call_flags = op->args[nb_oargs + nb_iargs + 1];
} else { } else {
nb_iargs = def->nb_iargs; nb_iargs = def->nb_iargs;
nb_oargs = def->nb_oargs; nb_oargs = def->nb_oargs;
@ -2006,7 +2004,7 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)
/* Make sure that input arguments are available. */ /* Make sure that input arguments are available. */
for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) { for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) {
arg = args[i]; arg = op->args[i];
/* Note this unsigned test catches TCG_CALL_ARG_DUMMY too. */ /* Note this unsigned test catches TCG_CALL_ARG_DUMMY too. */
if (arg < nb_globals) { if (arg < nb_globals) {
dir = dir_temps[arg]; dir = dir_temps[arg];
@ -2016,11 +2014,10 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)
? INDEX_op_ld_i32 ? INDEX_op_ld_i32
: INDEX_op_ld_i64); : INDEX_op_ld_i64);
TCGOp *lop = tcg_op_insert_before(s, op, lopc, 3); TCGOp *lop = tcg_op_insert_before(s, op, lopc, 3);
TCGArg *largs = lop->args;
largs[0] = dir; lop->args[0] = dir;
largs[1] = temp_idx(s, its->mem_base); lop->args[1] = temp_idx(s, its->mem_base);
largs[2] = its->mem_offset; lop->args[2] = its->mem_offset;
/* Loaded, but synced with memory. */ /* Loaded, but synced with memory. */
temp_state[arg] = TS_MEM; temp_state[arg] = TS_MEM;
@ -2032,11 +2029,11 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)
No action is required except keeping temp_state up to date No action is required except keeping temp_state up to date
so that we reload when needed. */ so that we reload when needed. */
for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) { for (i = nb_oargs; i < nb_iargs + nb_oargs; i++) {
arg = args[i]; arg = op->args[i];
if (arg < nb_globals) { if (arg < nb_globals) {
dir = dir_temps[arg]; dir = dir_temps[arg];
if (dir != 0) { if (dir != 0) {
args[i] = dir; op->args[i] = dir;
changes = true; changes = true;
if (IS_DEAD_ARG(i)) { if (IS_DEAD_ARG(i)) {
temp_state[arg] = TS_DEAD; temp_state[arg] = TS_DEAD;
@ -2067,7 +2064,7 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)
/* Outputs become available. */ /* Outputs become available. */
for (i = 0; i < nb_oargs; i++) { for (i = 0; i < nb_oargs; i++) {
arg = args[i]; arg = op->args[i];
if (arg >= nb_globals) { if (arg >= nb_globals) {
continue; continue;
} }
@ -2075,7 +2072,7 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)
if (dir == 0) { if (dir == 0) {
continue; continue;
} }
args[i] = dir; op->args[i] = dir;
changes = true; changes = true;
/* The output is now live and modified. */ /* The output is now live and modified. */
@ -2088,11 +2085,10 @@ static bool liveness_pass_2(TCGContext *s, uint8_t *temp_state)
? INDEX_op_st_i32 ? INDEX_op_st_i32
: INDEX_op_st_i64); : INDEX_op_st_i64);
TCGOp *sop = tcg_op_insert_after(s, op, sopc, 3); TCGOp *sop = tcg_op_insert_after(s, op, sopc, 3);
TCGArg *sargs = sop->args;
sargs[0] = dir; sop->args[0] = dir;
sargs[1] = temp_idx(s, its->mem_base); sop->args[1] = temp_idx(s, its->mem_base);
sargs[2] = its->mem_offset; sop->args[2] = its->mem_offset;
temp_state[arg] = TS_MEM; temp_state[arg] = TS_MEM;
} }
@ -2909,7 +2905,6 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
num_insns = -1; num_insns = -1;
for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) { for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) {
TCGOp * const op = &s->gen_op_buf[oi]; TCGOp * const op = &s->gen_op_buf[oi];
TCGArg * const args = op->args;
TCGOpcode opc = op->opc; TCGOpcode opc = op->opc;
const TCGOpDef *def = &s->tcg_op_defs[opc]; const TCGOpDef *def = &s->tcg_op_defs[opc];
TCGLifeData arg_life = op->life; TCGLifeData arg_life = op->life;
@ -2921,11 +2916,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
switch (opc) { switch (opc) {
case INDEX_op_mov_i32: case INDEX_op_mov_i32:
case INDEX_op_mov_i64: case INDEX_op_mov_i64:
tcg_reg_alloc_mov(s, def, args, arg_life); tcg_reg_alloc_mov(s, def, op->args, arg_life);
break; break;
case INDEX_op_movi_i32: case INDEX_op_movi_i32:
case INDEX_op_movi_i64: case INDEX_op_movi_i64:
tcg_reg_alloc_movi(s, args, arg_life); tcg_reg_alloc_movi(s, op->args, arg_life);
break; break;
case INDEX_op_insn_start: case INDEX_op_insn_start:
if (num_insns >= 0) { if (num_insns >= 0) {
@ -2935,22 +2930,22 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
for (i = 0; i < TARGET_INSN_START_WORDS; ++i) { for (i = 0; i < TARGET_INSN_START_WORDS; ++i) {
target_ulong a; target_ulong a;
#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
a = ((target_ulong)args[i * 2 + 1] << 32) | args[i * 2]; a = deposit64(op->args[i * 2], 32, 32, op->args[i * 2 + 1]);
#else #else
a = args[i]; a = op->args[i];
#endif #endif
s->gen_insn_data[num_insns][i] = a; s->gen_insn_data[num_insns][i] = a;
} }
break; break;
case INDEX_op_discard: case INDEX_op_discard:
temp_dead(s, &s->temps[args[0]]); temp_dead(s, &s->temps[op->args[0]]);
break; break;
case INDEX_op_set_label: case INDEX_op_set_label:
tcg_reg_alloc_bb_end(s, s->reserved_regs); tcg_reg_alloc_bb_end(s, s->reserved_regs);
tcg_out_label(s, arg_label(s, args[0]), s->code_ptr); tcg_out_label(s, arg_label(s, op->args[0]), s->code_ptr);
break; break;
case INDEX_op_call: case INDEX_op_call:
tcg_reg_alloc_call(s, op->callo, op->calli, args, arg_life); tcg_reg_alloc_call(s, op->callo, op->calli, op->args, arg_life);
break; break;
default: default:
/* Sanity check that we've not introduced any unhandled opcodes. */ /* Sanity check that we've not introduced any unhandled opcodes. */
@ -2958,7 +2953,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
/* Note: in order to speed up the code, it would be much /* Note: in order to speed up the code, it would be much
faster to have specialized register allocator functions for faster to have specialized register allocator functions for
some common argument patterns */ some common argument patterns */
tcg_reg_alloc_op(s, def, opc, args, arg_life); tcg_reg_alloc_op(s, def, opc, op->args, arg_life);
break; break;
} }
#ifdef CONFIG_DEBUG_TCG #ifdef CONFIG_DEBUG_TCG