[pypy-svn] r78588 - in pypy/branch/jit-unroll-loops/pypy/jit/metainterp: optimizeopt test

arigo at codespeak.net arigo at codespeak.net
Sun Oct 31 12:03:06 CET 2010


Author: arigo
Date: Sun Oct 31 12:03:03 2010
New Revision: 78588

Modified:
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/string.py
   pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_optimizeopt.py
Log:
Fix VStringConcatValue: it cannot easily pass the 'lengthbox'
around the unrolled loop, so we reset it to None and (re-)compute
it lazily.


Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/string.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/string.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/optimizeopt/string.py	Sun Oct 31 12:03:03 2010
@@ -180,12 +180,22 @@
 class VStringConcatValue(VAbstractStringValue):
     """The concatenation of two other strings."""
 
-    def setup(self, left, right, lengthbox):
+    lengthbox = None     # or the computed length
+
+    def setup(self, left, right):
         self.left = left
         self.right = right
-        self.lengthbox = lengthbox
 
-    def getstrlen(self, _, mode):
+    def getstrlen(self, newoperations, mode):
+        if self.lengthbox is None:
+            len1box = self.left.getstrlen(newoperations, mode)
+            if len1box is None:
+                return None
+            len2box = self.right.getstrlen(newoperations, mode)
+            if len2box is None:
+                return None
+            self.lengthbox = _int_add(newoperations, len1box, len2box)
+            # ^^^ may still be None, if newoperations is None
         return self.lengthbox
 
     @specialize.arg(1)
@@ -223,6 +233,7 @@
         if self.box is None:
             self.left.enum_forced_boxes(boxes, already_seen)
             self.right.enum_forced_boxes(boxes, already_seen)
+            self.lengthbox = None
         else:
             boxes.append(self.box)
 
@@ -322,6 +333,8 @@
             return ConstInt(box1.value + box2.value)
     elif isinstance(box2, ConstInt) and box2.value == 0:
         return box1
+    if newoperations is None:
+        return None
     resbox = BoxInt()
     newoperations.append(ResOperation(rop.INT_ADD, [box1, box2], resbox))
     return resbox
@@ -481,11 +494,8 @@
         vleft.ensure_nonnull()
         vright.ensure_nonnull()
         newoperations = self.optimizer.newoperations
-        len1box = vleft.getstrlen(newoperations, mode)
-        len2box = vright.getstrlen(newoperations, mode)
-        lengthbox = _int_add(newoperations, len1box, len2box)
         value = self.make_vstring_concat(op.result, op, mode)
-        value.setup(vleft, vright, lengthbox)
+        value.setup(vleft, vright)
         return True
 
     def opt_call_stroruni_STR_SLICE(self, op, mode):

Modified: pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/jit-unroll-loops/pypy/jit/metainterp/test/test_optimizeopt.py	Sun Oct 31 12:03:03 2010
@@ -3990,7 +3990,7 @@
         jump(p2, p3)
         """
         expected = """
-        [p1, p2]
+        [p2, p1]
         i1 = strlen(p1)
         i2 = strlen(p2)
         i3 = int_add(i1, i2)
@@ -4000,7 +4000,7 @@
         i5 = strlen(p2)
         i6 = int_add(i4, i5)      # will be killed by the backend
         copystrcontent(p2, p3, 0, i4, i5)
-        jump(p2, p3)
+        jump(p3, p2)
         """
         self.optimize_strunicode_loop(ops, expected)
 



More information about the Pypy-commit mailing list