tcg: Initialize cpu_env generically

This is identical for each target.  So, move the initialization to
common code.  Move the variable itself out of tcg_ctx and name it
cpu_env to minimize changes within targets.

This also means we can remove tcg_global_reg_new_{ptr,i32,i64},
since there are no longer global-register temps created by targets.

Reviewed-by: Emilio G. Cota <cota@braap.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson
2017-10-24 13:53:42 -07:00
parent 3468b59e18
commit 1c2adb958f
26 changed files with 28 additions and 133 deletions
+4 -6
View File
@@ -18,7 +18,7 @@ static inline void gen_tb_start(TranslationBlock *tb)
count = tcg_temp_new_i32(); count = tcg_temp_new_i32();
} }
tcg_gen_ld_i32(count, tcg_ctx->tcg_env, tcg_gen_ld_i32(count, cpu_env,
-ENV_OFFSET + offsetof(CPUState, icount_decr.u32)); -ENV_OFFSET + offsetof(CPUState, icount_decr.u32));
if (tb_cflags(tb) & CF_USE_ICOUNT) { if (tb_cflags(tb) & CF_USE_ICOUNT) {
@@ -36,7 +36,7 @@ static inline void gen_tb_start(TranslationBlock *tb)
tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, tcg_ctx->exitreq_label); tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, tcg_ctx->exitreq_label);
if (tb_cflags(tb) & CF_USE_ICOUNT) { if (tb_cflags(tb) & CF_USE_ICOUNT) {
tcg_gen_st16_i32(count, tcg_ctx->tcg_env, tcg_gen_st16_i32(count, cpu_env,
-ENV_OFFSET + offsetof(CPUState, icount_decr.u16.low)); -ENV_OFFSET + offsetof(CPUState, icount_decr.u16.low));
} }
@@ -61,16 +61,14 @@ static inline void gen_tb_end(TranslationBlock *tb, int num_insns)
static inline void gen_io_start(void) static inline void gen_io_start(void)
{ {
TCGv_i32 tmp = tcg_const_i32(1); TCGv_i32 tmp = tcg_const_i32(1);
tcg_gen_st_i32(tmp, tcg_ctx->tcg_env, tcg_gen_st_i32(tmp, cpu_env, -ENV_OFFSET + offsetof(CPUState, can_do_io));
-ENV_OFFSET + offsetof(CPUState, can_do_io));
tcg_temp_free_i32(tmp); tcg_temp_free_i32(tmp);
} }
static inline void gen_io_end(void) static inline void gen_io_end(void)
{ {
TCGv_i32 tmp = tcg_const_i32(0); TCGv_i32 tmp = tcg_const_i32(0);
tcg_gen_st_i32(tmp, tcg_ctx->tcg_env, tcg_gen_st_i32(tmp, cpu_env, -ENV_OFFSET + offsetof(CPUState, can_do_io));
-ENV_OFFSET + offsetof(CPUState, can_do_io));
tcg_temp_free_i32(tmp); tcg_temp_free_i32(tmp);
} }
-4
View File
@@ -78,7 +78,6 @@ struct DisasContext {
#define DISAS_PC_STALE DISAS_TARGET_2 #define DISAS_PC_STALE DISAS_TARGET_2
/* global register indexes */ /* global register indexes */
static TCGv_env cpu_env;
static TCGv cpu_std_ir[31]; static TCGv cpu_std_ir[31];
static TCGv cpu_fir[31]; static TCGv cpu_fir[31];
static TCGv cpu_pc; static TCGv cpu_pc;
@@ -126,9 +125,6 @@ void alpha_translate_init(void)
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
for (i = 0; i < 31; i++) { for (i = 0; i < 31; i++) {
cpu_std_ir[i] = tcg_global_mem_new_i64(cpu_env, cpu_std_ir[i] = tcg_global_mem_new_i64(cpu_env,
offsetof(CPUAlphaState, ir[i]), offsetof(CPUAlphaState, ir[i]),
-4
View File
@@ -58,7 +58,6 @@
#define IS_USER(s) (s->user) #define IS_USER(s) (s->user)
#endif #endif
TCGv_env cpu_env;
/* We reuse the same 64-bit temporaries for efficiency. */ /* We reuse the same 64-bit temporaries for efficiency. */
static TCGv_i64 cpu_V0, cpu_V1, cpu_M0; static TCGv_i64 cpu_V0, cpu_V1, cpu_M0;
static TCGv_i32 cpu_R[16]; static TCGv_i32 cpu_R[16];
@@ -81,9 +80,6 @@ void arm_translate_init(void)
{ {
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
cpu_R[i] = tcg_global_mem_new_i32(cpu_env, cpu_R[i] = tcg_global_mem_new_i32(cpu_env,
offsetof(CPUARMState, regs[i]), offsetof(CPUARMState, regs[i]),
-1
View File
@@ -80,7 +80,6 @@ typedef struct DisasCompare {
} DisasCompare; } DisasCompare;
/* Share the TCG temporaries common between 32 and 64 bit modes. */ /* Share the TCG temporaries common between 32 and 64 bit modes. */
extern TCGv_env cpu_env;
extern TCGv_i32 cpu_NF, cpu_ZF, cpu_CF, cpu_VF; extern TCGv_i32 cpu_NF, cpu_ZF, cpu_CF, cpu_VF;
extern TCGv_i64 cpu_exclusive_addr; extern TCGv_i64 cpu_exclusive_addr;
extern TCGv_i64 cpu_exclusive_val; extern TCGv_i64 cpu_exclusive_val;
-3
View File
@@ -66,7 +66,6 @@
#define CC_MASK_NZVC 0xf #define CC_MASK_NZVC 0xf
#define CC_MASK_RNZV 0x10e #define CC_MASK_RNZV 0x10e
static TCGv_env cpu_env;
static TCGv cpu_R[16]; static TCGv cpu_R[16];
static TCGv cpu_PR[16]; static TCGv cpu_PR[16];
static TCGv cc_x; static TCGv cc_x;
@@ -3368,8 +3367,6 @@ void cris_initialize_tcg(void)
{ {
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
cc_x = tcg_global_mem_new(cpu_env, cc_x = tcg_global_mem_new(cpu_env,
offsetof(CPUCRISState, cc_x), "cc_x"); offsetof(CPUCRISState, cc_x), "cc_x");
cc_src = tcg_global_mem_new(cpu_env, cc_src = tcg_global_mem_new(cpu_env,
-2
View File
@@ -1272,8 +1272,6 @@ void cris_initialize_crisv10_tcg(void)
{ {
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
cc_x = tcg_global_mem_new(cpu_env, cc_x = tcg_global_mem_new(cpu_env,
offsetof(CPUCRISState, cc_x), "cc_x"); offsetof(CPUCRISState, cc_x), "cc_x");
cc_src = tcg_global_mem_new(cpu_env, cc_src = tcg_global_mem_new(cpu_env,
-4
View File
@@ -83,7 +83,6 @@ typedef struct DisasInsn {
} DisasInsn; } DisasInsn;
/* global register indexes */ /* global register indexes */
static TCGv_env cpu_env;
static TCGv cpu_gr[32]; static TCGv cpu_gr[32];
static TCGv cpu_iaoq_f; static TCGv cpu_iaoq_f;
static TCGv cpu_iaoq_b; static TCGv cpu_iaoq_b;
@@ -126,9 +125,6 @@ void hppa_translate_init(void)
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
TCGV_UNUSED(cpu_gr[0]); TCGV_UNUSED(cpu_gr[0]);
for (i = 1; i < 32; i++) { for (i = 1; i < 32; i++) {
cpu_gr[i] = tcg_global_mem_new(cpu_env, cpu_gr[i] = tcg_global_mem_new(cpu_env,
-3
View File
@@ -72,7 +72,6 @@
//#define MACRO_TEST 1 //#define MACRO_TEST 1
/* global register indexes */ /* global register indexes */
static TCGv_env cpu_env;
static TCGv cpu_A0; static TCGv cpu_A0;
static TCGv cpu_cc_dst, cpu_cc_src, cpu_cc_src2, cpu_cc_srcT; static TCGv cpu_cc_dst, cpu_cc_src, cpu_cc_src2, cpu_cc_srcT;
static TCGv_i32 cpu_cc_op; static TCGv_i32 cpu_cc_op;
@@ -8367,8 +8366,6 @@ void tcg_x86_init(void)
}; };
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
cpu_cc_op = tcg_global_mem_new_i32(cpu_env, cpu_cc_op = tcg_global_mem_new_i32(cpu_env,
offsetof(CPUX86State, cc_op), "cc_op"); offsetof(CPUX86State, cc_op), "cc_op");
cpu_cc_dst = tcg_global_mem_new(cpu_env, offsetof(CPUX86State, cc_dst), cpu_cc_dst = tcg_global_mem_new(cpu_env, offsetof(CPUX86State, cc_dst),
-4
View File
@@ -53,7 +53,6 @@
#define DISAS_UPDATE DISAS_TARGET_1 /* cpu state was modified dynamically */ #define DISAS_UPDATE DISAS_TARGET_1 /* cpu state was modified dynamically */
#define DISAS_TB_JUMP DISAS_TARGET_2 /* only pc was modified statically */ #define DISAS_TB_JUMP DISAS_TARGET_2 /* only pc was modified statically */
static TCGv_env cpu_env;
static TCGv cpu_R[32]; static TCGv cpu_R[32];
static TCGv cpu_pc; static TCGv cpu_pc;
static TCGv cpu_ie; static TCGv cpu_ie;
@@ -1208,9 +1207,6 @@ void lm32_translate_init(void)
{ {
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
for (i = 0; i < ARRAY_SIZE(cpu_R); i++) { for (i = 0; i < ARRAY_SIZE(cpu_R); i++) {
cpu_R[i] = tcg_global_mem_new(cpu_env, cpu_R[i] = tcg_global_mem_new(cpu_env,
offsetof(CPULM32State, regs[i]), offsetof(CPULM32State, regs[i]),
-5
View File
@@ -44,8 +44,6 @@
static TCGv_i32 cpu_halted; static TCGv_i32 cpu_halted;
static TCGv_i32 cpu_exception_index; static TCGv_i32 cpu_exception_index;
static TCGv_env cpu_env;
static char cpu_reg_names[2 * 8 * 3 + 5 * 4]; static char cpu_reg_names[2 * 8 * 3 + 5 * 4];
static TCGv cpu_dregs[8]; static TCGv cpu_dregs[8];
static TCGv cpu_aregs[8]; static TCGv cpu_aregs[8];
@@ -69,9 +67,6 @@ void m68k_tcg_init(void)
char *p; char *p;
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
#define DEFO32(name, offset) \ #define DEFO32(name, offset) \
QREG_##name = tcg_global_mem_new_i32(cpu_env, \ QREG_##name = tcg_global_mem_new_i32(cpu_env, \
offsetof(CPUM68KState, offset), #name); offsetof(CPUM68KState, offset), #name);
-4
View File
@@ -53,7 +53,6 @@
#define DISAS_TB_JUMP DISAS_TARGET_2 /* only pc was modified statically */ #define DISAS_TB_JUMP DISAS_TARGET_2 /* only pc was modified statically */
static TCGv env_debug; static TCGv env_debug;
static TCGv_env cpu_env;
static TCGv cpu_R[32]; static TCGv cpu_R[32];
static TCGv cpu_SR[18]; static TCGv cpu_SR[18];
static TCGv env_imm; static TCGv env_imm;
@@ -1855,9 +1854,6 @@ void mb_tcg_init(void)
{ {
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
env_debug = tcg_global_mem_new(cpu_env, env_debug = tcg_global_mem_new(cpu_env,
offsetof(CPUMBState, debug), offsetof(CPUMBState, debug),
"debug0"); "debug0");
-4
View File
@@ -1376,7 +1376,6 @@ enum {
}; };
/* global register indices */ /* global register indices */
static TCGv_env cpu_env;
static TCGv cpu_gpr[32], cpu_PC; static TCGv cpu_gpr[32], cpu_PC;
static TCGv cpu_HI[MIPS_DSP_ACC], cpu_LO[MIPS_DSP_ACC]; static TCGv cpu_HI[MIPS_DSP_ACC], cpu_LO[MIPS_DSP_ACC];
static TCGv cpu_dspctrl, btarget, bcond; static TCGv cpu_dspctrl, btarget, bcond;
@@ -20454,9 +20453,6 @@ void mips_tcg_init(void)
{ {
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
TCGV_UNUSED(cpu_gpr[0]); TCGV_UNUSED(cpu_gpr[0]);
for (i = 1; i < 32; i++) for (i = 1; i < 32; i++)
cpu_gpr[i] = tcg_global_mem_new(cpu_env, cpu_gpr[i] = tcg_global_mem_new(cpu_env,
-3
View File
@@ -56,7 +56,6 @@ enum {
static TCGv cpu_pc; static TCGv cpu_pc;
static TCGv cpu_gregs[16]; static TCGv cpu_gregs[16];
static TCGv_env cpu_env;
static TCGv cc_a, cc_b; static TCGv cc_a, cc_b;
#include "exec/gen-icount.h" #include "exec/gen-icount.h"
@@ -101,8 +100,6 @@ void moxie_translate_init(void)
"$r10", "$r11", "$r12", "$r13" "$r10", "$r11", "$r12", "$r13"
}; };
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
cpu_pc = tcg_global_mem_new_i32(cpu_env, cpu_pc = tcg_global_mem_new_i32(cpu_env,
offsetof(CPUMoxieState, pc), "$pc"); offsetof(CPUMoxieState, pc), "$pc");
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
-4
View File
@@ -789,7 +789,6 @@ static const char * const regnames[] = {
"rpc" "rpc"
}; };
static TCGv_ptr cpu_env;
static TCGv cpu_R[NUM_CORE_REGS]; static TCGv cpu_R[NUM_CORE_REGS];
#include "exec/gen-icount.h" #include "exec/gen-icount.h"
@@ -947,9 +946,6 @@ void nios2_tcg_init(void)
{ {
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
for (i = 0; i < NUM_CORE_REGS; i++) { for (i = 0; i < NUM_CORE_REGS; i++) {
cpu_R[i] = tcg_global_mem_new(cpu_env, cpu_R[i] = tcg_global_mem_new(cpu_env,
offsetof(CPUNios2State, regs[i]), offsetof(CPUNios2State, regs[i]),
-3
View File
@@ -53,7 +53,6 @@ typedef struct DisasContext {
bool singlestep_enabled; bool singlestep_enabled;
} DisasContext; } DisasContext;
static TCGv_env cpu_env;
static TCGv cpu_sr; static TCGv cpu_sr;
static TCGv cpu_R[32]; static TCGv cpu_R[32];
static TCGv cpu_R0; static TCGv cpu_R0;
@@ -80,8 +79,6 @@ void openrisc_translate_init(void)
}; };
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
cpu_sr = tcg_global_mem_new(cpu_env, cpu_sr = tcg_global_mem_new(cpu_env,
offsetof(CPUOpenRISCState, sr), "sr"); offsetof(CPUOpenRISCState, sr), "sr");
cpu_dflag = tcg_global_mem_new_i32(cpu_env, cpu_dflag = tcg_global_mem_new_i32(cpu_env,
-4
View File
@@ -51,7 +51,6 @@
/* Code translation helpers */ /* Code translation helpers */
/* global register indexes */ /* global register indexes */
static TCGv_env cpu_env;
static char cpu_reg_names[10*3 + 22*4 /* GPR */ static char cpu_reg_names[10*3 + 22*4 /* GPR */
+ 10*4 + 22*5 /* SPE GPRh */ + 10*4 + 22*5 /* SPE GPRh */
+ 10*4 + 22*5 /* FPR */ + 10*4 + 22*5 /* FPR */
@@ -85,9 +84,6 @@ void ppc_translate_init(void)
char* p; char* p;
size_t cpu_reg_names_size; size_t cpu_reg_names_size;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
p = cpu_reg_names; p = cpu_reg_names;
cpu_reg_names_size = sizeof(cpu_reg_names); cpu_reg_names_size = sizeof(cpu_reg_names);
-6
View File
@@ -37,10 +37,6 @@
#include "qemu/log.h" #include "qemu/log.h"
#include "qemu/host-utils.h" #include "qemu/host-utils.h"
#include "exec/cpu_ldst.h" #include "exec/cpu_ldst.h"
/* global register indexes */
static TCGv_env cpu_env;
#include "exec/gen-icount.h" #include "exec/gen-icount.h"
#include "exec/helper-proto.h" #include "exec/helper-proto.h"
#include "exec/helper-gen.h" #include "exec/helper-gen.h"
@@ -112,8 +108,6 @@ void s390x_translate_init(void)
{ {
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
psw_addr = tcg_global_mem_new_i64(cpu_env, psw_addr = tcg_global_mem_new_i64(cpu_env,
offsetof(CPUS390XState, psw.addr), offsetof(CPUS390XState, psw.addr),
"psw_addr"); "psw_addr");
-4
View File
@@ -65,7 +65,6 @@ enum {
}; };
/* global register indexes */ /* global register indexes */
static TCGv_env cpu_env;
static TCGv cpu_gregs[32]; static TCGv cpu_gregs[32];
static TCGv cpu_sr, cpu_sr_m, cpu_sr_q, cpu_sr_t; static TCGv cpu_sr, cpu_sr_m, cpu_sr_q, cpu_sr_t;
static TCGv cpu_pc, cpu_ssr, cpu_spc, cpu_gbr; static TCGv cpu_pc, cpu_ssr, cpu_spc, cpu_gbr;
@@ -99,9 +98,6 @@ void sh4_translate_init(void)
"FPR12_BANK1", "FPR13_BANK1", "FPR14_BANK1", "FPR15_BANK1", "FPR12_BANK1", "FPR13_BANK1", "FPR14_BANK1", "FPR15_BANK1",
}; };
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
for (i = 0; i < 24; i++) { for (i = 0; i < 24; i++) {
cpu_gregs[i] = tcg_global_mem_new_i32(cpu_env, cpu_gregs[i] = tcg_global_mem_new_i32(cpu_env,
offsetof(CPUSH4State, gregs[i]), offsetof(CPUSH4State, gregs[i]),
-4
View File
@@ -41,7 +41,6 @@
according to jump_pc[T2] */ according to jump_pc[T2] */
/* global register indexes */ /* global register indexes */
static TCGv_env cpu_env;
static TCGv_ptr cpu_regwptr; static TCGv_ptr cpu_regwptr;
static TCGv cpu_cc_src, cpu_cc_src2, cpu_cc_dst; static TCGv cpu_cc_src, cpu_cc_src2, cpu_cc_dst;
static TCGv_i32 cpu_cc_op; static TCGv_i32 cpu_cc_op;
@@ -5911,9 +5910,6 @@ void sparc_tcg_init(void)
unsigned int i; unsigned int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
cpu_regwptr = tcg_global_mem_new_ptr(cpu_env, cpu_regwptr = tcg_global_mem_new_ptr(cpu_env,
offsetof(CPUSPARCState, regwptr), offsetof(CPUSPARCState, regwptr),
"regwptr"); "regwptr");
-3
View File
@@ -33,7 +33,6 @@
#define FMT64X "%016" PRIx64 #define FMT64X "%016" PRIx64
static TCGv_env cpu_env;
static TCGv cpu_pc; static TCGv cpu_pc;
static TCGv cpu_regs[TILEGX_R_COUNT]; static TCGv cpu_regs[TILEGX_R_COUNT];
@@ -2445,8 +2444,6 @@ void tilegx_tcg_init(void)
{ {
int i; int i;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
tcg_ctx->tcg_env = cpu_env;
cpu_pc = tcg_global_mem_new_i64(cpu_env, offsetof(CPUTLGState, pc), "pc"); cpu_pc = tcg_global_mem_new_i64(cpu_env, offsetof(CPUTLGState, pc), "pc");
for (i = 0; i < TILEGX_R_COUNT; i++) { for (i = 0; i < TILEGX_R_COUNT; i++) {
cpu_regs[i] = tcg_global_mem_new_i64(cpu_env, cpu_regs[i] = tcg_global_mem_new_i64(cpu_env,

Some files were not shown because too many files have changed in this diff Show More