Author: David Schneider <[email protected]>
Branch: ppc-jit-backend
Changeset: r49432:d1fa57a9cf80
Date: 2011-11-15 10:34 +0100
http://bitbucket.org/pypy/pypy/changeset/d1fa57a9cf80/

Log:    add a helper method to the register manager to allocate a scratch
        register

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
@@ -86,6 +86,16 @@
             assert isinstance(c, ConstPtr)
             return locations.ImmLocation(rffi.cast(lltype.Signed, c.value))
 
+    def allocate_scratch_reg(self, type=INT, selected_reg=None, 
forbidden_vars=None):
+        """Allocate a scratch register, possibly spilling a managed register.
+        This register is freed after emitting the current operation and can not
+        be spilled"""
+        box = TempBox()
+        reg = self.force_allocate_reg(box,
+                            selected_reg=selected_reg,
+                            forbidden_vars=forbidden_vars)
+        return reg, box
+
 class PPCFrameManager(FrameManager):
     def __init__(self):
         FrameManager.__init__(self)
@@ -170,6 +180,12 @@
         return self.rm.force_allocate_reg(var, forbidden_vars, selected_reg,
                 need_lower_byte)
 
+    def allocate_scratch_reg(self, type=INT, forbidden_vars=[], 
selected_reg=None):
+        assert type == INT # XXX extend this once floats are supported
+        return self.rm.allocate_scratch_reg(type=type,
+                        forbidden_vars=forbidden_vars,
+                        selected_reg=selected_reg)
+
     def _check_invariants(self):
         self.rm._check_invariants()
 
@@ -458,7 +474,6 @@
     def prepare_getarrayitem_gc(self, op):
         a0, a1 = boxes = list(op.getarglist())
         _, scale, ofs, _, ptr = self._unpack_arraydescr(op.getdescr())
-
         base_loc, base_box  = self._ensure_value_is_boxed(a0, boxes)
         boxes.append(base_box)
         ofs_loc, ofs_box = self._ensure_value_is_boxed(a1, boxes)
diff --git a/pypy/jit/backend/ppc/ppcgen/test/test_register_manager.py 
b/pypy/jit/backend/ppc/ppcgen/test/test_register_manager.py
new file mode 100644
--- /dev/null
+++ b/pypy/jit/backend/ppc/ppcgen/test/test_register_manager.py
@@ -0,0 +1,8 @@
+from pypy.jit.backend.ppc.ppcgen import regalloc, register
+
+class TestPPCRegisterManager(object):
+    def test_allocate_scratch_register(self):
+        rm = regalloc.PPCRegisterManager({})
+        reg, box = rm.allocate_scratch_reg()
+        assert reg in register.MANAGED_REGS
+        assert rm.stays_alive(box) == False
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to