tcg: Introduce tcg_op_buf_count and tcg_op_buf_full

The method by which we count the number of ops emitted
is going to change. Abstract that away into some inlines.

Backports commit fe700adb3db5b028b504423b946d4ee5200a8f2f from qemu.
This commit is contained in:
Richard Henderson 2018-02-09 09:03:18 -05:00 committed by Lioncash
parent 78378289e3
commit a41b9acc0c
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
7 changed files with 35 additions and 40 deletions

View file

@ -11083,7 +11083,6 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,
CPUARMState *env = &cpu->env;
DisasContext dc1, *dc = &dc1;
CPUBreakpoint *bp;
uint16_t *gen_opc_end;
int j, lj;
target_ulong pc_start;
target_ulong next_page_start;
@ -11097,8 +11096,6 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,
dc->uc = env->uc;
dc->tb = tb;
gen_opc_end = tcg_ctx->gen_opc_buf + OPC_MAX_SIZE;
dc->is_jmp = DISAS_NEXT;
dc->pc = pc_start;
dc->singlestep_enabled = cs->singlestep_enabled;
@ -11191,7 +11188,7 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,
}
if (search_pc) {
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
if (lj < j) {
lj++;
while (lj < j) {
@ -11241,14 +11238,14 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,
* ensures prefetch aborts occur at the right place.
*/
num_insns++;
} while (!dc->is_jmp && tcg_ctx->gen_opc_ptr < gen_opc_end &&
} while (!dc->is_jmp && !tcg_op_buf_full(tcg_ctx) &&
!cs->singlestep_enabled &&
!dc->ss_active &&
dc->pc < next_page_start &&
num_insns < max_insns);
/* if too long translation, save this info */
if (tcg_ctx->gen_opc_ptr >= gen_opc_end || num_insns >= max_insns) {
if (tcg_op_buf_full(tcg_ctx) || num_insns >= max_insns) {
block_full = true;
}
@ -11308,7 +11305,7 @@ done_generating:
gen_tb_end(tcg_ctx, tb, num_insns);
if (search_pc) {
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
lj++;
while (lj <= j) {
tcg_ctx->gen_opc_instr_start[lj++] = 0;

View file

@ -11257,7 +11257,6 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,
CPUARMState *env = &cpu->env;
DisasContext dc1, *dc = &dc1;
CPUBreakpoint *bp;
uint16_t *gen_opc_end;
int j, lj;
target_ulong pc_start;
target_ulong next_page_start;
@ -11281,8 +11280,6 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,
dc->uc = env->uc;
dc->tb = tb;
gen_opc_end = tcg_ctx->gen_opc_buf + OPC_MAX_SIZE;
dc->is_jmp = DISAS_NEXT;
dc->pc = pc_start;
@ -11437,7 +11434,7 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,
}
}
if (search_pc) {
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
if (lj < j) {
lj++;
while (lj < j)
@ -11511,7 +11508,7 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,
* Also stop translation when a page boundary is reached. This
* ensures prefetch aborts occur at the right place. */
num_insns ++;
} while (!dc->is_jmp && tcg_ctx->gen_opc_ptr < gen_opc_end &&
} while (!dc->is_jmp && !tcg_op_buf_full(tcg_ctx) &&
!cs->singlestep_enabled &&
!dc->ss_active &&
dc->pc < next_page_start &&
@ -11527,7 +11524,7 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,
}
/* if too long translation, save this info */
if (tcg_ctx->gen_opc_ptr >= gen_opc_end || num_insns >= max_insns) {
if (tcg_op_buf_full(tcg_ctx) || num_insns >= max_insns) {
block_full = true;
}
@ -11628,7 +11625,7 @@ done_generating:
gen_tb_end(tcg_ctx, tb, num_insns);
if (search_pc) {
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
lj++;
while (lj <= j)
tcg_ctx->gen_opc_instr_start[lj++] = 0;

View file

@ -8591,7 +8591,6 @@ static inline void gen_intermediate_code_internal(uint8_t *gen_opc_cc_op,
TCGContext *tcg_ctx = env->uc->tcg_ctx;
DisasContext dc1, *dc = &dc1;
target_ulong pc_ptr;
uint16_t *gen_opc_end;
CPUBreakpoint *bp;
int j, lj;
uint64_t flags;
@ -8694,8 +8693,6 @@ static inline void gen_intermediate_code_internal(uint8_t *gen_opc_cc_op,
goto done_generating;
}
gen_opc_end = tcg_ctx->gen_opc_buf + OPC_MAX_SIZE;
dc->is_jmp = DISAS_NEXT;
lj = -1;
max_insns = tb->cflags & CF_COUNT_MASK;
@ -8724,7 +8721,7 @@ static inline void gen_intermediate_code_internal(uint8_t *gen_opc_cc_op,
}
}
if (search_pc) {
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
if (lj < j) {
lj++;
while (lj < j)
@ -8757,7 +8754,7 @@ static inline void gen_intermediate_code_internal(uint8_t *gen_opc_cc_op,
break;
}
/* if too long translation, stop generation too */
if (tcg_ctx->gen_opc_ptr >= gen_opc_end ||
if (tcg_op_buf_full(tcg_ctx) ||
(pc_ptr - pc_start) >= (TARGET_PAGE_SIZE - 32) ||
num_insns >= max_insns) {
gen_jmp_im(dc, pc_ptr - dc->cs_base);
@ -8773,7 +8770,7 @@ done_generating:
/* we don't forget to fill the last values */
if (search_pc) {
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
lj++;
while (lj <= j)
tcg_ctx->gen_opc_instr_start[lj++] = 0;

View file

@ -3066,7 +3066,6 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb,
CPUState *cs = CPU(cpu);
CPUM68KState *env = &cpu->env;
DisasContext dc1, *dc = &dc1;
uint16_t *gen_opc_end;
CPUBreakpoint *bp;
int j, lj;
target_ulong pc_start;
@ -3082,8 +3081,6 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb,
dc->tb = tb;
dc->uc = env->uc;
gen_opc_end = tcg_ctx->gen_opc_buf + OPC_MAX_SIZE;
dc->env = env;
dc->is_jmp = DISAS_NEXT;
dc->pc = pc_start;
@ -3133,7 +3130,7 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb,
break;
}
if (search_pc) {
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
if (lj < j) {
lj++;
while (lj < j)
@ -3148,13 +3145,13 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb,
dc->insn_pc = dc->pc;
disas_m68k_insn(env, dc);
num_insns++;
} while (!dc->is_jmp && tcg_ctx->gen_opc_ptr < gen_opc_end &&
} while (!dc->is_jmp && !tcg_op_buf_full(tcg_ctx) &&
!cs->singlestep_enabled &&
(pc_offset) < (TARGET_PAGE_SIZE - 32) &&
num_insns < max_insns);
/* if too long translation, save this info */
if (tcg_ctx->gen_opc_ptr >= gen_opc_end || num_insns >= max_insns)
if (tcg_op_buf_full(tcg_ctx) || num_insns >= max_insns)
block_full = true;
//if (tb->cflags & CF_LAST_IO)
@ -3189,7 +3186,7 @@ done_generating:
gen_tb_end(tcg_ctx, tb, num_insns);
if (search_pc) {
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
lj++;
while (lj <= j)
tcg_ctx->gen_opc_instr_start[lj++] = 0;

View file

@ -19161,7 +19161,6 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
CPUMIPSState *env = &cpu->env;
DisasContext ctx;
target_ulong pc_start;
uint16_t *gen_opc_end;
CPUBreakpoint *bp;
int j, lj = -1;
int num_insns;
@ -19176,7 +19175,6 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
qemu_log("search pc %d\n", search_pc);
pc_start = tb->pc;
gen_opc_end = tcg_ctx->gen_opc_buf + OPC_MAX_SIZE;
ctx.uc = env->uc;
ctx.pc = pc_start;
ctx.saved_pc = -1;
@ -19243,7 +19241,7 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
}
if (search_pc) {
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
if (lj < j) {
lj++;
while (lj < j)
@ -19328,7 +19326,7 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
break;
if (tcg_ctx->gen_opc_ptr >= gen_opc_end) {
if (tcg_op_buf_full(tcg_ctx)) {
break;
}
@ -19339,7 +19337,7 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
// break;
}
if (tcg_ctx->gen_opc_ptr >= gen_opc_end || num_insns >= max_insns) {
if (tcg_op_buf_full(tcg_ctx) || num_insns >= max_insns) {
block_full = true;
}
@ -19371,7 +19369,7 @@ done_generating:
gen_tb_end(tcg_ctx, tb, num_insns);
if (search_pc) {
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
lj++;
while (lj <= j)
tcg_ctx->gen_opc_instr_start[lj++] = 0;

View file

@ -5369,7 +5369,6 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu,
CPUState *cs = CPU(cpu);
CPUSPARCState *env = &cpu->env;
target_ulong pc_start, last_pc;
uint16_t *gen_opc_end;
DisasContext dc1, *dc = &dc1;
CPUBreakpoint *bp;
int j, lj = -1;
@ -5392,7 +5391,6 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu,
dc->fpu_enabled = tb_fpu_enabled(tb->flags);
dc->address_mask_32bit = tb_am_enabled(tb->flags);
dc->singlestep = (cs->singlestep_enabled); // || singlestep);
gen_opc_end = tcg_ctx->gen_opc_buf + OPC_MAX_SIZE;
// early check to see if the address of this block is the until address
@ -5440,7 +5438,7 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu,
}
if (spc) {
qemu_log("Search PC...\n");
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
if (lj < j) {
lj++;
while (lj < j)
@ -5481,12 +5479,12 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu,
if (dc->singlestep) {
break;
}
} while ((tcg_ctx->gen_opc_ptr < gen_opc_end) &&
} while (!tcg_op_buf_full(tcg_ctx) &&
(dc->pc - pc_start) < (TARGET_PAGE_SIZE - 32) &&
num_insns < max_insns);
/* if too long translation, save this info */
if (tcg_ctx->gen_opc_ptr >= gen_opc_end || num_insns >= max_insns)
if (tcg_op_buf_full(tcg_ctx) || num_insns >= max_insns)
block_full = true;
exit_gen_loop:
@ -5511,7 +5509,7 @@ done_generating:
gen_tb_end(tcg_ctx, tb, num_insns);
if (spc) {
j = tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
j = tcg_op_buf_count(tcg_ctx);
lj++;
while (lj <= j)
tcg_ctx->gen_opc_instr_start[lj++] = 0;

View file

@ -451,7 +451,6 @@ typedef struct TCGTempSet {
unsigned long l[BITS_TO_LONGS(TCG_MAX_TEMPS)];
} TCGTempSet;
/* pool based memory allocation */
void *tcg_malloc_internal(TCGContext *s, int size);
@ -781,6 +780,18 @@ struct TCGContext {
int exitreq_label; // gen_tb_start()
};
/* The number of opcodes emitted so far. */
static inline int tcg_op_buf_count(TCGContext *tcg_ctx)
{
return tcg_ctx->gen_opc_ptr - tcg_ctx->gen_opc_buf;
}
/* Test for whether to terminate the TB for using too many opcodes. */
static inline bool tcg_op_buf_full(TCGContext *tcg_ctx)
{
return tcg_op_buf_count(tcg_ctx) >= OPC_MAX_SIZE;
}
typedef struct TCGTargetOpDef {
TCGOpcode op;
const char *args_ct_str[TCG_MAX_OP_ARGS];