[pypy-svn] pypy jit-virtual_state: only produce preamble for the first loop and then reuse it for the rest

hakanardo commits-noreply at bitbucket.org
Sun Feb 6 17:18:12 CET 2011


Author: Hakan Ardo <hakan at debian.org>
Branch: jit-virtual_state
Changeset: r41659:cd09aab2ef91
Date: 2011-02-06 16:42 +0100
http://bitbucket.org/pypy/pypy/changeset/cd09aab2ef91/

Log:	only produce preamble for the first loop and then reuse it for the
	rest

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
@@ -640,6 +640,7 @@
                 modifier = VirtualStateAdder(self.optimizer)
                 virtual_state = modifier.get_virtual_state(args)
                 for sh in short:
+                    #import pdb; pdb.set_trace()
                     ok = False
                     extra_guards = []
                     if sh.virtual_state.generalization_of(virtual_state):

diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py
--- a/pypy/jit/metainterp/compile.py
+++ b/pypy/jit/metainterp/compile.py
@@ -80,11 +80,11 @@
 
 # ____________________________________________________________
 
-def compile_new_loop(metainterp, old_loop_tokens, greenkey, start, start_resumedescr):
+def compile_new_loop(metainterp, old_loop_tokens, greenkey, start,
+                     start_resumedescr, full_preamble_needed=True):
     """Try to compile a new loop by closing the current history back
     to the first operation.
     """
-    full_preamble_needed=True
     history = metainterp.history
     loop = create_empty_loop(metainterp)
     loop.inputargs = history.inputargs

diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py
--- a/pypy/jit/metainterp/pyjitpl.py
+++ b/pypy/jit/metainterp/pyjitpl.py
@@ -1914,7 +1914,7 @@
         greenkey = original_boxes[:num_green_args]
         self.history.record(rop.JUMP, live_arg_boxes[num_green_args:], None)
         loop_token = compile.compile_new_loop(self, [], greenkey, start,
-                                              start_resumedescr)
+                                              start_resumedescr, False)
         self.history.operations.pop()     # remove the JUMP
         if loop_token is None:
             return
@@ -1928,7 +1928,8 @@
         self.history.record(rop.JUMP, bridge_arg_boxes[num_green_args:], None)
         try:
             target_loop_token = compile.compile_new_bridge(self,
-                                                           [loop_token],
+                                                           #[loop_token],
+                                                           old_loop_tokens,
                                                            self.resumekey,
                                                            True)
         except RetraceLoop:

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
@@ -466,6 +466,8 @@
                         str(untag(self.fieldnums[i])))
 
     def generalization_of(self, other):
+        if not self._generalization_of(other):
+            return False
         assert len(self.fielddescrs) == len(self.fieldstate)
         assert len(other.fielddescrs) == len(other.fieldstate)
         if len(self.fielddescrs) != len(other.fielddescrs):
@@ -477,7 +479,7 @@
             if not self.fieldstate[i].generalization_of(other.fieldstate[i]):
                 return False
 
-        return self._generalization_of(other)
+        return True
 
     def _generalization_of(self, other):
         raise NotImplementedError

diff --git a/pypy/jit/metainterp/test/test_basic.py b/pypy/jit/metainterp/test/test_basic.py
--- a/pypy/jit/metainterp/test/test_basic.py
+++ b/pypy/jit/metainterp/test/test_basic.py
@@ -1499,7 +1499,7 @@
         res = self.meta_interp(f, [299], listops=True)
         assert res == f(299)
         self.check_loops(guard_class=0, guard_value=3)        
-        self.check_loops(guard_class=0, guard_value=8, everywhere=True)
+        self.check_loops(guard_class=0, guard_value=6, everywhere=True)
 
     def test_merge_guardnonnull_guardclass(self):
         from pypy.rlib.objectmodel import instantiate
@@ -1530,7 +1530,7 @@
         self.check_loops(guard_class=0, guard_nonnull=0,
                          guard_nonnull_class=2, guard_isnull=1)
         self.check_loops(guard_class=0, guard_nonnull=0,
-                         guard_nonnull_class=5, guard_isnull=3,
+                         guard_nonnull_class=4, guard_isnull=2,
                          everywhere=True)
 
     def test_merge_guardnonnull_guardvalue(self):
@@ -1560,8 +1560,8 @@
         assert res == f(299)
         self.check_loops(guard_class=0, guard_nonnull=0, guard_value=2,
                          guard_nonnull_class=0, guard_isnull=1)
-        self.check_loops(guard_class=0, guard_nonnull=0, guard_value=5,
-                         guard_nonnull_class=0, guard_isnull=3,
+        self.check_loops(guard_class=0, guard_nonnull=0, guard_value=4,
+                         guard_nonnull_class=0, guard_isnull=2,
                          everywhere=True)
 
     def test_merge_guardnonnull_guardvalue_2(self):
@@ -1591,8 +1591,8 @@
         assert res == f(299)
         self.check_loops(guard_class=0, guard_nonnull=0, guard_value=2,
                          guard_nonnull_class=0, guard_isnull=1)
-        self.check_loops(guard_class=0, guard_nonnull=0, guard_value=5,
-                         guard_nonnull_class=0, guard_isnull=3,
+        self.check_loops(guard_class=0, guard_nonnull=0, guard_value=4,
+                         guard_nonnull_class=0, guard_isnull=2,
                          everywhere=True)
 
     def test_merge_guardnonnull_guardclass_guardvalue(self):
@@ -1625,8 +1625,8 @@
         assert res == f(399)
         self.check_loops(guard_class=0, guard_nonnull=0, guard_value=3,
                          guard_nonnull_class=0, guard_isnull=1)
-        self.check_loops(guard_class=0, guard_nonnull=0, guard_value=8,
-                         guard_nonnull_class=0, guard_isnull=3,
+        self.check_loops(guard_class=0, guard_nonnull=0, guard_value=6,
+                         guard_nonnull_class=0, guard_isnull=2,
                          everywhere=True)
 
     def test_residual_call_doesnt_lose_info(self):

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
@@ -541,6 +541,28 @@
             return sa
         assert self.meta_interp(f, [20]) == f(20)
 
+    def test_dual_counter(self):
+        myjitdriver = JitDriver(greens = [], reds = ['n', 's', 'node1', 'node2'])
+        def f(n, s):
+            node1 = self._new()
+            node1.value = 1
+            node2 = self._new()
+            node2.value = 2
+            while n > 0:
+                myjitdriver.can_enter_jit(n=n, s=s, node1=node1, node2=node2)
+                myjitdriver.jit_merge_point(n=n, s=s, node1=node1, node2=node2)
+                if (n>>s) & 1:
+                    next = self._new()
+                    next.value = node1.value + 1
+                    node1 = next
+                else:
+                    next = self._new()
+                    next.value = node2.value + 1
+                    node2 = next
+                n -= 1
+            return node1.value + node2.value
+        assert self.meta_interp(f, [300, 3]) == f(300, 3)
+        
 
 class VirtualMiscTests:
 


More information about the Pypy-commit mailing list