[pypy-commit] pypy optresult: small progress, I might reverse the whole approach though

fijal noreply at buildbot.pypy.org
Sat Nov 29 15:16:31 CET 2014


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: optresult
Changeset: r74759:4080e1ba1276
Date: 2014-11-29 16:16 +0200
http://bitbucket.org/pypy/pypy/changeset/4080e1ba1276/

Log:	small progress, I might reverse the whole approach though

diff --git a/rpython/jit/metainterp/optimizeopt/intbounds.py b/rpython/jit/metainterp/optimizeopt/intbounds.py
--- a/rpython/jit/metainterp/optimizeopt/intbounds.py
+++ b/rpython/jit/metainterp/optimizeopt/intbounds.py
@@ -237,13 +237,11 @@
         v1 = self.getvalue(op.getarg(0))
         v2 = self.getvalue(op.getarg(1))
         resbound = v1.intbound.add_bound(v2.intbound)
-        r = self.getvalue(op)
         if resbound.bounded():
             # Transform into INT_ADD.  The following guard will be killed
             # by optimize_GUARD_NO_OVERFLOW; if we see instead an
             # optimize_GUARD_OVERFLOW, then InvalidLoop.
-            newop = op.copy_and_change(rop.INT_ADD)
-            r.box = newop
+            newop = self.replace_op_with(op, rop.INT_ADD)
         else:
             newop = op
         self.emit_operation(newop) # emit the op
@@ -253,14 +251,12 @@
     def optimize_INT_SUB_OVF(self, op):
         v1 = self.getvalue(op.getarg(0))
         v2 = self.getvalue(op.getarg(1))
-        r = self.getvalue(op)
         if v1 is v2:
             self.make_constant_int(op, 0)
             return
         resbound = v1.intbound.sub_bound(v2.intbound)
         if resbound.bounded():
-            newop = op.copy_and_change(rop.INT_SUB)
-            r.box = newop
+            newop = self.replace_op_with(op, rop.INT_SUB)
         else:
             newop = op
         self.emit_operation(newop) # emit the op
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
@@ -293,6 +293,9 @@
     def getvalue(self, box):
         return self.optimizer.getvalue(box)
 
+    def replace_op_with(self, op, newopnum, args=None):
+        return self.optimizer.replace_op_with(op, newopnum, args)
+
     def make_constant(self, box, constbox):
         return self.optimizer.make_constant(box, constbox)
 
@@ -497,6 +500,12 @@
         except KeyError:
             self.values[box] = ConstantValue(constbox)
 
+    def replace_op_with(self, op, newopnum, args=None):
+        v = self.getvalue(op)
+        newop = op.copy_and_change(newopnum, args=args)
+        v.box = newop
+        return newop
+
     def make_constant_int(self, box, intvalue):
         self.make_constant(box, ConstInt(intvalue))
 
diff --git a/rpython/jit/metainterp/optimizeopt/pure.py b/rpython/jit/metainterp/optimizeopt/pure.py
--- a/rpython/jit/metainterp/optimizeopt/pure.py
+++ b/rpython/jit/metainterp/optimizeopt/pure.py
@@ -41,7 +41,7 @@
             args = self.optimizer.make_args_key(op.getopnum(),
                                                 op.getarglist(), op.getdescr())
             oldop = self.pure_operations.get(args, None)
-            if oldop is not None and oldop.getdescr() is op.getdescr():
+            if oldop is not None:
                 self.optimizer.make_equal_to(op, self.getvalue(oldop), True)
                 return
             else:
diff --git a/rpython/jit/metainterp/optimizeopt/rewrite.py b/rpython/jit/metainterp/optimizeopt/rewrite.py
--- a/rpython/jit/metainterp/optimizeopt/rewrite.py
+++ b/rpython/jit/metainterp/optimizeopt/rewrite.py
@@ -220,8 +220,7 @@
                     self.make_equal_to(op, v2)
                     return
                 elif v1.box.getfloatstorage() == -1.0:
-                    newop = op.copy_and_change(rop.FLOAT_NEG, args=[rhs])
-                    self.getvalue(op).box = newop
+                    newop = self.replace_op_with(op, rop.FLOAT_NEG, args=[rhs])
                     self.emit_operation(newop)
                     return
         self.emit_operation(op)
@@ -244,8 +243,8 @@
                 rfraction = math.frexp(reciprocal)[0]
                 if rfraction == 0.5 or rfraction == -0.5:
                     c = ConstFloat(longlong.getfloatstorage(reciprocal))
-                    newop = op.copy_and_change(rop.FLOAT_MUL, args=[arg1, c])
-                    self.getvalue(op).box = newop
+                    newop = self.replace_op_with(op, rop.FLOAT_MUL,
+                                                 args=[arg1, c])
         self.emit_operation(newop)
 
     def optimize_FLOAT_NEG(self, op):
@@ -405,10 +404,9 @@
         # change the op to be a normal call, from the backend's point of view
         # there is no reason to have a separate operation for this
         self.loop_invariant_producer[key] = op
-        opnum = OpHelpers.call_for_descr(op.getdescr())
-        newop = op.copy_and_change(opnum)
+        newop = self.replace_op_with(op,
+                                     OpHelpers.call_for_descr(op.getdescr()))
         resvalue = self.optimizer.getvalue(op)
-        resvalue.box = newop
         self.emit_operation(newop)
         self.loop_invariant_results[key] = resvalue
     optimize_CALL_LOOPINVARIANT_R = optimize_CALL_LOOPINVARIANT_I
@@ -521,6 +519,7 @@
                                       [op.getarg(1),
                                        ConstInt(index + source_start)],
                                        descr=arraydescr)
+                    newop.is_source_op = True
                     self.optimizer.send_extra_operation(newop)
                     val = self.getvalue(newop)
                 if val is None:
diff --git a/rpython/jit/metainterp/optimizeopt/virtualize.py b/rpython/jit/metainterp/optimizeopt/virtualize.py
--- a/rpython/jit/metainterp/optimizeopt/virtualize.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualize.py
@@ -606,10 +606,10 @@
         # 'jit_virtual_ref'.  The jit_virtual_ref structure may be forced soon,
         # but the point is that doing so does not force the original structure.
         newop = ResOperation(rop.NEW_WITH_VTABLE, [c_cls])
+        newop.source_op = op
         vrefvalue = self.make_virtual(c_cls, newop)
-        assert op not in self.optimizer.values
-        self.optimizer.values[op] = vrefvalue
         token = ResOperation(rop.FORCE_TOKEN, [])
+        token.is_source_op = True
         self.emit_operation(token)
         vrefvalue.setfield(descr_virtual_token, self.getvalue(token))
         vrefvalue.setfield(descr_forced, self.optimizer.cpu.ts.CVAL_NULLREF)


More information about the pypy-commit mailing list