[pypy-svn] pypy arm-backend-2: implement redirect_call_assembler

bivab commits-noreply at bitbucket.org
Wed Feb 2 13:50:32 CET 2011


Author: David Schneider <david.schneider at picle.org>
Branch: arm-backend-2
Changeset: r41556:1743ab839eb9
Date: 2011-01-30 17:24 +0100
http://bitbucket.org/pypy/pypy/changeset/1743ab839eb9/

Log:	implement redirect_call_assembler

diff --git a/pypy/jit/backend/arm/runner.py b/pypy/jit/backend/arm/runner.py
--- a/pypy/jit/backend/arm/runner.py
+++ b/pypy/jit/backend/arm/runner.py
@@ -105,3 +105,6 @@
         # end of "no gc operation!" block
         assert fail_index == fail_index_2
         return faildescr
+
+    def redirect_call_assembler(self, oldlooptoken, newlooptoken):
+        self.assembler.redirect_call_assembler(oldlooptoken, newlooptoken)

diff --git a/pypy/jit/backend/arm/opassembler.py b/pypy/jit/backend/arm/opassembler.py
--- a/pypy/jit/backend/arm/opassembler.py
+++ b/pypy/jit/backend/arm/opassembler.py
@@ -719,6 +719,17 @@
             regalloc.possibly_free_var(op.result)
         return fcond
 
+    # ../x86/assembler.py:668
+    def redirect_call_assembler(self, oldlooptoken, newlooptoken):
+        # we overwrite the instructions at the old _x86_direct_bootstrap_code
+        # to start with a JMP to the new _x86_direct_bootstrap_code.
+        # Ideally we should rather patch all existing CALLs, but well.
+        oldadr = oldlooptoken._arm_direct_bootstrap_code
+        target = newlooptoken._arm_direct_bootstrap_code
+        mc = ARMv7Builder()
+        mc.B(target)
+        mc.copy_to_raw_memory(oldadr)
+
     def emit_guard_call_may_force(self, op, guard_op, arglocs, regalloc, fcond):
         self.mc.LDR_ri(r.ip.value, r.fp.value)
         self.mc.CMP_ri(r.ip.value, 0)

diff --git a/pypy/jit/backend/arm/test/test_runner.py b/pypy/jit/backend/arm/test/test_runner.py
--- a/pypy/jit/backend/arm/test/test_runner.py
+++ b/pypy/jit/backend/arm/test/test_runner.py
@@ -11,6 +11,9 @@
                                          BoxObj, Const,
                                          ConstObj, BoxFloat, ConstFloat)
 from pypy.jit.metainterp.resoperation import ResOperation, rop
+from pypy.jit.tool.oparser import parse
+from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.annlowlevel import llhelper
 
 skip_unless_arm()
 
@@ -55,3 +58,46 @@
 
     def test_cond_call_gc_wb(self, *args):
         py.test.skip('needs gc support')
+
+    def test_redirect_call_assember(self):
+        called = []
+        def assembler_helper(failindex, virtualizable):
+            return self.cpu.get_latest_value_int(0)
+
+        FUNCPTR = lltype.Ptr(lltype.FuncType([lltype.Signed, llmemory.GCREF],
+                                             lltype.Signed))
+        class FakeJitDriverSD:
+            index_of_virtualizable = -1
+            _assembler_helper_ptr = llhelper(FUNCPTR, assembler_helper)
+            assembler_helper_adr = llmemory.cast_ptr_to_adr(
+                _assembler_helper_ptr)
+
+        lt1, lt2, lt3 = [LoopToken() for x in range(3)]
+        lt2.outermost_jitdriver_sd = FakeJitDriverSD()
+        loop1 = parse('''
+        [i0]
+        i1 = call_assembler(i0, descr=lt2)
+        guard_not_forced()[]
+        finish(i1)
+        ''', namespace=locals())
+        loop2 = parse('''
+        [i0]
+        i1 = int_add(i0, 1)
+        finish(i1)
+        ''')
+        loop3 = parse('''
+        [i0]
+        i1 = int_sub(i0, 1)
+        finish(i1)
+        ''')
+        self.cpu.compile_loop(loop2.inputargs, loop2.operations, lt2)
+        self.cpu.compile_loop(loop3.inputargs, loop3.operations, lt3)
+        self.cpu.compile_loop(loop1.inputargs, loop1.operations, lt1)
+        self.cpu.set_future_value_int(0, 11)
+        res = self.cpu.execute_token(lt1)
+        assert self.cpu.get_latest_value_int(0) == 12
+
+        self.cpu.redirect_call_assembler(lt2, lt3)
+        self.cpu.set_future_value_int(0, 11)
+        res = self.cpu.execute_token(lt1)
+        assert self.cpu.get_latest_value_int(0) == 10


More information about the Pypy-commit mailing list