Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: optresult-unroll
Changeset: r79077:8b79d27afa90
Date: 2015-08-19 21:00 +0200
http://bitbucket.org/pypy/pypy/changeset/8b79d27afa90/

Log:    start fighting with test_virtualstate

diff --git a/rpython/jit/metainterp/optimizeopt/info.py 
b/rpython/jit/metainterp/optimizeopt/info.py
--- a/rpython/jit/metainterp/optimizeopt/info.py
+++ b/rpython/jit/metainterp/optimizeopt/info.py
@@ -38,6 +38,9 @@
     def get_known_class(self, cpu):
         return None
 
+    def getlenbound(self):
+        return None
+
     def getnullness(self):
         if self.is_null():
             return INFO_NULL
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py 
b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -2733,7 +2733,7 @@
             '''
             p1.nextdescr = p2
             where p2 is a node_vtable, valuedescr=i2
-            ''', rop.GUARD_TRUE, values=[InputArgInt(0),
+            ''', rop.GUARD_TRUE, values=[InputArgInt(18),
                                          InputArgRef(self.nodeaddr)])
 
     def test_expand_fail_lazy_setfield_2(self):
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
@@ -8,6 +8,7 @@
 from rpython.jit.metainterp.resoperation import InputArgInt, InputArgRef,\
      InputArgFloat
 from rpython.rtyper.lltypesystem import lltype, llmemory
+from rpython.rtyper import rclass
 from rpython.jit.metainterp.optimizeopt.test.test_util import LLtypeMixin, 
BaseTest, \
                                                            equaloplists
 from rpython.jit.metainterp.optimizeopt.intutils import IntBound,\
@@ -25,10 +26,13 @@
 
 class BaseTestGenerateGuards(BaseTest):
 
-    def _box_or_value(self, box_or_value=None):
-        if box_or_value is None:
+    def _box_or_value(self, boxinfo=None):
+        if boxinfo is None:
             return None, None
-        elif isinstance(box_or_value, OptValue):
+        else:
+            xxx
+        # el
+        if isinstance(box_or_value, OptValue):
             value = box_or_value
             box = value.box
         else:
@@ -57,19 +61,21 @@
         assert equaloplists(guards, loop.operations, False,
                             boxmap)
 
-    def check_no_guards(self, info1, info2, box_or_value=None, state=None):
-        value, _ = self._box_or_value(box_or_value)
+    def check_no_guards(self, info1, info2, boxinfo=None, state=None):
+        assert boxinfo is None
+        boxinfo, _ = self._box_or_value(boxinfo)
         if info1.position == -1:
             info1.position = 0
         if info2.position == -1:
             info2.position = 0
         if state is None:
             state = GenerateGuardState(self.cpu)
-        info1.generate_guards(info2, value, state)
+        info1.generate_guards(info2, boxinfo, None, state)
         assert not state.extra_guards
         return state
 
     def check_invalid(self, info1, info2, box_or_value=None, state=None):
+        assert box_or_value is None
         value, _ = self._box_or_value(box_or_value)
         if info1.position == -1:
             info1.position = 0
@@ -78,7 +84,7 @@
         if state is None:
             state = GenerateGuardState(self.cpu)
         with py.test.raises(VirtualStatesCantMatch):
-            info1.generate_guards(info2, value, state)
+            info1.generate_guards(info2, None, None, state)
 
     def test_make_inputargs(self):
         optimizer = FakeOptimizer()
@@ -150,22 +156,23 @@
                 if i != j:
                     assert not isgeneral('r', inorder[j], 'r', inorder[i])
 
-        i1 = IntLowerBound(10)
-        i2 = IntUnbounded()
+        i1 = IntUnbounded()
+        i2 = IntLowerBound(10)
         assert isgeneral('i', i1, 'i', i2)
         assert not isgeneral('i', i2, 'i', i1)
 
-        assert isgeneral(OptValue(ConstInt(7)), OptValue(ConstInt(7)))
-        S = lltype.GcStruct('S')
+        assert isgeneral('i', ConstIntBound(7), 'i', ConstIntBound(7))
+        S = lltype.GcStruct('S', ('parent', rclass.OBJECT))
         foo = lltype.malloc(S)
+        foo_vtable = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
+        foo.parent.typeptr = foo_vtable
         fooref = lltype.cast_opaque_ptr(llmemory.GCREF, foo)
-        assert isgeneral(OptValue(ConstPtr(fooref)),
-                         OptValue(ConstPtr(fooref)))
+        assert isgeneral('r', info.ConstPtrInfo(ConstPtr(fooref)),
+                         'r', info.ConstPtrInfo(ConstPtr(fooref)))
 
-        value1 = PtrOptValue(BoxPtr())
-        value1.make_nonnull(None)
-        value2 = PtrOptValue(ConstPtr(self.nullptr))
-        assert not isgeneral(value1, value2)
+        value1 = info.NonNullPtrInfo()
+        value2 = info.ConstPtrInfo(ConstPtr(self.nullptr))
+        assert not isgeneral('r', value1, 'r', value2)
 
     def test_field_matching_generalization(self):
         const1 = NotVirtualStateInfo(OptValue(ConstInt(1)))
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
@@ -1,6 +1,7 @@
 from rpython.jit.metainterp.walkvirtual import VirtualVisitor
 from rpython.jit.metainterp.history import (ConstInt, Const,
         ConstPtr, ConstFloat)
+from rpython.jit.metainterp.optimizeopt import info
 from rpython.jit.metainterp.optimizeopt.intutils import IntUnbounded
 from rpython.jit.metainterp.resoperation import rop, ResOperation,\
      AbstractInputArg
@@ -36,17 +37,17 @@
 class AbstractVirtualStateInfo(object):
     position = -1
 
-    def generate_guards(self, other, value, state):
+    def generate_guards(self, other, op, opinfo, state):
         """ generate guards (output in the list extra_guards) that make runtime
         values of the shape other match the shape of self. if that's not
         possible, VirtualStatesCantMatch is thrown and bad gets keys set which
         parts of the state are the problem.
 
-        the function can peek into value (and particularly also the boxes in
-        the value) as a guiding heuristic whether making such guards makes
-        sense. if None is passed in for value, no guard is ever generated, and
+        the function can peek into opinfo (and particularly also the op)
+        as a guiding heuristic whether making such guards makes
+        sense. if None is passed in for op, no guard is ever generated, and
         this function degenerates to a generalization check."""
-        assert value is None or isinstance(value, OptValue)
+        assert opinfo is None or isinstance(opinfo, info.AbstractInfo)
         assert self.position != -1
         if self.position in state.renum:
             if state.renum[self.position] != other.position:
@@ -60,7 +61,7 @@
         else:
             state.renum[self.position] = other.position
             try:
-                self._generate_guards(other, value, state)
+                self._generate_guards(other, op, opinfo, state)
             except VirtualStatesCantMatch, e:
                 state.bad[self] = state.bad[other] = None
                 if e.state is None:
@@ -105,14 +106,15 @@
     def __init__(self, fielddescrs):
         self.fielddescrs = fielddescrs
 
-    def _generate_guards(self, other, value, state):
+    def _generate_guards(self, other, box, opinfo, state):
         if not self._generalization_of_structpart(other):
             raise VirtualStatesCantMatch("different kinds of structs")
 
         assert isinstance(other, AbstractVirtualStructStateInfo)
         assert len(self.fielddescrs) == len(self.fieldstate)
         assert len(other.fielddescrs) == len(other.fieldstate)
-        if value is not None:
+        if box is not None:
+            yyy
             assert isinstance(value, virtualize.AbstractVirtualStructValue)
             assert value.is_virtual()
 
@@ -120,6 +122,7 @@
             raise VirtualStatesCantMatch("field descrs don't match")
 
         for i in range(len(self.fielddescrs)):
+            yyy
             if other.fielddescrs[i] is not self.fielddescrs[i]:
                 raise VirtualStatesCantMatch("field descrs don't match")
             if value is not None:
@@ -186,7 +189,7 @@
     def __init__(self, arraydescr):
         self.arraydescr = arraydescr
 
-    def _generate_guards(self, other, value, state):
+    def _generate_guards(self, other, box, opinfo, state):
         if not isinstance(other, VArrayStateInfo):
             raise VirtualStatesCantMatch("other is not an array")
         if self.arraydescr is not other.arraydescr:
@@ -195,6 +198,7 @@
             raise VirtualStatesCantMatch("other has a different length")
         v = None
         for i in range(len(self.fieldstate)):
+            xxxx
             if value is not None:
                 assert isinstance(value, virtualize.VArrayValue)
                 v = value._items[i]
@@ -290,48 +294,33 @@
     constbox = None
     known_class = None
     
-    def __init__(self, cpu, type, info):
+    def __init__(self, cpu, type, info, is_opaque=False):
+        self.is_opaque = is_opaque
         if info and info.is_constant():
+            self.level = LEVEL_CONSTANT
             self.constbox = info.getconst()
-            self.level = LEVEL_CONSTANT
-        elif type == 'r' and info:
-            if info.get_known_class(cpu):
+            if type == 'r':
                 self.known_class = info.get_known_class(cpu)
-                self.level = LEVEL_KNOWNCLASS
-            elif info.is_nonnull():
-                self.level = LEVEL_NONNULL
-        return
+        elif type == 'r':
+            if info:
+                self.known_class = info.get_known_class(cpu)
+                if self.known_class:
+                    self.level = LEVEL_KNOWNCLASS
+                elif info.is_nonnull():
+                    self.level = LEVEL_NONNULL
+                self.lenbound = info.getlenbound()
+        elif type == 'i':
+            self.intbound = info
 
     def is_const(self):
         return self.constbox is not None
-        yyy
-        self.level = LEVEL_UNKNOWN
-        if ptrinfo is not None:
-            self.known_class = ptrinfo.get_known_class(cpu)
-        return
-        xxx
-        self.is_opaque = is_opaque
-        self.known_class = value.get_known_class()
-        self.level = value.getlevel()
-        if value.getintbound() is None:
-            self.intbound = IntUnbounded()
-        else:
-            self.intbound = value.getintbound().clone()
-        if value.is_constant():
-            self.constbox = value.box
-        else:
-            self.constbox = None
-        self.position_in_notvirtuals = -1
-        self.lenbound = value.getlenbound()
 
     def is_virtual(self):
         return False
 
-    def _generate_guards(self, other, value, state):
-        if value is None or self.is_opaque:
+    def _generate_guards(self, other, box, opinfo, state):
+        if self.is_opaque:
             box = None # generating guards for opaque pointers isn't safe
-        else:
-            box = value.box
         # XXX This will always retrace instead of forcing anything which
         # might be what we want sometimes?
         if not isinstance(other, NotVirtualStateInfo):
@@ -417,13 +406,12 @@
                 raise VirtualStatesCantMatch("other not constant")
         assert 0, "unreachable"
 
-    def _generate_guards_intbounds(self, other, box, extra_guards):
+    def _generate_guards_intbounds(self, other, boxinfo, extra_guards):
         if self.intbound is None:
             return
         if self.intbound.contains_bound(other.intbound):
             return
-        xxx
-        if (box is not None and isinstance(box, BoxInt) and
+        if (boxinfo is not None and isinstance(box, BoxInt) and
                 self.intbound.contains(box.getint())):
             # this may generate a few more guards than needed, but they are
             # optimized away when emitting them
@@ -503,7 +491,7 @@
         assert len(self.state) == len(other.state)
         try:
             for i in range(len(self.state)):
-                self.state[i].generate_guards(other.state[i], None, state)
+                self.state[i].generate_guards(other.state[i], None, None, 
state)
         except VirtualStatesCantMatch:
             return False
         return True
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to