[pypy-svn] r74272 - in pypy/branch/blackhole-improvement/pypy/jit: codewriter codewriter/test metainterp metainterp/test

arigo at codespeak.net arigo at codespeak.net
Fri Apr 30 10:37:41 CEST 2010


Author: arigo
Date: Fri Apr 30 10:37:37 2010
New Revision: 74272

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_regalloc.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py
Log:
Kill the int_rename operation, and do its job with an explicit
list of operations int_push/int_copy/int_copy/.../int_copy/int_pop.


Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py	Fri Apr 30 10:37:37 2010
@@ -262,16 +262,18 @@
         for kind in KINDS:
             if kind in renamings:
                 frm, to = renamings[kind]
-                # If there is no cycle among the renamings, produce a series
-                # of %s_copy.  Otherwise, just one %s_rename.
+                # Produce a series of %s_copy.  If there is a cycle, it
+                # is handled with a %s_push to save the first value of
+                # the cycle, some number of %s_copy, and finally a
+                # %s_pop to load the last value.
                 result = reorder_renaming_list(frm, to)
-                if result is not None:
-                    for v, w in result:
+                for v, w in result:
+                    if w is None:
+                        self.emitline('%s_push' % kind, v)
+                    elif v is None:
+                        self.emitline('%s_pop' % kind, w)
+                    else:
                         self.emitline('%s_copy' % kind, v, w)
-                else:
-                    frm = ListOfKind(kind, frm)
-                    to  = ListOfKind(kind, to)
-                    self.emitline('%s_rename' % kind, frm, to)
 
     def emitline(self, *line):
         self.ssarepr.insns.append(line)
@@ -326,6 +328,10 @@
             else:
                 still_pending_indices.append(i)
         if len(pending_indices) == len(still_pending_indices):
-            return None    # no progress -- there is a cycle
+            # no progress -- there is a cycle
+            assert None not in not_read
+            result.append((frm[pending_indices[0]], None))
+            frm[pending_indices[0]] = None
+            continue
         pending_indices = still_pending_indices
     return result

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_flatten.py	Fri Apr 30 10:37:37 2010
@@ -56,9 +56,12 @@
     result = reorder_renaming_list([4, 5, 1, 2], [1, 2, 3, 4])
     assert result == [(1, 3), (4, 1), (2, 4), (5, 2)]
     result = reorder_renaming_list([1, 2], [2, 1])
-    assert result == None
-    result = reorder_renaming_list([4, 3, 1, 2, 6], [1, 2, 3, 4, 5])
-    assert result == None
+    assert result == [(1, None), (2, 1), (None, 2)]
+    result = reorder_renaming_list([4, 3, 6, 1, 2, 5, 7],
+                                   [1, 2, 5, 3, 4, 6, 8])
+    assert result == [(7, 8),
+                      (4, None), (2, 4), (3, 2), (1, 3), (None, 1),
+                      (6, None), (5, 6), (None, 5)]
 
 def test_repr():
     assert repr(Register('int', 13)) == '%i13'

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_regalloc.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_regalloc.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_regalloc.py	Fri Apr 30 10:37:37 2010
@@ -77,7 +77,9 @@
             L1:
             int_gt %i0, $0, %i2
             goto_if_not L2, %i2
-            int_rename I[%i1, %i0], I[%i0, %i1]
+            int_push %i1
+            int_copy %i0, %i1
+            int_pop %i0
             goto L1
             L2:
             int_return %i1
@@ -110,7 +112,10 @@
             L1:
             int_gt %i0, $0, %i3
             goto_if_not L2, %i3
-            int_rename I[%i1, %i2, %i0], I[%i0, %i1, %i2]
+            int_push %i1
+            int_copy %i2, %i1
+            int_copy %i0, %i2
+            int_pop %i0
             goto L1
             L2:
             int_return %i1

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	Fri Apr 30 10:37:37 2010
@@ -266,13 +266,13 @@
                 position = self.handle_exception_in_frame(e, code)
 
     def get_result_i(self):
-        return self.registers_i[0]
+        return self.tmpreg_i
 
     def get_result_r(self):
-        return self.registers_r[0]
+        return self.tmpreg_r
 
     def get_result_f(self):
-        return self.registers_f[0]
+        return self.tmpreg_f
 
     def _get_result_anytype(self):
         "NOT_RPYTHON"
@@ -291,6 +291,7 @@
         while i >= 0:
             self.registers_r[i] = NULL
             i -= 1
+        self.tmpreg_r = NULL
         self.exception_last_value = None
 
     def handle_exception_in_frame(self, e, code):
@@ -466,6 +467,26 @@
     bhimpl_ref_guard_value = bhimpl_ref_copy
     bhimpl_float_guard_value = bhimpl_float_copy
 
+    @arguments("self", "i")
+    def bhimpl_int_push(self, a):
+        self.tmpreg_i = a
+    @arguments("self", "r")
+    def bhimpl_ref_push(self, a):
+        self.tmpreg_r = a
+    @arguments("self", "f")
+    def bhimpl_float_push(self, a):
+        self.tmpreg_f = a
+
+    @arguments("self", returns="i")
+    def bhimpl_int_pop(self):
+        return self.tmpreg_i
+    @arguments("self", returns="r")
+    def bhimpl_ref_pop(self):
+        return self.tmpreg_r
+    @arguments("self", returns="f")
+    def bhimpl_float_pop(self):
+        return self.tmpreg_f
+
     # ----------
     # float operations
 
@@ -526,21 +547,21 @@
 
     @arguments("self", "i")
     def bhimpl_int_return(self, a):
-        self.registers_i[0] = a
+        self.tmpreg_i = a
         if not we_are_translated():
             self._return_type = "int"
         raise LeaveFrame
 
     @arguments("self", "r")
     def bhimpl_ref_return(self, a):
-        self.registers_r[0] = a
+        self.tmpreg_r = a
         if not we_are_translated():
             self._return_type = "ref"
         raise LeaveFrame
 
     @arguments("self", "f")
     def bhimpl_float_return(self, a):
-        self.registers_f[0] = a
+        self.tmpreg_f = a
         if not we_are_translated():
             self._return_type = "float"
         raise LeaveFrame

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py	Fri Apr 30 10:37:37 2010
@@ -1389,6 +1389,16 @@
         # this checks that the logic triggered by make_a_counter_per_value()
         # works and prevents generating tons of bridges
 
+    def test_swap_values(self):
+        def f(x, y):
+            if x > 5:
+                x, y = y, x
+            return x - y
+        res = self.interp_operations(f, [10, 2])
+        assert res == -8
+        res = self.interp_operations(f, [3, 2])
+        assert res == 1
+
 
 class TestOOtype(BasicTests, OOJitMixin):
 



More information about the Pypy-commit mailing list