From cb7b19ad260b0828296236afe3054e249c792d48 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 8 Feb 2018 13:03:59 -0500 Subject: [PATCH] tcg: Change ts->mem_reg to ts->mem_base Chain the temporaries together via pointers intstead of indices. The mem_reg value is now mem_base->reg. This will be important later. This does require that the frame pointer have a global temporary allocated for it. This is simple bar the existing reserved_regs check. Backports commit b3a62939561e07bc34493444fa926b6137cba4e8 from qemu --- qemu/tcg/tcg.c | 60 ++++++++++++++++++++++++++++---------------------- qemu/tcg/tcg.h | 4 ++-- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/qemu/tcg/tcg.c b/qemu/tcg/tcg.c index 376b1bbe..da78da1a 100644 --- a/qemu/tcg/tcg.c +++ b/qemu/tcg/tcg.c @@ -387,13 +387,6 @@ void tcg_prologue_init(TCGContext *s) #endif } -void tcg_set_frame(TCGContext *s, int reg, intptr_t start, intptr_t size) -{ - s->frame_start = start; - s->frame_end = start + size; - s->frame_reg = reg; -} - void tcg_func_start(TCGContext *s) { tcg_pool_reset(s); @@ -422,18 +415,15 @@ static inline void tcg_temp_alloc(TCGContext *s, int n) tcg_abort(); } -static inline int tcg_global_reg_new_internal(TCGContext *s, TCGType type, int reg, - const char *name) +static int tcg_global_reg_new_internal(TCGContext *s, TCGType type, + int reg, const char *name) { TCGTemp *ts; int idx; -#if TCG_TARGET_REG_BITS == 32 - if (type != TCG_TYPE_I32) - tcg_abort(); -#endif - if (tcg_regset_test_reg(s->reserved_regs, reg)) + if (TCG_TARGET_REG_BITS == 32 && type != TCG_TYPE_I32) { tcg_abort(); + } idx = s->nb_globals; tcg_temp_alloc(s, s->nb_globals + 1); ts = &s->temps[s->nb_globals]; @@ -447,10 +437,23 @@ static inline int tcg_global_reg_new_internal(TCGContext *s, TCGType type, int r return idx; } +void tcg_set_frame(TCGContext *s, int reg, intptr_t start, intptr_t size) +{ + int idx; + s->frame_start = start; + s->frame_end = start + size; + idx = tcg_global_reg_new_internal(s, TCG_TYPE_PTR, reg, "_frame"); + s->frame_temp = &s->temps[idx]; +} + TCGv_i32 tcg_global_reg_new_i32(TCGContext *s, int reg, const char *name) { int idx; + if (tcg_regset_test_reg(s->reserved_regs, reg)) { + tcg_abort(); + } + idx = tcg_global_reg_new_internal(s, TCG_TYPE_I32, reg, name); return MAKE_TCGV_I32(idx); } @@ -459,6 +462,10 @@ TCGv_i64 tcg_global_reg_new_i64(TCGContext *s, int reg, const char *name) { int idx; + if (tcg_regset_test_reg(s->reserved_regs, reg)) { + tcg_abort(); + } + idx = tcg_global_reg_new_internal(s, TCG_TYPE_I64, reg, name); return MAKE_TCGV_I64(idx); } @@ -467,7 +474,7 @@ int tcg_global_mem_new_internal(TCGContext *s, TCGType type, TCGv_ptr base, intptr_t offset, const char *name) { TCGTemp *ts, *base_ts = &s->temps[GET_TCGV_PTR(base)]; - int idx, reg = base_ts->reg; + int idx; idx = s->nb_globals; #if TCG_TARGET_REG_BITS == 32 @@ -479,7 +486,7 @@ int tcg_global_mem_new_internal(TCGContext *s, TCGType type, TCGv_ptr base, ts->type = TCG_TYPE_I32; ts->fixed_reg = 0; ts->mem_allocated = 1; - ts->mem_reg = reg; + ts->mem_base = base_ts; #ifdef HOST_WORDS_BIGENDIAN ts->mem_offset = offset + 4; #else @@ -494,7 +501,7 @@ int tcg_global_mem_new_internal(TCGContext *s, TCGType type, TCGv_ptr base, ts->type = TCG_TYPE_I32; ts->fixed_reg = 0; ts->mem_allocated = 1; - ts->mem_reg = reg; + ts->mem_base = base_ts; #ifdef HOST_WORDS_BIGENDIAN ts->mem_offset = offset; #else @@ -514,7 +521,7 @@ int tcg_global_mem_new_internal(TCGContext *s, TCGType type, TCGv_ptr base, ts->type = type; ts->fixed_reg = 0; ts->mem_allocated = 1; - ts->mem_reg = reg; + ts->mem_base = base_ts; ts->mem_offset = offset; ts->name = name; s->nb_globals++; @@ -1803,7 +1810,8 @@ static void dump_regs(TCGContext *s) printf("%s", tcg_target_reg_names[ts->reg]); break; case TEMP_VAL_MEM: - printf("%d(%s)", (int)ts->mem_offset, tcg_target_reg_names[ts->mem_reg]); + printf("%d(%s)", (int)ts->mem_offset + tcg_target_reg_names[ts->mem_base->reg]); break; case TEMP_VAL_CONST: printf("$0x%" TCG_PRIlx, ts->val); @@ -1876,7 +1884,7 @@ static void temp_allocate_frame(TCGContext *s, int temp) tcg_abort(); } ts->mem_offset = s->current_frame_offset; - ts->mem_reg = s->frame_reg; + ts->mem_base = s->frame_temp; ts->mem_allocated = 1; s->current_frame_offset += sizeof(tcg_target_long); } @@ -1894,7 +1902,7 @@ static inline void tcg_reg_sync(TCGContext *s, int reg) if (!ts->mem_allocated) { temp_allocate_frame(s, temp); } - tcg_out_st(s, ts->type, reg, ts->mem_reg, ts->mem_offset); + tcg_out_st(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset); } ts->mem_coherent = 1; } @@ -2110,7 +2118,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, ts->reg = tcg_reg_alloc(s, (TCGRegSet)s->tcg_target_available_regs[itype], allocated_regs); if (ts->val_type == TEMP_VAL_MEM) { - tcg_out_ld(s, itype, ts->reg, ts->mem_reg, ts->mem_offset); + tcg_out_ld(s, itype, ts->reg, ts->mem_base->reg, ts->mem_offset); ts->mem_coherent = 1; } else if (ts->val_type == TEMP_VAL_CONST) { tcg_out_movi(s, itype, ts->reg, ts->val); @@ -2129,7 +2137,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOpDef *def, if (!ots->mem_allocated) { temp_allocate_frame(s, args[0]); } - tcg_out_st(s, otype, ts->reg, ots->mem_reg, ots->mem_offset); + tcg_out_st(s, otype, ts->reg, ots->mem_base->reg, ots->mem_offset); if (IS_DEAD_ARG(1)) { temp_dead(s, args[1]); } @@ -2201,7 +2209,7 @@ static void tcg_reg_alloc_op(TCGContext *s, ts = &s->temps[arg]; if (ts->val_type == TEMP_VAL_MEM) { reg = tcg_reg_alloc(s, arg_ct->u.regs, allocated_regs); - tcg_out_ld(s, ts->type, reg, ts->mem_reg, ts->mem_offset); + tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset); ts->val_type = TEMP_VAL_REG; ts->reg = reg; ts->mem_coherent = 1; @@ -2395,7 +2403,7 @@ static int tcg_reg_alloc_call(TCGContext *s, const TCGOpDef *def, reg = tcg_reg_alloc(s, (TCGRegSet)s->tcg_target_available_regs[ts->type], s->reserved_regs); /* XXX: not correct if reading values from the stack */ - tcg_out_ld(s, ts->type, reg, ts->mem_reg, ts->mem_offset); + tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset); tcg_out_st(s, ts->type, reg, TCG_REG_CALL_STACK, stack_offset); } else if (ts->val_type == TEMP_VAL_CONST) { reg = tcg_reg_alloc(s, (TCGRegSet)s->tcg_target_available_regs[ts->type], @@ -2425,7 +2433,7 @@ static int tcg_reg_alloc_call(TCGContext *s, const TCGOpDef *def, tcg_out_mov(s, ts->type, reg, ts->reg); } } else if (ts->val_type == TEMP_VAL_MEM) { - tcg_out_ld(s, ts->type, reg, ts->mem_reg, ts->mem_offset); + tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset); } else if (ts->val_type == TEMP_VAL_CONST) { /* XXX: sign extend ? */ tcg_out_movi(s, ts->type, reg, ts->val); diff --git a/qemu/tcg/tcg.h b/qemu/tcg/tcg.h index b135cd91..588b649a 100644 --- a/qemu/tcg/tcg.h +++ b/qemu/tcg/tcg.h @@ -433,7 +433,7 @@ typedef struct TCGTemp { int val_type; int reg; tcg_target_long val; - int mem_reg; + struct TCGTemp *mem_base; intptr_t mem_offset; unsigned int fixed_reg:1; unsigned int mem_coherent:1; @@ -616,7 +616,7 @@ struct TCGContext { intptr_t current_frame_offset; intptr_t frame_start; intptr_t frame_end; - int frame_reg; + TCGTemp *frame_temp; tcg_insn_unit *code_ptr; TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */