Author: Armin Rigo <ar...@tunes.org>
Branch: conditional_call_value_2
Changeset: r86988:0e155e8e286a
Date: 2016-09-11 09:53 +0200
http://bitbucket.org/pypy/pypy/changeset/0e155e8e286a/

Log:    Goal

diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -1178,33 +1178,47 @@
         hop.exception_is_here()
         return hop.gendirectcall(ll_record_exact_class, v_inst, v_cls)
 
-def _jit_conditional_call(condition, function, *args):
-    pass
+def _jit_conditional_call_value(value, special_constant, function, *args):
+    """NOT_RPYTHON"""
 
 @specialize.call_location()
 def conditional_call(condition, function, *args):
     if we_are_jitted():
-        _jit_conditional_call(condition, function, *args)
+        _jit_conditional_call_value(condition, True, function, *args)
     else:
         if condition:
             function(*args)
 conditional_call._always_inline_ = True
 
+@specialize.call_location()
+def conditional_call_value(value, special_constant, function, *args):
+    if we_are_jitted():
+        return _jit_conditional_call_value(value, special_constant,
+                                           function, *args)
+    else:
+        if value == special_constant:
+            value = function(*args)
+        return value
+conditional_call_value._always_inline_ = True
+
 class ConditionalCallEntry(ExtRegistryEntry):
-    _about_ = _jit_conditional_call
+    _about_ = _jit_conditional_call_value
 
     def compute_result_annotation(self, *args_s):
         self.bookkeeper.emulate_pbc_call(self.bookkeeper.position_key,
-                                         args_s[1], args_s[2:])
+                                         args_s[2], args_s[3:])
+        return args_s[0]
 
     def specialize_call(self, hop):
         from rpython.rtyper.lltypesystem import lltype
 
-        args_v = hop.inputargs(lltype.Bool, lltype.Void, *hop.args_r[2:])
-        args_v[1] = hop.args_r[1].get_concrete_llfn(hop.args_s[1],
-                                                    hop.args_s[2:], 
hop.spaceop)
+        r_value = hop.args_r[0]
+        args_v = hop.inputargs(r_value, r_value, lltype.Void, *hop.args_r[3:])
+        args_v[2] = hop.args_r[2].get_concrete_llfn(hop.args_s[2],
+                                                    hop.args_s[3:], 
hop.spaceop)
         hop.exception_is_here()
-        return hop.genop('jit_conditional_call', args_v)
+        return hop.genop('jit_conditional_call_value', args_v,
+                         resulttype=r_value)
 
 def enter_portal_frame(unique_id):
     """call this when starting to interpret a function. calling this is not
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
@@ -3,7 +3,7 @@
 from rpython.conftest import option
 from rpython.annotator.model import UnionError
 from rpython.rlib.jit import (hint, we_are_jitted, JitDriver, elidable_promote,
-    JitHintError, oopspec, isconstant, conditional_call,
+    JitHintError, oopspec, isconstant, conditional_call, 
conditional_call_value,
     elidable, unroll_safe, dont_look_inside,
     enter_portal_frame, leave_portal_frame)
 from rpython.rlib.rarithmetic import r_uint
@@ -309,3 +309,14 @@
             leave_portal_frame()
         t = Translation(g, [])
         t.compile_c() # does not crash
+
+    def test_conditional_call_value(self):
+        def g(m):
+            return m + 42
+        def f(n, m):
+            return conditional_call_value(n, -1, g, m)
+
+        res = self.interpret(f, [10, 200])
+        assert res == 10
+        res = self.interpret(f, [-1, 200])
+        assert res == 242
diff --git a/rpython/rtyper/lltypesystem/lloperation.py 
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -430,7 +430,7 @@
     'jit_force_quasi_immutable': LLOp(canrun=True),
     'jit_record_exact_class'  : LLOp(canrun=True),
     'jit_ffi_save_result':  LLOp(canrun=True),
-    'jit_conditional_call': LLOp(),
+    'jit_conditional_call_value': LLOp(),
     'jit_enter_portal_frame': LLOp(canrun=True),
     'jit_leave_portal_frame': LLOp(canrun=True),
     'get_exception_addr':   LLOp(),
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to