tcg: Add insn_start_words to TCGContext
This will enable replacement of TARGET_INSN_START_WORDS in tcg.c. Split out "tcg/insn-start-words.h" and use it in target/. Reviewed-by: Anton Johansson <anjo@rev.ng> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
e03291cd9a
commit
747bd69d0f
@ -311,7 +311,8 @@ void perf_report_code(uint64_t guest_pc, TranslationBlock *tb,
|
|||||||
const void *start)
|
const void *start)
|
||||||
{
|
{
|
||||||
struct debuginfo_query *q;
|
struct debuginfo_query *q;
|
||||||
size_t insn;
|
size_t insn, start_words;
|
||||||
|
uint64_t *gen_insn_data;
|
||||||
|
|
||||||
if (!perfmap && !jitdump) {
|
if (!perfmap && !jitdump) {
|
||||||
return;
|
return;
|
||||||
@ -325,9 +326,12 @@ void perf_report_code(uint64_t guest_pc, TranslationBlock *tb,
|
|||||||
debuginfo_lock();
|
debuginfo_lock();
|
||||||
|
|
||||||
/* Query debuginfo for each guest instruction. */
|
/* Query debuginfo for each guest instruction. */
|
||||||
|
gen_insn_data = tcg_ctx->gen_insn_data;
|
||||||
|
start_words = tcg_ctx->insn_start_words;
|
||||||
|
|
||||||
for (insn = 0; insn < tb->icount; insn++) {
|
for (insn = 0; insn < tb->icount; insn++) {
|
||||||
/* FIXME: This replicates the restore_state_to_opc() logic. */
|
/* FIXME: This replicates the restore_state_to_opc() logic. */
|
||||||
q[insn].address = tcg_ctx->gen_insn_data[insn][0];
|
q[insn].address = gen_insn_data[insn * start_words + 0];
|
||||||
if (tb_cflags(tb) & CF_PCREL) {
|
if (tb_cflags(tb) & CF_PCREL) {
|
||||||
q[insn].address |= (guest_pc & TARGET_PAGE_MASK);
|
q[insn].address |= (guest_pc & TARGET_PAGE_MASK);
|
||||||
} else {
|
} else {
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
#include "tb-context.h"
|
#include "tb-context.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "perf.h"
|
#include "perf.h"
|
||||||
|
#include "tcg/insn-start-words.h"
|
||||||
|
|
||||||
TBContext tb_ctx;
|
TBContext tb_ctx;
|
||||||
|
|
||||||
@ -127,22 +128,26 @@ static int64_t decode_sleb128(const uint8_t **pp)
|
|||||||
static int encode_search(TranslationBlock *tb, uint8_t *block)
|
static int encode_search(TranslationBlock *tb, uint8_t *block)
|
||||||
{
|
{
|
||||||
uint8_t *highwater = tcg_ctx->code_gen_highwater;
|
uint8_t *highwater = tcg_ctx->code_gen_highwater;
|
||||||
|
uint64_t *insn_data = tcg_ctx->gen_insn_data;
|
||||||
|
uint16_t *insn_end_off = tcg_ctx->gen_insn_end_off;
|
||||||
uint8_t *p = block;
|
uint8_t *p = block;
|
||||||
int i, j, n;
|
int i, j, n;
|
||||||
|
|
||||||
for (i = 0, n = tb->icount; i < n; ++i) {
|
for (i = 0, n = tb->icount; i < n; ++i) {
|
||||||
uint64_t prev;
|
uint64_t prev, curr;
|
||||||
|
|
||||||
for (j = 0; j < TARGET_INSN_START_WORDS; ++j) {
|
for (j = 0; j < TARGET_INSN_START_WORDS; ++j) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
prev = (!(tb_cflags(tb) & CF_PCREL) && j == 0 ? tb->pc : 0);
|
prev = (!(tb_cflags(tb) & CF_PCREL) && j == 0 ? tb->pc : 0);
|
||||||
} else {
|
} else {
|
||||||
prev = tcg_ctx->gen_insn_data[i - 1][j];
|
prev = insn_data[(i - 1) * TARGET_INSN_START_WORDS + j];
|
||||||
}
|
}
|
||||||
p = encode_sleb128(p, tcg_ctx->gen_insn_data[i][j] - prev);
|
curr = insn_data[i * TARGET_INSN_START_WORDS + j];
|
||||||
|
p = encode_sleb128(p, curr - prev);
|
||||||
}
|
}
|
||||||
prev = (i == 0 ? 0 : tcg_ctx->gen_insn_end_off[i - 1]);
|
prev = (i == 0 ? 0 : insn_end_off[i - 1]);
|
||||||
p = encode_sleb128(p, tcg_ctx->gen_insn_end_off[i] - prev);
|
curr = insn_end_off[i];
|
||||||
|
p = encode_sleb128(p, curr - prev);
|
||||||
|
|
||||||
/* Test for (pending) buffer overflow. The assumption is that any
|
/* Test for (pending) buffer overflow. The assumption is that any
|
||||||
one row beginning below the high water mark cannot overrun
|
one row beginning below the high water mark cannot overrun
|
||||||
@ -358,6 +363,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
|||||||
tcg_ctx->tlb_fast_offset =
|
tcg_ctx->tlb_fast_offset =
|
||||||
(int)offsetof(ArchCPU, neg.tlb.f) - (int)offsetof(ArchCPU, env);
|
(int)offsetof(ArchCPU, neg.tlb.f) - (int)offsetof(ArchCPU, env);
|
||||||
#endif
|
#endif
|
||||||
|
tcg_ctx->insn_start_words = TARGET_INSN_START_WORDS;
|
||||||
|
|
||||||
tb_overflow:
|
tb_overflow:
|
||||||
|
|
||||||
@ -451,7 +457,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
|||||||
fprintf(logfile, "OUT: [size=%d]\n", gen_code_size);
|
fprintf(logfile, "OUT: [size=%d]\n", gen_code_size);
|
||||||
fprintf(logfile,
|
fprintf(logfile,
|
||||||
" -- guest addr 0x%016" PRIx64 " + tb prologue\n",
|
" -- guest addr 0x%016" PRIx64 " + tb prologue\n",
|
||||||
tcg_ctx->gen_insn_data[insn][0]);
|
tcg_ctx->gen_insn_data[insn * TARGET_INSN_START_WORDS]);
|
||||||
chunk_start = tcg_ctx->gen_insn_end_off[insn];
|
chunk_start = tcg_ctx->gen_insn_end_off[insn];
|
||||||
disas(logfile, tb->tc.ptr, chunk_start);
|
disas(logfile, tb->tc.ptr, chunk_start);
|
||||||
|
|
||||||
@ -464,7 +470,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
|||||||
size_t chunk_end = tcg_ctx->gen_insn_end_off[insn];
|
size_t chunk_end = tcg_ctx->gen_insn_end_off[insn];
|
||||||
if (chunk_end > chunk_start) {
|
if (chunk_end > chunk_start) {
|
||||||
fprintf(logfile, " -- guest addr 0x%016" PRIx64 "\n",
|
fprintf(logfile, " -- guest addr 0x%016" PRIx64 "\n",
|
||||||
tcg_ctx->gen_insn_data[insn][0]);
|
tcg_ctx->gen_insn_data[insn * TARGET_INSN_START_WORDS]);
|
||||||
disas(logfile, tb->tc.ptr + chunk_start,
|
disas(logfile, tb->tc.ptr + chunk_start,
|
||||||
chunk_end - chunk_start);
|
chunk_end - chunk_start);
|
||||||
chunk_start = chunk_end;
|
chunk_start = chunk_end;
|
||||||
|
17
include/tcg/insn-start-words.h
Normal file
17
include/tcg/insn-start-words.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
/*
|
||||||
|
* Define TARGET_INSN_START_WORDS
|
||||||
|
* Copyright (c) 2008 Fabrice Bellard
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TARGET_INSN_START_WORDS
|
||||||
|
|
||||||
|
#include "cpu.h"
|
||||||
|
|
||||||
|
#ifndef TARGET_INSN_START_EXTRA_WORDS
|
||||||
|
# define TARGET_INSN_START_WORDS 1
|
||||||
|
#else
|
||||||
|
# define TARGET_INSN_START_WORDS (1 + TARGET_INSN_START_EXTRA_WORDS)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* TARGET_INSN_START_WORDS */
|
@ -22,20 +22,20 @@
|
|||||||
# error
|
# error
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TARGET_INSN_START_WORDS == 1
|
#ifndef TARGET_INSN_START_EXTRA_WORDS
|
||||||
static inline void tcg_gen_insn_start(target_ulong pc)
|
static inline void tcg_gen_insn_start(target_ulong pc)
|
||||||
{
|
{
|
||||||
TCGOp *op = tcg_emit_op(INDEX_op_insn_start, 64 / TCG_TARGET_REG_BITS);
|
TCGOp *op = tcg_emit_op(INDEX_op_insn_start, 64 / TCG_TARGET_REG_BITS);
|
||||||
tcg_set_insn_start_param(op, 0, pc);
|
tcg_set_insn_start_param(op, 0, pc);
|
||||||
}
|
}
|
||||||
#elif TARGET_INSN_START_WORDS == 2
|
#elif TARGET_INSN_START_EXTRA_WORDS == 1
|
||||||
static inline void tcg_gen_insn_start(target_ulong pc, target_ulong a1)
|
static inline void tcg_gen_insn_start(target_ulong pc, target_ulong a1)
|
||||||
{
|
{
|
||||||
TCGOp *op = tcg_emit_op(INDEX_op_insn_start, 2 * 64 / TCG_TARGET_REG_BITS);
|
TCGOp *op = tcg_emit_op(INDEX_op_insn_start, 2 * 64 / TCG_TARGET_REG_BITS);
|
||||||
tcg_set_insn_start_param(op, 0, pc);
|
tcg_set_insn_start_param(op, 0, pc);
|
||||||
tcg_set_insn_start_param(op, 1, a1);
|
tcg_set_insn_start_param(op, 1, a1);
|
||||||
}
|
}
|
||||||
#elif TARGET_INSN_START_WORDS == 3
|
#elif TARGET_INSN_START_EXTRA_WORDS == 2
|
||||||
static inline void tcg_gen_insn_start(target_ulong pc, target_ulong a1,
|
static inline void tcg_gen_insn_start(target_ulong pc, target_ulong a1,
|
||||||
target_ulong a2)
|
target_ulong a2)
|
||||||
{
|
{
|
||||||
@ -45,7 +45,7 @@ static inline void tcg_gen_insn_start(target_ulong pc, target_ulong a1,
|
|||||||
tcg_set_insn_start_param(op, 2, a2);
|
tcg_set_insn_start_param(op, 2, a2);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# error "Unhandled number of operands to insn_start"
|
#error Unhandled TARGET_INSN_START_EXTRA_WORDS value
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TARGET_LONG_BITS == 32
|
#if TARGET_LONG_BITS == 32
|
||||||
|
@ -188,9 +188,9 @@ DEF(mulsh_i64, 1, 2, 0, IMPL64 | IMPL(TCG_TARGET_HAS_mulsh_i64))
|
|||||||
|
|
||||||
#define DATA64_ARGS (TCG_TARGET_REG_BITS == 64 ? 1 : 2)
|
#define DATA64_ARGS (TCG_TARGET_REG_BITS == 64 ? 1 : 2)
|
||||||
|
|
||||||
/* QEMU specific */
|
/* There are tcg_ctx->insn_start_words here, not just one. */
|
||||||
DEF(insn_start, 0, 0, DATA64_ARGS * TARGET_INSN_START_WORDS,
|
DEF(insn_start, 0, 0, DATA64_ARGS, TCG_OPF_NOT_PRESENT)
|
||||||
TCG_OPF_NOT_PRESENT)
|
|
||||||
DEF(exit_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
|
DEF(exit_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
|
||||||
DEF(goto_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
|
DEF(goto_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
|
||||||
DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
|
DEF(goto_ptr, 0, 1, 0, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)
|
||||||
|
@ -173,12 +173,6 @@ typedef uint64_t TCGRegSet;
|
|||||||
#define TCG_TARGET_HAS_v256 0
|
#define TCG_TARGET_HAS_v256 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TARGET_INSN_START_EXTRA_WORDS
|
|
||||||
# define TARGET_INSN_START_WORDS 1
|
|
||||||
#else
|
|
||||||
# define TARGET_INSN_START_WORDS (1 + TARGET_INSN_START_EXTRA_WORDS)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum TCGOpcode {
|
typedef enum TCGOpcode {
|
||||||
#define DEF(name, oargs, iargs, cargs, flags) INDEX_op_ ## name,
|
#define DEF(name, oargs, iargs, cargs, flags) INDEX_op_ ## name,
|
||||||
#include "tcg/tcg-opc.h"
|
#include "tcg/tcg-opc.h"
|
||||||
@ -526,6 +520,7 @@ struct TCGContext {
|
|||||||
uint8_t page_bits;
|
uint8_t page_bits;
|
||||||
uint8_t tlb_dyn_max_bits;
|
uint8_t tlb_dyn_max_bits;
|
||||||
#endif
|
#endif
|
||||||
|
uint8_t insn_start_words;
|
||||||
|
|
||||||
TCGRegSet reserved_regs;
|
TCGRegSet reserved_regs;
|
||||||
intptr_t current_frame_offset;
|
intptr_t current_frame_offset;
|
||||||
@ -597,7 +592,7 @@ struct TCGContext {
|
|||||||
TCGTemp *reg_to_temp[TCG_TARGET_NB_REGS];
|
TCGTemp *reg_to_temp[TCG_TARGET_NB_REGS];
|
||||||
|
|
||||||
uint16_t gen_insn_end_off[TCG_MAX_INSNS];
|
uint16_t gen_insn_end_off[TCG_MAX_INSNS];
|
||||||
uint64_t gen_insn_data[TCG_MAX_INSNS][TARGET_INSN_START_WORDS];
|
uint64_t *gen_insn_data;
|
||||||
|
|
||||||
/* Exit to translator on overflow. */
|
/* Exit to translator on overflow. */
|
||||||
sigjmp_buf jmp_trans;
|
sigjmp_buf jmp_trans;
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "qemu/log.h"
|
#include "qemu/log.h"
|
||||||
#ifdef CONFIG_TCG
|
#ifdef CONFIG_TCG
|
||||||
#include "tcg/tcg.h"
|
#include "tcg/insn-start-words.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void cpu_sync_avx_hflag(CPUX86State *env)
|
void cpu_sync_avx_hflag(CPUX86State *env)
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#ifndef CONFIG_USER_ONLY
|
#ifndef CONFIG_USER_ONLY
|
||||||
#include "hw/boards.h"
|
#include "hw/boards.h"
|
||||||
#endif
|
#endif
|
||||||
#include "tcg/tcg.h"
|
#include "tcg/insn-start-words.h"
|
||||||
|
|
||||||
#define TO_SPR(group, number) (((group) << 11) + (number))
|
#define TO_SPR(group, number) (((group) << 11) + (number))
|
||||||
|
|
||||||
|
16
tcg/tcg.c
16
tcg/tcg.c
@ -1501,6 +1501,8 @@ void tcg_func_start(TCGContext *s)
|
|||||||
tcg_debug_assert(s->tlb_fast_offset < 0);
|
tcg_debug_assert(s->tlb_fast_offset < 0);
|
||||||
tcg_debug_assert(s->tlb_fast_offset >= MIN_TLB_MASK_TABLE_OFS);
|
tcg_debug_assert(s->tlb_fast_offset >= MIN_TLB_MASK_TABLE_OFS);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
tcg_debug_assert(s->insn_start_words > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static TCGTemp *tcg_temp_alloc(TCGContext *s)
|
static TCGTemp *tcg_temp_alloc(TCGContext *s)
|
||||||
@ -2445,7 +2447,7 @@ static void tcg_dump_ops(TCGContext *s, FILE *f, bool have_prefs)
|
|||||||
nb_oargs = 0;
|
nb_oargs = 0;
|
||||||
col += ne_fprintf(f, "\n ----");
|
col += ne_fprintf(f, "\n ----");
|
||||||
|
|
||||||
for (i = 0; i < TARGET_INSN_START_WORDS; ++i) {
|
for (i = 0, k = s->insn_start_words; i < k; ++i) {
|
||||||
col += ne_fprintf(f, " %016" PRIx64,
|
col += ne_fprintf(f, " %016" PRIx64,
|
||||||
tcg_get_insn_start_param(op, i));
|
tcg_get_insn_start_param(op, i));
|
||||||
}
|
}
|
||||||
@ -6024,7 +6026,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start)
|
|||||||
#ifdef CONFIG_PROFILER
|
#ifdef CONFIG_PROFILER
|
||||||
TCGProfile *prof = &s->prof;
|
TCGProfile *prof = &s->prof;
|
||||||
#endif
|
#endif
|
||||||
int i, num_insns;
|
int i, start_words, num_insns;
|
||||||
TCGOp *op;
|
TCGOp *op;
|
||||||
|
|
||||||
#ifdef CONFIG_PROFILER
|
#ifdef CONFIG_PROFILER
|
||||||
@ -6147,6 +6149,10 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start)
|
|||||||
s->pool_labels = NULL;
|
s->pool_labels = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
start_words = s->insn_start_words;
|
||||||
|
s->gen_insn_data =
|
||||||
|
tcg_malloc(sizeof(uint64_t) * s->gen_tb->icount * start_words);
|
||||||
|
|
||||||
num_insns = -1;
|
num_insns = -1;
|
||||||
QTAILQ_FOREACH(op, &s->ops, link) {
|
QTAILQ_FOREACH(op, &s->ops, link) {
|
||||||
TCGOpcode opc = op->opc;
|
TCGOpcode opc = op->opc;
|
||||||
@ -6172,8 +6178,8 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start)
|
|||||||
assert(s->gen_insn_end_off[num_insns] == off);
|
assert(s->gen_insn_end_off[num_insns] == off);
|
||||||
}
|
}
|
||||||
num_insns++;
|
num_insns++;
|
||||||
for (i = 0; i < TARGET_INSN_START_WORDS; ++i) {
|
for (i = 0; i < start_words; ++i) {
|
||||||
s->gen_insn_data[num_insns][i] =
|
s->gen_insn_data[num_insns * start_words + i] =
|
||||||
tcg_get_insn_start_param(op, i);
|
tcg_get_insn_start_param(op, i);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -6219,7 +6225,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start)
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tcg_debug_assert(num_insns >= 0);
|
tcg_debug_assert(num_insns + 1 == s->gen_tb->icount);
|
||||||
s->gen_insn_end_off[num_insns] = tcg_current_code_size(s);
|
s->gen_insn_end_off[num_insns] = tcg_current_code_size(s);
|
||||||
|
|
||||||
/* Generate TB finalization at the end of block */
|
/* Generate TB finalization at the end of block */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user