[pypy-commit] pypy conditional_call_value_2: in-progress. Issue: there is a lot of logic to handle call_pure already.

arigo pypy.commits at gmail.com
Sun Sep 11 11:18:58 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: conditional_call_value_2
Changeset: r87003:c0e117b21066
Date: 2016-09-11 17:18 +0200
http://bitbucket.org/pypy/pypy/changeset/c0e117b21066/

Log:	in-progress. Issue: there is a lot of logic to handle call_pure
	already. Maybe we should kill the resop call_pure and convert
	(hopefully not too hard) that logic to be about cond_call_pure?

diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -1738,8 +1738,7 @@
         effectinfo = descr.get_extra_info()
         assert not effectinfo.check_forces_virtual_or_virtualizable()
         exc = effectinfo.check_can_raise()
-        pure = effectinfo.check_is_elidable()
-        assert pure == (opnum != rop.COND_CALL)
+        pure = effectinfo.check_is_elidable() or (opnum != rop.COND_CALL)
         return self.execute_varargs(opnum,
                                     [condbox, specialvalbox] + allboxes,
                                     descr, exc, pure)
diff --git a/rpython/jit/metainterp/test/test_call.py b/rpython/jit/metainterp/test/test_call.py
--- a/rpython/jit/metainterp/test/test_call.py
+++ b/rpython/jit/metainterp/test/test_call.py
@@ -54,7 +54,6 @@
         self.check_resops(guard_no_exception=0)
 
     def test_cond_call_i(self):
-        @jit.elidable
         def f(n):
             return n * 200
 
@@ -65,7 +64,6 @@
         assert self.interp_operations(main, [15]) == 15
 
     def test_cond_call_r(self):
-        @jit.elidable
         def f(n):
             return [n]
 
@@ -81,7 +79,6 @@
         assert self.interp_operations(main, [5]) == 1
 
     def test_cond_call_constant_in_pyjitpl(self):
-        @jit.elidable
         def f(a, b):
             return a + b
         def main(n):
@@ -97,7 +94,6 @@
 
     def test_cond_call_constant_in_optimizer(self):
         myjitdriver = jit.JitDriver(greens = ['m'], reds = ['n', 'p'])
-        @jit.elidable
         def externfn(x):
             return x - 3
         class V:
@@ -118,12 +114,8 @@
 
     def test_cond_call_constant_in_optimizer_2(self):
         myjitdriver = jit.JitDriver(greens = ['m'], reds = ['n', 'p'])
-        @jit.elidable
         def externfn(x):
             return 2
-        class V:
-            def __init__(self, value):
-                self.value = value
         def f(n, m, p):
             while n > 0:
                 myjitdriver.can_enter_jit(n=n, p=p, m=m)
@@ -141,12 +133,8 @@
 
     def test_cond_call_constant_in_optimizer_3(self):
         myjitdriver = jit.JitDriver(greens = ['m'], reds = ['n', 'p'])
-        @jit.elidable
         def externfn(x):
             return 1
-        class V:
-            def __init__(self, value):
-                self.value = value
         def f(n, m, p):
             while n > 0:
                 myjitdriver.can_enter_jit(n=n, p=p, m=m)
@@ -165,6 +153,25 @@
         self.check_resops(call_pure_i=0, cond_call_pure_i=0, call_i=2,
                           int_sub=4)
 
+    def test_cond_call_constant_in_optimizer_4(self):
+        class X:
+            def __init__(self, value):
+                self.value = value
+                self.triple = -1
+            def _compute_triple(self):
+                self.triple = self.value * 3
+                return self.triple
+            def get_triple(self):
+                return jit.conditional_call_elidable(self.triple, -1,
+                                                     X._compute_triple, self)
+        def main(n, initvalue):
+            x = X(n)
+            x.triple = initvalue
+            return x.get_triple() + x.get_triple()
+
+        assert self.interp_operations(main, [100, -1]) == 600
+        self.check_operations_history(finish=1)   # empty history
+
 
 class TestCall(LLJitMixin, CallTest):
     pass
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -1210,8 +1210,8 @@
 
     whichever is better for the JIT.  Usually it first checks if 'value'
     is equal to 'special_constant', and conditionally calls
-    'function(*args)' if it is.  The 'function' must be marked as
-    @elidable.
+    'function(*args)' if it is.  The 'function' must not be marked as
+    @elidable, but is treated almost like an @elidable.
 
     If 'value != special_constant', then the JIT assumes that both
     solutions would work and _are equal_.  This means that if, say, all
@@ -1226,8 +1226,6 @@
         return _jit_conditional_call_elidable(value, special_constant,
                                               function, *args)
     else:
-        if not we_are_translated():
-            assert function._elidable_function_ # must call an elidable function
         if not we_are_translated() or isinstance(value, int):
             if value == special_constant:
                 value = function(*args)
@@ -1245,10 +1243,6 @@
         s_res = self.bookkeeper.emulate_pbc_call(self.bookkeeper.position_key,
                                                  args_s[2], args_s[3:])
         if self.instance is _jit_conditional_call_elidable:
-            function = args_s[2].const
-            assert getattr(function, '_elidable_function_', False), (
-                "jit.conditional_call_elidable() must call an elidable "
-                "function, but got %r" % (function,))
             return annmodel.unionof(s_res, args_s[0])
 
     def specialize_call(self, hop):
diff --git a/rpython/rlib/test/test_jit.py b/rpython/rlib/test/test_jit.py
--- a/rpython/rlib/test/test_jit.py
+++ b/rpython/rlib/test/test_jit.py
@@ -311,7 +311,6 @@
         t.compile_c() # does not crash
 
     def test_conditional_call_elidable(self):
-        @elidable
         def g(m):
             return m + 42
         def f(n, m):
@@ -326,7 +325,6 @@
 
     def test_compiled_conditional_call_elidable(self):
         from rpython.translator.c.test.test_genc import compile
-        @elidable
         def g(m):
             return m + 42
         def f(n, m):


More information about the pypy-commit mailing list