[pypy-svn] r74643 - in pypy/branch/blackhole-improvement/pypy/jit: codewriter codewriter/test metainterp

arigo at codespeak.net arigo at codespeak.net
Fri May 21 18:44:13 CEST 2010


Author: arigo
Date: Fri May 21 18:44:11 2010
New Revision: 74643

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/codewriter.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_call.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py
Log:
Port a first test about virtualrefs.


Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/call.py	Fri May 21 18:44:11 2010
@@ -15,6 +15,7 @@
 
 
 class CallControl(object):
+    virtualref_info = None  # optionally set from outside to a VirtualRefInfo()
 
     def __init__(self, cpu=None, portal_graph=None):
         self.cpu = cpu

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/codewriter.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/codewriter.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/codewriter.py	Fri May 21 18:44:11 2010
@@ -68,6 +68,9 @@
             self.transform_graph_to_jitcode(graph, jitcode,
                                             graph is maingraph, verbose)
 
+    def setup_vrefinfo(self, vrefinfo):
+        self.callcontrol.virtualref_info = vrefinfo
+
     def find_all_graphs(self, policy):
         return self.callcontrol.find_all_graphs(policy)
 

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py	Fri May 21 18:44:11 2010
@@ -288,9 +288,18 @@
 
     def handle_builtin_call(self, op):
         oopspec_name, args = support.decode_builtin_call(op)
+        if oopspec_name.startswith('virtual_ref'):
+            return self._handle_virtual_ref_call(op, oopspec_name, args)
         op1 = self._prepare_builtin_call(op, oopspec_name, args)
         return self.handle_residual_call(op1)
 
+    def _handle_virtual_ref_call(self, op, oopspec_name, args):
+        vrefinfo = self.callcontrol.virtualref_info
+        heaptracker.register_known_gctype(self.cpu,
+                                          vrefinfo.jit_virtual_ref_vtable,
+                                          vrefinfo.JIT_VIRTUAL_REF)
+        return SpaceOperation(oopspec_name, list(args), op.result)
+
     handle_residual_indirect_call = handle_residual_call
 
     def handle_regular_indirect_call(self, op):

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_call.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_call.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_call.py	Fri May 21 18:44:11 2010
@@ -146,3 +146,8 @@
     assert jitcode.name == "foo"
     pending = list(cc.enum_pending_graphs())
     assert pending == [(somegraph, jitcode)]
+
+# ____________________________________________________________
+
+def test_jit_force_virtualizable_effectinfo():
+    py.test.skip("XXX add a test for CallControl.getcalldescr() -> EF_xxx")

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py	Fri May 21 18:44:11 2010
@@ -10,6 +10,7 @@
 from pypy.rlib.rarithmetic import ovfcheck
 from pypy.rlib.jit import dont_look_inside, _we_are_jitted, JitDriver
 from pypy.rlib.objectmodel import keepalive_until_here
+from pypy.rlib import jit
 
 
 class FakeRegAlloc:
@@ -23,6 +24,11 @@
             self.num_colors += 1
         return self.seen[v]
 
+def fake_regallocs():
+    return {'int': FakeRegAlloc(),
+            'ref': FakeRegAlloc(),
+            'float': FakeRegAlloc()}
+
 class FakeDescr(AbstractDescr):
     def __repr__(self):
         return '<Descr>'
@@ -38,11 +44,14 @@
     _builtin_func_for_spec_cache = FakeDict()
 
 class FakeCPU:
-    rtyper = FakeRTyper()
+    def __init__(self, rtyper):
+        self.rtyper = rtyper
     def calldescrof(self, FUNC, ARGS, RESULT):
         return FakeDescr()
     def fielddescrof(self, STRUCT, name):
         return FakeDescr()
+    def sizeof(self, STRUCT):
+        return FakeDescr()
 
 class FakeCallControl:
     _descr_cannot_raise = FakeDescr()
@@ -60,10 +69,15 @@
     def found_jitdriver(self, jitdriver):
         assert isinstance(jitdriver, JitDriver)
 
-def fake_regallocs():
-    return {'int': FakeRegAlloc(),
-            'ref': FakeRegAlloc(),
-            'float': FakeRegAlloc()}
+class FakeCallControlWithVRefInfo:
+    class virtualref_info:
+        JIT_VIRTUAL_REF = lltype.GcStruct('VREF', ('parent', rclass.OBJECT))
+        jit_virtual_ref_vtable = lltype.malloc(rclass.OBJECT_VTABLE,
+                                               immortal=True)
+    def guess_call_kind(self, op):
+        return 'builtin'
+
+# ____________________________________________________________
 
 def test_reorder_renaming_list():
     result = reorder_renaming_list([], [])
@@ -83,6 +97,9 @@
 def test_repr():
     assert repr(Register('int', 13)) == '%i13'
 
+# ____________________________________________________________
+
+
 class TestFlatten:
 
     def make_graphs(self, func, values, type_system='lltype'):
@@ -90,11 +107,12 @@
         return self.rtyper.annotator.translator.graphs
 
     def encoding_test(self, func, args, expected,
-                      transform=False, liveness=False):
+                      transform=False, liveness=False, cc=None):
         graphs = self.make_graphs(func, args)
         if transform:
             from pypy.jit.codewriter.jtransform import transform_graph
-            transform_graph(graphs[0], FakeCPU(), FakeCallControl())
+            cc = cc or FakeCallControl()
+            transform_graph(graphs[0], FakeCPU(self.rtyper), cc)
         ssarepr = flatten_graph(graphs[0], fake_regallocs(),
                                 _include_all_exc_links=not transform)
         if liveness:
@@ -556,3 +574,15 @@
             L1:
             int_return $34
         """, transform=True, liveness=True)
+
+    def test_vref_simple(self):
+        from pypy.jit.codewriter.call import CallControl
+        class X:
+            pass
+        def f():
+            return jit.virtual_ref(X())
+        self.encoding_test(f, [], """
+            new_with_vtable <Descr> -> %r0
+            virtual_ref %r0 -> %r1
+            ref_return %r1
+        """, transform=True, cc=FakeCallControlWithVRefInfo())

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py	Fri May 21 18:44:11 2010
@@ -164,6 +164,7 @@
         #
         from pypy.jit.metainterp.virtualref import VirtualRefInfo
         self.metainterp_sd.virtualref_info = VirtualRefInfo(self)
+        self.codewriter.setup_vrefinfo(self.metainterp_sd.virtualref_info)
         if self.jitdriver.virtualizables:
             from pypy.jit.metainterp.virtualizable import VirtualizableInfo
             self.metainterp_sd.virtualizable_info = VirtualizableInfo(self)



More information about the Pypy-commit mailing list