[pypy-svn] r77815 - in pypy/branch/jitffi/pypy/jit: codewriter metainterp/optimizeopt metainterp/test
antocuni at codespeak.net
antocuni at codespeak.net
Tue Oct 12 11:25:24 CEST 2010
Author: antocuni
Date: Tue Oct 12 11:25:21 2010
New Revision: 77815
Modified:
pypy/branch/jitffi/pypy/jit/codewriter/effectinfo.py
pypy/branch/jitffi/pypy/jit/codewriter/jtransform.py
pypy/branch/jitffi/pypy/jit/metainterp/optimizeopt/fficall.py
pypy/branch/jitffi/pypy/jit/metainterp/test/test_optimizeopt.py
Log:
use the new "official" way to detect oopspec, i.e. by using Effectinfo.OS_*.
This should be make the code translatable
Modified: pypy/branch/jitffi/pypy/jit/codewriter/effectinfo.py
==============================================================================
--- pypy/branch/jitffi/pypy/jit/codewriter/effectinfo.py (original)
+++ pypy/branch/jitffi/pypy/jit/codewriter/effectinfo.py Tue Oct 12 11:25:21 2010
@@ -31,6 +31,9 @@
OS_STREQ_NONNULL_CHAR = 12 # s1 == char (assert s1!=NULL)
OS_STREQ_CHECKNULL_CHAR = 13 # s1!=NULL and s1==char
OS_STREQ_LENGTHOK = 14 # s1 == s2 (assert len(s1)==len(s2))
+ OS_LIBFFI_PREPARE = 15
+ OS_LIBFFI_PUSH_ARG = 16
+ OS_LIBFFI_CALL = 17
def __new__(cls, readonly_descrs_fields,
write_descrs_fields, write_descrs_arrays,
Modified: pypy/branch/jitffi/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/branch/jitffi/pypy/jit/codewriter/jtransform.py (original)
+++ pypy/branch/jitffi/pypy/jit/codewriter/jtransform.py Tue Oct 12 11:25:21 2010
@@ -318,6 +318,8 @@
prepare = self._handle_stroruni_call
elif oopspec_name.startswith('virtual_ref'):
prepare = self._handle_virtual_ref_call
+ elif oopspec_name.startswith('libffi_'):
+ prepare = self._handle_libffi_call
else:
prepare = self.prepare_builtin_call
try:
@@ -1121,6 +1123,20 @@
vrefinfo.JIT_VIRTUAL_REF)
return SpaceOperation(oopspec_name, list(args), op.result)
+ # -----------
+ # rlib.libffi
+
+ def _handle_libffi_call(self, op, oopspec_name, args):
+ if oopspec_name == 'libffi_prepare_call':
+ oopspecindex = EffectInfo.OS_LIBFFI_PREPARE
+ elif oopspec_name.startswith('libffi_push_'):
+ oopspecindex = EffectInfo.OS_LIBFFI_PUSH_ARG
+ elif oopspec_name.startswith('libffi_call_'):
+ oopspecindex = EffectInfo.OS_LIBFFI_CALL
+ else:
+ assert False, 'unsupported oopspec: %s' % oopspec_name
+ return self._handle_oopspec_call(op, args, oopspecindex)
+
def rewrite_op_jit_force_virtual(self, op):
return self._do_builtin_call(op)
Modified: pypy/branch/jitffi/pypy/jit/metainterp/optimizeopt/fficall.py
==============================================================================
--- pypy/branch/jitffi/pypy/jit/metainterp/optimizeopt/fficall.py (original)
+++ pypy/branch/jitffi/pypy/jit/metainterp/optimizeopt/fficall.py Tue Oct 12 11:25:21 2010
@@ -1,6 +1,7 @@
from pypy.rpython.annlowlevel import cast_base_ptr_to_instance
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.libffi import Func
+from pypy.jit.codewriter.effectinfo import EffectInfo
from pypy.jit.metainterp.resoperation import rop, ResOperation
from pypy.jit.metainterp.optimizeutil import _findall
from pypy.jit.metainterp.optimizeopt.optimizer import Optimization
@@ -60,35 +61,25 @@
def __init__(self):
self.func_infos = {}
- def get_oopspec(self, funcval):
- # XXX: not RPython at all, just a hack while waiting to have an
- # "official" way to know if and which oopspec we are calling
- funcname = str(funcval.box)
- if '_libffi_prepare_call' in funcname:
- return 'prepare_call'
- elif '_libffi_push_' in funcname:
- return 'push_arg'
- elif '_libffi_call' in funcname:
- return 'call'
- return None
-
def optimize_CALL(self, op):
if we_are_translated():
self.emit_operation(op)
return
#
- targetval = self.getvalue(op.getarg(0))
- oopspec = self.get_oopspec(targetval)
- if oopspec not in ('prepare_call', 'push_arg', 'call'):
+ effectinfo = op.getdescr().get_extra_info()
+ oopspec = effectinfo.oopspecindex
+ if oopspec not in (EffectInfo.OS_LIBFFI_PREPARE,
+ EffectInfo.OS_LIBFFI_PUSH_ARG,
+ EffectInfo.OS_LIBFFI_CALL):
self.emit_operation(op) # normal case
return
#
try:
- if oopspec == 'prepare_call':
+ if oopspec == EffectInfo.OS_LIBFFI_PREPARE:
self.do_prepare_call(op)
- elif oopspec == 'push_arg':
+ elif oopspec == EffectInfo.OS_LIBFFI_PUSH_ARG:
self.do_push_arg(op)
- elif oopspec == 'call':
+ elif oopspec == EffectInfo.OS_LIBFFI_CALL:
op = self.do_call(op)
self.emit_operation(op)
except NonConstantFuncVal:
Modified: pypy/branch/jitffi/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/jitffi/pypy/jit/metainterp/test/test_optimizeopt.py (original)
+++ pypy/branch/jitffi/pypy/jit/metainterp/test/test_optimizeopt.py Tue Oct 12 11:25:21 2010
@@ -4503,6 +4503,7 @@
from pypy.rpython.lltypesystem import llmemory
from pypy.rlib.libffi import Func, types
from pypy.jit.metainterp.history import AbstractDescr
+from pypy.jit.codewriter.effectinfo import EffectInfo
class MyCallDescr(AbstractDescr):
"""
@@ -4534,22 +4535,30 @@
class namespace:
cpu = LLtypeMixin.cpu
- plaincalldescr = LLtypeMixin.plaincalldescr
+ FUNC = LLtypeMixin.FUNC
int_float__int = MyCallDescr('if', 'i')
funcptr = FakeLLObject()
func = FakeLLObject(_fake_class=Func,
argtypes=[types.sint, types.double],
restype=types.sint)
-
+ #
+ def calldescr(cpu, FUNC, oopspecindex):
+ einfo = EffectInfo([], [], [], oopspecindex=oopspecindex)
+ return cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, einfo)
+ #
+ libffi_prepare = calldescr(cpu, FUNC, EffectInfo.OS_LIBFFI_PREPARE)
+ libffi_push_arg = calldescr(cpu, FUNC, EffectInfo.OS_LIBFFI_PUSH_ARG)
+ libffi_call = calldescr(cpu, FUNC, EffectInfo.OS_LIBFFI_CALL)
+
namespace = namespace.__dict__
def test_ffi_call_opt(self):
ops = """
[i0, f1]
- call("_libffi_prepare_call", ConstPtr(func), descr=plaincalldescr)
- call("_libffi_push_arg_Signed", ConstPtr(func), i0, descr=plaincalldescr)
- call("_libffi_push_arg_Float", ConstPtr(func), f1, descr=plaincalldescr)
- i3 = call("_libffi_call", ConstPtr(func), 12345, descr=plaincalldescr)
+ call(0, ConstPtr(func), descr=libffi_prepare)
+ call(0, ConstPtr(func), i0, descr=libffi_push_arg)
+ call(0, ConstPtr(func), f1, descr=libffi_push_arg)
+ i3 = call(0, ConstPtr(func), 12345, descr=libffi_call)
jump(i3, f1)
"""
expected = """
@@ -4562,21 +4571,13 @@
def test_ffi_call_nonconst(self):
ops = """
[i0, f1, p2]
- call("_libffi_prepare_call", p2, descr=plaincalldescr)
- call("_libffi_push_arg_Signed", p2, i0, descr=plaincalldescr)
- call("_libffi_push_arg_Float", p2, f1, descr=plaincalldescr)
- i3 = call("_libffi_call", p2, 1, descr=plaincalldescr)
- jump(i3, f1, p2)
- """
- expected = """
- [i0, f1, p2]
- call("_libffi_prepare_call", p2, descr=plaincalldescr)
- call("_libffi_push_arg_Signed", p2, i0, descr=plaincalldescr)
- call("_libffi_push_arg_Float", p2, f1, descr=plaincalldescr)
- i3 = call("_libffi_call", p2, 1, descr=plaincalldescr)
+ call(0, p2, descr=libffi_prepare)
+ call(0, p2, i0, descr=libffi_push_arg)
+ call(0, p2, f1, descr=libffi_push_arg)
+ i3 = call(0, p2, 12345, descr=libffi_call)
jump(i3, f1, p2)
-
"""
+ expected = ops
loop = self.optimize_loop(ops, 'Not, Not, Not', expected)
More information about the Pypy-commit
mailing list