Author: hager <sven.ha...@uni-duesseldorf.de>
Branch: ppc-jit-backend
Changeset: r50753:99496f3054f6
Date: 2011-12-20 15:28 +0100
http://bitbucket.org/pypy/pypy/changeset/99496f3054f6/

Log:    (arigo, hager): Reconsider spilling in PPC

diff --git a/pypy/jit/backend/ppc/ppcgen/arch.py 
b/pypy/jit/backend/ppc/ppcgen/arch.py
--- a/pypy/jit/backend/ppc/ppcgen/arch.py
+++ b/pypy/jit/backend/ppc/ppcgen/arch.py
@@ -1,7 +1,8 @@
 # Constants that depend on whether we are on 32-bit or 64-bit
 
 from pypy.jit.backend.ppc.ppcgen.register import (NONVOLATILES,
-                                                  NONVOLATILES_FLOAT)
+                                                  NONVOLATILES_FLOAT,
+                                                  MANAGED_REGS)
 
 import sys
 if sys.maxint == (2**31 - 1):
@@ -22,3 +23,5 @@
 FPR_SAVE_AREA           = len(NONVOLATILES_FLOAT) * DWORD
 FLOAT_INT_CONVERSION    = WORD
 MAX_REG_PARAMS          = 8
+
+FORCE_INDEX_OFS         = len(MANAGED_REGS) * WORD
diff --git a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py 
b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
--- a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
+++ b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
@@ -185,7 +185,8 @@
 
                 spilling_pointer is the address of the FORCE_INDEX.
             """
-            return self.decode_registers_and_descr(mem_loc, stack_pointer, 
spilling_pointer)
+            return self.decode_registers_and_descr(mem_loc, stack_pointer,
+                    spilling_pointer)
 
         self.failure_recovery_func = failure_recovery_func
 
@@ -201,10 +202,7 @@
             '''
         enc = rffi.cast(rffi.CCHARP, mem_loc)
         managed_size = WORD * len(r.MANAGED_REGS)
-        # XXX do some sanity considerations
-        spilling_depth = spp_loc - stack_loc + managed_size
-        spilling_area = rffi.cast(rffi.CCHARP, stack_loc + managed_size)
-        assert spilling_depth >= 0
+
         assert spp_loc > stack_loc
 
         regs = rffi.cast(rffi.CCHARP, spp_loc)
@@ -235,7 +233,8 @@
                 if group == self.FLOAT_TYPE:
                     assert 0, "not implemented yet"
                 else:
-                    value = decode32(spilling_area, spilling_depth - 
stack_location * WORD)
+                    start = spp_loc - (stack_location + 1) * WORD
+                    value = rffi.cast(rffi.LONGP, start)[0]
             else: # REG_LOC
                 reg = ord(enc[i])
                 if group == self.FLOAT_TYPE:
@@ -669,12 +668,15 @@
             if op.has_no_side_effect() and op.result not in regalloc.longevity:
                 regalloc.possibly_free_vars_for_op(op)
             elif self.can_merge_with_next_guard(op, pos, operations)\
-                    and opnum in (rop.CALL_RELEASE_GIL, rop.CALL_ASSEMBLER):  
# XXX fix  
+                    and opnum in (rop.CALL_RELEASE_GIL, rop.CALL_ASSEMBLER,\
+                    rop.CALL_MAY_FORCE):  # XXX fix  
                 regalloc.next_instruction()
                 arglocs = regalloc.operations_with_guard[opnum](regalloc, op,
                                         operations[pos+1])
                 operations_with_guard[opnum](self, op,
                                         operations[pos+1], arglocs, regalloc)
+            elif not we_are_translated() and op.getopnum() == -124:
+                regalloc.prepare_force_spill(op)
             else:
                 arglocs = regalloc.operations[opnum](regalloc, op)
                 if arglocs is not None:
@@ -756,14 +758,14 @@
             tok.pos_recovery_stub = pos 
 
             memaddr = self.gen_exit_stub(descr, tok.failargs,
-                                            tok.faillocs, 
save_exc=tok.save_exc)
+                                            tok.faillocs,
+                                            save_exc=tok.save_exc)
             # store info on the descr
             descr._ppc_frame_depth = tok.faillocs[0].getint()
             descr._failure_recovery_code = memaddr
             descr._ppc_guard_pos = pos
 
-    def gen_exit_stub(self, descr, args, arglocs, fcond=c.NE,
-                               save_exc=False):
+    def gen_exit_stub(self, descr, args, arglocs, save_exc=False):
         memaddr = self.gen_descr_encoding(descr, args, arglocs)
 
         # store addr in force index field
diff --git a/pypy/jit/backend/ppc/ppcgen/regalloc.py 
b/pypy/jit/backend/ppc/ppcgen/regalloc.py
--- a/pypy/jit/backend/ppc/ppcgen/regalloc.py
+++ b/pypy/jit/backend/ppc/ppcgen/regalloc.py
@@ -100,7 +100,7 @@
 class PPCFrameManager(FrameManager):
     def __init__(self):
         FrameManager.__init__(self)
-        self.frame_depth = 1
+        self.frame_depth = 0
 
     @staticmethod
     def frame_pos(loc, type):
@@ -865,6 +865,10 @@
         assert (1 << scale) == size
         return size, scale, ofs, ofs_length, ptr
 
+    def prepare_force_spill(self, op):
+        self.force_spill_var(op.getarg(0))
+        return []
+
 def add_none_argument(fn):
     return lambda self, op: fn(self, op, None)
 
diff --git a/pypy/jit/backend/ppc/runner.py b/pypy/jit/backend/ppc/runner.py
--- a/pypy/jit/backend/ppc/runner.py
+++ b/pypy/jit/backend/ppc/runner.py
@@ -6,7 +6,7 @@
 from pypy.jit.metainterp import history, compile
 from pypy.jit.metainterp.history import BoxPtr
 from pypy.jit.backend.x86.assembler import Assembler386
-from pypy.jit.backend.x86.arch import FORCE_INDEX_OFS
+from pypy.jit.backend.ppc.ppcgen.arch import FORCE_INDEX_OFS
 from pypy.jit.backend.x86.profagent import ProfileAgent
 from pypy.jit.backend.llsupport.llmodel import AbstractLLCPU
 from pypy.jit.backend.x86 import regloc
diff --git a/pypy/jit/backend/test/runner_test.py 
b/pypy/jit/backend/test/runner_test.py
--- a/pypy/jit/backend/test/runner_test.py
+++ b/pypy/jit/backend/test/runner_test.py
@@ -540,6 +540,21 @@
         result = self.cpu.get_latest_value_ref(0)
         assert result == u_box.value
 
+    def test_spilling(self):
+        ops = '''
+        [i0]
+        force_spill(i0)
+        finish(i0)
+        '''
+        loop = parse(ops, namespace=locals())
+        looptoken = LoopToken()
+        self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
+        
+        self.cpu.set_future_value_int(0, 42)
+        fail = self.cpu.execute_token(looptoken)
+        result = self.cpu.get_latest_value_int(0)
+        assert result == 42
+
     def test_bh_call(self):
         cpu = self.cpu
         #
@@ -632,6 +647,7 @@
                                          'float', descr=calldescr)
             assert abs(res.getfloat() - 4.6) < 0.0001
 
+
     def test_call_many_arguments(self):
         # Test calling a function with a large number of arguments (more than
         # 6, which will force passing some arguments on the stack on 64-bit)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to