[pypy-commit] pypy default: don't put guard_nonnull for things that have a known class

cfbolz noreply at buildbot.pypy.org
Thu Jul 7 15:39:01 CEST 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r45407:8061dbe5a513
Date: 2011-07-07 15:35 +0200
http://bitbucket.org/pypy/pypy/changeset/8061dbe5a513/

Log:	don't put guard_nonnull for things that have a known class

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
@@ -310,26 +310,24 @@
                 self.opimpl_goto_if_not(condbox, target)
         ''' % (_opimpl, _opimpl.upper())).compile()
 
+
+    def _establish_nullity(self, box, orgpc):
+        value = box.nonnull()
+        if value:
+            if box not in self.metainterp.known_class_boxes:
+                self.generate_guard(rop.GUARD_NONNULL, box, resumepc=orgpc)
+        else:
+            self.generate_guard(rop.GUARD_ISNULL, box, resumepc=orgpc)
+        return value
+
     @arguments("orgpc", "box", "label")
     def opimpl_goto_if_not_ptr_nonzero(self, orgpc, box, target):
-        value = box.nonnull()
-        if value:
-            opnum = rop.GUARD_NONNULL
-        else:
-            opnum = rop.GUARD_ISNULL
-        self.generate_guard(opnum, box, resumepc=orgpc)
-        if not value:
+        if not self._establish_nullity(box, orgpc):
             self.pc = target
 
     @arguments("orgpc", "box", "label")
     def opimpl_goto_if_not_ptr_iszero(self, orgpc, box, target):
-        value = box.nonnull()
-        if value:
-            opnum = rop.GUARD_NONNULL
-        else:
-            opnum = rop.GUARD_ISNULL
-        self.generate_guard(opnum, box, resumepc=orgpc)
-        if value:
+        if self._establish_nullity(box, orgpc):
             self.pc = target
 
     @arguments("box", "box", "box")
diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -1021,21 +1021,22 @@
         res = self.meta_interp(main, [])
         assert res == 55
 
-
-    def test_dont_record_guard_class(self):
+    def test_dont_record_repeated_guard_class(self):
         class A:
             pass
         class B(A):
             pass
         def fn(n):
-            if n:
+            if n == -7:
+                obj = None
+            elif n:
                 obj = A()
             else:
                 obj = B()
             return isinstance(obj, B) + isinstance(obj, B) + isinstance(obj, B) + isinstance(obj, B)
         res = self.interp_operations(fn, [0])
-        assert res
-        self.check_operations_history(guard_class=1)
+        assert res == 4
+        self.check_operations_history(guard_class=1, guard_nonnull=1)
         res = self.interp_operations(fn, [1])
         assert not res
 


More information about the pypy-commit mailing list