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

arigo at codespeak.net arigo at codespeak.net
Sat Jul 18 19:46:42 CEST 2009


Author: arigo
Date: Sat Jul 18 19:46:41 2009
New Revision: 66371

Modified:
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizefindnode.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizefindnode.py
Log:
Finish bridge_matches() -- case of virtuals.


Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizefindnode.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizefindnode.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizefindnode.py	Sat Jul 18 19:46:41 2009
@@ -249,15 +249,37 @@
 class __extend__(VirtualInstanceSpecNode):
     def make_instance_node(self):
         instnode = InstanceNode(escaped=False)
+        instnode.knownclsbox = self.known_class
         instnode.curfields = av_newdict()
         for ofs, subspecnode in self.fields:
             instnode.curfields[ofs] = subspecnode.make_instance_node()
         return instnode
+
     def matches_instance_node(self, exitnode):
         if exitnode.unique == UNIQUE_NO:
             return False
-        else:
-            xxx
+        #
+        assert exitnode.unique == UNIQUE_YES
+        if not self.known_class.equals(exitnode.knownclsbox):
+            # unique match, but the class is known to be a mismatch
+            return False
+        #
+        d = exitnode.curfields
+        seen = 0
+        for ofs, subspecnode in self.fields:
+            try:
+                if d is None:
+                    raise KeyError
+                instnode = d[ofs]
+                seen += 1
+            except KeyError:
+                instnode = NodeFinder.node_escaped
+            if not subspecnode.matches_instance_node(instnode):
+                return False
+        if d is not None and len(d) > seen:
+            return False          # some key is in d but not in self.fields
+        return True
+
 
 class BridgeSpecializationFinder(NodeFinder):
 

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizefindnode.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizefindnode.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizefindnode.py	Sat Jul 18 19:46:41 2009
@@ -526,6 +526,53 @@
         self.find_bridge(ops, 'Fixed(node_vtable)', 'Fixed(node_vtable2)',
                          mismatch=True)
 
+    def test_bridge_simple_virtual(self):
+        ops = """
+        [p0]
+        setfield_gc(p0, 123, descr=valuedescr)
+        jump(p0)
+        """
+        self.find_bridge(ops, 'Virtual(node_vtable)', 'Not')
+        self.find_bridge(ops, 'Virtual(node_vtable)', 'Fixed(node_vtable)')
+        self.find_bridge(ops, 'Virtual(node_vtable)',
+                              'Virtual(node_vtable, valuedescr=Not)')
+        self.find_bridge(ops, 'Virtual(node_vtable, valuedescr=Not)',
+                              'Virtual(node_vtable, valuedescr=Not)')
+        self.find_bridge(ops, 'Virtual(node_vtable, valuedescr=Not)',
+                            '''Virtual(node_vtable,
+                                       valuedescr=Not,
+                                       nextdescr=Not)''')
+        self.find_bridge(ops, '''Virtual(node_vtable,
+                                         valuedescr=Not,
+                                         nextdescr=Fixed(node_vtable2))''',
+                              '''Virtual(node_vtable,
+                                         valuedescr=Not,
+                                         nextdescr=Fixed(node_vtable2))''')
+        self.find_bridge(ops, '''Virtual(node_vtable,
+                                         valuedescr=Not,
+                                         nextdescr=Fixed(node_vtable2))''',
+                              '''Virtual(node_vtable,
+                                         valuedescr=Not,
+                                         nextdescr=Not)''')
+        #
+        self.find_bridge(ops, 'Virtual(node_vtable)', 'Virtual(node_vtable)',
+                         mismatch=True)    # because of missing valuedescr
+        self.find_bridge(ops, 'Virtual(node_vtable)', 'Fixed(node_vtable2)',
+                         mismatch=True)    # bad class
+        self.find_bridge(ops, 'Virtual(node_vtable)',
+                         'Virtual(node_vtable2, valuedescr=Not)',
+                         mismatch=True)    # bad class
+        self.find_bridge(ops, 'Virtual(node_vtable, valuedescr=Not)',
+                            '''Virtual(node_vtable,
+                                       valuedescr=Not,
+                                       nextdescr=Fixed(node_vtable))''',
+                         mismatch=True)    # unexpected nextdescr
+        self.find_bridge(ops, 'Virtual(node_vtable, valuedescr=Not)',
+                            '''Virtual(node_vtable,
+                                       valuedescr=Not,
+                                       nextdescr=Virtual(node_vtable))''',
+                         mismatch=True)    # unexpected nextdescr
+
 
 class TestLLtype(BaseTestOptimize, LLtypeMixin):
     pass



More information about the Pypy-commit mailing list