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

arigo at codespeak.net arigo at codespeak.net
Thu Dec 3 22:16:26 CET 2009


Author: arigo
Date: Thu Dec  3 22:16:25 2009
New Revision: 69881

Modified:
   pypy/branch/virtual-forcing/pypy/jit/backend/test/runner_test.py
   pypy/branch/virtual-forcing/pypy/jit/backend/x86/assembler.py
   pypy/branch/virtual-forcing/pypy/jit/backend/x86/regalloc.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/codewriter.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/executor.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/resoperation.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_codewriter.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_vref.py
Log:
Step 1: implement rop.VIRTUAL_REF as a SAME_AS operation everywhere.


Modified: pypy/branch/virtual-forcing/pypy/jit/backend/test/runner_test.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/backend/test/runner_test.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/backend/test/runner_test.py	Thu Dec  3 22:16:25 2009
@@ -779,6 +779,12 @@
             r = self.execute_operation(rop.SAME_AS, [BoxFloat(5.5)], 'float')
             assert r.value == 5.5
 
+    def test_virtual_ref(self):
+        # if VIRTUAL_REF reaches the backend, it should just be a SAME_AS
+        u_box = self.alloc_unicode(u"hello\u1234")
+        r = self.execute_operation(rop.VIRTUAL_REF, [u_box], 'ref')
+        assert r.value == u_box.value
+
     def test_jump(self):
         # this test generates small loops where the JUMP passes many
         # arguments of various types, shuffling them around.

Modified: pypy/branch/virtual-forcing/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/backend/x86/assembler.py	Thu Dec  3 22:16:25 2009
@@ -506,6 +506,7 @@
     def genop_same_as(self, op, arglocs, resloc):
         self.mov(arglocs[0], resloc)
     genop_cast_ptr_to_int = genop_same_as
+    genop_virtual_ref = genop_same_as
 
     def genop_int_mod(self, op, arglocs, resloc):
         self.mc.CDQ()

Modified: pypy/branch/virtual-forcing/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/backend/x86/regalloc.py	Thu Dec  3 22:16:25 2009
@@ -869,6 +869,7 @@
         resloc = self.force_allocate_reg(op.result)
         self.Perform(op, [argloc], resloc)
     consider_cast_ptr_to_int = consider_same_as
+    consider_virtual_ref = consider_same_as
 
     def consider_strlen(self, op, ignored):
         base_loc = self.rm.make_sure_var_in_reg(op.args[0], op.args)

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/codewriter.py	Thu Dec  3 22:16:25 2009
@@ -1571,6 +1571,10 @@
         assert vinfo.is_vtypeptr(op.args[0].concretetype)
         self.vable_flags[op.args[0]] = op.args[2].value
 
+    def serialize_op_jit_force_virtual(self, op):
+        raise ForcingVirtualRef("forcing a virtual_ref, i.e. calling it, "
+                                "should not be seen by the JIT")
+
     serialize_op_oostring  = handle_builtin_call
     serialize_op_oounicode = handle_builtin_call
     serialize_op_gc_identityhash = handle_builtin_call
@@ -1696,3 +1700,6 @@
     def __str__(self):
         return "using virtualizable array in illegal way in %r" % (
             self.args[0],)
+
+class ForcingVirtualRef(Exception):
+    pass

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	Thu Dec  3 22:16:25 2009
@@ -103,6 +103,9 @@
 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

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	Thu Dec  3 22:16:25 2009
@@ -238,7 +238,7 @@
     for _opimpl in ['int_is_true', 'int_neg', 'int_invert', 'bool_not',
                     'cast_ptr_to_int', 'cast_float_to_int',
                     'cast_int_to_float', 'float_neg', 'float_abs',
-                    'float_is_true',
+                    'float_is_true', 'virtual_ref',
                     ]:
         exec py.code.Source('''
             @arguments("box")

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/resoperation.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/resoperation.py	Thu Dec  3 22:16:25 2009
@@ -206,6 +206,7 @@
     'NEW_WITH_VTABLE/1',
     'NEW_ARRAY/1d',
     'FORCE_TOKEN/0',
+    'VIRTUAL_REF/1',
     '_NOSIDEEFFECT_LAST', # ----- end of no_side_effect operations -----
 
     'SETARRAYITEM_GC/3d',

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_codewriter.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_codewriter.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_codewriter.py	Thu Dec  3 22:16:25 2009
@@ -2,7 +2,7 @@
 from pypy.rlib import jit
 from pypy.jit.metainterp import support, typesystem
 from pypy.jit.metainterp.policy import JitPolicy
-from pypy.jit.metainterp.codewriter import CodeWriter
+from pypy.jit.metainterp.codewriter import CodeWriter, ForcingVirtualRef
 from pypy.jit.metainterp.test.test_basic import LLJitMixin, OOJitMixin
 from pypy.translator.translator import graphof
 from pypy.rpython.lltypesystem.rbuiltin import ll_instantiate
@@ -448,6 +448,21 @@
         jitcode = cw.make_one_bytecode((graphs[0], None), False)
         assert 'virtual_ref' in jitcode._source
 
+    def test_vref_forced(self):
+        class X:
+            pass
+        def f():
+            vref = jit.virtual_ref(X())
+            return vref()
+        graphs = self.make_graphs(f, [])
+        assert graphs[0].func is f
+        assert graphs[1].func is jit.virtual_ref
+        cw = CodeWriter(self.rtyper)
+        cw.candidate_graphs = [graphs[0]]
+        cw._start(self.metainterp_sd, None)
+        py.test.raises(ForcingVirtualRef, cw.make_one_bytecode,
+                       (graphs[0], None), False)    # assert it does not work
+
 
 class ImmutableFieldsTests:
 

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_vref.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_vref.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_vref.py	Thu Dec  3 22:16:25 2009
@@ -5,6 +5,21 @@
 
 class VRefTests:
 
+    def test_make_vref_simple(self):
+        class X:
+            pass
+        class ExCtx:
+            pass
+        exctx = ExCtx()
+        #
+        def f():
+            exctx.topframeref = virtual_ref(X())
+            exctx.topframeref = None
+            return 1
+        #
+        self.interp_operations(f, [])
+        self.check_operations_history(virtual_ref=1)
+
     def test_simple_no_access(self):
         myjitdriver = JitDriver(greens = [], reds = ['n'])
         #



More information about the Pypy-commit mailing list