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

arigo at codespeak.net arigo at codespeak.net
Mon May 24 18:08:48 CEST 2010


Author: arigo
Date: Mon May 24 18:08:46 2010
New Revision: 74714

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/flatten.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/support.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_recursive.py
Log:
Automatically sorting the lists given to the JitDriver gives troubles
later when we need to reorder them back to match the one expected by the
callbacks.  Instead, just give the lists in the right order and that's it.


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	Mon May 24 18:08:46 2010
@@ -295,7 +295,8 @@
     def insert_renamings(self, link):
         renamings = {}
         lst = [(self.getcolor(v), self.getcolor(link.target.inputargs[i]))
-               for i, v in enumerate(link.args)]
+               for i, v in enumerate(link.args)
+               if v.concretetype is not lltype.Void]
         lst.sort(key=lambda(v, w): w.index)
         for v, w in lst:
             if v == w:

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/support.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/support.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/support.py	Mon May 24 18:08:46 2010
@@ -78,7 +78,7 @@
 
 def decode_hp_hint_args(op):
     # Returns (list-of-green-vars, list-of-red-vars) without Voids.
-    # Both lists are sorted: first INT, then REF, then FLOAT.
+    # Both lists must be sorted: first INT, then REF, then FLOAT.
     assert op.opname == 'jit_marker'
     jitdriver = op.args[1].value
     numgreens = len(jitdriver.greens)
@@ -91,7 +91,11 @@
         from pypy.jit.metainterp.history import getkind
         lst = [v for v in args_v if v.concretetype is not lltype.Void]
         _kind2count = {'int': 1, 'ref': 2, 'float': 3}
-        lst.sort(key=lambda v: _kind2count[getkind(v.concretetype)])
+        lst2 = sorted(lst, key=lambda v: _kind2count[getkind(v.concretetype)])
+        # a crash here means that you have to reorder the variable named in
+        # the JitDriver.  Indeed, greens and reds must both be sorted: first
+        # all INTs, followed by all REFs, followed by all FLOATs.
+        assert lst == lst2
         return lst
     #
     return (_sort(greens_v), _sort(reds_v))

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	Mon May 24 18:08:46 2010
@@ -1146,14 +1146,13 @@
         elif sd.result_type == 'int':
             raise sd.DoneWithThisFrameInt(self.final_result_i())
         elif sd.result_type == 'ref':
-            raise sd.DoneWithThisFrameRef(self.final_result_r())
+            raise sd.DoneWithThisFrameRef(self.cpu, self.final_result_r())
         elif sd.result_type == 'float':
             raise sd.DoneWithThisFrameFloat(self.final_result_f())
         else:
             assert False
 
     def _exit_frame_with_exception(self, e):
-        # rare case
         sd = self.builder.metainterp_sd
         e = lltype.cast_opaque_ptr(llmemory.GCREF, e)
         raise sd.ExitFrameWithExceptionRef(self.cpu, e)

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	Mon May 24 18:08:46 2010
@@ -854,7 +854,7 @@
         assert not res
 
     def test_isinstance_2(self):
-        driver = JitDriver(greens = [], reds = ['x', 'n', 'sum'])
+        driver = JitDriver(greens = [], reds = ['n', 'sum', 'x'])
         class A:
             pass
         class B(A):
@@ -1078,10 +1078,10 @@
 
     def test_residual_external_call(self):
         import math
-        myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res'])
+        myjitdriver = JitDriver(greens = [], reds = ['y', 'x', 'res'])
         def f(x, y):
             x = float(x)
-            res = 0
+            res = 0.0
             while y > 0:
                 myjitdriver.can_enter_jit(x=x, y=y, res=res)
                 myjitdriver.jit_merge_point(x=x, y=y, res=res)
@@ -1320,7 +1320,7 @@
         self.check_loops(call=1)
 
     def test_bug_optimizeopt_mutates_ops(self):
-        myjitdriver = JitDriver(greens = [], reds = ['x', 'res', 'a', 'const'])
+        myjitdriver = JitDriver(greens = [], reds = ['x', 'res', 'const', 'a'])
         class A(object):
             pass
         class B(A):

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_recursive.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_recursive.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_recursive.py	Mon May 24 18:08:46 2010
@@ -1,7 +1,7 @@
 import py
 from pypy.rlib.jit import JitDriver, we_are_jitted, OPTIMIZER_SIMPLE, hint
 from pypy.jit.metainterp.test.test_basic import LLJitMixin, OOJitMixin
-from pypy.jit.metainterp.policy import StopAtXPolicy
+from pypy.jit.codewriter.policy import StopAtXPolicy
 from pypy.rpython.annlowlevel import hlstr
 from pypy.jit.metainterp.warmspot import CannotInlineCanEnterJit, get_stats
 
@@ -105,11 +105,11 @@
             def can_inline(*args):
                 return True
         else:
-            def can_inline(code, i):
+            def can_inline(i, code):
                 code = hlstr(code)
                 return not JUMP_BACK in code
 
-        jitdriver = JitDriver(greens = ['code', 'i'], reds = ['n'],
+        jitdriver = JitDriver(greens = ['i', 'code'], reds = ['n'],
                               can_inline = can_inline)
  
         def interpret(codenum, n, i):



More information about the Pypy-commit mailing list