[pypy-commit] pypy guard-compatible: make the heapcache remember that we already produced a guard_compatible for a
cfbolz
pypy.commits at gmail.com
Sun Mar 20 08:47:10 EDT 2016
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: guard-compatible
Changeset: r83187:57232342ceba
Date: 2016-03-20 13:06 +0100
http://bitbucket.org/pypy/pypy/changeset/57232342ceba/
Log: make the heapcache remember that we already produced a
guard_compatible for a box
diff --git a/rpython/jit/metainterp/heapcache.py b/rpython/jit/metainterp/heapcache.py
--- a/rpython/jit/metainterp/heapcache.py
+++ b/rpython/jit/metainterp/heapcache.py
@@ -9,6 +9,7 @@
def reset_keep_likely_virtual(self):
self.known_class = False
+ self.guard_compatible = False
self.known_nullity = False
# did we see the allocation during tracing?
self.seen_allocation = False
@@ -303,6 +304,15 @@
def nullity_now_known(self, box):
self.getvalue(box).known_nullity = True
+ def have_guard_compatible(self, box):
+ value = self.getvalue(box, create=False)
+ if value:
+ return value.guard_compatible
+ return False
+
+ def have_guard_compatible_now(self, box):
+ self.getvalue(box).guard_compatible = True
+
def is_nonstandard_virtualizable(self, box):
value = self.getvalue(box, create=False)
if value:
diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -1202,11 +1202,12 @@
@arguments("box", "orgpc")
def opimpl_ref_guard_compatible(self, box, orgpc):
if isinstance(box, Const):
- return box # no promotion needed, already a Const
- else:
+ return # no guard needed, already a Const
+ elif not self.metainterp.heapcache.have_guard_compatible(box):
promoted_box = executor.constant_from_op(box)
self.metainterp.generate_guard(rop.GUARD_COMPATIBLE, box, [promoted_box],
resumepc=orgpc)
+ self.metainterp.heapcache.have_guard_compatible_now(box)
# importantly, there is no replace_box here!
@arguments("box", "orgpc")
diff --git a/rpython/jit/metainterp/test/test_compatible.py b/rpython/jit/metainterp/test/test_compatible.py
--- a/rpython/jit/metainterp/test/test_compatible.py
+++ b/rpython/jit/metainterp/test/test_compatible.py
@@ -153,3 +153,29 @@
assert x < 30
# XXX check number of bridges
+
+ def test_dont_record_repeated_guard_compatible(self):
+ class A:
+ pass
+ class B(A):
+ pass
+ @jit.elidable_compatible()
+ def extern(x):
+ return isinstance(x, A)
+ @jit.dont_look_inside
+ def pick(n):
+ if n:
+ x = a
+ else:
+ x = b
+ return x
+ a = A()
+ b = B()
+ def fn(n):
+ x = pick(n)
+ return extern(x) + extern(x) + extern(x)
+
+ res = self.interp_operations(fn, [1])
+ assert res == 3
+ self.check_operations_history(guard_compatible=1)
+
More information about the pypy-commit
mailing list