[pypy-svn] r61788 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test

fijal at codespeak.net fijal at codespeak.net
Thu Feb 12 16:05:54 CET 2009


Author: fijal
Date: Thu Feb 12 16:05:53 2009
New Revision: 61788

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vable_optimize.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
Log:
(arigo, fijal)
Pass the first virtualizable test, in simple enough case


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	Thu Feb 12 16:05:53 2009
@@ -21,21 +21,20 @@
             return False
         return instnode.cls.source.equals(self.known_class)
 
-class VirtualizableSpecNode(FixedClassSpecNode):
+class SpecNodeWithFields(FixedClassSpecNode):
     def __init__(self, known_class, fields):
         FixedClassSpecNode.__init__(self, known_class)
         self.fields = fields
 
+class VirtualizableSpecNode(SpecNodeWithFields):
+
     def equals(self, other):
         xxx
 
     def matches(self, instnode):
         xxx
 
-class VirtualInstanceSpecNode(FixedClassSpecNode):
-    def __init__(self, known_class, fields):
-        FixedClassSpecNode.__init__(self, known_class)
-        self.fields = fields
+class VirtualInstanceSpecNode(SpecNodeWithFields):
 
     def equals(self, other):
         if not isinstance(other, VirtualInstanceSpecNode):
@@ -108,14 +107,14 @@
 def extract_runtime_data(cpu, specnode, valuebox, resultlist):
     if not isinstance(specnode, VirtualInstanceSpecNode):
         resultlist.append(valuebox)
-        return
-    for ofs, subspecnode in specnode.fields:
-        cls = specnode.known_class.getint()
-        tp = cpu.typefor(ofs)
-        fieldbox = cpu.execute_operation('getfield_gc',
-                                         [valuebox, ConstInt(ofs)],
-                                         tp)
-        extract_runtime_data(cpu, subspecnode, fieldbox, resultlist)
+    if isinstance(specnode, SpecNodeWithFields):
+        for ofs, subspecnode in specnode.fields:
+            cls = specnode.known_class.getint()
+            tp = cpu.typefor(ofs)
+            fieldbox = cpu.execute_operation('getfield_gc',
+                                             [valuebox, ConstInt(ofs)],
+                                             tp)
+            extract_runtime_data(cpu, subspecnode, fieldbox, resultlist)
 
 
 class InstanceNode(object):
@@ -332,8 +331,7 @@
                 instnode.cls = InstanceNode(specnode.known_class)
             else:
                 assert instnode.cls.source.equals(specnode.known_class)
-            if isinstance(specnode, (VirtualInstanceSpecNode,
-                                     VirtualizableSpecNode)):
+            if isinstance(specnode, SpecNodeWithFields):
                 curfields = {}
                 for ofs, subspecnode in specnode.fields:
                     subinstnode = instnode.origfields[ofs]
@@ -356,8 +354,7 @@
     def expanded_version_of_rec(self, specnode, instnode, newboxlist):
         if not isinstance(specnode, VirtualInstanceSpecNode):
             newboxlist.append(instnode.source)
-        if isinstance(specnode, (VirtualInstanceSpecNode,
-                                 VirtualizableSpecNode)):
+        if isinstance(specnode, SpecNodeWithFields):
             for ofs, subspecnode in specnode.fields:
                 subinstnode = instnode.curfields[ofs]  # should really be there
                 self.expanded_version_of_rec(subspecnode, subinstnode,

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Thu Feb 12 16:05:53 2009
@@ -402,43 +402,20 @@
 
     @arguments("orgpc", "box", returns="box")
     def opimpl_guard_value(self, pc, box):
-        return self.implement_guard_value(pc, box)
+        self.implement_guard_value(pc, box)
 
     @arguments("orgpc", "box", returns="box")
     def opimpl_guard_class(self, pc, box):
-        obj = box.getptr(lltype.Ptr(rclass.OBJECT))
-        cls = llmemory.cast_ptr_to_adr(obj.typeptr)
-        clsbox = ConstInt(self.metainterp.cpu.cast_adr_to_int(cls))
         if isinstance(box, Box):
+            clsbox = self.cls_of_box(box)
             self.generate_guard(pc, 'guard_class', box, [clsbox])
-        return clsbox
-
-    @arguments("orgpc", "box", "virtualizabledesc", "int")
-    def opimpl_guard_nonvirtualized__1(self, pc, box, vdesc, guard_field):
-        self.execute('#virtualizabledesc', [box, vdesc], 'void', False)
-        self.generate_guard(pc, 'guard_nonvirtualized__1', box,
-                            [ConstInt(guard_field)])
-    @arguments("orgpc", "box", "virtualizabledesc", "int")
-    def opimpl_guard_nonvirtualized__2(self, pc, box, vdesc, guard_field):
-        self.execute('#virtualizabledesc', [box, vdesc], 'void', False)
-        self.generate_guard(pc, 'guard_nonvirtualized__2', box,
-                            [ConstInt(guard_field)])
-    @arguments("orgpc", "box", "virtualizabledesc", "int")
-    def opimpl_guard_nonvirtualized__4(self, pc, box, vdesc, guard_field):
-        self.execute('#virtualizabledesc', [box, vdesc], 'void', False)
-        self.generate_guard(pc, 'guard_nonvirtualized__4', box,
-                            [ConstInt(guard_field)])
-    @arguments("orgpc", "box", "virtualizabledesc", "int")
-    def opimpl_guard_nonvirtualized__8(self, pc, box, vdesc, guard_field):
-        self.execute('#virtualizabledesc', [box, vdesc], 'void', False)
-        self.generate_guard(pc, 'guard_nonvirtualized__8', box,
-                            [ConstInt(guard_field)])
 
     @arguments("orgpc", "box", "virtualizabledesc", "int")
-    def opimpl_guard_nonvirtualized_ptr(self, pc, box, vdesc, guard_field):
-        self.execute('#virtualizabledesc', [box, vdesc], 'void', False)
-        self.generate_guard(pc, 'guard_nonvirtualized_ptr', box,
-                            [ConstInt(guard_field)])
+    def opimpl_guard_nonvirtualized(self, pc, box, vdesc, guard_field):
+        clsbox = self.cls_of_box(box)
+        op = self.generate_guard(pc, 'guard_nonvirtualized', box,
+                                 [clsbox, ConstInt(guard_field)])
+        op.desc = vdesc
         
     @arguments("box")
     def opimpl_keepalive(self, box):
@@ -548,6 +525,7 @@
         self.pc = pc
         guard_op.key = self.metainterp.record_state()
         self.pc = saved_pc
+        return guard_op
 
     def implement_guard_value(self, pc, box):
         if isinstance(box, Box):
@@ -557,6 +535,11 @@
         else:
             return box     # no promotion needed, already a Const
 
+    def cls_of_box(self, box):
+        obj = box.getptr(lltype.Ptr(rclass.OBJECT))
+        cls = llmemory.cast_ptr_to_adr(obj.typeptr)
+        return ConstInt(self.metainterp.cpu.cast_adr_to_int(cls))
+
     def follow_jump(self):
         self.pc -= 3
         self.pc = self.load_3byte()

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vable_optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vable_optimize.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_vable_optimize.py	Thu Feb 12 16:05:53 2009
@@ -88,7 +88,7 @@
         ResOperation('setfield_gc', [fr, ConstInt(ofs_node), n2], []),
         Jump('jump', [sum2, fr], []),
         ]
-    ops[1].desc = xy_desc
+    ops[1].vdesc = xy_desc
 
 def test_A_find_nodes():
     spec = PerfectSpecializer(A.ops)

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	Thu Feb 12 16:05:53 2009
@@ -5,6 +5,7 @@
 from pypy.rlib.jit import JitDriver
 from pypy.jit.metainterp.test.test_basic import LLJitMixin, OOJitMixin
 from pypy.rpython.lltypesystem.rvirtualizable2 import VABLERTIPTR
+from pypy.jit.metainterp.test.test_vable_optimize import XY, xy_vtable
 
 promote_virtualizable = lloperation.llop.promote_virtualizable
 debug_print = lloperation.llop.debug_print
@@ -19,6 +20,7 @@
         def setup():
             xy = lltype.malloc(XY)
             xy.vable_rti = lltype.nullptr(VABLERTIPTR.TO)
+            xy.parent.typeptr = xy_vtable
             return xy
         def f(n):
             xy = setup()



More information about the Pypy-commit mailing list