@@ -352,6 +352,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
tcg_ctx->guest_mo = TCG_MO_ALL;
#endif
+#if defined(CONFIG_HELPER_TO_TCG) && defined(TARGET_HELPER_DISPATCHER)
+ tcg_ctx->helper_dispatcher = TARGET_HELPER_DISPATCHER;
+#endif
+
restart_translate:
trace_translate_block(tb, pc, tb->tc.ptr);
@@ -549,6 +549,10 @@ struct TCGContext {
/* Exit to translator on overflow. */
sigjmp_buf jmp_trans;
+
+
+ bool (*helper_dispatcher)(void *func, TCGTemp *ret_temp,
+ int nargs, TCGTemp **args);
};
static inline bool temp_readonly(TCGTemp *ts)
@@ -2252,6 +2252,11 @@ static void tcg_gen_callN(void *func, TCGHelperInfo *info,
}
total_args = info->nr_out + info->nr_in + 2;
+ if (unlikely(tcg_ctx->helper_dispatcher) &&
+ tcg_ctx->helper_dispatcher(info->func, ret, total_args, args)) {
+ return;
+ }
+
op = tcg_op_alloc(INDEX_op_call, total_args);
#ifdef CONFIG_PLUGIN
Adds a function pointer to the TCGContext which may be set by targets via the TARGET_HELPER_DISPATCHER macro. The dispatcher is function (void *func, TCGTemp *ret, int nargs, TCGTemp **args) -> bool which allows targets to hook the generation of helper calls in TCG and take over translation. Specifically, this will be used by helper-to-tcg to replace helper function translation, without having to modify frontends. Signed-off-by: Anton Johansson <anjo@rev.ng> --- accel/tcg/translate-all.c | 4 ++++ include/tcg/tcg.h | 4 ++++ tcg/tcg.c | 5 +++++ 3 files changed, 13 insertions(+)