Author: Maciej Fijalkowski <[email protected]>
Branch: result-in-resops
Changeset: r58486:0ed7c47bcde4
Date: 2012-10-27 00:40 +0200
http://bitbucket.org/pypy/pypy/changeset/0ed7c47bcde4/
Log: guard class removal
diff --git a/pypy/jit/metainterp/optimizeopt/intbounds.py
b/pypy/jit/metainterp/optimizeopt/intbounds.py
--- a/pypy/jit/metainterp/optimizeopt/intbounds.py
+++ b/pypy/jit/metainterp/optimizeopt/intbounds.py
@@ -195,17 +195,17 @@
self.emit_operation(op)
def optimize_INT_ADD_OVF(self, op):
- v1 = self.getvalue(op.getarg(0))
- v2 = self.getvalue(op.getarg(1))
+ op = self.getforwarded(op)
+ v1 = self.getforwarded(op.getarg(0))
+ v2 = self.getforwarded(op.getarg(1))
resbound = v1.getintbound().add_bound(v2.getintbound())
if resbound.bounded():
# Transform into INT_ADD. The following guard will be killed
# by optimize_GUARD_NO_OVERFLOW; if we see instead an
# optimize_GUARD_OVERFLOW, then InvalidLoop.
- op = self.optimizer.copy_and_change(op, rop.INT_ADD)
- self.emit_operation(op) # emit the op
- r = self.getvalue(op)
- r.getintbound().intersect(resbound)
+ op = op.make_forwarded_copy(rop.INT_ADD)
+ op.getintbound().intersect(resbound)
+ return op
def optimize_INT_SUB_OVF(self, op):
v1 = self.getvalue(op.getarg(0))
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
@@ -165,16 +165,6 @@
return self.box.same_constant(other.box)
return self is other
- def get_constant_class(self, cpu):
- xxx
- level = self.level
- if level == LEVEL_KNOWNCLASS:
- return self.known_class
- elif level == LEVEL_CONSTANT:
- return cpu.ts.cls_of_box(self.op)
- else:
- return None
-
def make_constant_class(self, classbox, guardop, index):
assert self.level < LEVEL_KNOWNCLASS
self.known_class = classbox
@@ -464,6 +454,11 @@
if isinstance(op, Const):
return op
+ def get_constant_class(self, op):
+ if op.is_constant():
+ xxx
+ return op.getknownclass()
+
def get_newoperations(self):
self.flush()
return self._newoperations
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
@@ -210,7 +210,10 @@
self.postprocess_guard(op, CONST_1)
def postprocess_GUARD_FALSE(self, op):
- self.postprocess_guard(op, CONST_0)
+ self.postprocess_guard(op, CONST_0)
+
+ def postprocess_GUARD_NO_OVERFLOW(self, op):
+ pass # to be killed
def postprocess_default(self, op):
if op.is_guard():
@@ -237,7 +240,7 @@
def optimize_GUARD_VALUE(self, op):
value = self.getforwarded(op.getarg(0))
- if value.getlastguard():
+ if value.getlastguardpos() != -1:
xxx
# there already has been a guard_nonnull or guard_class or
# guard_nonnull_class on this value, which is rather silly.
@@ -286,7 +289,7 @@
value = self.getvalue(op.getarg(0))
expectedclassbox = op.getarg(1)
assert isinstance(expectedclassbox, Const)
- realclassbox = value.get_constant_class(self.optimizer.cpu)
+ realclassbox = self.optimizer.get_constant_class(value)
if realclassbox is not None:
assert realclassbox.same_constant(expectedclassbox)
return
@@ -294,16 +297,16 @@
self.optimizer.get_pos())
def optimize_GUARD_CLASS(self, op):
- value = self.getvalue(op.getarg(0))
+ value = self.getforwarded(op.getarg(0))
expectedclassbox = op.getarg(1)
assert isinstance(expectedclassbox, Const)
- realclassbox = value.get_constant_class(self.optimizer.cpu)
+ realclassbox = self.optimizer.get_constant_class(value)
if realclassbox is not None:
if realclassbox.same_constant(expectedclassbox):
return
raise InvalidLoop('A GUARD_CLASS was proven to always fail')
- emit_operation = True
- if value.last_guard:
+ if value.getlastguardpos() != -1:
+ xxx
# there already has been a guard_nonnull or guard_class or
# guard_nonnull_class on this value.
old_guard_op = value.last_guard
@@ -320,14 +323,17 @@
new_op.set_extra("failargs",
old_guard_op.get_extra("failargs"))
self.optimizer.replace_op(value, new_op)
op = new_op
- emit_operation = False
+ return
value.last_guard = None
- pos = value.last_guard_pos
else:
- pos = self.optimizer.get_pos()
- if emit_operation:
- self.emit_operation(op)
- value.make_constant_class(expectedclassbox, op, pos)
+ value.setlastguardpos(self.optimizer.get_pos())
+ return op
+
+ def postprocess_GUARD_CLASS(self, op):
+ value = self.getforwarded(op.getarg(0))
+ expectedclassbox = op.getarg(1)
+ assert isinstance(expectedclassbox, Const)
+ value.setknownclass(expectedclassbox)
def optimize_GUARD_NONNULL_CLASS(self, op):
value = self.getvalue(op.getarg(0))
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
@@ -167,19 +167,19 @@
def test_constant_propagate_ovf(self):
ops = """
[i]
- guard_value(i, 2) []
+ guard_value(i, 2)
i0 = int_add_ovf(i, 3)
- guard_no_overflow() []
+ guard_no_overflow()
i1 = int_is_true(i0)
- guard_true(i1) []
+ guard_true(i1)
i2 = int_is_zero(i1)
- guard_false(i2) []
- guard_value(i0, 5) []
+ guard_false(i2)
+ guard_value(i0, 5)
jump(i)
"""
expected = """
[i]
- guard_value(i, 2) []
+ guard_value(i, 2)
jump(2)
"""
self.optimize_loop(ops, expected)
@@ -224,13 +224,13 @@
def test_remove_guard_class_1(self):
ops = """
[p0]
- guard_class(p0, ConstClass(node_vtable)) []
- guard_class(p0, ConstClass(node_vtable)) []
+ guard_class(p0, ConstClass(node_vtable))
+ guard_class(p0, ConstClass(node_vtable))
jump(p0)
"""
expected = """
[p0]
- guard_class(p0, ConstClass(node_vtable)) []
+ guard_class(p0, ConstClass(node_vtable))
jump(p0)
"""
self.optimize_loop(ops, expected)
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
@@ -4,7 +4,7 @@
from pypy.tool.sourcetools import func_with_new_name
from pypy.jit.metainterp.resoperation import opclasses, opclasses_mutable,
rop,\
- INT, ConstInt, Const
+ INT, REF, ConstInt, Const
from pypy.jit.metainterp.optimizeopt.intutils import ImmutableIntUnbounded,\
ConstantIntBound
@@ -16,8 +16,8 @@
return False # for optimization
class __extend__(Const):
- def getlastguard(self):
- return None
+ def getlastguardpos(self):
+ return -1
def create_mutable_subclasses():
def addattr(cls, attr, default_value=None):
@@ -34,7 +34,7 @@
def _copy_extra_attrs(self, new):
paren_cls._copy_extra_attrs(self, new)
for attr in cls.attributes_to_copy:
- setattr(new, getattr(self, attr))
+ setattr(new, attr, getattr(self, attr))
cls._copy_extra_attrs = _copy_extra_attrs
imm_int_unbound = ImmutableIntUnbounded()
@@ -53,9 +53,10 @@
# all the integers have bounds
addattr(Mutable, 'intbound', imm_int_unbound)
addattr(Mutable, 'boolbox', False)
+ elif cls.type == REF:
+ addattr(Mutable, 'knownclass', None)
# for tracking last guard and merging GUARD_VALUE with
# GUARD_NONNULL etc
- addattr(Mutable, 'lastguard', None)
addattr(Mutable, 'lastguardpos', -1)
Mutable.__name__ = cls.__name__ + '_mutable'
if Mutable.attributes_to_copy:
diff --git a/pypy/jit/metainterp/resoperation.py
b/pypy/jit/metainterp/resoperation.py
--- a/pypy/jit/metainterp/resoperation.py
+++ b/pypy/jit/metainterp/resoperation.py
@@ -1043,9 +1043,6 @@
arg1 or self._arg1,
descr or self.getdescr(),
mutable=True)
- if self.is_guard():
- res.set_rd_frame_info_list(self.get_rd_frame_info_list())
- res.set_rd_snapshot(self.get_rd_snapshot())
assert not self._forwarded
self._forwarded = res
self._copy_extra_attrs(res)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit