[pypy-commit] pypy unrecursive-opt: Turn callbacks into postprocess dispatch.

jerith noreply at buildbot.pypy.org
Sun Oct 4 11:12:17 CEST 2015


Author: Jeremy Thurgood <firxen at gmail.com>
Branch: unrecursive-opt
Changeset: r79967:c28bff45d6ed
Date: 2015-10-04 11:12 +0200
http://bitbucket.org/pypy/pypy/changeset/c28bff45d6ed/

Log:	Turn callbacks into postprocess dispatch.

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
@@ -53,11 +53,14 @@
        redundant guards"""
 
     def opt_default(self, op):
-        return IntBoundsCallbackArgs(op)
+        return op
 
     def propagate_forward(self, op):
         return dispatch_opt(self, op)
 
+    def propagate_postprocess(self, op):
+        return dispatch_postprocess(self, op)
+
     def propagate_bounds_backward(self, box):
         # FIXME: This takes care of the instruction where box is the reuslt
         #        but the bounds produced by all instructions where box is
@@ -70,9 +73,9 @@
             dispatch_bounds_ops(self, box)
 
     def _optimize_guard_true_false_value(self, op):
-        return IntBoundsCallbackArgs(op, self._optimize_guard_true_false_value_callback)
+        return op
 
-    def _optimize_guard_true_false_value_callback(self, op):
+    def _postprocess_guard_true_false_value(self, op):
         if op.getarg(0).type == 'i':
             self.propagate_bounds_backward(op.getarg(0))
 
@@ -80,6 +83,10 @@
     optimize_GUARD_FALSE = _optimize_guard_true_false_value
     optimize_GUARD_VALUE = _optimize_guard_true_false_value
 
+    postprocess_GUARD_TRUE = _postprocess_guard_true_false_value
+    postprocess_GUARD_FALSE = _postprocess_guard_true_false_value
+    postprocess_GUARD_VALUE = _postprocess_guard_true_false_value
+
     def optimize_INT_OR_or_XOR(self, op):
         v1 = self.get_box_replacement(op.getarg(0))
         v2 = self.get_box_replacement(op.getarg(1))
@@ -89,9 +96,9 @@
             else:
                 self.make_constant_int(op, 0)
             return None
-        return IntBoundsCallbackArgs(op, self.optimize_INT_OR_or_XOR_callback)
+        return op
 
-    def optimize_INT_OR_or_XOR_callback(self, op):
+    def postprocess_INT_OR_or_XOR(self, op):
         v1 = self.get_box_replacement(op.getarg(0))
         b1 = self.getintbound(v1)
         v2 = self.get_box_replacement(op.getarg(1))
@@ -105,10 +112,13 @@
     optimize_INT_OR = optimize_INT_OR_or_XOR
     optimize_INT_XOR = optimize_INT_OR_or_XOR
 
+    postprocess_INT_OR = postprocess_INT_OR_or_XOR
+    postprocess_INT_XOR = postprocess_INT_OR_or_XOR
+
     def optimize_INT_AND(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_INT_AND_callback)
+        return op
 
-    def optimize_INT_AND_callback(self, op):
+    def postprocess_INT_AND(self, op):
         b1 = self.getintbound(op.getarg(0))
         b2 = self.getintbound(op.getarg(1))
         r = self.getintbound(op)
@@ -125,9 +135,9 @@
             r.intersect(IntBound(0, next_pow2_m1(lesser)))
 
     def optimize_INT_SUB(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_INT_SUB_callback)
+        return op
 
-    def optimize_INT_SUB_callback(self, op):
+    def postprocess_INT_SUB(self, op):
         b1 = self.getintbound(op.getarg(0))
         b2 = self.getintbound(op.getarg(1))
         b = b1.sub_bound(b2)
@@ -138,7 +148,7 @@
         arg1 = self.get_box_replacement(op.getarg(0))
         arg2 = self.get_box_replacement(op.getarg(1))
         if self.is_raw_ptr(arg1) or self.is_raw_ptr(arg2):
-            return IntBoundsCallbackArgs(op)
+            return op
         v1 = self.getintbound(arg1)
         v2 = self.getintbound(arg2)
 
@@ -172,9 +182,9 @@
                         arg2 = ConstInt(sum)
                         op = self.replace_op_with(op, rop.INT_ADD, args=[arg1, arg2])
 
-        return IntBoundsCallbackArgs(op, self.optimize_INT_ADD_callback)
+        return op
 
-    def optimize_INT_ADD_callback(self, op):
+    def postprocess_INT_ADD(self, op):
         b1 = self.getintbound(op.getarg(0))
         b2 = self.getintbound(op.getarg(1))
         r = self.getintbound(op)
@@ -183,9 +193,9 @@
             r.intersect(b)
 
     def optimize_INT_MUL(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_INT_MUL_callback)
+        return op
 
-    def optimize_INT_MUL_callback(self, op):
+    def postprocess_INT_MUL(self, op):
         b1 = self.getintbound(op.getarg(0))
         b2 = self.getintbound(op.getarg(1))
         r = self.getintbound(op)
@@ -194,9 +204,9 @@
             r.intersect(b)
 
     def optimize_INT_FLOORDIV(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_INT_FLOORDIV_callback)
+        return op
 
-    def optimize_INT_FLOORDIV_callback(self, op):
+    def postprocess_INT_FLOORDIV(self, op):
         b1 = self.getintbound(op.getarg(0))
         b2 = self.getintbound(op.getarg(1))
         r = self.getintbound(op)
@@ -215,9 +225,9 @@
                 arg2 = ConstInt(val-1)
                 op = self.replace_op_with(op, rop.INT_AND,
                                           args=[arg1, arg2])
-        return IntBoundsCallbackArgs(op, self.optimize_INT_MOD_callback)
+        return op
 
-    def optimize_INT_MOD_callback(self, op):
+    def postprocess_INT_MOD(self, op):
         b1 = self.getintbound(op.getarg(0))
         b2 = self.getintbound(op.getarg(1))
         known_nonneg = (b1.known_ge(IntBound(0, 0)) and
@@ -236,9 +246,9 @@
             r.make_lt(IntBound(val, val))
 
     def optimize_INT_LSHIFT(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_INT_LSHIFT_callback)
+        return op
 
-    def optimize_INT_LSHIFT_callback(self, op):
+    def postprocess_INT_LSHIFT(self, op):
         arg0 = self.get_box_replacement(op.getarg(0))
         b1 = self.getintbound(arg0)
         arg1 = self.get_box_replacement(op.getarg(1))
@@ -262,9 +272,9 @@
             # constant result (likely 0, for rshifts that kill all bits)
             self.make_constant_int(op, b.lower)
             return None
-        return IntBoundsCallbackArgs(op, self.optimize_INT_RSHIFT_callback)
+        return op
 
-    def optimize_INT_RSHIFT_callback(self, op):
+    def postprocess_INT_RSHIFT(self, op):
         b1 = self.getintbound(op.getarg(0))
         b2 = self.getintbound(op.getarg(1))
         b = b1.rshift_bound(b2)
@@ -295,7 +305,7 @@
                 self.pure_from_args(rop.INT_SUB, [args[0], result], args[1])
             #elif opnum == rop.INT_MUL_OVF:
             #    self.pure(rop.INT_MUL, args[:], result)
-            return IntBoundsCallbackArgs(op)
+            return op
 
     def optimize_GUARD_OVERFLOW(self, op):
         # If INT_xxx_OVF was replaced by INT_xxx, *but* we still see
@@ -308,7 +318,7 @@
             raise InvalidLoop('An INT_xxx_OVF was proven not to overflow but' +
                               'guarded with GUARD_OVERFLOW')
 
-        return IntBoundsCallbackArgs(op)
+        return op
 
     def optimize_INT_ADD_OVF(self, op):
         b1 = self.getintbound(op.getarg(0))
@@ -319,9 +329,9 @@
             # by optimize_GUARD_NO_OVERFLOW; if we see instead an
             # optimize_GUARD_OVERFLOW, then InvalidLoop.
             op = self.replace_op_with(op, rop.INT_ADD)
-        return IntBoundsCallbackArgs(op, self.optimize_INT_ADD_OVF_callback)
+        return op
 
-    def optimize_INT_ADD_OVF_callback(self, op):
+    def postprocess_INT_ADD_OVF(self, op):
         b1 = self.getintbound(op.getarg(0))
         b2 = self.getintbound(op.getarg(1))
         resbound = b1.add_bound(b2)
@@ -339,9 +349,9 @@
         resbound = b0.sub_bound(b1)
         if resbound.bounded():
             op = self.replace_op_with(op, rop.INT_SUB)
-        return IntBoundsCallbackArgs(op, self.optimize_INT_SUB_OVF_callback)
+        return op
 
-    def optimize_INT_SUB_OVF_callback(self, op):
+    def postprocess_INT_SUB_OVF(self, op):
         arg0 = self.get_box_replacement(op.getarg(0))
         arg1 = self.get_box_replacement(op.getarg(1))
         b0 = self.getintbound(arg0)
@@ -356,9 +366,9 @@
         resbound = b1.mul_bound(b2)
         if resbound.bounded():
             op = self.replace_op_with(op, rop.INT_MUL)
-        return IntBoundsCallbackArgs(op, self.optimize_INT_MUL_OVF_callback)
+        return op
 
-    def optimize_INT_MUL_OVF_callback(self, op):
+    def postprocess_INT_MUL_OVF(self, op):
         b1 = self.getintbound(op.getarg(0))
         b2 = self.getintbound(op.getarg(1))
         resbound = b1.mul_bound(b2)
@@ -375,7 +385,7 @@
         elif b1.known_ge(b2) or arg1 is arg2:
             self.make_constant_int(op, 0)
         else:
-            return IntBoundsCallbackArgs(op)
+            return op
 
     def optimize_INT_GT(self, op):
         arg1 = self.get_box_replacement(op.getarg(0))
@@ -387,7 +397,7 @@
         elif b1.known_le(b2) or arg1 is arg2:
             self.make_constant_int(op, 0)
         else:
-            return IntBoundsCallbackArgs(op)
+            return op
 
     def optimize_INT_LE(self, op):
         arg1 = self.get_box_replacement(op.getarg(0))
@@ -399,7 +409,7 @@
         elif b1.known_gt(b2):
             self.make_constant_int(op, 0)
         else:
-            return IntBoundsCallbackArgs(op)
+            return op
 
     def optimize_INT_GE(self, op):
         arg1 = self.get_box_replacement(op.getarg(0))
@@ -411,7 +421,7 @@
         elif b1.known_lt(b2):
             self.make_constant_int(op, 0)
         else:
-            return IntBoundsCallbackArgs(op)
+            return op
 
     def optimize_INT_EQ(self, op):
         arg0 = self.get_box_replacement(op.getarg(0))
@@ -425,7 +435,7 @@
         elif arg0.same_box(arg1):
             self.make_constant_int(op, 1)
         else:
-            return IntBoundsCallbackArgs(op)
+            return op
 
     def optimize_INT_NE(self, op):
         arg0 = self.get_box_replacement(op.getarg(0))
@@ -439,14 +449,14 @@
         elif arg0 is arg1:
             self.make_constant_int(op, 0)
         else:
-            return IntBoundsCallbackArgs(op)
+            return op
 
     def optimize_INT_FORCE_GE_ZERO(self, op):
         b = self.getintbound(op.getarg(0))
         if b.known_ge(IntBound(0, 0)):
             self.make_equal_to(op, op.getarg(0))
         else:
-            return IntBoundsCallbackArgs(op)
+            return op
 
     def optimize_INT_SIGNEXT(self, op):
         b = self.getintbound(op.getarg(0))
@@ -457,9 +467,9 @@
         if bounds.contains_bound(b):
             self.make_equal_to(op, op.getarg(0))
         else:
-            return IntBoundsCallbackArgs(op, self.optimize_INT_SIGNEXT_callback)
+            return op
 
-    def optimize_INT_SIGNEXT_callback(self, op):
+    def postprocess_INT_SIGNEXT(self, op):
         numbits = op.getarg(1).getint() * 8
         start = -(1 << (numbits - 1))
         stop = 1 << (numbits - 1)
@@ -468,32 +478,32 @@
         bres.intersect(bounds)
 
     def optimize_ARRAYLEN_GC(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_ARRAYLEN_GC_callback)
+        return op
 
-    def optimize_ARRAYLEN_GC_callback(self, op):
+    def postprocess_ARRAYLEN_GC(self, op):
         array = self.ensure_ptr_info_arg0(op)
         self.optimizer.setintbound(op, array.getlenbound(None))
 
     def optimize_STRLEN(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_STRLEN_callback)
+        return op
 
-    def optimize_STRLEN_callback(self, op):
+    def postprocess_STRLEN(self, op):
         self.make_nonnull_str(op.getarg(0), vstring.mode_string)
         array = self.getptrinfo(op.getarg(0))
         self.optimizer.setintbound(op, array.getlenbound(vstring.mode_string))
 
     def optimize_UNICODELEN(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_UNICODELEN_callback)
+        return op
 
-    def optimize_UNICODELEN_callback(self, op):
+    def postprocess_UNICODELEN(self, op):
         self.make_nonnull_str(op.getarg(0), vstring.mode_unicode)
         array = self.getptrinfo(op.getarg(0))
         self.optimizer.setintbound(op, array.getlenbound(vstring.mode_unicode))
 
     def optimize_STRGETITEM(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_STRGETITEM_callback)
+        return op
 
-    def optimize_STRGETITEM_callback(self, op):
+    def postprocess_STRGETITEM(self, op):
         v1 = self.getintbound(op)
         v2 = self.getptrinfo(op.getarg(0))
         intbound = self.getintbound(op.getarg(1))
@@ -505,9 +515,9 @@
         v1.make_lt(IntUpperBound(256))
 
     def optimize_GETFIELD_RAW_I(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_GETFIELD_RAW_I_callback)
+        return op
 
-    def optimize_GETFIELD_RAW_I_callback(self, op):
+    def postprocess_GETFIELD_RAW_I(self, op):
         descr = op.getdescr()
         if descr.is_integer_bounded():
             b1 = self.getintbound(op)
@@ -520,14 +530,24 @@
     optimize_GETFIELD_GC_R = optimize_GETFIELD_RAW_I
     optimize_GETFIELD_GC_F = optimize_GETFIELD_RAW_I
 
+    postprocess_GETFIELD_RAW_F = postprocess_GETFIELD_RAW_I
+    postprocess_GETFIELD_RAW_R = postprocess_GETFIELD_RAW_I
+    postprocess_GETFIELD_GC_I = postprocess_GETFIELD_RAW_I
+    postprocess_GETFIELD_GC_R = postprocess_GETFIELD_RAW_I
+    postprocess_GETFIELD_GC_F = postprocess_GETFIELD_RAW_I
+
     optimize_GETINTERIORFIELD_GC_I = optimize_GETFIELD_RAW_I
     optimize_GETINTERIORFIELD_GC_R = optimize_GETFIELD_RAW_I
     optimize_GETINTERIORFIELD_GC_F = optimize_GETFIELD_RAW_I
 
+    postprocess_GETINTERIORFIELD_GC_I = postprocess_GETFIELD_RAW_I
+    postprocess_GETINTERIORFIELD_GC_R = postprocess_GETFIELD_RAW_I
+    postprocess_GETINTERIORFIELD_GC_F = postprocess_GETFIELD_RAW_I
+
     def optimize_GETARRAYITEM_RAW_I(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_GETARRAYITEM_RAW_I_callback)
+        return op
 
-    def optimize_GETARRAYITEM_RAW_I_callback(self, op):
+    def postprocess_GETARRAYITEM_RAW_I(self, op):
         descr = op.getdescr()
         if descr and descr.is_item_integer_bounded():
             intbound = self.getintbound(op)
@@ -539,10 +559,15 @@
     optimize_GETARRAYITEM_GC_F = optimize_GETARRAYITEM_RAW_I
     optimize_GETARRAYITEM_GC_R = optimize_GETARRAYITEM_RAW_I
 
+    postprocess_GETARRAYITEM_RAW_F = postprocess_GETARRAYITEM_RAW_I
+    postprocess_GETARRAYITEM_GC_I = postprocess_GETARRAYITEM_RAW_I
+    postprocess_GETARRAYITEM_GC_F = postprocess_GETARRAYITEM_RAW_I
+    postprocess_GETARRAYITEM_GC_R = postprocess_GETARRAYITEM_RAW_I
+
     def optimize_UNICODEGETITEM(self, op):
-        return IntBoundsCallbackArgs(op, self.optimize_UNICODEGETITEM_callback)
+        return op
 
-    def optimize_UNICODEGETITEM_callback(self, op):
+    def postprocess_UNICODEGETITEM(self, op):
         b1 = self.getintbound(op)
         b1.make_ge(IntLowerBound(0))
         v2 = self.getptrinfo(op.getarg(0))
@@ -709,3 +734,4 @@
 dispatch_opt = make_dispatcher_method(OptIntBounds, 'optimize_',
         default=OptIntBounds.opt_default)
 dispatch_bounds_ops = make_dispatcher_method(OptIntBounds, 'propagate_bounds_')
+dispatch_postprocess = make_dispatcher_method(OptIntBounds, 'postprocess_')
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
@@ -538,12 +538,12 @@
                 op.set_forwarded(None)
 
     def send_extra_operation(self, op):
-        callback_args = self.optimizations[0].propagate_forward(op)
-        if callback_args is None:
+        newop = self.optimizations[0].propagate_forward(op)
+        if newop is None:
             return
-        self.optimizations[0].last_emitted_operation = callback_args.op
-        self.first_optimization.propagate_forward(callback_args.op)
-        callback_args.callback()
+        self.optimizations[0].last_emitted_operation = newop
+        self.first_optimization.propagate_forward(newop)
+        self.optimizations[0].propagate_postprocess(newop)
 
     def propagate_forward(self, op):
         dispatch_opt(self, op)


More information about the pypy-commit mailing list