[pypy-svn] r74230 - in pypy/branch/blackhole-improvement/pypy/jit: backend/llgraph metainterp
arigo at codespeak.net
arigo at codespeak.net
Thu Apr 29 17:48:49 CEST 2010
Author: arigo
Date: Thu Apr 29 17:48:47 2010
New Revision: 74230
Modified:
pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py
pypy/branch/blackhole-improvement/pypy/jit/metainterp/executor.py
pypy/branch/blackhole-improvement/pypy/jit/metainterp/history.py
pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
Log:
Port residual_call to pyjitpl. In-progress.
Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py Thu Apr 29 17:48:47 2010
@@ -29,6 +29,9 @@
self.extrainfo = extrainfo
self.name = name
+ def get_return_type(self):
+ return self.typeinfo
+
def get_extra_info(self):
return self.extrainfo
Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/executor.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/executor.py Thu Apr 29 17:48:47 2010
@@ -9,8 +9,58 @@
from pypy.tool.sourcetools import func_with_new_name
from pypy.rlib.unroll import unrolling_iterable
from pypy.jit.metainterp.history import BoxInt, BoxPtr, BoxFloat, check_descr
+from pypy.jit.metainterp.history import INT, REF, FLOAT
from pypy.jit.metainterp import resoperation
from pypy.jit.metainterp.resoperation import rop
+from pypy.jit.metainterp.blackhole import BlackholeInterpreter, NULL
+
+# ____________________________________________________________
+
+def do_call(cpu, argboxes, descr):
+ # count the number of arguments of the different types
+ count_i = count_r = count_f = 0
+ for i in range(1, len(argboxes)):
+ type = argboxes[i].type
+ if type == INT: count_i += 1
+ elif type == REF: count_r += 1
+ elif type == FLOAT: count_f += 1
+ # allocate lists for each type that has at least one argument
+ if count_i: args_i = [0] * count_i
+ else: args_i = None
+ if count_r: args_r = [NULL] * count_r
+ else: args_r = None
+ if count_f: args_f = [0.0] * count_f
+ else: args_f = None
+ # fill in the lists
+ count_i = count_r = count_f = 0
+ for i in range(1, len(argboxes)):
+ box = argboxes[i]
+ if box.type == INT:
+ args_i[count_i] = box.getint()
+ count_i += 1
+ elif box.type == REF:
+ args_r[count_r] = box.getptr_base()
+ count_r += 1
+ elif box.type == FLOAT:
+ args_f[count_f] = box.getfloat()
+ count_f += 1
+ # get the function address as an integer
+ func = argboxes[0].getint()
+ # do the call using the correct function from the cpu
+ rettype = descr.get_return_type()
+ if rettype == INT:
+ result = cpu.bh_call_i(func, descr, args_i, args_r, args_f)
+ return BoxInt(result)
+ if rettype == REF:
+ result = cpu.bh_call_r(func, descr, args_i, args_r, args_f)
+ return BoxPtr(result)
+ if rettype == FLOAT:
+ result = cpu.bh_call_f(func, descr, args_i, args_r, args_f)
+ return BoxFloat(result)
+ if rettype == 'v': # void
+ cpu.bh_call_v(func, descr, args_i, args_r, args_f)
+ return None
+ raise AssertionError("bad rettype")
# ____________________________________________________________
@@ -33,7 +83,6 @@
def make_execute_list(cpuclass):
from pypy.jit.backend.model import AbstractCPU
- from pypy.jit.metainterp.blackhole import BlackholeInterpreter
if 0: # enable this to trace calls to do_xxx
def wrap(fn):
def myfn(*args):
@@ -74,7 +123,11 @@
if func is not None:
execute[value] = func
continue
- pass #XXX...
+ name = 'do_' + key.lower()
+ if name in globals():
+ execute[value] = globals()[name]
+ continue
+ pass # XXX...
cpuclass._execute_by_num_args = execute_by_num_args
def make_execute_function_with_boxes(name, func):
@@ -98,12 +151,14 @@
elif argtype == 'r': value = argbox.getptr_base()
elif argtype == 'f': value = argbox.getfloat()
newargs = newargs + (value,)
+ assert not argboxes
#
result = func(*newargs)
#
if resulttype == 'i': return BoxInt(result)
if resulttype == 'r': return BoxPtr(result)
if resulttype == 'f': return BoxFloat(result)
+ return None
#
return func_with_new_name(do, 'do_' + name)
Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/history.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/history.py Thu Apr 29 17:48:47 2010
@@ -125,6 +125,12 @@
def _clone_if_mutable(self):
return self
+ def get_return_type(self):
+ """ Implement in call descr.
+ Must return INT, REF, FLOAT, or 'v' for void.
+ """
+ raise NotImplementedError
+
def get_extra_info(self):
""" Implement in call descr
"""
Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py Thu Apr 29 17:48:47 2010
@@ -609,10 +609,29 @@
def opimpl_call(self, callee, varargs):
return self.perform_call(callee, varargs)
+ @arguments("box", "descr", "boxes")
+ def _opimpl_residual_call1(self, funcbox, calldescr, argboxes):
+ return self.do_residual_call(funcbox, calldescr, argboxes, exc=True)
@arguments("box", "descr", "boxes2")
- def opimpl_residual_call_ir_i(self, funcbox, calldescr, argboxes):
+ def _opimpl_residual_call2(self, funcbox, calldescr, argboxes):
+ return self.do_residual_call(funcbox, calldescr, argboxes, exc=True)
+ @arguments("box", "descr", "boxes3")
+ def _opimpl_residual_call3(self, funcbox, calldescr, argboxes):
return self.do_residual_call(funcbox, calldescr, argboxes, exc=True)
+ opimpl_residual_call_r_i = _opimpl_residual_call1
+ opimpl_residual_call_r_r = _opimpl_residual_call1
+ opimpl_residual_call_r_f = _opimpl_residual_call1
+ opimpl_residual_call_r_v = _opimpl_residual_call1
+ opimpl_residual_call_ir_i = _opimpl_residual_call2
+ opimpl_residual_call_ir_r = _opimpl_residual_call2
+ opimpl_residual_call_ir_f = _opimpl_residual_call2
+ opimpl_residual_call_ir_v = _opimpl_residual_call2
+ opimpl_residual_call_irf_i = _opimpl_residual_call3
+ opimpl_residual_call_irf_r = _opimpl_residual_call3
+ opimpl_residual_call_irf_f = _opimpl_residual_call3
+ opimpl_residual_call_irf_v = _opimpl_residual_call3
+
@arguments("descr", "varargs")
def opimpl_residual_call_loopinvariant(self, calldescr, varargs):
return self.execute_varargs(rop.CALL_LOOPINVARIANT, varargs, calldescr, exc=True)
@@ -1016,23 +1035,24 @@
@specialize.arg(1)
def execute_varargs(self, opnum, argboxes, descr, exc):
- resbox = self.metainterp.execute_and_record_varargs(opnum, argboxes,
- descr=descr)
- if resbox is not None:
- self.make_result_box(resbox)
- if exc:
- return self.metainterp.handle_exception()
- else:
- return self.metainterp.assert_no_exception()
+ return self.metainterp.execute_and_record_varargs(opnum, argboxes,
+ descr=descr)
+## if resbox is not None:
+## self.make_result_box(resbox)
+## if exc:
+## return self.metainterp.handle_exception()
+## else:
+## return self.metainterp.assert_no_exception()
def do_residual_call(self, funcbox, descr, argboxes, exc):
+ allboxes = [funcbox] + argboxes
effectinfo = descr.get_extra_info()
if 0:# XXX effectinfo is None or effectinfo.forces_virtual_or_virtualizable:
# residual calls require attention to keep virtualizables in-sync
self.metainterp.vable_and_vrefs_before_residual_call()
# xxx do something about code duplication
resbox = self.metainterp.execute_and_record_varargs(
- rop.CALL_MAY_FORCE, argboxes, descr=descr)
+ rop.CALL_MAY_FORCE, allboxes, descr=descr)
self.metainterp.vable_and_vrefs_after_residual_call()
if resbox is not None:
self.make_result_box(resbox)
@@ -1042,7 +1062,7 @@
else:
return self.metainterp.assert_no_exception()
else:
- return self.execute_varargs(rop.CALL, argboxes, descr, exc)
+ return self.execute_varargs(rop.CALL, allboxes, descr, exc)
# ____________________________________________________________
More information about the Pypy-commit
mailing list