tcg: Use tcg_malloc to allocate TCGLabel

Pre-allocating 512 of them per TB is a waste.

Backports commit 51e3972c41598adc91fe3f4767057f5198dcc15c from qemu
This commit is contained in:
Richard Henderson 2018-02-09 14:47:48 -05:00 committed by Lioncash
parent 00b0a50f47
commit 6bd102ba86
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
2 changed files with 23 additions and 26 deletions

View file

@ -238,15 +238,10 @@ static void tcg_out_label(TCGContext *s, TCGLabel *l, tcg_insn_unit *ptr)
TCGLabel *gen_new_label(TCGContext *s) TCGLabel *gen_new_label(TCGContext *s)
{ {
int idx; TCGLabel *l = tcg_malloc(s, sizeof(TCGLabel));
TCGLabel *l; TCGLabel ltmp = {0};
ltmp.id = s->nb_labels++;
if (s->nb_labels >= TCG_MAX_LABELS) *l = ltmp;
tcg_abort();
idx = s->nb_labels++;
l = &s->labels[idx];
l->has_value = 0;
l->u.first_reloc = NULL;
return l; return l;
} }
@ -1125,12 +1120,20 @@ void tcg_dump_ops(TCGContext *s)
i = 0; i = 0;
break; break;
} }
for (; i < nb_cargs; i++) { switch (c) {
if (k != 0) { case INDEX_op_set_label:
printf(","); case INDEX_op_br:
} case INDEX_op_brcond_i32:
case INDEX_op_brcond_i64:
printf("$0x%" TCG_PRIlx, args[k++]); case INDEX_op_brcond2_i32:
qemu_log("%s$L%d", k ? "," : "", arg_label(s, args[k])->id);
i++, k++;
break;
default:
break;
}
for (; i < nb_cargs; i++, k++) {
qemu_log("%s$0x%" TCG_PRIlx, k ? "," : "", args[k]);
} }
} }
printf("\n"); printf("\n");

View file

@ -170,7 +170,8 @@ typedef struct TCGRelocation {
} TCGRelocation; } TCGRelocation;
typedef struct TCGLabel { typedef struct TCGLabel {
int has_value; unsigned has_value : 1;
unsigned id : 31;
union { union {
uintptr_t value; uintptr_t value;
tcg_insn_unit *value_ptr; tcg_insn_unit *value_ptr;
@ -186,8 +187,6 @@ typedef struct TCGPool {
#define TCG_POOL_CHUNK_SIZE 32768 #define TCG_POOL_CHUNK_SIZE 32768
#define TCG_MAX_LABELS 512
#define TCG_MAX_TEMPS 512 #define TCG_MAX_TEMPS 512
/* when the size of the arguments of a called function is smaller than /* when the size of the arguments of a called function is smaller than
@ -696,8 +695,6 @@ struct TCGContext {
uint16_t gen_opc_icount[OPC_BUF_SIZE]; uint16_t gen_opc_icount[OPC_BUF_SIZE];
uint8_t gen_opc_instr_start[OPC_BUF_SIZE]; uint8_t gen_opc_instr_start[OPC_BUF_SIZE];
TCGLabel labels[TCG_MAX_LABELS];
// Unicorn engine variables // Unicorn engine variables
struct uc_struct *uc; struct uc_struct *uc;
/* qemu/target-i386/translate.c: global register indexes */ /* qemu/target-i386/translate.c: global register indexes */
@ -903,9 +900,7 @@ TCGLabel *gen_new_label(TCGContext* s);
static inline TCGArg label_arg(TCGContext *tcg_ctx, TCGLabel *l) static inline TCGArg label_arg(TCGContext *tcg_ctx, TCGLabel *l)
{ {
ptrdiff_t idx = l - tcg_ctx->labels; return (uintptr_t)l;
tcg_debug_assert(idx >= 0 && idx < tcg_ctx->nb_labels);
return idx;
} }
/** /**
@ -916,10 +911,9 @@ static inline TCGArg label_arg(TCGContext *tcg_ctx, TCGLabel *l)
* encoding of the TCG opcode stream. * encoding of the TCG opcode stream.
*/ */
static inline TCGLabel *arg_label(TCGContext *tcg_ctx, TCGArg idx) static inline TCGLabel *arg_label(TCGContext *tcg_ctx, TCGArg i)
{ {
tcg_debug_assert(idx < tcg_ctx->nb_labels); return (TCGLabel *)(uintptr_t)i;
return &tcg_ctx->labels[idx];
} }
/** /**