[pypy-svn] pypy jit-virtual_state: supporting VirtualStruct

hakanardo commits-noreply at bitbucket.org
Fri Feb 4 08:24:28 CET 2011


Author: Hakan Ardo <hakan at debian.org>
Branch: jit-virtual_state
Changeset: r41600:76a3cb0c3800
Date: 2011-02-04 08:24 +0100
http://bitbucket.org/pypy/pypy/changeset/76a3cb0c3800/

Log:	supporting VirtualStruct

diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py b/pypy/jit/metainterp/optimizeopt/unroll.py
--- a/pypy/jit/metainterp/optimizeopt/unroll.py
+++ b/pypy/jit/metainterp/optimizeopt/unroll.py
@@ -125,6 +125,17 @@
         self.snapshot_map[snapshot] = new_snapshot
         return new_snapshot
 
+class VirtualState(object):
+    def __init__(self, state):
+        self.state = state
+
+    def more_general_than(self, other):
+        assert len(self.state) == len(other.state)
+        for i in range(len(self.state)):
+            if not self.state[i].more_general_than(other.state[i]):
+                return False
+        return True
+
 class VirtualStateAdder(resume.ResumeDataVirtualAdder):
     def __init__(self, optimizer):
         self.fieldboxes = {}
@@ -155,7 +166,7 @@
         for box in jump_args:
             value = self.getvalue(box)
             value.get_args_for_fail(self)
-        return [self.state(box) for box in jump_args]
+        return VirtualState([self.state(box) for box in jump_args])
 
 
     def make_not_virtual(self, value):
@@ -167,7 +178,7 @@
         self.level = value.level
         self.intbound = value.intbound.clone()
         if value.is_constant():
-            self.constbox = value.box.clonebox()
+            self.constbox = value.box
         else:
             self.constbox = None
 
@@ -176,12 +187,15 @@
         # might be what we want sometimes?
         if not isinstance(other, NotVirtualInfo):
             return False
-        if self.constbox:
-            if not self.constbox.same_const(other):
+        if other.level < self.level:
+            return False
+        if self.level == LEVEL_CONSTANT:
+            if not self.constbox.same_constant(other.constbox):
                 return False
-        return (self.known_class == other.known_class and
-                self.level == other.level and
-                self.intbound.contains_bound(other.intbound))
+        elif self.level == LEVEL_KNOWNCLASS:
+            if self.known_class != other.known_class: # FIXME: use issubclass?
+                return False
+        return self.intbound.contains_bound(other.intbound)
             
 
 class UnrollOptimizer(Optimization):
@@ -590,12 +604,8 @@
                 virtual_state = modifier.get_virtual_state(args)
                 print 'len', len(short)
                 for sh in short:
-                    assert len(virtual_state) == len(sh.virtual_state)
-                    
-                    for i in range(len(virtual_state)):
-                        if not sh.virtual_state[i].more_general_than(virtual_state[i]):
-                            break
-                    else:
+                    if sh.virtual_state.more_general_than(virtual_state):
+                        # FIXME: Do we still need the dry run
                         if self.inline(sh.operations, sh.inputargs,
                                        op.getarglist(), dryrun=True):
                             try:

diff --git a/pypy/jit/metainterp/resume.py b/pypy/jit/metainterp/resume.py
--- a/pypy/jit/metainterp/resume.py
+++ b/pypy/jit/metainterp/resume.py
@@ -452,6 +452,23 @@
                         str(self.fielddescrs[i]),
                         str(untag(self.fieldnums[i])))
 
+    def more_general_than(self, other):
+        if not isinstance(other, AbstractVirtualStructInfo):
+            return False
+        assert len(self.fielddescrs) == len(self.fieldstate)
+        assert len(other.fielddescrs) == len(other.fieldstate)
+        if len(self.fielddescrs) != len(other.fielddescrs):
+            return False
+        
+        for i in range(len(self.fielddescrs)):
+            if other.fielddescrs[i] is not self.fielddescrs[i]:
+                return False
+            if not self.fieldstate[i].more_general_than(other.fieldstate[i]):
+                return False
+        return True
+            
+        
+
 class VirtualInfo(AbstractVirtualStructInfo):
     def __init__(self, known_class, fielddescrs):
         AbstractVirtualStructInfo.__init__(self, fielddescrs)

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
@@ -186,7 +186,7 @@
         self.check_loop_count(2)
         self.check_loops(new=0, new_with_vtable=0,
                                 getfield_gc=0, setfield_gc=0)
-
+        
     def test_two_loops_with_escaping_virtual(self):
         myjitdriver = JitDriver(greens = [], reds = ['n', 'node'])
         def externfn(node):


More information about the Pypy-commit mailing list