[pypy-svn] r69065 - in pypy/branch/merge-guards/pypy/jit/metainterp: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Sun Nov 8 16:18:39 CET 2009


Author: cfbolz
Date: Sun Nov  8 16:18:38 2009
New Revision: 69065

Modified:
   pypy/branch/merge-guards/pypy/jit/metainterp/optimizeopt.py
   pypy/branch/merge-guards/pypy/jit/metainterp/test/test_optimizeopt.py
Log:
(pedronis, cfbolz): replace guard_class(x, ...), guard_value(x, ...) by just a guard_value.


Modified: pypy/branch/merge-guards/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/merge-guards/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/branch/merge-guards/pypy/jit/metainterp/optimizeopt.py	Sun Nov  8 16:18:38 2009
@@ -42,7 +42,9 @@
 
 
 class OptValue(object):
-    _attrs_ = ('box', 'known_class', 'level')
+    _attrs_ = ('box', 'known_class', 'guard_class_index', 'level')
+    guard_class_index = -1
+
     level = LEVEL_UNKNOWN
 
     def __init__(self, box):
@@ -85,10 +87,11 @@
         else:
             return None
 
-    def make_constant_class(self, classbox):
+    def make_constant_class(self, classbox, opindex):
         if self.level < LEVEL_KNOWNCLASS:
             self.known_class = classbox
             self.level = LEVEL_KNOWNCLASS
+            self.guard_class_index = opindex
 
     def is_nonnull(self):
         level = self.level
@@ -570,7 +573,7 @@
         op2.args = exitargs[:]
         self.emit_operation(op2, must_clone=False)
 
-    def optimize_guard(self, op, constbox):
+    def optimize_guard(self, op, constbox, emit_operation=True):
         value = self.getvalue(op.args[0])
         if value.is_constant():
             box = value.box
@@ -578,13 +581,23 @@
             if not box.same_constant(constbox):
                 raise InvalidLoop
             return
-        self.emit_operation(op)
+        if emit_operation:
+            self.emit_operation(op)
         value.make_constant(constbox)
 
     def optimize_GUARD_VALUE(self, op):
+        value = self.getvalue(op.args[0])
+        emit_operation = True
+        if value.guard_class_index != -1:
+            # there already has been a guard_class on this value, which is
+            # rather silly. replace the original guard_class with a guard_value
+            guard_class_op = self.newoperations[value.guard_class_index]
+            guard_class_op.opnum = op.opnum
+            guard_class_op.args[1] = op.args[1]
+            emit_operation = False
         constbox = op.args[1]
         assert isinstance(constbox, Const)
-        self.optimize_guard(op, constbox)
+        self.optimize_guard(op, constbox, emit_operation)
 
     def optimize_GUARD_TRUE(self, op):
         self.optimize_guard(op, CONST_1)
@@ -604,7 +617,7 @@
             assert realclassbox.same_constant(expectedclassbox)
             return
         self.emit_operation(op)
-        value.make_constant_class(expectedclassbox)
+        value.make_constant_class(expectedclassbox, len(self.newoperations) - 1)
 
     def optimize_GUARD_NO_EXCEPTION(self, op):
         if not self.exception_might_have_happened:

Modified: pypy/branch/merge-guards/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/merge-guards/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/merge-guards/pypy/jit/metainterp/test/test_optimizeopt.py	Sun Nov  8 16:18:38 2009
@@ -1513,6 +1513,23 @@
                        'Virtual(node_vtable, nextdescr=Virtual(node_vtable))',
                        None)
 
+    def test_merge_guard_class_guard_value(self):
+        ops = """
+        [p1, i0, i1, i2, p2]
+        guard_class(p1, ConstClass(node_vtable)) [i0]
+        i3 = int_add(i1, i2)
+        guard_value(p1, ConstPtr(myptr)) [i1]
+        jump(p2, i0, i1, i3, p2)
+        """
+        expected = """
+        [p1, i0, i1, i2, p2]
+        guard_value(p1, ConstPtr(myptr)) [i0]
+        i3 = int_add(i1, i2)
+        jump(p2, i0, i1, i3, p2)
+        """
+        self.optimize_loop(ops, "Not, Not, Not, Not, Not", expected)
+
+
     # ----------
 
     def make_fail_descr(self):



More information about the Pypy-commit mailing list