Author: Maciej Fijalkowski <[email protected]>
Branch: result-in-resops
Changeset: r58487:c9dbbd6d9b9d
Date: 2012-10-27 00:56 +0200
http://bitbucket.org/pypy/pypy/changeset/c9dbbd6d9b9d/

Log:    one more test_guard_class

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
@@ -300,9 +300,6 @@
     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)
 
@@ -357,7 +354,7 @@
         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
@@ -379,7 +376,6 @@
         self.optimizations = optimizations
         for opt in optimizations:
             opt.optimizer = self
-        self.setup()
 
     def force_at_end_of_preamble(self):
         for o in self.optimizations:
@@ -424,11 +420,8 @@
             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
@@ -456,7 +449,7 @@
 
     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):
@@ -564,7 +557,7 @@
             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):
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
@@ -331,6 +331,8 @@
 
     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)
@@ -538,7 +540,7 @@
         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
 
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py 
b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -240,7 +240,7 @@
         [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 = """
@@ -255,7 +255,7 @@
         ops = """
         [i0]
         p0 = same_as_r(ConstPtr(myptr))
-        guard_class(p0, ConstClass(node_vtable)) []
+        guard_class(p0, ConstClass(node_vtable))
         jump(i0)
         """
         expected = """
diff --git a/pypy/jit/metainterp/optimizeopt/virtualize.py 
b/pypy/jit/metainterp/optimizeopt/virtualize.py
--- a/pypy/jit/metainterp/optimizeopt/virtualize.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualize.py
@@ -358,11 +358,6 @@
     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)
@@ -468,7 +463,8 @@
             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)
diff --git a/pypy/jit/metainterp/optmodel.py b/pypy/jit/metainterp/optmodel.py
--- a/pypy/jit/metainterp/optmodel.py
+++ b/pypy/jit/metainterp/optmodel.py
@@ -19,6 +19,9 @@
     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)
@@ -45,6 +48,14 @@
             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():
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to