[pypy-commit] pypy conditional_call_value: work in progress
fijal
noreply at buildbot.pypy.org
Mon May 4 16:12:36 CEST 2015
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: conditional_call_value
Changeset: r77040:5d4b74957c3a
Date: 2015-05-04 16:12 +0200
http://bitbucket.org/pypy/pypy/changeset/5d4b74957c3a/
Log: work in progress
diff --git a/rpython/jit/codewriter/jtransform.py b/rpython/jit/codewriter/jtransform.py
--- a/rpython/jit/codewriter/jtransform.py
+++ b/rpython/jit/codewriter/jtransform.py
@@ -1492,7 +1492,7 @@
return []
return getattr(self, 'handle_jit_marker__%s' % key)(op, jitdriver)
- def rewrite_op_jit_conditional_call(self, op):
+ def _rewrite_op_jit_conditional_call(self, op):
have_floats = False
for arg in op.args:
if getkind(arg.concretetype) == 'float':
@@ -1500,16 +1500,27 @@
break
if len(op.args) > 4 + 2 or have_floats:
raise Exception("Conditional call does not support floats or more than 4 arguments")
- callop = SpaceOperation('direct_call', op.args[1:], op.result)
+ import pdb
+ pdb.set_trace()
+ if op.opname == 'jit_conditional_call':
+ callop = SpaceOperation('direct_call', op.args[1:], op.result)
+ cutoff = 2
+ else:
+ callop = SpaceOperation('direct_call', [op.args[1]] + op.args[3:],
+ op.result)
+ cutoff = 3
calldescr = self.callcontrol.getcalldescr(callop)
assert not calldescr.get_extra_info().check_forces_virtual_or_virtualizable()
op1 = self.rewrite_call(op, 'conditional_call',
- op.args[:2], args=op.args[2:],
+ op.args[:cutoff], args=op.args[cutoff:],
calldescr=calldescr)
if self.callcontrol.calldescr_canraise(calldescr):
op1 = [op1, SpaceOperation('-live-', [], None)]
return op1
+ rewrite_op_jit_conditional_call = _rewrite_op_jit_conditional_call
+ rewrite_op_jit_conditional_call_value = _rewrite_op_jit_conditional_call
+
def handle_jit_marker__jit_merge_point(self, op, jitdriver):
assert self.portal_jd is not None, (
"'jit_merge_point' in non-portal graph!")
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
@@ -56,6 +56,16 @@
assert self.interp_operations(main, [10]) == 1
assert self.interp_operations(main, [5]) == 0
+ def test_cond_call_value(self):
+ def f(n):
+ return n
+
+ def main(n):
+ return jit.conditional_call_value(n == 10, f, -3, n)
+
+ assert self.interp_operations(main, [10]) == 10
+ assert self.interp_operations(main, [5]) == -3
+
def test_cond_call_disappears(self):
driver = jit.JitDriver(greens = [], reds = ['n'])
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -1115,7 +1115,7 @@
_jit_conditional_call(condition, function, *args)
else:
if condition:
- function(*args)
+ return function(*args)
conditional_call._always_inline_ = True
class ConditionalCallEntry(ExtRegistryEntry):
@@ -1134,6 +1134,44 @@
hop.exception_is_here()
return hop.genop('jit_conditional_call', args_v)
+def _jit_conditional_call_value(condition, function, default_value, *args):
+ return default_value
+
+ at specialize.call_location()
+def conditional_call_value(condition, function, default_value, *args):
+ if we_are_jitted():
+ return _jit_conditional_call_value(condition, function, default_value,
+ *args)
+ else:
+ if condition:
+ return function(*args)
+ return default_value
+conditional_call._always_inline_ = True
+
+class ConditionalCallValueEntry(ExtRegistryEntry):
+ _about_ = _jit_conditional_call_value
+
+ def compute_result_annotation(self, *args_s):
+ import pdb
+ pdb.set_trace()
+ s_result = self.bookkeeper.emulate_pbc_call(
+ self.bookkeeper.position_key, args_s[1], args_s[3:],
+ callback=args_s[1])
+ return s_result
+
+ def specialize_call(self, hop):
+ import pdb
+ pdb.set_trace()
+ 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[3:], hop.spaceop)
+ hop.exception_is_here()
+ resulttype = hop.r_result
+ return hop.genop('jit_conditional_call_value', args_v,
+ resulttype=resulttype)
+
class Counters(object):
counters="""
TRACING
diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py
--- a/rpython/rtyper/llinterp.py
+++ b/rpython/rtyper/llinterp.py
@@ -548,6 +548,9 @@
def op_jit_conditional_call(self, *args):
raise NotImplementedError("should not be called while not jitted")
+ def op_jit_conditional_call_value(self, *args):
+ raise NotImplementedError("should not be called while not jitted")
+
def op_get_exception_addr(self, *args):
raise NotImplementedError
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
@@ -451,7 +451,8 @@
'jit_force_quasi_immutable': LLOp(canrun=True),
'jit_record_known_class' : LLOp(canrun=True),
'jit_ffi_save_result': LLOp(canrun=True),
- 'jit_conditional_call': LLOp(),
+ 'jit_conditional_call': LLOp(),
+ 'jit_conditional_call_value': LLOp(),
'get_exception_addr': LLOp(),
'get_exc_value_addr': LLOp(),
'do_malloc_fixedsize':LLOp(canmallocgc=True),
More information about the pypy-commit
mailing list