diff mbox series

[02/37] accel/tcg: Build plugin-gen.c once

Message ID 20250313034524.3069690-3-richard.henderson@linaro.org
State New
Headers show
Series accel/tcg, codebase: Build once patches | expand

Commit Message

Richard Henderson March 13, 2025, 3:44 a.m. UTC
We assert that env immediately follows CPUState in cpu-all.h.
Change the offsetof expressions to be based on CPUState instead
of ArchCPU.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 accel/tcg/plugin-gen.c | 13 +++++--------
 accel/tcg/meson.build  |  7 ++++---
 2 files changed, 9 insertions(+), 11 deletions(-)

Comments

Pierrick Bouvier March 13, 2025, 4:46 p.m. UTC | #1
On 3/12/25 20:44, Richard Henderson wrote:
> We assert that env immediately follows CPUState in cpu-all.h.
> Change the offsetof expressions to be based on CPUState instead
> of ArchCPU.
> 

Nice change.
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>

> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   accel/tcg/plugin-gen.c | 13 +++++--------
>   accel/tcg/meson.build  |  7 ++++---
>   2 files changed, 9 insertions(+), 11 deletions(-)
> 
> diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c
> index 7e5f040bf7..c1da753894 100644
> --- a/accel/tcg/plugin-gen.c
> +++ b/accel/tcg/plugin-gen.c
> @@ -22,13 +22,12 @@
>   #include "qemu/osdep.h"
>   #include "qemu/plugin.h"
>   #include "qemu/log.h"
> -#include "cpu.h"
>   #include "tcg/tcg.h"
>   #include "tcg/tcg-temp-internal.h"
> -#include "tcg/tcg-op.h"
> -#include "exec/exec-all.h"
> +#include "tcg/tcg-op-common.h"
>   #include "exec/plugin-gen.h"
>   #include "exec/translator.h"
> +#include "exec/translation-block.h"
>   
>   enum plugin_gen_from {
>       PLUGIN_GEN_FROM_TB,
> @@ -89,15 +88,13 @@ static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb,
>       qemu_plugin_add_dyn_cb_arr(arr);
>   
>       tcg_gen_st_ptr(tcg_constant_ptr((intptr_t)arr), tcg_env,
> -                   offsetof(CPUState, neg.plugin_mem_cbs) -
> -                   offsetof(ArchCPU, env));
> +                   offsetof(CPUState, neg.plugin_mem_cbs) - sizeof(CPUState));
>   }
>   
>   static void gen_disable_mem_helper(void)
>   {
>       tcg_gen_st_ptr(tcg_constant_ptr(0), tcg_env,
> -                   offsetof(CPUState, neg.plugin_mem_cbs) -
> -                   offsetof(ArchCPU, env));
> +                   offsetof(CPUState, neg.plugin_mem_cbs) - sizeof(CPUState));
>   }
>   
>   static TCGv_i32 gen_cpu_index(void)
> @@ -113,7 +110,7 @@ static TCGv_i32 gen_cpu_index(void)
>       }
>       TCGv_i32 cpu_index = tcg_temp_ebb_new_i32();
>       tcg_gen_ld_i32(cpu_index, tcg_env,
> -                   -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index));
> +                   offsetof(CPUState, cpu_index) - sizeof(CPUState));
>       return cpu_index;
>   }
>   
> diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build
> index 14bf797fda..185830d0f5 100644
> --- a/accel/tcg/meson.build
> +++ b/accel/tcg/meson.build
> @@ -3,6 +3,10 @@ common_ss.add(when: 'CONFIG_TCG', if_true: files(
>     'tcg-runtime.c',
>     'tcg-runtime-gvec.c',
>   ))
> +if get_option('plugins')
> +  common_ss.add(when: 'CONFIG_TCG', if_true: files('plugin-gen.c'))
> +endif
> +
>   tcg_specific_ss = ss.source_set()
>   tcg_specific_ss.add(files(
>     'tcg-all.c',
> @@ -12,9 +16,6 @@ tcg_specific_ss.add(files(
>     'translator.c',
>   ))
>   tcg_specific_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-exec.c'))
> -if get_option('plugins')
> -  tcg_specific_ss.add(files('plugin-gen.c'))
> -endif
>   specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_specific_ss)
>   
>   specific_ss.add(when: ['CONFIG_SYSTEM_ONLY', 'CONFIG_TCG'], if_true: files(
Alex Bennée March 13, 2025, 10:57 p.m. UTC | #2
Richard Henderson <richard.henderson@linaro.org> writes:

> We assert that env immediately follows CPUState in cpu-all.h.
> Change the offsetof expressions to be based on CPUState instead
> of ArchCPU.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
diff mbox series

Patch

diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c
index 7e5f040bf7..c1da753894 100644
--- a/accel/tcg/plugin-gen.c
+++ b/accel/tcg/plugin-gen.c
@@ -22,13 +22,12 @@ 
 #include "qemu/osdep.h"
 #include "qemu/plugin.h"
 #include "qemu/log.h"
-#include "cpu.h"
 #include "tcg/tcg.h"
 #include "tcg/tcg-temp-internal.h"
-#include "tcg/tcg-op.h"
-#include "exec/exec-all.h"
+#include "tcg/tcg-op-common.h"
 #include "exec/plugin-gen.h"
 #include "exec/translator.h"
+#include "exec/translation-block.h"
 
 enum plugin_gen_from {
     PLUGIN_GEN_FROM_TB,
@@ -89,15 +88,13 @@  static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb,
     qemu_plugin_add_dyn_cb_arr(arr);
 
     tcg_gen_st_ptr(tcg_constant_ptr((intptr_t)arr), tcg_env,
-                   offsetof(CPUState, neg.plugin_mem_cbs) -
-                   offsetof(ArchCPU, env));
+                   offsetof(CPUState, neg.plugin_mem_cbs) - sizeof(CPUState));
 }
 
 static void gen_disable_mem_helper(void)
 {
     tcg_gen_st_ptr(tcg_constant_ptr(0), tcg_env,
-                   offsetof(CPUState, neg.plugin_mem_cbs) -
-                   offsetof(ArchCPU, env));
+                   offsetof(CPUState, neg.plugin_mem_cbs) - sizeof(CPUState));
 }
 
 static TCGv_i32 gen_cpu_index(void)
@@ -113,7 +110,7 @@  static TCGv_i32 gen_cpu_index(void)
     }
     TCGv_i32 cpu_index = tcg_temp_ebb_new_i32();
     tcg_gen_ld_i32(cpu_index, tcg_env,
-                   -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index));
+                   offsetof(CPUState, cpu_index) - sizeof(CPUState));
     return cpu_index;
 }
 
diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build
index 14bf797fda..185830d0f5 100644
--- a/accel/tcg/meson.build
+++ b/accel/tcg/meson.build
@@ -3,6 +3,10 @@  common_ss.add(when: 'CONFIG_TCG', if_true: files(
   'tcg-runtime.c',
   'tcg-runtime-gvec.c',
 ))
+if get_option('plugins')
+  common_ss.add(when: 'CONFIG_TCG', if_true: files('plugin-gen.c'))
+endif
+
 tcg_specific_ss = ss.source_set()
 tcg_specific_ss.add(files(
   'tcg-all.c',
@@ -12,9 +16,6 @@  tcg_specific_ss.add(files(
   'translator.c',
 ))
 tcg_specific_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-exec.c'))
-if get_option('plugins')
-  tcg_specific_ss.add(files('plugin-gen.c'))
-endif
 specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_specific_ss)
 
 specific_ss.add(when: ['CONFIG_SYSTEM_ONLY', 'CONFIG_TCG'], if_true: files(