[pypy-commit] pypy optresult: fix forcing before guards

fijal noreply at buildbot.pypy.org
Mon May 25 16:48:08 CEST 2015


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: optresult
Changeset: r77541:1930c0682911
Date: 2015-05-25 16:43 +0200
http://bitbucket.org/pypy/pypy/changeset/1930c0682911/

Log:	fix forcing before guards

diff --git a/rpython/jit/metainterp/optimizeopt/heap.py b/rpython/jit/metainterp/optimizeopt/heap.py
--- a/rpython/jit/metainterp/optimizeopt/heap.py
+++ b/rpython/jit/metainterp/optimizeopt/heap.py
@@ -133,6 +133,7 @@
     def __init__(self):
         # mapping descr -> CachedField
         self.cached_fields = OrderedDict()
+        
         # XXXX the rest is old
         # cached array items:  {array descr: {index: CachedField}}
         self.cached_arrayitems = {}
@@ -364,7 +365,7 @@
             return
         cf.force_lazy_setfield(self, can_cache)
 
-    def force_lazy_setarrayitem(self, arraydescr, indexvalue=None, can_cache=True):
+    def force_lazy_setarrayitem(self, arraydescr, indexop=None, can_cache=True):
         try:
             submap = self.cached_arrayitems[arraydescr]
         except KeyError:
@@ -392,6 +393,12 @@
 
     def force_lazy_setfields_and_arrayitems_for_guard(self):
         pendingfields = []
+        for descr, cf in self.cached_fields.iteritems():
+            op = cf._lazy_setfield
+            if op is None:
+                continue
+            cf.force_lazy_setfield(self)
+        return pendingfields
         for cf in self._lazy_setfields_and_arrayitems:
             self._assert_valid_cf(cf)
             op = cf._lazy_setfield
@@ -434,34 +441,11 @@
         self.emit_operation(op)
         # then remember the result of reading the field
         structinfo.setfield(op.getdescr(), op, self)
-
-    def xxx_optimize_GETFIELD_GC_I(self, op):
-        opinfo = self.ensure_ptr_info_arg0(op)
-        fld = opinfo.getfield(op.getdescr(), self)
-        if fld is not None:
-            self.make_equal_to(op, fld)
-            return
-        self.emit_operation(op)
-        opinfo.setfield(op.getdescr(), op, self)
-        return
-        xxx
-        return
-        structvalue = self.getvalue(op.getarg(0))
-        cf = self.field_cache(op.getdescr())
-        fieldvalue = cf.getfield_from_cache(self, structvalue)
-        if fieldvalue is not None:
-            self.make_equal_to(op, fieldvalue)
-            return
-        # default case: produce the operation
-        structvalue.ensure_nonnull()
-        self.emit_operation(op)
-        # then remember the result of reading the field
-        fieldvalue = self.getvalue(op)
-        cf.remember_field_value(structvalue, fieldvalue, op, self.optimizer)
     optimize_GETFIELD_GC_R = optimize_GETFIELD_GC_I
     optimize_GETFIELD_GC_F = optimize_GETFIELD_GC_I
 
     def optimize_GETFIELD_GC_PURE_I(self, op):
+        xxx
         structvalue = self.getvalue(op.getarg(0))
         cf = self.field_cache(op.getdescr())
         fieldvalue = cf.getfield_from_cache(self, structvalue)
@@ -486,24 +470,24 @@
         cf.do_setfield(self, op)
 
     def optimize_GETARRAYITEM_GC_I(self, op):
-        self.emit_operation(op)
-        return # XXX
-        arrayvalue = self.getvalue(op.getarg(0))
-        indexvalue = self.getvalue(op.getarg(1))
+        arrayinfo = self.ensure_ptr_info_arg0(op)
+        indexb = self.getintbound(op.getarg(1))
         cf = None
-        if indexvalue.is_constant():
-            arrayvalue.make_len_gt(MODE_ARRAY, op.getdescr(), indexvalue.box.getint())
+        if indexb.is_constant():
+            # XXXX lgt bound
+            #arrayvalue.make_len_gt(MODE_ARRAY, op.getdescr(), indexvalue.box.getint())
             # use the cache on (arraydescr, index), which is a constant
-            cf = self.arrayitem_cache(op.getdescr(), indexvalue.box.getint())
-            fieldvalue = cf.getfield_from_cache(self, arrayvalue)
+            #cf = self.arrayitem_cache(op.getdescr(), indexvalue.box.getint())
+            #fieldvalue = cf.getfield_from_cache(self, arrayvalue)
+            fieldvalue = None
             if fieldvalue is not None:
                 self.make_equal_to(op, fieldvalue)
                 return
         else:
             # variable index, so make sure the lazy setarrayitems are done
-            self.force_lazy_setarrayitem(op.getdescr(), indexvalue=indexvalue)
+            self.force_lazy_setarrayitem(op.getdescr(), op.getarg(1))
         # default case: produce the operation
-        arrayvalue.ensure_nonnull()
+        self.make_nonnull(op.getarg(0))
         self.emit_operation(op)
         # the remember the result of reading the array item
         if cf is not None:
@@ -513,22 +497,23 @@
     optimize_GETARRAYITEM_GC_F = optimize_GETARRAYITEM_GC_I
 
     def optimize_GETARRAYITEM_GC_PURE_I(self, op):
-        arrayvalue = self.getvalue(op.getarg(0))
-        indexvalue = self.getvalue(op.getarg(1))
+        arrayinfo = self.ensure_ptr_info_arg0(op)
+        indexb = self.getintbound(op.getarg(1))
         cf = None
-        if indexvalue.is_constant():
-            arrayvalue.make_len_gt(MODE_ARRAY, op.getdescr(), indexvalue.box.getint())
+        if indexb.is_constant():
+            #arrayvalue.make_len_gt(MODE_ARRAY, op.getdescr(), indexvalue.box.getint())
             # use the cache on (arraydescr, index), which is a constant
-            cf = self.arrayitem_cache(op.getdescr(), indexvalue.box.getint())
-            fieldvalue = cf.getfield_from_cache(self, arrayvalue)
+            #cf = self.arrayitem_cache(op.getdescr(), indexvalue.box.getint())
+            #fieldvalue = cf.getfield_from_cache(self, arrayvalue)
+            fieldvalue = None
             if fieldvalue is not None:
                 self.make_equal_to(op, fieldvalue)
                 return
         else:
             # variable index, so make sure the lazy setarrayitems are done
-            self.force_lazy_setarrayitem(op.getdescr(), indexvalue=indexvalue)
+            self.force_lazy_setarrayitem(op.getdescr(), op.getarg(1))
         # default case: produce the operation
-        arrayvalue.ensure_nonnull()
+        self.make_nonnull(op.getarg(0))
         self.emit_operation(op)
 
     optimize_GETARRAYITEM_GC_PURE_R = optimize_GETARRAYITEM_GC_PURE_I
diff --git a/rpython/jit/metainterp/optimizeopt/info.py b/rpython/jit/metainterp/optimizeopt/info.py
--- a/rpython/jit/metainterp/optimizeopt/info.py
+++ b/rpython/jit/metainterp/optimizeopt/info.py
@@ -128,11 +128,19 @@
             self.flags = FLAG_VIRTUAL
     
 class ArrayPtrInfo(AbstractVirtualPtrInfo):
-    _attrs_ = ('length', '_items', '_descr')
+    _attrs_ = ('length', '_items', '_descr', 'lengthbound')
 
-    def __init__(self, descr, const, size, clear, is_virtual):
+    def __init__(self, descr, const=None, size=0, clear=False,
+                 is_virtual=False):
+        self._descr = descr
+        self.lengthbound = None
         if is_virtual:
             self.flags = FLAG_VIRTUAL
+            self._init_items(const, size, clear)
+        else:
+            self._items = None
+
+    def _init_items(self, const, size, clear):
         self.length = size
         if clear:
             self._items = [const] * size
diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -606,8 +606,10 @@
             else:
                 opinfo = info.StructPtrInfo()
             opinfo.init_fields(op.getdescr().parent_descr)
+        elif op.is_getarrayitem() or op.getopnum() == rop.SETARRAYITEM_GC:
+            opinfo = info.ArrayPtrInfo(op.getdescr())
         else:
-            yyy
+            zzz
         arg0.set_forwarded(opinfo)
         return opinfo
 
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -1557,8 +1557,8 @@
         i4 = getarrayitem_gc_i(p3, i3, descr=arraydescr)
         i5 = int_add(i3, i4)
         #
+        setarrayitem_gc(p3, 0, i5, descr=arraydescr)
         setfield_gc(p1, i2, descr=valuedescr)
-        setarrayitem_gc(p3, 0, i5, descr=arraydescr)
         setfield_gc(p1, i4, descr=nextdescr)
         jump(p1, i1, i2, p3)
         """
diff --git a/rpython/jit/metainterp/resoperation.py b/rpython/jit/metainterp/resoperation.py
--- a/rpython/jit/metainterp/resoperation.py
+++ b/rpython/jit/metainterp/resoperation.py
@@ -225,7 +225,14 @@
 
     def is_getfield(self):
         return self.opnum in (rop.GETFIELD_GC_I, rop.GETFIELD_GC_F,
-                              rop.GETFIELD_GC_R)
+                              rop.GETFIELD_GC_R, rop.GETFIELD_GC_PURE_I,
+                              rop.GETFIELD_GC_PURE_R, rop.GETFIELD_GC_PURE_F)
+
+    def is_getarrayitem(self):
+        return self.opnum in (rop.GETARRAYITEM_GC_I, rop.GETARRAYITEM_GC_F,
+                              rop.GETARRAYITEM_GC_R, rop.GETARRAYITEM_GC_PURE_I,
+                              rop.GETARRAYITEM_GC_PURE_F,
+                              rop.GETARRAYITEM_GC_PURE_R)
 
     def is_real_call(self):
         opnum = self.opnum


More information about the pypy-commit mailing list