aboutsummaryrefslogtreecommitdiff
path: root/accel/tcg/plugin-gen.c
diff options
context:
space:
mode:
Diffstat (limited to 'accel/tcg/plugin-gen.c')
-rw-r--r--accel/tcg/plugin-gen.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c
index 1ef0755..7e5f040 100644
--- a/accel/tcg/plugin-gen.c
+++ b/accel/tcg/plugin-gen.c
@@ -102,6 +102,15 @@ static void gen_disable_mem_helper(void)
static TCGv_i32 gen_cpu_index(void)
{
+ /*
+ * Optimize when we run with a single vcpu. All values using cpu_index,
+ * including scoreboard index, will be optimized out.
+ * User-mode calls tb_flush when setting this flag. In system-mode, all
+ * vcpus are created before generating code.
+ */
+ if (!tcg_cflags_has(current_cpu, CF_PARALLEL)) {
+ return tcg_constant_i32(current_cpu->cpu_index);
+ }
TCGv_i32 cpu_index = tcg_temp_ebb_new_i32();
tcg_gen_ld_i32(cpu_index, tcg_env,
-offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index));