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

fijal at codespeak.net fijal at codespeak.net
Wed Feb 11 15:19:09 CET 2009


Author: fijal
Date: Wed Feb 11 15:19:08 2009
New Revision: 61732

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_loop.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_send.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_tlc.py
Log:
(arigo, fijal)
Make a next test for automatically promoting vars from whatever they are
to greens at merge point


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/codewriter.py	Wed Feb 11 15:19:08 2009
@@ -506,7 +506,8 @@
         assert self.portal, "jit_marker in non-main graph!"
         if op.args[0].value == 'jit_merge_point':
             self.emit('jit_merge_point')
-            self.emit_varargs(op.args[2:])
+            assert ([self.var_position(i) for i in op.args[2:]] ==
+                    range(0, 2*(len(op.args) - 2), 2))
         elif op.args[0].value == 'can_enter_jit':
             self.emit('can_enter_jit')
             self.emit_varargs(op.args[2:])

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Wed Feb 11 15:19:08 2009
@@ -486,18 +486,21 @@
     def opimpl_keepalive(self, box):
         pass     # xxx?
 
-    def _check_for_black_hole(self, varargs):
+    def generate_merge_point(self, pc, varargs):
         if isinstance(self.metainterp.history, history.BlackHole):
-            raise self.metainterp.ContinueRunningNormally(varargs)        
+            raise self.metainterp.ContinueRunningNormally(varargs)
+        num_green_args = self.metainterp.warmrunnerdesc.num_green_args
+        for i in range(num_green_args):
+            varargs[i] = self.implement_guard_value(pc, varargs[i])
 
-    @arguments("varargs")
-    def opimpl_can_enter_jit(self, varargs):
-        self._check_for_black_hole(varargs)
+    @arguments("orgpc", "varargs")
+    def opimpl_can_enter_jit(self, pc, varargs):
+        self.generate_merge_point(pc, varargs)
         raise GenerateMergePoint(varargs)
 
-    @arguments("varargs")
-    def opimpl_jit_merge_point(self, varargs):
-        self._check_for_black_hole(varargs)
+    @arguments("orgpc")
+    def opimpl_jit_merge_point(self, pc):
+        self.generate_merge_point(pc, self.env)
 
     @arguments("jumptarget")
     def opimpl_setup_exception_block(self, exception_target):

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_loop.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_loop.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_loop.py	Wed Feb 11 15:19:08 2009
@@ -280,3 +280,89 @@
         loops = get_stats().loops
         assert loops[0].operations[0].opname == 'merge_point'
         assert loops[1].operations[0].opname == 'catch'
+
+
+    def test_example(self):
+        myjitdriver = JitDriver(greens = ['i'],
+                                reds = ['res', 'a'])
+        CO_INCREASE = 0
+        CO_JUMP_BACK_3 = 1
+        CO_DECREASE = 2
+        
+        code = [CO_INCREASE, CO_INCREASE, CO_INCREASE,
+                CO_JUMP_BACK_3, CO_INCREASE, CO_DECREASE]
+        
+        def add(res, a):
+            return res + a
+
+        def sub(res, a):
+            return res - a
+        
+        def main_interpreter_loop(a):
+            i = 0
+            res = 0
+            c = len(code)
+            while i < c:
+                myjitdriver.jit_merge_point(res=res, i=i, a=a)
+                elem = code[i]
+                if elem == CO_INCREASE:
+                    res = add(res, a)
+                elif elem == CO_DECREASE:
+                    res = sub(res, a)
+                else:
+                    if res > 100:
+                        pass
+                    else:
+                        i = i - 3
+                        myjitdriver.can_enter_jit(res=res, i=i, a=a)
+                        continue
+                i = i + 1
+            return res
+
+        res = self.meta_interp(main_interpreter_loop, [1])
+        assert res == 102
+        self.check_loop_count(1)
+        self.check_loops({'merge_point' : 1, 'int_add' : 3, 'int_gt' : 1,
+                          'guard_false' : 1, 'jump' : 1})
+
+    def test_automatic_promotion(self):
+        myjitdriver = JitDriver(greens = ['i'],
+                                reds = ['res', 'a'])
+        CO_INCREASE = 0
+        CO_JUMP_BACK_3 = 1
+        
+        code = [CO_INCREASE, CO_INCREASE, CO_INCREASE,
+                CO_JUMP_BACK_3, CO_INCREASE]
+        
+        def add(res, a):
+            return res + a
+
+        def sub(res, a):
+            return res - a
+        
+        def main_interpreter_loop(a):
+            i = 0
+            res = 0
+            c = len(code)
+            while True:
+                myjitdriver.jit_merge_point(res=res, i=i, a=a)
+                if i >= c:
+                    break
+                elem = code[i]
+                if elem == CO_INCREASE:
+                    i += a
+                    res += a
+                else:
+                    if res > 100:
+                        i += 1
+                    else:
+                        i = i - 3
+                        myjitdriver.can_enter_jit(res=res, i=i, a=a)
+            return res
+
+        res = self.meta_interp(main_interpreter_loop, [1])
+        assert res == main_interpreter_loop(1)
+        self.check_loop_count(1)
+        # XXX maybe later optimize guard_value away
+        self.check_loops({'merge_point' : 1, 'int_add' : 6, 'int_gt' : 1,
+                          'guard_false' : 1, 'jump' : 1, 'guard_value' : 3})

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_send.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_send.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_send.py	Wed Feb 11 15:19:08 2009
@@ -285,49 +285,6 @@
         self.check_loop_count(1)
         self.check_loops(int_add=0, int_mul=1, guard_class=0)
 
-    def test_example(self):
-        myjitdriver = JitDriver(greens = ['i'],
-                                reds = ['res', 'a'])
-        CO_INCREASE = 0
-        CO_JUMP_BACK_3 = 1
-        CO_DECREASE = 2
-        
-        code = [CO_INCREASE, CO_INCREASE, CO_INCREASE,
-                CO_JUMP_BACK_3, CO_INCREASE, CO_DECREASE]
-        
-        def add(res, a):
-            return res + a
-
-        def sub(res, a):
-            return res - a
-        
-        def main_interpreter_loop(a):
-            i = 0
-            res = 0
-            c = len(code)
-            while i < c:
-                myjitdriver.jit_merge_point(res=res, i=i, a=a)
-                elem = code[i]
-                if elem == CO_INCREASE:
-                    res = add(res, a)
-                elif elem == CO_DECREASE:
-                    res = sub(res, a)
-                else:
-                    if res > 100:
-                        pass
-                    else:
-                        i = i - 3
-                        myjitdriver.can_enter_jit(res=res, i=i, a=a)
-                        continue
-                i = i + 1
-            return res
-
-        res = self.meta_interp(main_interpreter_loop, [1])
-        assert res == 102
-        self.check_loop_count(1)
-        self.check_loops({'merge_point' : 1, 'int_add' : 3, 'int_gt' : 1,
-                          'guard_false' : 1, 'jump' : 1})
-
 class TestOOtype(SendTests, OOJitMixin):
     pass
 

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_tlc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_tlc.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_tlc.py	Wed Feb 11 15:19:08 2009
@@ -10,9 +10,11 @@
 class TLCTests:
 
     def _get_interp(self, bytecode, pool):
-        def interp(inputarg):
+        codes = [bytecode, '']
+        pools = [pool, None]
+        def interp(i, inputarg):
             args = [tlc.IntObj(inputarg)]
-            obj = tlc.interp_eval(bytecode, 0, args, pool)
+            obj = tlc.interp_eval(codes[i], 0, args, pools[i])
             return obj.int_o()
         return interp
 
@@ -20,7 +22,7 @@
         pool = tlc.ConstantPool()
         bytecode = tlc.compile(src, pool)
         interp = self._get_interp(bytecode, pool)
-        return self.meta_interp(interp, [inputarg], view=False)
+        return self.meta_interp(interp, [0, inputarg], view=False)
 
     def test_method(self):
         code = """
@@ -42,7 +44,6 @@
         assert res == 42
 
     def test_accumulator(self):
-        py.test.skip("takes too long and does not optimize :-(")
         path = py.path.local(tlc.__file__).dirpath('accumulator.tlc.src')
         code = path.read()
         res = self.exec_code(code, 20)



More information about the Pypy-commit mailing list