Author: Armin Rigo <[email protected]>
Branch: heapcache-refactor
Changeset: r83103:be27b70f8af9
Date: 2016-03-17 12:15 +0100
http://bitbucket.org/pypy/pypy/changeset/be27b70f8af9/

Log:    progress on arrays

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,7 +9,8 @@
 HF_KNOWN_CLASS     = 0x02
 HF_KNOWN_NULLITY   = 0x04
 HF_SEEN_ALLOCATION = 0x08   # did we see the allocation during tracing?
-HF_NONSTD_VABLE    = 0x10
+HF_IS_UNESCAPED    = 0x10
+HF_NONSTD_VABLE    = 0x20
 
 @always_inline
 def add_flags(ref_frontend_op, flags):
@@ -35,7 +36,6 @@
         self.reset_keep_likely_virtual()
 
     def reset_keep_likely_virtual(self):
-        self.is_unescaped = False
         self.length = None
         self.dependencies = None
 
@@ -221,12 +221,11 @@
 
     def _escape_box(self, box):
         if isinstance(box, RefFrontendOp):
-            remove_flags(box, HF_LIKELY_VIRTUAL)
+            remove_flags(box, HF_LIKELY_VIRTUAL | HF_IS_UNESCAPED)
         #
         value = self.getvalue(box, create=False)
         if not value:
             return
-        value.is_unescaped = False
         deps = value.dependencies
         value.dependencies = None
         if deps is not None:
@@ -357,12 +356,10 @@
         self._set_flag(box, HF_NONSTD_VABLE)
 
     def is_unescaped(self, box):
-        value = self.getvalue(box, create=False)
-        if value:
-            return value.is_unescaped
-        return False
+        return self._check_flag(box, HF_IS_UNESCAPED)
 
     def is_likely_virtual(self, box):
+        # note: this is different from _check_flag()
         return (isinstance(box, RefFrontendOp) and
                 self.test_likely_virtual_version(box) and
                 test_flags(box, HF_LIKELY_VIRTUAL))
@@ -370,9 +367,7 @@
     def new(self, box):
         assert isinstance(box, RefFrontendOp)
         self.update_version(box)
-        add_flags(box, HF_LIKELY_VIRTUAL | HF_SEEN_ALLOCATION)
-        value = self.getvalue(box)
-        value.is_unescaped = True
+        add_flags(box, HF_LIKELY_VIRTUAL | HF_SEEN_ALLOCATION | 
HF_IS_UNESCAPED)
 
     def new_array(self, box, lengthbox):
         self.new(box)
@@ -405,17 +400,12 @@
     def getarrayitem(self, box, indexbox, descr):
         if not isinstance(indexbox, ConstInt):
             return None
-        value = self.getvalue(box, create=False)
-        if value is None:
-            return None
         index = indexbox.getint()
         cache = self.heap_array_cache.get(descr, None)
         if cache:
             indexcache = cache.get(index, None)
             if indexcache is not None:
-                resvalue = indexcache.read(value)
-                if resvalue:
-                    return resvalue.box
+                return indexcache.read(box)
         return None
 
     def _get_or_make_array_cache_entry(self, indexbox, descr):
@@ -431,10 +421,9 @@
 
     def getarrayitem_now_known(self, box, indexbox, fieldbox, descr):
         value = self.getvalue(box)
-        fieldvalue = self.getvalue(fieldbox)
         indexcache = self._get_or_make_array_cache_entry(indexbox, descr)
         if indexcache:
-            indexcache.read_now_known(value, fieldvalue)
+            indexcache.read_now_known(box, fieldbox)
 
     def setarrayitem(self, box, indexbox, fieldbox, descr):
         if not isinstance(indexbox, ConstInt):
@@ -442,11 +431,9 @@
             if cache is not None:
                 cache.clear()
             return
-        value = self.getvalue(box)
-        fieldvalue = self.getvalue(fieldbox)
         indexcache = self._get_or_make_array_cache_entry(indexbox, descr)
         if indexcache:
-            indexcache.do_write_with_aliasing(value, fieldvalue)
+            indexcache.do_write_with_aliasing(box, fieldbox)
 
     def arraylen(self, box):
         value = self.getvalue(box, create=False)
diff --git a/rpython/jit/metainterp/test/test_heapcache.py 
b/rpython/jit/metainterp/test/test_heapcache.py
--- a/rpython/jit/metainterp/test/test_heapcache.py
+++ b/rpython/jit/metainterp/test/test_heapcache.py
@@ -124,6 +124,10 @@
 
     def test_heapcache_read_fields_multiple(self):
         h = HeapCache()
+        box1 = RefFrontendOp(1)
+        box2 = RefFrontendOp(2)
+        box3 = RefFrontendOp(3)
+        box4 = RefFrontendOp(4)
         h.getfield_now_known(box1, descr1, box2)
         h.getfield_now_known(box3, descr1, box4)
         assert h.getfield(box1, descr1) is box2
@@ -139,6 +143,10 @@
 
     def test_heapcache_write_fields_multiple(self):
         h = HeapCache()
+        box1 = RefFrontendOp(1)
+        box2 = RefFrontendOp(2)
+        box3 = RefFrontendOp(3)
+        box4 = RefFrontendOp(4)
         h.setfield(box1, box2, descr1)
         assert h.getfield(box1, descr1) is box2
         h.setfield(box3, box4, descr1)
@@ -146,6 +154,10 @@
         assert h.getfield(box1, descr1) is None # box1 and box3 can alias
 
         h = HeapCache()
+        box1 = RefFrontendOp(1)
+        box2 = RefFrontendOp(2)
+        box3 = RefFrontendOp(3)
+        box4 = RefFrontendOp(4)
         h.new(box1)
         h.setfield(box1, box2, descr1)
         assert h.getfield(box1, descr1) is box2
@@ -154,6 +166,10 @@
         assert h.getfield(box1, descr1) is None # box1 and box3 can alias
 
         h = HeapCache()
+        box1 = RefFrontendOp(1)
+        box2 = RefFrontendOp(2)
+        box3 = RefFrontendOp(3)
+        box4 = RefFrontendOp(4)
         h.new(box1)
         h.new(box3)
         h.setfield(box1, box2, descr1)
@@ -167,6 +183,10 @@
 
     def test_heapcache_arrays(self):
         h = HeapCache()
+        box1 = RefFrontendOp(1)
+        box2 = RefFrontendOp(2)
+        box3 = RefFrontendOp(3)
+        box4 = RefFrontendOp(4)
         assert h.getarrayitem(box1, index1, descr1) is None
         assert h.getarrayitem(box1, index1, descr2) is None
         assert h.getarrayitem(box1, index2, descr1) is None
@@ -209,6 +229,10 @@
 
     def test_heapcache_array_nonconst_index(self):
         h = HeapCache()
+        box1 = RefFrontendOp(1)
+        box2 = RefFrontendOp(2)
+        box3 = RefFrontendOp(3)
+        box4 = RefFrontendOp(4)
         h.setarrayitem(box1, index1, box2, descr1)
         h.setarrayitem(box1, index2, box4, descr1)
         assert h.getarrayitem(box1, index1, descr1) is box2
@@ -219,6 +243,10 @@
 
     def test_heapcache_read_fields_multiple_array(self):
         h = HeapCache()
+        box1 = RefFrontendOp(1)
+        box2 = RefFrontendOp(2)
+        box3 = RefFrontendOp(3)
+        box4 = RefFrontendOp(4)
         h.getarrayitem_now_known(box1, index1, box2, descr1)
         h.getarrayitem_now_known(box3, index1, box4, descr1)
         assert h.getarrayitem(box1, index1, descr1) is box2
@@ -234,6 +262,10 @@
 
     def test_heapcache_write_fields_multiple_array(self):
         h = HeapCache()
+        box1 = RefFrontendOp(1)
+        box2 = RefFrontendOp(2)
+        box3 = RefFrontendOp(3)
+        box4 = RefFrontendOp(4)
         h.setarrayitem(box1, index1, box2, descr1)
         assert h.getarrayitem(box1, index1, descr1) is box2
         h.setarrayitem(box3, index1, box4, descr1)
@@ -241,6 +273,10 @@
         assert h.getarrayitem(box1, index1, descr1) is None # box1 and box3 
can alias
 
         h = HeapCache()
+        box1 = RefFrontendOp(1)
+        box2 = RefFrontendOp(2)
+        box3 = RefFrontendOp(3)
+        box4 = RefFrontendOp(4)
         h.new(box1)
         h.setarrayitem(box1, index1, box2, descr1)
         assert h.getarrayitem(box1, index1, descr1) is box2
@@ -249,6 +285,10 @@
         assert h.getarrayitem(box1, index1, descr1) is None # box1 and box3 
can alias
 
         h = HeapCache()
+        box1 = RefFrontendOp(1)
+        box2 = RefFrontendOp(2)
+        box3 = RefFrontendOp(3)
+        box4 = RefFrontendOp(4)
         h.new(box1)
         h.new(box3)
         h.setarrayitem(box1, index1, box2, descr1)
@@ -262,6 +302,8 @@
 
     def test_length_cache(self):
         h = HeapCache()
+        box1 = RefFrontendOp(1)
+        box2 = RefFrontendOp(2)
         h.new_array(box1, lengthbox1)
         assert h.arraylen(box1) is lengthbox1
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to