[pypy-commit] pypy optresult: (fijal, arigo) make nonnull tests pass

fijal noreply at buildbot.pypy.org
Fri Feb 27 18:00:54 CET 2015


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: optresult
Changeset: r76185:4011499ac0a2
Date: 2015-02-27 19:00 +0200
http://bitbucket.org/pypy/pypy/changeset/4011499ac0a2/

Log:	(fijal, arigo) make nonnull tests pass

diff --git a/rpython/jit/metainterp/optimizeopt/info.py b/rpython/jit/metainterp/optimizeopt/info.py
--- a/rpython/jit/metainterp/optimizeopt/info.py
+++ b/rpython/jit/metainterp/optimizeopt/info.py
@@ -25,10 +25,19 @@
 class PtrInfo(AbstractInfo):
     _attrs_ = ()
 
+    def is_nonnull(self):
+        return False
+
+    def is_null(self):
+        return False
+
     
 class NonNullPtrInfo(PtrInfo):
     _attrs_ = ()
 
+    def is_nonnull(self):
+        return True
+
     
 class InstancePtrInfo(NonNullPtrInfo):
     _attrs_ = ('_known_class', '_is_virtual', '_fields')
diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -332,6 +332,9 @@
     def make_equal_to(self, box, value):
         return self.optimizer.make_equal_to(box, value)
 
+    def make_nonnull(self, op):
+        return self.optimizer.make_nonnull(op)
+
     def get_constant_box(self, box):
         return self.optimizer.get_constant_box(box)
 
@@ -555,6 +558,14 @@
     def make_constant_int(self, box, intvalue):
         self.make_constant(box, ConstInt(intvalue))
 
+    def make_nonnull(self, op):
+        op = self.get_box_replacement(op)
+        opinfo = op.get_forwarded()
+        if opinfo is not None:
+            assert opinfo.is_nonnull()
+            return
+        op.set_forwarded(info.NonNullPtrInfo())
+
     def new_ptr_box(self):
         xxx
         return self.cpu.ts.BoxRef()
@@ -642,24 +653,6 @@
         self._last_emitted_op = op
         self._newoperations.append(op)
 
-    def get_op_replacement(self, op):
-        # XXX this is wrong
-        xxx
-        changed = False
-        for i, arg in enumerate(op.getarglist()):
-            try:
-                v = self.values[arg]
-            except KeyError:
-                pass
-            else:
-                box = v.get_key_box()
-                if box is not arg:
-                    if not changed:
-                        changed = True
-                        op = op.copy_and_change(op.getopnum())
-                    op.setarg(i, box)
-        return op
-
     def replace_guard_op(self, old_op_pos, new_op):
         old_op = self._newoperations[old_op_pos]
         assert old_op.is_guard()
diff --git a/rpython/jit/metainterp/optimizeopt/rewrite.py b/rpython/jit/metainterp/optimizeopt/rewrite.py
--- a/rpython/jit/metainterp/optimizeopt/rewrite.py
+++ b/rpython/jit/metainterp/optimizeopt/rewrite.py
@@ -129,9 +129,9 @@
 
         # If one side of the op is 0 the result is the other side.
         if arg1.is_constant() and arg1.getint() == 0:
-            self.make_equal_to(op, v2)
+            self.make_equal_to(op, arg2)
         elif arg2.is_constant() and arg2.getint() == 0:
-            self.make_equal_to(op, v1)
+            self.make_equal_to(op, arg1)
         else:
             self.emit_operation(op)
             self.optimizer.pure_reverse(op)
@@ -274,15 +274,15 @@
         value.make_constant(self.optimizer.cpu.ts.CONST_NULL)
 
     def optimize_GUARD_NONNULL(self, op):
-        value = self.getvalue(op.getarg(0))
-        if value.is_nonnull():
+        opinfo = self.getptrinfo(op.getarg(0))
+        if opinfo.is_nonnull():
             return
-        elif value.is_null():
+        elif opinfo.is_null():
             r = self.optimizer.metainterp_sd.logger_ops.repr_of_resop(op)
             raise InvalidLoop('A GUARD_NONNULL (%s) was proven to always fail'
                               % r)
         self.emit_operation(op)
-        value.make_nonnull(self.optimizer)
+        self.make_nonnull(op.getarg(0))
 
     def optimize_GUARD_VALUE(self, op):
         ## value = self.getvalue(op.getarg(0))


More information about the pypy-commit mailing list