[pypy-commit] pypy virtual-raw-mallocs: kill support for rawbuffer virtualstate: we do not need to have it for optimizing cffi, and it seems to cause bugs

antocuni noreply at buildbot.pypy.org
Thu Dec 27 17:12:04 CET 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: virtual-raw-mallocs
Changeset: r59585:2af85b28ba8e
Date: 2012-12-27 11:58 +0100
http://bitbucket.org/pypy/pypy/changeset/2af85b28ba8e/

Log:	kill support for rawbuffer virtualstate: we do not need to have it
	for optimizing cffi, and it seems to cause bugs

diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -1894,12 +1894,18 @@
         call('free', i0, descr=raw_free_descr)
         i3 = call('malloc', 10, descr=raw_malloc_descr)
         setarrayitem_raw(i3, 0, i2, descr=rawarraydescr)
+        label('foo')
         jump(i3)
         """
         expected = """
-        [i1]
+        [i0]
+        i1 = getarrayitem_raw(i0, 0, descr=rawarraydescr)
         i2 = int_add(i1, 1)
-        jump(i2)
+        call('free', i0, descr=raw_free_descr)
+        label('foo')
+        i3 = call('malloc', 10, descr=raw_malloc_descr)
+        setarrayitem_raw(i3, 0, i2, descr=rawarraydescr)
+        jump(i3)
         """
         self.optimize_loop(ops, expected)
 
diff --git a/pypy/jit/metainterp/optimizeopt/virtualize.py b/pypy/jit/metainterp/optimizeopt/virtualize.py
--- a/pypy/jit/metainterp/optimizeopt/virtualize.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualize.py
@@ -251,16 +251,6 @@
     def set_item_value(self, i, newval):
         raise NotImplementedError
 
-    def force_at_end_of_preamble(self, already_forced, optforce):
-        if self in already_forced:
-            return self
-        already_forced[self] = self
-        for index in range(self.getlength()):
-            itemval = self.get_item_value(index)
-            itemval = itemval.force_at_end_of_preamble(already_forced, optforce)
-            self.set_item_value(index, itemval)
-        return self
-
     def get_args_for_fail(self, modifier):
         if self.box is None and not modifier.already_seen_virtual(self.keybox):
             # checks for recursion: it is False unless
@@ -300,6 +290,19 @@
         assert isinstance(itemvalue, optimizer.OptValue)
         self._items[index] = itemvalue
 
+    def force_at_end_of_preamble(self, already_forced, optforce):
+        # note that this method is on VArrayValue instead of
+        # AbstractVArrayValue because we do not want to support virtualstate
+        # for rawbuffers for now
+        if self in already_forced:
+            return self
+        already_forced[self] = self
+        for index in range(self.getlength()):
+            itemval = self.get_item_value(index)
+            itemval = itemval.force_at_end_of_preamble(already_forced, optforce)
+            self.set_item_value(index, itemval)
+        return self
+
     def _really_force(self, optforce):
         assert self.source_op is not None
         if not we_are_translated():
diff --git a/pypy/jit/metainterp/optimizeopt/virtualstate.py b/pypy/jit/metainterp/optimizeopt/virtualstate.py
--- a/pypy/jit/metainterp/optimizeopt/virtualstate.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualstate.py
@@ -158,7 +158,15 @@
     def debug_header(self, indent):
         debug_print(indent + 'VStructStateInfo(%d):' % self.position)
 
-class AbstractVArrayStateInfo(AbstractVirtualStateInfo):
+
+class VArrayStateInfo(AbstractVirtualStateInfo):
+
+    def __init__(self, arraydescr):
+        self.arraydescr = arraydescr
+
+    def _generalization_of(self, other):
+        return (isinstance(other, VArrayStateInfo) and
+            self.arraydescr is other.arraydescr)
 
     def generalization_of(self, other, renum, bad):
         assert self.position != -1
@@ -186,7 +194,7 @@
         return True
 
     def enum_forced_boxes(self, boxes, value, optimizer):
-        if not isinstance(value, self.ValueClass):
+        if not isinstance(value, virtualize.VArrayValue):
             raise BadVirtualState
         if not value.is_virtual():
             raise BadVirtualState
@@ -206,16 +214,6 @@
     def debug_header(self, indent):
         debug_print(indent + 'VArrayStateInfo(%d):' % self.position)
 
-class VArrayStateInfo(AbstractVArrayStateInfo):
-
-    ValueClass = virtualize.VArrayValue
-    
-    def __init__(self, arraydescr):
-        self.arraydescr = arraydescr
-
-    def _generalization_of(self, other):
-        return (isinstance(other, VArrayStateInfo) and
-            self.arraydescr is other.arraydescr)
 
 
 class VArrayStructStateInfo(AbstractVirtualStateInfo):
@@ -293,13 +291,6 @@
         debug_print(indent + 'VArrayStructStateInfo(%d):' % self.position)
 
 
-class VRawBufferStateInfo(AbstractVArrayStateInfo):
-
-    ValueClass = virtualize.VRawBufferValue
-    
-    def _generalization_of(self, other):
-        return isinstance(other, VRawBufferStateInfo)
-
 
 class NotVirtualStateInfo(AbstractVirtualStateInfo):
     def __init__(self, value, is_opaque=False):
@@ -594,7 +585,7 @@
         return VArrayStructStateInfo(arraydescr, fielddescrs)
 
     def make_vrawbuffer(self, size, offsets, descrs):
-        return VRawBufferStateInfo()
+        raise NotImplementedError
 
 class BoxNotProducable(Exception):
     pass
diff --git a/pypy/jit/metainterp/test/test_virtual.py b/pypy/jit/metainterp/test/test_virtual.py
--- a/pypy/jit/metainterp/test/test_virtual.py
+++ b/pypy/jit/metainterp/test/test_virtual.py
@@ -1244,7 +1244,7 @@
         # the getarrayitem_raw is in the bridge
         self.check_resops(getarrayitem_raw=1, setarrayitem_raw=0)
 
-    def test_raw_malloc_two_iterations(self):
+    def test_raw_malloc_no_virtualstate(self):
         mydriver = JitDriver(greens=[], reds = 'auto')
         def f(n):
             res = 0
@@ -1262,8 +1262,9 @@
         assert f(10) == 45
         res = self.meta_interp(f, [10])
         assert res == 45
-        # the getarrayitem_raw is in the preamble
-        self.check_resops(getarrayitem_raw=1, setarrayitem_raw=0)
+        # make sure that the raw buffer is *not* virtualized because we do not
+        # support virtualstate
+        self.check_resops(getarrayitem_raw=2, setarrayitem_raw=2)
 
     def test_raw_malloc_only_chars(self):
         mydriver = JitDriver(greens=[], reds = 'auto')


More information about the pypy-commit mailing list