[pypy-commit] pypy small-unroll-improvements: start recursively generating guards for virtuals

cfbolz noreply at buildbot.pypy.org
Tue Apr 8 18:10:12 CEST 2014


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: small-unroll-improvements
Changeset: r70491:3e921143ad82
Date: 2014-04-08 18:09 +0200
http://bitbucket.org/pypy/pypy/changeset/3e921143ad82/

Log:	start recursively generating guards for virtuals

diff --git a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
@@ -154,12 +154,14 @@
             value = OptValue(box)
         return value, box
 
-    def guards(self, info1, info2, box_or_value, expected):
+    def guards(self, info1, info2, box_or_value, expected, inputargs=None):
         value, box = self._box_or_value(box_or_value)
+        if inputargs is None:
+            inputargs = [box]
         info1.position = info2.position = 0
         guards = []
         info1.generate_guards(info2, value, self.cpu, guards, {})
-        self.compare(guards, expected, [box])
+        self.compare(guards, expected, inputargs)
 
     def compare(self, guards, expected, inputargs):
         loop = self.parse(expected)
@@ -418,7 +420,6 @@
         self.compare(guards, expected, [box2])
 
     def test_generate_guards_on_virtual_fields_matches(self):
-        py.test.skip("not yet")
         innervalue1 = OptValue(self.nodebox)
         constclassbox = self.cpu.ts.cls_of_box(self.nodebox)
         innervalue1.make_constant_class(constclassbox, -1)
@@ -433,7 +434,7 @@
         info2 = VirtualStateInfo(ConstInt(42), [1])
         info2.fieldstate = [innerinfo2]
 
-        value1 = VirtualValue(self.cpu, constclassbox, BoxInt())
+        value1 = VirtualValue(self.cpu, constclassbox, self.nodebox)
         value1._fields = {1: OptValue(self.nodebox)}
 
         expected = """
@@ -441,7 +442,7 @@
         guard_nonnull(p0) []
         guard_class(p0, ConstClass(node_vtable)) []
         """
-        self.guards(info1, info2, value1, expected)
+        self.guards(info1, info2, value1, expected, [self.nodebox])
 
     # _________________________________________________________________________
     # the below tests don't really have anything to do with guard generation
diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py b/rpython/jit/metainterp/optimizeopt/virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py
@@ -103,6 +103,27 @@
 
         return True
 
+
+    def _generate_guards(self, other, value, cpu, extra_guards, renum, bad):
+        if not self._generalization_of_structpart(other):
+            raise InvalidLoop("XXX")
+
+        assert isinstance(other, AbstractVirtualStructStateInfo)
+        assert len(self.fielddescrs) == len(self.fieldstate)
+        assert len(other.fielddescrs) == len(other.fieldstate)
+        assert isinstance(value, virtualize.AbstractVirtualStructValue)
+        assert value.is_virtual()
+
+        if len(self.fielddescrs) != len(other.fielddescrs):
+            raise InvalidLoop("XXX")
+
+        for i in range(len(self.fielddescrs)):
+            if other.fielddescrs[i] is not self.fielddescrs[i]:
+                raise InvalidLoop("XXX")
+            v = value._fields[self.fielddescrs[i]] # must be there
+            self.fieldstate[i].generate_guards(other.fieldstate[i], v, cpu, extra_guards, renum)
+
+
     def _generalization_of_structpart(self, other):
         raise NotImplementedError
 


More information about the pypy-commit mailing list