Commits

Maciej Fijalkowski committed 0ed7c47

guard class removal

  • Participants
  • Parent commits d7e2f9e
  • Branches result-in-resops

Comments (0)

Files changed (6)

File pypy/jit/metainterp/optimizeopt/intbounds.py

         self.emit_operation(op)
 
     def optimize_INT_ADD_OVF(self, op):
-        v1 = self.getvalue(op.getarg(0))
-        v2 = self.getvalue(op.getarg(1))
+        op = self.getforwarded(op)
+        v1 = self.getforwarded(op.getarg(0))
+        v2 = self.getforwarded(op.getarg(1))
         resbound = v1.getintbound().add_bound(v2.getintbound())
         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.
-            op = self.optimizer.copy_and_change(op, rop.INT_ADD)
-        self.emit_operation(op) # emit the op
-        r = self.getvalue(op)
-        r.getintbound().intersect(resbound)
+            op = op.make_forwarded_copy(rop.INT_ADD)
+            op.getintbound().intersect(resbound)
+        return op
 
     def optimize_INT_SUB_OVF(self, op):
         v1 = self.getvalue(op.getarg(0))

File pypy/jit/metainterp/optimizeopt/optimizer.py

             return self.box.same_constant(other.box)
         return self is other
 
-    def get_constant_class(self, cpu):
-        xxx
-        level = self.level
-        if level == LEVEL_KNOWNCLASS:
-            return self.known_class
-        elif level == LEVEL_CONSTANT:
-            return cpu.ts.cls_of_box(self.op)
-        else:
-            return None
-
     def make_constant_class(self, classbox, guardop, index):
         assert self.level < LEVEL_KNOWNCLASS
         self.known_class = classbox
         if isinstance(op, Const):
             return op
 
+    def get_constant_class(self, op):
+        if op.is_constant():
+            xxx
+        return op.getknownclass()
+
     def get_newoperations(self):
         self.flush()
         return self._newoperations

File pypy/jit/metainterp/optimizeopt/rewrite.py

         self.postprocess_guard(op, CONST_1)
 
     def postprocess_GUARD_FALSE(self, op):
-        self.postprocess_guard(op, CONST_0)        
+        self.postprocess_guard(op, CONST_0)
+
+    def postprocess_GUARD_NO_OVERFLOW(self, op):
+        pass # to be killed
 
     def postprocess_default(self, op):
         if op.is_guard():
 
     def optimize_GUARD_VALUE(self, op):
         value = self.getforwarded(op.getarg(0))
-        if value.getlastguard():
+        if value.getlastguardpos() != -1:
             xxx
             # there already has been a guard_nonnull or guard_class or
             # guard_nonnull_class on this value, which is rather silly.
         value = self.getvalue(op.getarg(0))
         expectedclassbox = op.getarg(1)
         assert isinstance(expectedclassbox, Const)
-        realclassbox = value.get_constant_class(self.optimizer.cpu)
+        realclassbox = self.optimizer.get_constant_class(value)
         if realclassbox is not None:
             assert realclassbox.same_constant(expectedclassbox)
             return
                                   self.optimizer.get_pos())
 
     def optimize_GUARD_CLASS(self, op):
-        value = self.getvalue(op.getarg(0))
+        value = self.getforwarded(op.getarg(0))
         expectedclassbox = op.getarg(1)
         assert isinstance(expectedclassbox, Const)
-        realclassbox = value.get_constant_class(self.optimizer.cpu)
+        realclassbox = self.optimizer.get_constant_class(value)
         if realclassbox is not None:
             if realclassbox.same_constant(expectedclassbox):
                 return
             raise InvalidLoop('A GUARD_CLASS was proven to always fail')
-        emit_operation = True
-        if value.last_guard:
+        if value.getlastguardpos() != -1:
+            xxx
             # there already has been a guard_nonnull or guard_class or
             # guard_nonnull_class on this value.
             old_guard_op = value.last_guard
                 new_op.set_extra("failargs", old_guard_op.get_extra("failargs"))
                 self.optimizer.replace_op(value, new_op)
                 op = new_op
-                emit_operation = False
+                return
             value.last_guard = None
-            pos = value.last_guard_pos
         else:
-            pos = self.optimizer.get_pos()
-        if emit_operation:
-            self.emit_operation(op)
-        value.make_constant_class(expectedclassbox, op, pos)
+            value.setlastguardpos(self.optimizer.get_pos())
+        return op
+
+    def postprocess_GUARD_CLASS(self, op):
+        value = self.getforwarded(op.getarg(0))
+        expectedclassbox = op.getarg(1)
+        assert isinstance(expectedclassbox, Const)
+        value.setknownclass(expectedclassbox)
 
     def optimize_GUARD_NONNULL_CLASS(self, op):
         value = self.getvalue(op.getarg(0))

File pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py

     def test_constant_propagate_ovf(self):
         ops = """
         [i]
-        guard_value(i, 2) []
+        guard_value(i, 2)
         i0 = int_add_ovf(i, 3)
-        guard_no_overflow() []
+        guard_no_overflow()
         i1 = int_is_true(i0)
-        guard_true(i1) []
+        guard_true(i1)
         i2 = int_is_zero(i1)
-        guard_false(i2) []
-        guard_value(i0, 5) []
+        guard_false(i2)
+        guard_value(i0, 5)
         jump(i)
         """
         expected = """
         [i]
-        guard_value(i, 2) []
+        guard_value(i, 2)
         jump(2)
         """
         self.optimize_loop(ops, expected)
     def test_remove_guard_class_1(self):
         ops = """
         [p0]
-        guard_class(p0, ConstClass(node_vtable)) []
-        guard_class(p0, ConstClass(node_vtable)) []
+        guard_class(p0, ConstClass(node_vtable))
+        guard_class(p0, ConstClass(node_vtable))
         jump(p0)
         """
         expected = """
         [p0]
-        guard_class(p0, ConstClass(node_vtable)) []
+        guard_class(p0, ConstClass(node_vtable))
         jump(p0)
         """
         self.optimize_loop(ops, expected)

File pypy/jit/metainterp/optmodel.py

 
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.jit.metainterp.resoperation import opclasses, opclasses_mutable, rop,\
-     INT, ConstInt, Const
+     INT, REF, ConstInt, Const
 from pypy.jit.metainterp.optimizeopt.intutils import ImmutableIntUnbounded,\
      ConstantIntBound
 
         return False # for optimization
 
 class __extend__(Const):
-    def getlastguard(self):
-        return None
+    def getlastguardpos(self):
+        return -1
 
 def create_mutable_subclasses():
     def addattr(cls, attr, default_value=None):
         def _copy_extra_attrs(self, new):
             paren_cls._copy_extra_attrs(self, new)
             for attr in cls.attributes_to_copy:
-                setattr(new, getattr(self, attr))
+                setattr(new, attr, getattr(self, attr))
         cls._copy_extra_attrs = _copy_extra_attrs
 
     imm_int_unbound = ImmutableIntUnbounded()
                 # all the integers have bounds
                 addattr(Mutable, 'intbound', imm_int_unbound)
                 addattr(Mutable, 'boolbox', False)
+            elif cls.type == REF:
+                addattr(Mutable, 'knownclass', None)
             # for tracking last guard and merging GUARD_VALUE with
             # GUARD_NONNULL etc
-            addattr(Mutable, 'lastguard', None)
             addattr(Mutable, 'lastguardpos', -1)
             Mutable.__name__ = cls.__name__ + '_mutable'
             if Mutable.attributes_to_copy:

File pypy/jit/metainterp/resoperation.py

                              arg1 or self._arg1,
                              descr or self.getdescr(),
                              mutable=True)
-        if self.is_guard():
-            res.set_rd_frame_info_list(self.get_rd_frame_info_list())
-            res.set_rd_snapshot(self.get_rd_snapshot())
         assert not self._forwarded
         self._forwarded = res
         self._copy_extra_attrs(res)