[PATCH v2 02/50] accel/tcg: Add getpc helper

Anton Johansson via qemu development <[email protected]>
Newsgroups gmane.comp.emulators.qemu
Message-ID <[email protected]>
Introduces a helper function to return the current pc (returnaddress of
the helper), this allows helper-to-tcg to correctly translate nested
helper functions that checks for faulting memory operations.

This is useful as an optimization where a helper functions has a
commonly taken fast path that doesn't fault e.g.

  void HELPER(outer)(...)
  {
      ... // non faulting operations
      if (some_uncommon_condition) {
          helper_inner(..., GETPC())
      }
  }

the outer helper along with the condition can then be emitted as TCG,
and helper_inner() will be emitted as a gen_helper_inner(, ra), where ra
is the result of gen_helper_getpc().

NOTE: This is not ideal since we're introducing extra helper calls,
      and the solution doesn't deal with the "inner" function not being
      a helper.  A better solution and what we'll probably do in the
      next version of the patchset is to instead emit a helper
      definition for the "inner" function that uses GETPC().

Signed-off-by: Anton Johansson <[email protected]>
---
 accel/tcg/tcg-runtime.c | 5 +++++
 accel/tcg/tcg-runtime.h | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/accel/tcg/tcg-runtime.c b/accel/tcg/tcg-runtime.c
index d42c00736b..87b9530a50 100644
--- a/accel/tcg/tcg-runtime.c
+++ b/accel/tcg/tcg-runtime.c
@@ -162,3 +162,8 @@ void HELPER(exit_atomic)(CPUArchState *env)
 {
     cpu_loop_exit_atomic(env_cpu(env), GETPC());
 }
+
+uint64_t HELPER(getpc)(void)
+{
+    return GETPC();
+}
diff --git a/accel/tcg/tcg-runtime.h b/accel/tcg/tcg-runtime.h
index 197d658b40..e25712d1fc 100644
--- a/accel/tcg/tcg-runtime.h
+++ b/accel/tcg/tcg-runtime.h
@@ -30,6 +30,8 @@ DEF_HELPER_FLAGS_1(lookup_tb_ptr, TCG_CALL_NO_WG_SE, cptr, env)
 
 DEF_HELPER_FLAGS_1(exit_atomic, TCG_CALL_NO_WG, noreturn, env)
 
+DEF_HELPER_FLAGS_0(getpc, TCG_CALL_NO_RWG_SE, i64)
+
 #ifndef IN_HELPER_PROTO
 /*
  * Pass calls to memset directly to libc, without a thunk in qemu.
-- 
2.52.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.