[pypy-commit] pypy ffi-backend: Add the resop GETARRAYITEM_RAW_PURE to the JIT, and also make more
arigo
noreply at buildbot.pypy.org
Wed Aug 1 15:26:09 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r56521:fec6cba18f60
Date: 2012-08-01 15:25 +0200
http://bitbucket.org/pypy/pypy/changeset/fec6cba18f60/
Log: Add the resop GETARRAYITEM_RAW_PURE to the JIT, and also make more
use of GETARRAYITEM_GC_PURE. Tests.
diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -1550,6 +1550,7 @@
genop_getarrayitem_gc_pure = genop_getarrayitem_gc
genop_getarrayitem_raw = genop_getarrayitem_gc
+ genop_getarrayitem_raw_pure = genop_getarrayitem_gc
def genop_raw_load(self, op, arglocs, resloc):
base_loc, ofs_loc, size_loc, ofs, sign_loc = arglocs
diff --git a/pypy/jit/backend/x86/regalloc.py b/pypy/jit/backend/x86/regalloc.py
--- a/pypy/jit/backend/x86/regalloc.py
+++ b/pypy/jit/backend/x86/regalloc.py
@@ -1136,6 +1136,7 @@
consider_getarrayitem_raw = consider_getarrayitem_gc
consider_getarrayitem_gc_pure = consider_getarrayitem_gc
+ consider_getarrayitem_raw_pure = consider_getarrayitem_gc
consider_raw_load = consider_getarrayitem_gc
def consider_getinteriorfield_gc(self, op):
diff --git a/pypy/jit/codewriter/jtransform.py b/pypy/jit/codewriter/jtransform.py
--- a/pypy/jit/codewriter/jtransform.py
+++ b/pypy/jit/codewriter/jtransform.py
@@ -582,9 +582,14 @@
[v_base, arrayfielddescr, arraydescr,
op.args[1]], op.result)]
# normal case follows
+ pure = ''
+ immut = ARRAY._immutable_field(None)
+ if immut:
+ pure = '_pure'
arraydescr = self.cpu.arraydescrof(ARRAY)
kind = getkind(op.result.concretetype)
- return SpaceOperation('getarrayitem_%s_%s' % (ARRAY._gckind, kind[0]),
+ return SpaceOperation('getarrayitem_%s_%s%s' % (ARRAY._gckind,
+ kind[0], pure),
[op.args[0], arraydescr, op.args[1]],
op.result)
@@ -712,7 +717,7 @@
argname = getattr(STRUCT, '_gckind', 'gc')
if argname != 'raw':
raise Exception("%r: only supported for gckind=raw" % (op,))
- ofs = llmemory.offsetof(STRUCT, 'exchange_args')
+ ofs = llmemory.offsetof(STRUCT, op.args[1].value)
return SpaceOperation('int_add',
[op.args[0], Constant(ofs, lltype.Signed)],
op.result)
@@ -1514,7 +1519,7 @@
'check_neg_index')
extra = getkind(op.result.concretetype)[0]
if pure:
- extra = 'pure_' + extra
+ extra += '_pure'
op = SpaceOperation('getarrayitem_gc_%s' % extra,
[args[0], arraydescr, v_index], op.result)
return extraop + [op]
diff --git a/pypy/jit/metainterp/blackhole.py b/pypy/jit/metainterp/blackhole.py
--- a/pypy/jit/metainterp/blackhole.py
+++ b/pypy/jit/metainterp/blackhole.py
@@ -1129,9 +1129,9 @@
def bhimpl_getarrayitem_gc_f(cpu, array, arraydescr, index):
return cpu.bh_getarrayitem_gc_f(arraydescr, array, index)
- bhimpl_getarrayitem_gc_pure_i = bhimpl_getarrayitem_gc_i
- bhimpl_getarrayitem_gc_pure_r = bhimpl_getarrayitem_gc_r
- bhimpl_getarrayitem_gc_pure_f = bhimpl_getarrayitem_gc_f
+ bhimpl_getarrayitem_gc_i_pure = bhimpl_getarrayitem_gc_i
+ bhimpl_getarrayitem_gc_r_pure = bhimpl_getarrayitem_gc_r
+ bhimpl_getarrayitem_gc_f_pure = bhimpl_getarrayitem_gc_f
@arguments("cpu", "i", "d", "i", returns="i")
def bhimpl_getarrayitem_raw_i(cpu, array, arraydescr, index):
@@ -1140,6 +1140,9 @@
def bhimpl_getarrayitem_raw_f(cpu, array, arraydescr, index):
return cpu.bh_getarrayitem_raw_f(arraydescr, array, index)
+ bhimpl_getarrayitem_raw_i_pure = bhimpl_getarrayitem_raw_i
+ bhimpl_getarrayitem_raw_f_pure = bhimpl_getarrayitem_raw_f
+
@arguments("cpu", "r", "d", "i", "i")
def bhimpl_setarrayitem_gc_i(cpu, array, arraydescr, index, newvalue):
cpu.bh_setarrayitem_gc_i(arraydescr, array, index, newvalue)
diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py
--- a/pypy/jit/metainterp/pyjitpl.py
+++ b/pypy/jit/metainterp/pyjitpl.py
@@ -451,12 +451,20 @@
opimpl_getarrayitem_raw_f = _opimpl_getarrayitem_raw_any
@arguments("box", "descr", "box")
+ def _opimpl_getarrayitem_raw_pure_any(self, arraybox,arraydescr, indexbox):
+ return self.execute_with_descr(rop.GETARRAYITEM_RAW_PURE,
+ arraydescr, arraybox, indexbox)
+
+ opimpl_getarrayitem_raw_i_pure = _opimpl_getarrayitem_raw_pure_any
+ opimpl_getarrayitem_raw_f_pure = _opimpl_getarrayitem_raw_pure_any
+
+ @arguments("box", "descr", "box")
def _opimpl_getarrayitem_gc_pure_any(self, arraybox, arraydescr, indexbox):
return self._do_getarrayitem_gc_any(rop.GETARRAYITEM_GC_PURE, arraybox, arraydescr, indexbox)
- opimpl_getarrayitem_gc_pure_i = _opimpl_getarrayitem_gc_pure_any
- opimpl_getarrayitem_gc_pure_r = _opimpl_getarrayitem_gc_pure_any
- opimpl_getarrayitem_gc_pure_f = _opimpl_getarrayitem_gc_pure_any
+ opimpl_getarrayitem_gc_i_pure = _opimpl_getarrayitem_gc_pure_any
+ opimpl_getarrayitem_gc_r_pure = _opimpl_getarrayitem_gc_pure_any
+ opimpl_getarrayitem_gc_f_pure = _opimpl_getarrayitem_gc_pure_any
@arguments("box", "descr", "box", "box")
def _opimpl_setarrayitem_gc_any(self, arraybox, arraydescr,
diff --git a/pypy/jit/metainterp/resoperation.py b/pypy/jit/metainterp/resoperation.py
--- a/pypy/jit/metainterp/resoperation.py
+++ b/pypy/jit/metainterp/resoperation.py
@@ -460,6 +460,7 @@
'GETFIELD_GC_PURE/1d',
'GETFIELD_RAW_PURE/1d',
'GETARRAYITEM_GC_PURE/2d',
+ 'GETARRAYITEM_RAW_PURE/2d',
'UNICODELEN/1',
'UNICODEGETITEM/2',
#
diff --git a/pypy/jit/metainterp/test/support.py b/pypy/jit/metainterp/test/support.py
--- a/pypy/jit/metainterp/test/support.py
+++ b/pypy/jit/metainterp/test/support.py
@@ -42,6 +42,9 @@
trace_limit = sys.maxint
enable_opts = ALL_OPTS_DICT
+ if kwds.pop('disable_optimizations', False):
+ FakeWarmRunnerState.enable_opts = {}
+
func._jit_unroll_safe_ = True
rtyper = support.annotate(func, values, type_system=type_system,
translationoptions=translationoptions)
diff --git a/pypy/jit/metainterp/test/test_immutable.py b/pypy/jit/metainterp/test/test_immutable.py
--- a/pypy/jit/metainterp/test/test_immutable.py
+++ b/pypy/jit/metainterp/test/test_immutable.py
@@ -89,6 +89,42 @@
int_add=3)
+ def test_raw_field_and_array(self):
+ from pypy.rpython.lltypesystem import lltype
+ X = lltype.Struct('X',
+ ('a', lltype.Signed),
+ ('b', lltype.Array(lltype.Signed,
+ hints={'nolength': True, 'immutable': True})),
+ hints={'immutable': True})
+
+ x = lltype.malloc(X, 4, flavor='raw', immortal=True)
+ x.a = 6
+ x.b[2] = 7
+ xlist = [x, lltype.nullptr(X)]
+ def g(num):
+ if num < 0:
+ num = 0
+ return num
+ g._dont_inline_ = True
+ def f(num):
+ num = g(num)
+ x = xlist[num]
+ return x.a * x.b[2]
+ #
+ res = self.interp_operations(f, [0], disable_optimizations=True)
+ assert res == 42
+ self.check_operations_history(getfield_raw_pure=1,
+ getarrayitem_raw_pure=1,
+ int_mul=1)
+ #
+ # second try, in which we get num=0 constant-folded through f()
+ res = self.interp_operations(f, [-1], disable_optimizations=True)
+ assert res == 42
+ self.check_operations_history(getfield_raw_pure=0,
+ getarrayitem_raw_pure=0,
+ int_mul=0)
+
+
class TestLLtypeImmutableFieldsTests(ImmutableFieldsTests, LLJitMixin):
pass
diff --git a/pypy/rpython/lltypesystem/llmemory.py b/pypy/rpython/lltypesystem/llmemory.py
--- a/pypy/rpython/lltypesystem/llmemory.py
+++ b/pypy/rpython/lltypesystem/llmemory.py
@@ -540,6 +540,10 @@
return self.adr != cast_int_to_adr(other)
def __nonzero__(self):
return bool(self.adr)
+ def __add__(self, ofs):
+ if isinstance(ofs, FieldOffset) and ofs.TYPE is self.adr.ptr._TYPE.TO:
+ return AddressAsInt(cast_ptr_to_adr(self.adr.ptr.b))
+ return NotImplemented
def __repr__(self):
try:
return '<AddressAsInt %s>' % (self.adr.ptr,)
More information about the pypy-commit
mailing list