Commits

Maciej Fijalkowski committed 2b413dc

hack enough to make the next test pass

Comments (0)

Files changed (6)

pypy/jit/metainterp/optimizeopt/intbounds.py

         if b.bounded():
             r.getintbound().intersect(b)
 
-    def optimize_INT_ADD(self, op):
-        v1 = self.getvalue(op.getarg(0))
-        v2 = self.getvalue(op.getarg(1))
-        self.emit_operation(op)
-        r = self.getvalue(op)
+    def postprocess_INT_ADD(self, op):
+        v1 = self.getforwarded(op.getarg(0))
+        v2 = self.getforwarded(op.getarg(1))
+        r = self.getforwarded(op)
         b = v1.getintbound().add_bound(v2.getintbound())
         if b.bounded():
             r.getintbound().intersect(b)
                     self.propagate_bounds_backward(op.getarg(1))
 
     def propagate_bounds_INT_IS_TRUE(self, op):
-        r = self.getvalue(op)
+        r = self.getforwarded(op)
         if r.is_constant():
-            if r.op.same_constant(CONST_1):
-                v1 = self.getvalue(op.getarg(0))
+            if r.same_constant(CONST_1):
+                v1 = self.getforwarded(op.getarg(0))
                 if v1.getintbound().known_ge(IntBound(0, 0)):
                     v1.getintbound().make_gt(IntBound(0, 0))
                     self.propagate_bounds_backward(op.getarg(0))
 
     def propagate_bounds_INT_IS_ZERO(self, op):
-        r = self.getvalue(op)
+        r = self.getforwarded(op)
         if r.is_constant():
-            if r.op.same_constant(CONST_1):
-                v1 = self.getvalue(op.getarg(0))
+            if r.same_constant(CONST_1):
+                v1 = self.getforwarded(op.getarg(0))
                 # Clever hack, we can't use self.make_constant_int yet because
                 # the args aren't in the values dictionary yet so it runs into
                 # an assert, this is a clever way of expressing the same thing.
                 self.propagate_bounds_backward(op.getarg(0))
 
     def propagate_bounds_INT_ADD(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().sub_bound(v2.getintbound())
         if v1.getintbound().intersect(b):
             self.propagate_bounds_backward(op.getarg(0))

pypy/jit/metainterp/optimizeopt/optimizer.py

         descr.store_final_boxes(op, newboxes)
         #
         if op.getopnum() == rop.GUARD_VALUE:
+            xxx
             if self.getvalue(op.getarg(0)).is_bool_box:
                 # Hack: turn guard_value(bool) into guard_true/guard_false.
                 # This is done after the operation is emitted to let
         self._newoperations[value.last_guard_pos] = new_guard_op
 
     def constant_fold(self, op):
-        argboxes = [self.get_constant_box(op.getarg(i))
+        argboxes = [self.get_constant_op(op.getarg(i))
                     for i in range(op.numargs())]
         resbox = execute_nonspec(self.cpu, None,
                                  op.getopnum(), argboxes, op.getdescr())

pypy/jit/metainterp/optimizeopt/pure.py

 
         # otherwise, the operation remains
         if newop.returns_bool_result():
-            newop.is_bool_box = True
+            newop.setboolbox(True)
         if nextop:
             self.emit_operation(nextop)
         return newop

pypy/jit/metainterp/optimizeopt/rewrite.py

 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 Optimization
+from pypy.jit.metainterp.optimizeopt.optimizer import Optimization, CONST_1,\
+     CONST_0
 from pypy.jit.metainterp.resoperation import (opboolinvers, opboolreflex, rop,
                                               ConstInt, make_hashable_int,
                                               create_resop_2, Const)
         for op in self.loop_invariant_producer.values():
             sb.add_potential(op)
 
-    def propagate_forward(self, op):
-        if self.find_rewritable_bool(op):
-            return
-
-        dispatch_opt(self, op)
-
     def try_boolinvers(self, op, key_op):
         oldop = self.get_pure_result(key_op)
         if oldop is not None and oldop.getdescr() is op.getdescr():
     def optimize_INT_ADD(self, op):
         arg1 = op.getarg(0)
         arg2 = op.getarg(1)
-        v1 = self.getvalue(arg1)
-        v2 = self.getvalue(arg2)
+        v1 = self.getforwarded(arg1)
+        v2 = self.getforwarded(arg2)
 
         # If one side of the op is 0 the result is the other side.
-        if v1.is_constant() and v1.op.getint() == 0:
+        if v1.is_constant() and v1.getint() == 0:
             self.replace(op, arg2)
-        elif v2.is_constant() and v2.op.getint() == 0:
+        elif v2.is_constant() and v2.getint() == 0:
             self.replace(op, arg1)
         else:
-            self.emit_operation(op)
             # Synthesize the reverse op for optimize_default to reuse
             self.pure(op.getarg(0), rop.INT_SUB, op, op.getarg(1))
             self.pure(op.getarg(1), rop.INT_SUB, op, op.getarg(0))
+            return op
 
     def optimize_INT_MUL(self, op):
         v1 = self.getvalue(op.getarg(0))
     def optimize_guard(self, op, constbox, emit_operation=True):
         value = self.getforwarded(op.getarg(0))
         if value.is_constant():
-            xxx
-            box = value.op
-            assert isinstance(box, Const)
-            if not box.same_constant(constbox):
+            if not value.same_constant(constbox):
                 raise InvalidLoop('A GUARD_{VALUE,TRUE,FALSE} was proven to' +
                                   'always fail')
             return
         assert isinstance(constbox, Const)
         self.postprocess_guard(op, constbox)
 
+    def postprocess_GUARD_TRUE(self, op):
+        self.postprocess_guard(op, CONST_1)
+
+    def postprocess_GUARD_FALSE(self, op):
+        self.postprocess_guard(op, CONST_0)        
+
     def postprocess_default(self, op):
         if op.is_guard():
             xxx
     optimize_CALL_LOOPINVARIANT_v = _new_optimize_call_loopinvariant(rop.CALL_v)
 
     def _optimize_nullness(self, op, box, expect_nonnull):
+        return op
         value = self.getvalue(box)
         if value.is_nonnull():
             self.make_constant_int(op, expect_nonnull)
             self.emit_operation(op)
 
     def optimize_INT_IS_TRUE(self, op):
-        if self.getvalue(op.getarg(0)).is_bool_box:
+        value = self.getforwarded(op.getarg(0))
+        if value.getboolbox():
             self.replace(op, op.getarg(0))
             return
-        self._optimize_nullness(op, op.getarg(0), True)
+        return self._optimize_nullness(op, op.getarg(0), True)
 
     def optimize_INT_IS_ZERO(self, op):
         self._optimize_nullness(op, op.getarg(0), False)

pypy/jit/metainterp/optmodel.py

             if cls.type == INT:
                 # all the integers have bounds
                 addattr(Mutable, 'intbound', imm_int_unbound)
+                addattr(Mutable, 'boolbox', False)
             # for tracking last guard and merging GUARD_VALUE with
             # GUARD_NONNULL etc
             addattr(Mutable, 'lastguard', None)

pypy/jit/metainterp/resoperation.py

     def is_constant(self):
         return True
 
+    def getlastguard(self):
+        return None
+
 def repr_rpython(box, typechars):
     return '%s/%s%d' % (box._get_hash_(), typechars,
                         compute_unique_id(box))
     def repr_rpython(self):
         return repr_rpython(self, 'ci')
 
+    def getboolbox(self):
+        return False # for optimization
+
 CONST_FALSE = ConstInt(0)
 CONST_TRUE  = ConstInt(1)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.