Commits

Maciej Fijalkowski committed c9dbbd6

one more test_guard_class

Comments (0)

Files changed (5)

pypy/jit/metainterp/optimizeopt/optimizer.py

     def make_constant_int(self, box, intconst):
         return self.optimizer.make_constant_int(box, intconst)
 
-    def replace(self, box, value):
-        return self.optimizer.replace(box, value)
-
     def get_constant_op(self, op):
         return self.optimizer.get_constant_op(op)
 
         self.optimizer.forget_numberings(box)
 
 
-class Optimizer(Optimization):
+class Optimizer(object):
 
     def __init__(self, jitdriver_sd, metainterp_sd, loop, optimizations=None):
         self.jitdriver_sd = jitdriver_sd
         self.optimizations = optimizations
         for opt in optimizations:
             opt.optimizer = self
-        self.setup()
 
     def force_at_end_of_preamble(self):
         for o in self.optimizations:
             return op
         return op.getforwarded()
 
-    def setvalue(self, box, value):
-        xxx
-        assert not box.is_constant()
-        assert not box.has_extra("optimize_value")
-        box.set_extra("optimize_value", value)
+    def replace(self, op, with_):
+        self.getforwarded(op)._forwarded = with_
 
     def copy_op_if_modified_by_optimization(self, op):
         xxxx
 
     def get_constant_class(self, op):
         if op.is_constant():
-            xxx
+            return self.cpu.ts.cls_of_box(op)
         return op.getknownclass()
 
     def get_newoperations(self):
             op = self.store_final_boxes_in_guard(op)
         assert op is not None
         for i in range(op.numargs()):
-            op.setarg(i, self.getforwarded(op.getarg(i)))
+            op.setarg(i, self.getforwarded(op.getarg(i)).force(self))
         self._newoperations.append(op)
 
     def store_final_boxes_in_guard(self, op):

pypy/jit/metainterp/optimizeopt/rewrite.py

 
     def postprocess_GUARD_CLASS(self, op):
         value = self.getforwarded(op.getarg(0))
+        if value.is_constant():
+            return
         expectedclassbox = op.getarg(1)
         assert isinstance(expectedclassbox, Const)
         value.setknownclass(expectedclassbox)
         self.emit_operation(op)
 
     def optimize_SAME_AS_i(self, op):
-        self.replace(op, op.getarg(0))
+        self.optimizer.replace(op, op.getarg(0))
     optimize_SAME_AS_r = optimize_SAME_AS_i
     optimize_SAME_AS_f = optimize_SAME_AS_i
 

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

         [i0]
         p0 = new_with_vtable(ConstClass(node_vtable))
         escape(p0)
-        guard_class(p0, ConstClass(node_vtable)) []
+        guard_class(p0, ConstClass(node_vtable))
         jump(i0)
         """
         expected = """
         ops = """
         [i0]
         p0 = same_as_r(ConstPtr(myptr))
-        guard_class(p0, ConstClass(node_vtable)) []
+        guard_class(p0, ConstClass(node_vtable))
         jump(i0)
         """
         expected = """

pypy/jit/metainterp/optimizeopt/virtualize.py

     def new(self):
         return OptVirtualize()
 
-    def make_virtual(self, known_class, op):
-        vvalue = VirtualValue(self.optimizer.cpu, known_class, op)
-        self.setvalue(op, vvalue)
-        return vvalue
-
     def make_varray(self, arraydescr, size, op):
         if arraydescr.is_array_of_structs():
             vvalue = VArrayStructValue(arraydescr, size, op)
             self.emit_operation(op)
 
     def optimize_NEW_WITH_VTABLE(self, op):
-        self.make_virtual(op.getarg(0), op)
+        value = self.getforwarded(op)
+        value.setknownclass(op.getarg(0))
 
     def optimize_NEW(self, op):
         self.make_vstruct(op.getdescr(), op)

pypy/jit/metainterp/optmodel.py

     def getlastguardpos(self):
         return -1
 
+    def force(self, _):
+        return self
+
 def create_mutable_subclasses():
     def addattr(cls, attr, default_value=None):
         cls.attributes_to_copy.append('_' + attr)
             class Mutable(cls):
                 is_mutable = True
                 attributes_to_copy = []
+
+                if cls.getopnum() in (rop.NEW_WITH_VTABLE, rop.NEW):
+                    def force(self, optimizer):
+                        optimizer.emit_operation(self)
+                        return self
+                else:
+                    def force(self, _):
+                        return self
             if cls.is_guard() or cls.getopnum() == rop.FINISH:
                 addattr(Mutable, 'failargs')
             if cls.is_guard():