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

antocuni at codespeak.net antocuni at codespeak.net
Thu Jun 18 12:16:14 CEST 2009


Author: antocuni
Date: Thu Jun 18 12:16:12 2009
New Revision: 65811

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize3.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/oparser.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize3.py
Log:
port one more test from optimize.py, and fix the detection of escaped values


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize3.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize3.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize3.py	Thu Jun 18 12:16:12 2009
@@ -291,6 +291,8 @@
         methname = 'find_nodes_' + methname
         if hasattr(self, methname):
             return getattr(self, methname).im_func
+        elif hasattr(self, 'find_nodes_default_op'):
+            return self.find_nodes_default_op.im_func
         return None
 
     # hooks for LoopSpecializer
@@ -353,6 +355,16 @@
         node.origfields = r_dict(av_eq, av_hash)
         node.curfields = r_dict(av_eq, av_hash)
 
+    def find_nodes_default_op(self, spec, op):
+        if not op.has_no_side_effect():
+            #spec.first_escaping_op = False
+            for box in op.args:
+                if isinstance(box, Box):
+                    spec.getnode(box).escaped = True
+
+    def find_nodes_jump(self, spec, op):
+        pass
+
     def find_nodes_new_with_vtable(self, spec, op):
         box = op.result
         node = spec.newnode(box, escaped=False)

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/oparser.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/oparser.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/oparser.py	Thu Jun 18 12:16:12 2009
@@ -111,7 +111,10 @@
         try:
             opnum = getattr(rop, opname.upper())
         except AttributeError:
-            raise ParseError("unknown op: %s" % opname)
+            if opname == 'escape':
+                opnum = -123
+            else:
+                raise ParseError("unknown op: %s" % opname)
         endnum = line.rfind(')')
         if endnum == -1:
             raise ParseError("invalid line: %s" % line)

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize3.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize3.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize3.py	Thu Jun 18 12:16:12 2009
@@ -94,9 +94,10 @@
         loop.operations = operations
         return loop
 
-    def parse(self, s):
+    def parse(self, s, boxkinds=None):
         return parse(s, self.cpu, self.namespace,
-                     type_system=self.type_system)
+                     type_system=self.type_system,
+                     boxkinds=boxkinds)
 
     def optimize(self, lst, optlist=None):
         if not isinstance(lst, TreeLoop):
@@ -256,6 +257,43 @@
         """
         self.assert_equal(loop, expected)
 
+    def _get_virtual_escape_loop(self):
+        ops = """
+        [sum, n1]
+        guard_class(n1, ConstClass(node_vtable))
+            fail()
+        escape(n1)
+        v = getfield_gc(n1, descr=valuedescr)
+        v2 = int_sub(v, 1)
+        sum2 = int_add(sum, v)
+        n2 = new_with_vtable(ConstClass(node_vtable), descr=nodesize)
+        setfield_gc(n2, v2, descr=valuedescr)
+        escape(n2)
+        jump(sum2, n2)
+        """
+        loop = self.parse(ops, boxkinds={'sum': BoxInt,
+                                         'v': BoxInt,
+                                         'n': BoxPtr})
+        loop.setvalues(sum  = 0,
+                       n1   = self.nodebox.value,
+                       v    = 20,
+                       v2   = 19,
+                       sum2 = 20,
+                       n2   = self.nodebox2.value)
+        return loop
+
+    def test_virtual_escape_find_nodes(self):
+        loop = self._get_virtual_escape_loop()
+        spec = LoopSpecializer([OptimizeVirtuals()])
+        spec._init(loop)
+        spec.find_nodes()
+
+        b = loop.getboxes()
+        assert spec.nodes[b.n1].known_class.source.value == self.node_vtable_adr
+        assert spec.nodes[b.n1].escaped
+        assert spec.nodes[b.n2].known_class.source.value == self.node_vtable_adr
+        assert spec.nodes[b.n2].escaped
+    
 
 class TestLLtype(LLtypeMixin, BaseTestOptimize3):
     pass



More information about the Pypy-commit mailing list