Author: Maciej Fijalkowski <[email protected]>
Branch: result-in-resops
Changeset: r58417:3681c767716a
Date: 2012-10-25 13:23 +0200
http://bitbucket.org/pypy/pypy/changeset/3681c767716a/

Log:    slow progress

diff --git a/pypy/jit/metainterp/optimizeopt/heap.py 
b/pypy/jit/metainterp/optimizeopt/heap.py
--- a/pypy/jit/metainterp/optimizeopt/heap.py
+++ b/pypy/jit/metainterp/optimizeopt/heap.py
@@ -294,14 +294,12 @@
             # of virtualref_info and virtualizable_info are not gcptrs.
 
     def turned_constant(self, value):
-        assert value.is_constant()
-        newvalue = self.getvalue(value.op)
-        if value is not newvalue:
-            for cf in self.cached_fields.itervalues():
+        value = self.getforwarded(value)
+        for cf in self.cached_fields.itervalues():
+            cf.turned_constant(newvalue, value)
+        for submap in self.cached_arrayitems.itervalues():
+            for cf in submap.itervalues():
                 cf.turned_constant(newvalue, value)
-            for submap in self.cached_arrayitems.itervalues():
-                for cf in submap.itervalues():
-                    cf.turned_constant(newvalue, value)
 
     def force_lazy_setfield(self, descr, can_cache=True):
         try:
diff --git a/pypy/jit/metainterp/optimizeopt/intbounds.py 
b/pypy/jit/metainterp/optimizeopt/intbounds.py
--- a/pypy/jit/metainterp/optimizeopt/intbounds.py
+++ b/pypy/jit/metainterp/optimizeopt/intbounds.py
@@ -2,9 +2,9 @@
 from pypy.jit.metainterp.optimizeopt.optimizer import Optimization, CONST_1,\
      CONST_0, MODE_ARRAY, MODE_STR, MODE_UNICODE
 from pypy.jit.metainterp.optimizeopt.intutils import (IntBound, IntLowerBound,
-    IntUpperBound)
+    IntUpperBound, MININT, MAXINT)
 from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method
-from pypy.jit.metainterp.resoperation import rop, ConstInt, AbstractResOp
+from pypy.jit.metainterp.resoperation import rop, ConstInt, INT
 from pypy.jit.metainterp.optimize import InvalidLoop
 
 
@@ -15,25 +15,25 @@
     def new(self):
         return OptIntBounds()
 
-    #def propagate_forward(self, op):
-    #    dispatch_opt(self, op)
+    def process_inputargs(self, args):
+        for arg in args:
+            if arg.type == INT:
+                self.getforwarded(arg).setintbound(IntBound(MININT, MAXINT))
+    
+    def optimize_operation(self, op):
+        if op.type == INT:
+            self.getforwarded(op).setintbound(IntBound(MININT, MAXINT))
+        return Optimization.optimize_operation(self, op)
 
-    #def opt_default(self, op):
-    #    assert not op.is_ovf()
-    #    self.emit_operation(op)
-
-
-    def propagate_bounds_backward(self, box):
+    def propagate_bounds_backward(self, op):
         # FIXME: This takes care of the instruction where box is the reuslt
         #        but the bounds produced by all instructions where box is
         #        an argument might also be tighten
-        xxx
-        v = self.getvalue(box)
+        v = self.getforwarded(op)
         b = v.getintbound()
         if b.has_lower and b.has_upper and b.lower == b.upper:
             v.make_constant(ConstInt(b.lower))
-        if isinstance(box, AbstractResOp):
-            dispatch_bounds_ops(self, box)
+        dispatch_bounds_ops(self, op)
 
     def postprocess_GUARD_TRUE(self, op):
         self.propagate_bounds_backward(op.getarg(0))
@@ -436,9 +436,9 @@
             self.propagate_bounds_backward(op.getarg(1))
 
     def propagate_bounds_INT_SUB(self, op):
-        v1 = self.getvalue(op.getarg(0))
-        v2 = self.getvalue(op.getarg(1))
-        r = self.getvalue(op)
+        v1 = self.getforwarded(op.getarg(0))
+        v2 = self.getforwarded(op.getarg(1))
+        r = self.getforwarded(op)
         b = r.getintbound().add_bound(v2.getintbound())
         if v1.getintbound().intersect(b):
             self.propagate_bounds_backward(op.getarg(0))
@@ -470,6 +470,4 @@
     propagate_bounds_INT_MUL_OVF  = propagate_bounds_INT_MUL
 
 
-#dispatch_opt = make_dispatcher_method(OptIntBounds, 'optimize_',
-#        default=OptIntBounds.opt_default)
-#dispatch_bounds_ops = make_dispatcher_method(OptIntBounds, 
'propagate_bounds_')
+dispatch_bounds_ops = make_dispatcher_method(OptIntBounds, 'propagate_bounds_')
diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py 
b/pypy/jit/metainterp/optimizeopt/optimizer.py
--- a/pypy/jit/metainterp/optimizeopt/optimizer.py
+++ b/pypy/jit/metainterp/optimizeopt/optimizer.py
@@ -165,18 +165,6 @@
             return self.box.same_constant(other.box)
         return self is other
 
-    def make_constant(self, constbox):
-        """Replace 'self.box' with a Const box."""
-        assert isinstance(constbox, Const)
-        self.op = constbox
-        self.level = LEVEL_CONSTANT
-
-        if isinstance(constbox, ConstInt):
-            val = constbox.getint()
-            self.intbound = IntBound(val, val)
-        else:
-            self.intbound = IntUnbounded()
-
     def get_constant_class(self, cpu):
         xxx
         level = self.level
@@ -286,6 +274,9 @@
     #    self.last_emitted_operation = op
     #    self.next_optimization.propagate_forward(op)
 
+    def process_inputargs(self, args):
+        pass
+
     def optimize_operation(self, op):
         name = 'optimize_' + opname[op.getopnum()]
         next_func = getattr(self, name, self.optimize_default)
@@ -497,8 +488,8 @@
     def clear_newoperations(self):
         self._newoperations = []
 
-    def make_constant(self, box, constbox):
-        self.getvalue(box).make_constant(constbox)
+    def make_constant(self, op, constbox):
+        self.getforwarded(op)._forwarded = constbox
 
     def make_constant_int(self, box, intvalue):
         self.getvalue(box).make_constant(ConstInt(intvalue))
@@ -542,6 +533,8 @@
         if clear:
             self.clear_newoperations()
         i = 0
+        for opt in self.optimizations:
+            opt.process_inputargs(self.loop.inputargs)
         while i < len(self.loop.operations):
             op = self.loop.operations[i]
             orig_op = op
@@ -567,6 +560,7 @@
 
     def emit_operation(self, op):
         if op.returns_bool_result():
+            xxxx
             self.getvalue(op).is_bool_box = True
         self._emit_operation(op)
 
@@ -584,10 +578,11 @@
             self.exception_might_have_happened = True
         elif op.getopnum() == rop.FINISH:
             op = self.store_final_boxes_in_guard(op)
+        assert op is not None
         self._newoperations.append(op)
 
     def store_final_boxes_in_guard(self, op):
-        return # XXX we disable it for tests
+        return op # XXX we disable it for tests
         assert op.getdescr() is None
         descr = op.invent_descr(self.jitdriver_sd, self.metainterp_sd)
         op.setdescr(descr)
diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py 
b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -1,11 +1,10 @@
 from pypy.jit.codewriter.effectinfo import EffectInfo
 from pypy.jit.metainterp.optimize import InvalidLoop
 from pypy.jit.metainterp.optimizeopt.intutils import IntBound
-from pypy.jit.metainterp.optimizeopt.optimizer import *
-from pypy.jit.metainterp.optimizeopt.util import _findall, 
make_dispatcher_method
+from pypy.jit.metainterp.optimizeopt.optimizer import Optimization
 from pypy.jit.metainterp.resoperation import (opboolinvers, opboolreflex, rop,
                                               ConstInt, make_hashable_int,
-                                              create_resop_2)
+                                              create_resop_2, Const)
 from pypy.rlib.rarithmetic import highest_bit
 
 
@@ -205,14 +204,19 @@
         if emit_operation:
             return self.getforwarded(op)
 
-    def postprocess_guard(self, op):
+    def postprocess_guard(self, op, constbox):
         value = self.getforwarded(op.getarg(0))
-        value.make_constant(constbox)
-        self.optimizer.turned_constant(value)
+        self.optimizer.make_constant(value, constbox)
+        self.optimizer.turned_constant(op.getarg(0))
 
-    def postprocess_op(self, op):
+    def postprocess_GUARD_VALUE(self, op):
+        constbox = op.getarg(1)
+        assert isinstance(constbox, Const)
+        self.postprocess_guard(op, constbox)
+
+    def postprocess_default(self, op):
         if op.is_guard():
-            self.postprocess_guard(op)
+            xxx
 
     def optimize_GUARD_ISNULL(self, op):
         value = self.getvalue(op.getarg(0))
@@ -236,6 +240,7 @@
     def optimize_GUARD_VALUE(self, op):
         value = self.getforwarded(op.getarg(0))
         if value.getlastguard():
+            xxx
             # there already has been a guard_nonnull or guard_class or
             # guard_nonnull_class on this value, which is rather silly.
             # replace the original guard with a guard_value
@@ -271,7 +276,7 @@
             emit_operation = True
         constbox = op.getarg(1)
         assert isinstance(constbox, Const)
-        self.optimize_guard(op, constbox, emit_operation=emit_operation)
+        return self.optimize_guard(op, constbox, emit_operation=emit_operation)
 
     def optimize_GUARD_TRUE(self, op):
         self.optimize_guard(op, CONST_1)
diff --git a/pypy/jit/metainterp/optimizeopt/simplify.py 
b/pypy/jit/metainterp/optimizeopt/simplify.py
--- a/pypy/jit/metainterp/optimizeopt/simplify.py
+++ b/pypy/jit/metainterp/optimizeopt/simplify.py
@@ -46,6 +46,7 @@
         return op
         
     def optimize_JUMP(self, op):
+        op = self.getforwarded(op)
         if not self.unroll:
             descr = op.getdescr()
             newdescr = None
@@ -60,9 +61,8 @@
                 assert len(descr.target_tokens) == 1
                 newdescr = descr.target_tokens[0]
             if newdescr is not descr or op.opnum != rop.JUMP:
-                op = self.optimizer.copy_and_change(op, op.opnum,
-                                                    descr=newdescr)
-        self.emit_operation(op)
+                op.setdescr(newdescr)
+        return op
 
 #dispatch_opt = make_dispatcher_method(OptSimplify, 'optimize_',
 #        default=OptSimplify.emit_operation)
diff --git a/pypy/jit/metainterp/resoperation.py 
b/pypy/jit/metainterp/resoperation.py
--- a/pypy/jit/metainterp/resoperation.py
+++ b/pypy/jit/metainterp/resoperation.py
@@ -279,6 +279,8 @@
 class Const(AbstractValue):
     __slots__ = ()
 
+    _forwarded = None # always
+
     def constbox(self):
         return self
 
@@ -658,7 +660,7 @@
     # some debugging help
 
     def __setattr__(self, attr, val):
-        if attr not in ['_hash', '_str']:
+        if attr not in ['_hash', '_str', '_forwarded']:
             assert self._forwarded is None
         object.__setattr__(self, attr, val)
 
@@ -814,7 +816,7 @@
         # backend provides it with cpu.fielddescrof(), cpu.arraydescrof(),
         # cpu.calldescrof(), and cpu.typedescrof().
         self._check_descr(descr)
-        if self._descr is not None:
+        if self._descr is not None and not self.is_mutable:
             raise Exception("descr already set!")
         self._descr = descr
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to