[pypy-commit] pypy heap-caching-during-tracing: caching for pure ops
cfbolz
noreply at buildbot.pypy.org
Sun Jul 17 11:06:42 CEST 2011
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: heap-caching-during-tracing
Changeset: r45696:559198bd1ea6
Date: 2011-07-17 09:31 +0200
http://bitbucket.org/pypy/pypy/changeset/559198bd1ea6/
Log: caching for pure ops
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
@@ -517,23 +517,29 @@
@arguments("box", "descr")
def _opimpl_getfield_gc_any(self, box, fielddescr):
- frombox, tobox = self.metainterp.heap_cache.get(fielddescr, (None, None))
- if frombox is box:
- return tobox
- resbox = self.execute_with_descr(rop.GETFIELD_GC, fielddescr, box)
- self.metainterp.heap_cache[fielddescr] = (box, resbox)
- return resbox
+ return self._opimpl_getfield_gc_any_pureornot(
+ rop.GETFIELD_GC, box, fielddescr)
opimpl_getfield_gc_i = _opimpl_getfield_gc_any
opimpl_getfield_gc_r = _opimpl_getfield_gc_any
opimpl_getfield_gc_f = _opimpl_getfield_gc_any
@arguments("box", "descr")
def _opimpl_getfield_gc_pure_any(self, box, fielddescr):
- return self.execute_with_descr(rop.GETFIELD_GC_PURE, fielddescr, box)
+ return self._opimpl_getfield_gc_any_pureornot(
+ rop.GETFIELD_GC_PURE, box, fielddescr)
opimpl_getfield_gc_i_pure = _opimpl_getfield_gc_pure_any
opimpl_getfield_gc_r_pure = _opimpl_getfield_gc_pure_any
opimpl_getfield_gc_f_pure = _opimpl_getfield_gc_pure_any
+ @specialize.arg(1)
+ def _opimpl_getfield_gc_any_pureornot(self, opnum, box, fielddescr):
+ frombox, tobox = self.metainterp.heap_cache.get(fielddescr, (None, None))
+ if frombox is box:
+ return tobox
+ resbox = self.execute_with_descr(opnum, fielddescr, box)
+ self.metainterp.heap_cache[fielddescr] = (box, resbox)
+ return resbox
+
@arguments("orgpc", "box", "descr")
def _opimpl_getfield_gc_greenfield_any(self, pc, box, fielddescr):
ginfo = self.metainterp.jitdriver_sd.greenfield_info
diff --git a/pypy/jit/metainterp/test/test_tracingopts.py b/pypy/jit/metainterp/test/test_tracingopts.py
--- a/pypy/jit/metainterp/test/test_tracingopts.py
+++ b/pypy/jit/metainterp/test/test_tracingopts.py
@@ -303,7 +303,6 @@
def test_list_caching_negative(self):
def fn(n):
- jit.promote(n)
a = [0] * n
if n > 1000:
a.append(0)
@@ -357,3 +356,25 @@
res = self.meta_interp(f, [10, 1, 1], listops=True)
assert res == f(10, 1, 1)
self.check_history(getarrayitem_gc=0, getfield_gc=0)
+
+ def test_heap_caching_pure(self):
+ class A(object):
+ pass
+ p1 = A()
+ p2 = A()
+ def fn(n):
+ if n >= 0:
+ a = (n, n + 1)
+ p = p1
+ else:
+ a = (n + 1, n)
+ p = p2
+ p.x = a
+
+ return p.x[0] + p.x[1]
+ res = self.interp_operations(fn, [7])
+ assert res == 7 + 7 + 1
+ self.check_operations_history(getfield_gc=0, getfield_gc_pure=0)
+ res = self.interp_operations(fn, [-7])
+ assert res == -7 - 7 + 1
+ self.check_operations_history(getfield_gc=0, getfield_gc_pure=0)
More information about the pypy-commit
mailing list