[pypy-svn] r66419 - in pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Jul 19 19:58:13 CEST 2009
Author: arigo
Date: Sun Jul 19 19:58:09 2009
New Revision: 66419
Modified:
pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/history.py
pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py
pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/oparser.py
pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py
Log:
Treat oois(_, NULL) and ooisnot(_, NULL) as ooisnull(_) and oononnull(_).
Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/history.py (original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/history.py Sun Jul 19 19:58:09 2009
@@ -89,6 +89,9 @@
def get_(self):
raise NotImplementedError
+ def nonnull(self):
+ raise NotImplementedError
+
def clonebox(self):
raise NotImplementedError
@@ -216,6 +219,9 @@
def get_(self):
return self.value
+ def nonnull(self):
+ return self.value != 0
+
def set_future_value(self, cpu, j):
cpu.set_future_value_int(j, self.value)
@@ -261,6 +267,9 @@
def get_(self):
return llmemory.cast_adr_to_int(self.value)
+ def nonnull(self):
+ return self.value != llmemory.NULL
+
def set_future_value(self, cpu, j):
cpu.set_future_value_int(j, self.getint())
@@ -296,6 +305,9 @@
def getaddr(self, cpu):
return llmemory.cast_ptr_to_adr(self.value)
+ def nonnull(self):
+ return bool(self.value)
+
def set_future_value(self, cpu, j):
cpu.set_future_value_ptr(j, self.value)
@@ -330,6 +342,9 @@
else:
return 0
+ def nonnull(self):
+ return bool(self.value)
+
def set_future_value(self, cpu, j):
cpu.set_future_value_obj(j, self.value)
@@ -417,6 +432,9 @@
def get_(self):
return self.value
+ def nonnull(self):
+ return self.value != 0
+
def set_future_value(self, cpu, j):
cpu.set_future_value_int(j, self.value)
@@ -451,6 +469,9 @@
def get_(self):
return lltype.cast_ptr_to_int(self.value)
+ def nonnull(self):
+ return bool(self.value)
+
def set_future_value(self, cpu, j):
cpu.set_future_value_ptr(j, self.value)
@@ -486,6 +507,9 @@
else:
return 0
+ def nonnull(self):
+ return bool(self.value)
+
def set_future_value(self, cpu, j):
cpu.set_future_value_obj(j, self.value)
Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py (original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py Sun Jul 19 19:58:09 2009
@@ -1,4 +1,5 @@
from pypy.jit.metainterp.history import Const, Box
+from pypy.jit.metainterp.resoperation import rop
from pypy.jit.metainterp.optimizeutil import av_newdict, _findall
from pypy.rlib.objectmodel import we_are_translated
@@ -117,5 +118,29 @@
else:
self.optimize_default(op)
+ def optimize_OOISNOT(self, op):
+ if isinstance(op.args[1], Const) and not op.args[1].nonnull():
+ op.opnum = rop.OONONNULL
+ del op.args[1]
+ self.optimize_OONONNULL(op)
+ elif isinstance(op.args[0], Const) and not op.args[0].nonnull():
+ op.opnum = rop.OONONNULL
+ del op.args[0]
+ self.optimize_OONONNULL(op)
+ else:
+ self.optimize_default(op)
+
+ def optimize_OOIS(self, op):
+ if isinstance(op.args[1], Const) and not op.args[1].nonnull():
+ op.opnum = rop.OOISNULL
+ del op.args[1]
+ self.optimize_OOISNULL(op)
+ elif isinstance(op.args[0], Const) and not op.args[0].nonnull():
+ op.opnum = rop.OOISNULL
+ del op.args[0]
+ self.optimize_OOISNULL(op)
+ else:
+ self.optimize_default(op)
+
optimize_ops = _findall(Optimizer, 'optimize_')
Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/oparser.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/oparser.py (original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/oparser.py Sun Jul 19 19:58:09 2009
@@ -101,6 +101,11 @@
return ConstObj(ootype.cast_to_object(self.consts[name]))
elif arg == 'None':
return None
+ elif arg == 'NULL':
+ if self.type_system == 'lltype':
+ return ConstPtr(ConstPtr.value)
+ else:
+ return ConstObj(ConstObj.value)
return self.vars[arg]
def parse_op(self, line):
Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py (original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py Sun Jul 19 19:58:09 2009
@@ -189,6 +189,33 @@
"""
self.optimize(ops, 'Not', expected, i0=1, i1=0)
+ def test_oois_1(self):
+ ops = """
+ [p0]
+ guard_class(p0, ConstClass(node_vtable))
+ fail()
+ i0 = ooisnot(p0, NULL)
+ guard_true(i0)
+ fail()
+ i1 = oois(p0, NULL)
+ guard_false(i1)
+ fail()
+ i2 = ooisnot(NULL, p0)
+ guard_true(i0)
+ fail()
+ i3 = oois(NULL, p0)
+ guard_false(i1)
+ fail()
+ jump(p0)
+ """
+ expected = """
+ [p0]
+ guard_class(p0, ConstClass(node_vtable))
+ fail()
+ jump(p0)
+ """
+ self.optimize(ops, 'Not', expected, i0=1, i1=0, i2=1, i3=0)
+
class TestLLtype(BaseTestOptimizeOpt, LLtypeMixin):
pass
More information about the Pypy-commit
mailing list