mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 16:53:55 -06:00
tcg: Pass number of arguments to tcg_emit_op() / tcg_op_insert_*()
In order to have variable size allocated TCGOp, pass the number of arguments we use (and would allocate) up to tcg_op_alloc(). This alters tcg_emit_op(), tcg_op_insert_before() and tcg_op_insert_after() prototypes. In tcg_op_alloc() ensure the number of arguments is in range. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> [PMD: Extracted from bigger patch] Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221218211832.73312-2-philmd@linaro.org>
This commit is contained in:
parent
f266bec890
commit
d44789434b
7 changed files with 39 additions and 30 deletions
30
tcg/tcg.c
30
tcg/tcg.c
|
@ -1479,7 +1479,7 @@ bool tcg_op_supported(TCGOpcode op)
|
|||
and endian swap in tcg_reg_alloc_call(). */
|
||||
void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args)
|
||||
{
|
||||
int i, real_args, nb_rets, pi;
|
||||
int i, real_args, nb_rets, pi, max_args;
|
||||
unsigned typemask;
|
||||
const TCGHelperInfo *info;
|
||||
TCGOp *op;
|
||||
|
@ -1513,7 +1513,8 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args)
|
|||
}
|
||||
}
|
||||
|
||||
op = tcg_emit_op(INDEX_op_call);
|
||||
max_args = ARRAY_SIZE(op->args);
|
||||
op = tcg_emit_op(INDEX_op_call, max_args);
|
||||
|
||||
pi = 0;
|
||||
if (ret != NULL) {
|
||||
|
@ -1590,7 +1591,7 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args)
|
|||
|
||||
/* Make sure the fields didn't overflow. */
|
||||
tcg_debug_assert(TCGOP_CALLI(op) == real_args);
|
||||
tcg_debug_assert(pi <= ARRAY_SIZE(op->args));
|
||||
tcg_debug_assert(pi <= max_args);
|
||||
|
||||
if (TCG_TARGET_CALL_ARG_I32 == TCG_CALL_ARG_EXTEND) {
|
||||
for (i = 0; i < nargs; ++i) {
|
||||
|
@ -2294,11 +2295,12 @@ void tcg_remove_ops_after(TCGOp *op)
|
|||
}
|
||||
}
|
||||
|
||||
static TCGOp *tcg_op_alloc(TCGOpcode opc)
|
||||
static TCGOp *tcg_op_alloc(TCGOpcode opc, unsigned nargs)
|
||||
{
|
||||
TCGContext *s = tcg_ctx;
|
||||
TCGOp *op;
|
||||
|
||||
assert(nargs < ARRAY_SIZE(op->args));
|
||||
if (likely(QTAILQ_EMPTY(&s->free_ops))) {
|
||||
op = tcg_malloc(sizeof(TCGOp));
|
||||
} else {
|
||||
|
@ -2312,23 +2314,25 @@ static TCGOp *tcg_op_alloc(TCGOpcode opc)
|
|||
return op;
|
||||
}
|
||||
|
||||
TCGOp *tcg_emit_op(TCGOpcode opc)
|
||||
TCGOp *tcg_emit_op(TCGOpcode opc, unsigned nargs)
|
||||
{
|
||||
TCGOp *op = tcg_op_alloc(opc);
|
||||
TCGOp *op = tcg_op_alloc(opc, nargs);
|
||||
QTAILQ_INSERT_TAIL(&tcg_ctx->ops, op, link);
|
||||
return op;
|
||||
}
|
||||
|
||||
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *old_op, TCGOpcode opc)
|
||||
TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *old_op,
|
||||
TCGOpcode opc, unsigned nargs)
|
||||
{
|
||||
TCGOp *new_op = tcg_op_alloc(opc);
|
||||
TCGOp *new_op = tcg_op_alloc(opc, nargs);
|
||||
QTAILQ_INSERT_BEFORE(old_op, new_op, link);
|
||||
return new_op;
|
||||
}
|
||||
|
||||
TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *old_op, TCGOpcode opc)
|
||||
TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *old_op,
|
||||
TCGOpcode opc, unsigned nargs)
|
||||
{
|
||||
TCGOp *new_op = tcg_op_alloc(opc);
|
||||
TCGOp *new_op = tcg_op_alloc(opc, nargs);
|
||||
QTAILQ_INSERT_AFTER(&s->ops, old_op, new_op, link);
|
||||
return new_op;
|
||||
}
|
||||
|
@ -2937,7 +2941,7 @@ static bool liveness_pass_2(TCGContext *s)
|
|||
TCGOpcode lopc = (arg_ts->type == TCG_TYPE_I32
|
||||
? INDEX_op_ld_i32
|
||||
: INDEX_op_ld_i64);
|
||||
TCGOp *lop = tcg_op_insert_before(s, op, lopc);
|
||||
TCGOp *lop = tcg_op_insert_before(s, op, lopc, 3);
|
||||
|
||||
lop->args[0] = temp_arg(dir_ts);
|
||||
lop->args[1] = temp_arg(arg_ts->mem_base);
|
||||
|
@ -3003,7 +3007,7 @@ static bool liveness_pass_2(TCGContext *s)
|
|||
TCGOpcode sopc = (arg_ts->type == TCG_TYPE_I32
|
||||
? INDEX_op_st_i32
|
||||
: INDEX_op_st_i64);
|
||||
TCGOp *sop = tcg_op_insert_after(s, op, sopc);
|
||||
TCGOp *sop = tcg_op_insert_after(s, op, sopc, 3);
|
||||
TCGTemp *out_ts = dir_ts;
|
||||
|
||||
if (IS_DEAD_ARG(0)) {
|
||||
|
@ -3039,7 +3043,7 @@ static bool liveness_pass_2(TCGContext *s)
|
|||
TCGOpcode sopc = (arg_ts->type == TCG_TYPE_I32
|
||||
? INDEX_op_st_i32
|
||||
: INDEX_op_st_i64);
|
||||
TCGOp *sop = tcg_op_insert_after(s, op, sopc);
|
||||
TCGOp *sop = tcg_op_insert_after(s, op, sopc, 3);
|
||||
|
||||
sop->args[0] = temp_arg(dir_ts);
|
||||
sop->args[1] = temp_arg(arg_ts->mem_base);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue