[pypy-svn] r69908 - in pypy/branch/virtual-forcing/pypy/jit: backend metainterp metainterp/test

arigo at codespeak.net arigo at codespeak.net
Fri Dec 4 21:58:42 CET 2009


Author: arigo
Date: Fri Dec  4 21:58:40 2009
New Revision: 69908

Modified:
   pypy/branch/virtual-forcing/pypy/jit/backend/model.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/executor.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/optimizeopt.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_optimizefindnode.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_optimizeopt.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_pyjitpl.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/vref.py
Log:
Use the phase of optimizeopt.py to replace the VIRTUAL_REF
operation with a real structure of type vref.JIT_VIRTUAL_REF.
Small other fixes left and right.


Modified: pypy/branch/virtual-forcing/pypy/jit/backend/model.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/backend/model.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/backend/model.py	Fri Dec  4 21:58:40 2009
@@ -219,10 +219,6 @@
     def do_cast_ptr_to_int(self, ptrbox):
         raise NotImplementedError
 
-    def do_force_token(self):
-        # this should not be implemented at all by the backends
-        raise NotImplementedError
-
     def do_call_may_force(self, args, calldescr):
         return self.do_call(args, calldescr)
 

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/executor.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/executor.py	Fri Dec  4 21:58:40 2009
@@ -103,9 +103,6 @@
 def do_same_as(cpu, box1):
     return box1
 
-def do_virtual_ref(cpu, box1):
-    return box1.clonebox()
-
 def do_oois(cpu, box1, box2):
     tp = box1.type
     assert tp == box2.type
@@ -223,6 +220,12 @@
 
 # ____________________________________________________________
 
+def do_force_token(cpu):
+    raise NotImplementedError
+
+def do_virtual_ref(cpu, box1):
+    raise NotImplementedError
+
 def do_debug_merge_point(cpu, box1):
     from pypy.jit.metainterp.warmspot import get_stats
     loc = box1._get_str()

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/optimizeopt.py	Fri Dec  4 21:58:40 2009
@@ -736,6 +736,26 @@
     def optimize_OOIS(self, op):
         self._optimize_oois_ooisnot(op, False)
 
+    def optimize_VIRTUAL_REF(self, op):
+        value = self.getvalue(op.args[0])
+        if not value.is_virtual():   # virtual_ref(non-virtual) gives bad
+            raise compile.GiveUp     # results, so don't bother compiling it
+        #
+        # get some constants (these calls are all 'memo')
+        from pypy.jit.metainterp import vref
+        c_cls = vref.get_jit_virtual_ref_const_class(self.cpu)
+        descr_virtual_token = vref.get_descr_virtual_token(self.cpu)
+        descr_forced = vref.get_descr_forced(self.cpu)
+        #
+        # Replace the VIRTUAL_REF operation with a virtual structure of type
+        # 'vref.JIT_VIRTUAL_REF'.  The virtual structure may be forced soon,
+        # but the point is that doing so does not force the original structure.
+        op = ResOperation(rop.NEW_WITH_VTABLE, [c_cls], op.result)
+        vrefvalue = self.make_virtual(c_cls, op.result, op)
+        tokenbox = BoxInt()
+        self.emit_operation(ResOperation(rop.FORCE_TOKEN, [], tokenbox))
+        vrefvalue.setfield(descr_virtual_token, self.getvalue(tokenbox))
+
     def optimize_GETFIELD_GC(self, op):
         value = self.getvalue(op.args[0])
         if value.is_virtual():

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py	Fri Dec  4 21:58:40 2009
@@ -1775,8 +1775,8 @@
     def virtual_after_residual_call(self):
         if self.is_blackholing():
             return
-        for gcref in self.all_virtual_refs:
-            if vref.was_forced(gcref):
+        for vr in self.all_virtual_refs:
+            if vref.was_forced(vr):
                 break
         else:
             return

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_optimizefindnode.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_optimizefindnode.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_optimizefindnode.py	Fri Dec  4 21:58:40 2009
@@ -99,6 +99,12 @@
     nonwritedescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([], []))
     writeadescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([adescr], []))
     writearraydescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([adescr], [arraydescr]))
+    mayforcevirtdescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
+                 EffectInfo([], [], forces_virtual_or_virtualizable=True))
+
+    from pypy.jit.metainterp.vref import jit_virtual_ref_vtable
+    from pypy.jit.metainterp.vref import JIT_VIRTUAL_REF
+    virtualtokendescr = cpu.fielddescrof(JIT_VIRTUAL_REF, 'virtual_token')
 
     cpu.class_sizes = {cpu.cast_adr_to_int(node_vtable_adr): cpu.sizeof(NODE),
                       cpu.cast_adr_to_int(node_vtable_adr2): cpu.sizeof(NODE2),

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_optimizeopt.py	Fri Dec  4 21:58:40 2009
@@ -2031,6 +2031,43 @@
         """
         self.optimize_loop(ops, 'Not, Not, Not', expected)
 
+    def test_vref_nonvirtual(self):
+        ops = """
+        [p1]
+        p2 = virtual_ref(p1)
+        jump(p1)
+        """
+        py.test.raises(compile.GiveUp, self.optimize_loop, ops, 'Not', ops)
+
+    def test_vref_virtual_1(self):
+        ops = """
+        [p0, i1]
+        #
+        p1 = new_with_vtable(ConstClass(node_vtable))
+        p1b = new_with_vtable(ConstClass(node_vtable))
+        setfield_gc(p1b, 252, descr=valuedescr)
+        setfield_gc(p1, p1b, descr=nextdescr)
+        #
+        p2 = virtual_ref(p1)
+        setfield_gc(p0, p2, descr=nextdescr)
+        call_may_force(i1, descr=mayforcevirtdescr)
+        guard_not_forced() [i1]
+        setfield_gc(p0, NULL, descr=nextdescr)
+        jump(p0, i1)
+        """
+        expected = """
+        [p0, i1]
+        i3 = force_token()
+        p2 = new_with_vtable(ConstClass(jit_virtual_ref_vtable))
+        setfield_gc(p2, i3, descr=virtualtokendescr)
+        setfield_gc(p0, p2, descr=nextdescr)
+        call_may_force(i1, descr=mayforcevirtdescr)
+        guard_not_forced() [i1]
+        setfield_gc(p0, NULL, descr=nextdescr)
+        jump(p0, i1)
+        """
+        self.optimize_loop(ops, 'Not, Not', expected)
+
 
 class TestOOtype(BaseTestOptimizeOpt, OOtypeMixin):
 

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_pyjitpl.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_pyjitpl.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_pyjitpl.py	Fri Dec  4 21:58:40 2009
@@ -33,7 +33,8 @@
 def test_simple_opimpl_exist():
     rop = resoperation.rop
     for opnum, opname in resoperation.opname.items():
-        if opnum in (rop.SAME_AS, rop.CALL_PURE, rop.OOSEND_PURE):
+        if opnum in (rop.SAME_AS, rop.CALL_PURE, rop.OOSEND_PURE,
+                     rop.FORCE_TOKEN):
             continue
         if rop._NOSIDEEFFECT_FIRST <= opnum <= rop._NOSIDEEFFECT_LAST:
             assert hasattr(pyjitpl.MIFrame, 'opimpl_' + opname.lower()), opname

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/vref.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/vref.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/vref.py	Fri Dec  4 21:58:40 2009
@@ -1,5 +1,7 @@
 from pypy.rpython.rmodel import inputconst, log
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi, rclass
+from pypy.rlib.objectmodel import specialize
+from pypy.jit.metainterp import history
 
 
 def replace_force_virtual_with_call(make_helper_func, graphs):
@@ -46,6 +48,19 @@
 TOKEN_NONE    = 0
 TOKEN_TRACING = -1
 
+ at specialize.memo()
+def get_jit_virtual_ref_const_class(cpu):
+    adr = llmemory.cast_ptr_to_adr(jit_virtual_ref_vtable)
+    return history.ConstAddr(adr, cpu)
+
+ at specialize.memo()
+def get_descr_virtual_token(cpu):
+    return cpu.fielddescrof(JIT_VIRTUAL_REF, 'virtual_token')
+
+ at specialize.memo()
+def get_descr_forced(cpu):
+    return cpu.fielddescrof(JIT_VIRTUAL_REF, 'forced')
+
 def virtual_ref_during_tracing(real_object):
     assert real_object
     vref = lltype.malloc(JIT_VIRTUAL_REF)



More information about the Pypy-commit mailing list