[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 07/07: Prevent Lightning from stompling our registers

From: Andy Wingo
Subject: [Guile-commits] 07/07: Prevent Lightning from stompling our registers
Date: Sun, 2 Sep 2018 03:24:26 -0400 (EDT)

wingo pushed a commit to branch lightning
in repository guile.

commit 449ef7d9755b553cb0ad2629bca3bc42c5913e88
Author: Andy Wingo <address@hidden>
Date:   Sun Sep 2 09:21:54 2018 +0200

    Prevent Lightning from stompling our registers
    * libguile/jit.c (emit_exit): Add uses of SP and FP.
 libguile/jit.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/libguile/jit.c b/libguile/jit.c
index 76bb6bb..14efe42 100644
--- a/libguile/jit.c
+++ b/libguile/jit.c
@@ -729,6 +729,36 @@ emit_get_ip_relative_addr (scm_jit_state *j, jit_gpr_t 
dst, jit_gpr_t ip,
 static void
 emit_exit (scm_jit_state *j)
+  /* emit_exit drops back to the interpreter.  As such, it's always used
+     in a context like:
+        mcode = get_mcode
+        if mcode:
+           goto mcode
+        else
+           emit_exit
+     Likewise, this position is usually around calls or returns, where
+     SP and FP are both live.  However!  Lightning has a little register
+     allocator internally which it uses to get temporary registers.  It
+     tracks what registers are used, to avoid clobbering live registers.
+     Often the get_mcode operation looks like
+        jit_ldi (T0, code_loc)
+     But on many architectures, this requires a temporary, and because
+     Lightning doesn't see a use of SP or FP before the goto, it thinks
+     it can use these registers.
+     So, here we insert a bogus dependencies on SP and FP, on the exit
+     path.  On this path they aren't needed, but they should keep the
+     registers live up to the preceding branch, forcing the jit_ldi to
+     choose another temporary to use.  THREAD shouldn't need this
+     treatment as Lightning won't allocate a callee-save register as a
+     temporary, but who knows!
+  */
+  jit_xorr (FP, FP, FP);
+  jit_xorr (SP, SP, SP);
   jit_patch_abs (jit_jmpi (), exit_mcode);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]