Author: Maciej Fijalkowski <[email protected]>
Branch: optresult-unroll
Changeset: r78933:b98fe23848c6
Date: 2015-08-12 16:24 +0200
http://bitbucket.org/pypy/pypy/changeset/b98fe23848c6/
Log: fix some tests
diff --git a/rpython/jit/metainterp/compile.py
b/rpython/jit/metainterp/compile.py
--- a/rpython/jit/metainterp/compile.py
+++ b/rpython/jit/metainterp/compile.py
@@ -52,7 +52,8 @@
if unroll:
opt = UnrollOptimizer(metainterp_sd, jitdriver_sd, optimizations)
return opt.optimize_preamble(self.start_label, self.end_label,
- self.operations)
+ self.operations,
+ self.call_pure_results)
else:
xxx
@@ -93,7 +94,7 @@
assert unroll # we should not be here if it's disabled
opt = UnrollOptimizer(metainterp_sd, jitdriver_sd, optimizations)
return opt.optimize_peeled_loop(self.start_label, self.end_jump,
- self.operations, self.state)
+ self.operations, self.state, self.call_pure_results)
def show_procedures(metainterp_sd, procedure=None, error=None):
# debugging
diff --git a/rpython/jit/metainterp/optimizeopt/heap.py
b/rpython/jit/metainterp/optimizeopt/heap.py
--- a/rpython/jit/metainterp/optimizeopt/heap.py
+++ b/rpython/jit/metainterp/optimizeopt/heap.py
@@ -286,7 +286,10 @@
def clean_caches(self):
del self._lazy_setfields_and_arrayitems[:]
- for descr, cf in self.cached_fields.items():
+ items = self.cached_fields.items()
+ if not we_are_translated():
+ items.sort(key=str, reverse=True)
+ for descr, cf in items:
if not descr.is_always_pure():
cf.invalidate(descr)
for descr, submap in self.cached_arrayitems.iteritems():
@@ -474,8 +477,10 @@
cf.force_lazy_setfield(self, None, can_cache)
def force_all_lazy_setfields_and_arrayitems(self):
- # XXX fix the complexity here
- for descr, cf in self.cached_fields.items():
+ items = self.cached_fields.items()
+ if not we_are_translated():
+ items.sort(key=str, reverse=True)
+ for descr, cf in items:
cf.force_lazy_setfield(self, descr)
for submap in self.cached_arrayitems.itervalues():
for index, cf in submap.iteritems():
diff --git a/rpython/jit/metainterp/optimizeopt/shortpreamble.py
b/rpython/jit/metainterp/optimizeopt/shortpreamble.py
--- a/rpython/jit/metainterp/optimizeopt/shortpreamble.py
+++ b/rpython/jit/metainterp/optimizeopt/shortpreamble.py
@@ -54,9 +54,11 @@
opinfo = opt.optimizer.ensure_ptr_info_arg0(g)
pop = PreambleOp(self.res, preamble_op)
assert not opinfo.is_virtual()
+ descr = self.getfield_op.getdescr()
if g.is_getfield():
+ cf = optheap.field_cache(descr)
opinfo.setfield(preamble_op.getdescr(), self.res, pop,
- optheap=optheap)
+ optheap, cf)
else:
index = g.getarg(1).getint()
assert index >= 0
@@ -88,7 +90,7 @@
if optpure is None:
return
op = self.res
- if op.is_call():
+ if preamble_op.is_call():
optpure.extra_call_pure.append(PreambleOp(op, preamble_op))
else:
opt.pure(op.getopnum(), PreambleOp(op, preamble_op))
@@ -101,8 +103,11 @@
if newarg is None:
return None
arglist.append(newarg)
- return ProducedShortOp(self, op.copy_and_change(op.getopnum(),
- args=arglist))
+ if op.is_call():
+ opnum = OpHelpers.call_pure_for_descr(op.getdescr())
+ else:
+ opnum = op.getopnum()
+ return ProducedShortOp(self, op.copy_and_change(opnum, args=arglist))
def __repr__(self):
return "PureOp(%r)" % (self.res,)
@@ -189,7 +194,6 @@
# of AbstractShortOp
self.potential_ops = {}
self.produced_short_boxes = {}
- self.extra_short_boxes = {}
# a way to produce const boxes, e.g. setfield_gc(p0, Const).
# We need to remember those, but they don't produce any new boxes
self.const_short_boxes = []
@@ -212,7 +216,6 @@
for op, produced_op in self.produced_short_boxes.iteritems():
if not isinstance(produced_op, ShortInputArg):
short_boxes.append(produced_op)
- short_boxes += self.extra_short_boxes
for short_op in self.const_short_boxes:
getfield_op = short_op.getfield_op
@@ -233,7 +236,10 @@
elif isinstance(op, Const):
return op
elif op in self.potential_ops:
- return self.add_op_to_short(self.potential_ops[op]).preamble_op
+ r = self.add_op_to_short(self.potential_ops[op])
+ if r is None:
+ return None
+ return r.preamble_op
else:
return None
@@ -244,11 +250,20 @@
try:
if isinstance(shortop, CompoundOp):
lst = shortop.flatten(self, [])
- if len(lst) == 1:
- pop = lst[0]
+ if len(lst) == 0:
+ return None
else:
- pop = lst[0]
- for i in range(1, len(lst)):
+ index = -1
+ for i, item in enumerate(lst):
+ if not isinstance(item.short_op, HeapOp):
+ assert index == -1
+ index = i
+ if index == -1:
+ index = 0
+ pop = lst[index]
+ for i in range(len(lst)):
+ if i == index:
+ continue
opnum = OpHelpers.same_as_for_type(shortop.res.type)
new_name = ResOperation(opnum, [shortop.res])
assert lst[i].short_op is not pop.short_op
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -3602,8 +3602,8 @@
[p1, i1, p2, i2]
setfield_gc(p2, i2, descr=adescr)
i3 = call_i(i1, descr=readadescr)
+ setfield_gc(p2, i3, descr=adescr)
setfield_gc(p1, i3, descr=valuedescr)
- setfield_gc(p2, i3, descr=adescr)
jump(p1, i1, p2, i2)
"""
self.optimize_loop(ops, expected)
@@ -3622,8 +3622,8 @@
[p1, i1, p2, i2]
setfield_gc(p2, i2, descr=adescr)
i3 = call_i(i1, descr=writeadescr)
+ setfield_gc(p2, i3, descr=adescr)
setfield_gc(p1, i3, descr=valuedescr)
- setfield_gc(p2, i3, descr=adescr)
jump(p1, i1, p2, i2)
"""
self.optimize_loop(ops, expected)
@@ -3634,8 +3634,8 @@
setfield_gc(p1, i1, descr=valuedescr)
setfield_gc(p2, i2, descr=adescr)
i3 = call_i(i1, descr=plaincalldescr)
+ setfield_gc(p2, i3, descr=adescr)
setfield_gc(p1, i3, descr=valuedescr)
- setfield_gc(p2, i3, descr=adescr)
jump(p1, i1, p2, i2)
"""
self.optimize_loop(ops, ops)
@@ -3678,6 +3678,7 @@
'''
expected = '''
[p1, i4, i3]
+ setfield_gc(p1, i3, descr=valuedescr)
jump(p1, i3, i3)
'''
preamble = '''
@@ -3703,6 +3704,7 @@
'''
expected = '''
[p1, i4, i3]
+ setfield_gc(p1, i3, descr=valuedescr)
jump(p1, i3, i3)
'''
preamble = '''
@@ -3760,16 +3762,16 @@
jump(p1, i4, i3)
'''
expected = '''
- [p1, i4, i3, i5]
+ [p1, i4, i3]
setfield_gc(p1, i4, descr=valuedescr)
- jump(p1, i3, i5, i5)
+ jump(p1, i3, i3)
'''
preamble = '''
[p1, i1, i4]
setfield_gc(p1, i1, descr=valuedescr)
i3 = call_i(p1, descr=elidablecalldescr)
- i151 = same_as_i(i3)
- jump(p1, i4, i3, i151)
+ # i151 = same_as_i(i3)
+ jump(p1, i4, i3)
'''
self.optimize_loop(ops, expected, preamble)
@@ -3789,36 +3791,36 @@
escape_n(i1)
escape_n(i2)
i4 = call_i(123456, 4, i0, 6, descr=elidablecalldescr)
- i153 = same_as_i(i4)
- jump(i0, i4, i153)
+ # i153 = same_as_i(i4)
+ jump(i0, i4)
'''
expected = '''
- [i0, i4, i5]
+ [i0, i4]
escape_n(42)
escape_n(i4)
- jump(i0, i5, i5)
+ jump(i0, i4)
'''
self.optimize_loop(ops, expected, preamble, call_pure_results)
def test_call_pure_constant_folding_memoryerr(self):
ops = '''
[p0, i0]
- escape(i0)
- i3 = call_pure(123456, p0, descr=elidable2calldescr)
+ escape_n(i0)
+ i3 = call_pure_i(123456, p0, descr=elidable2calldescr)
guard_no_exception() []
jump(p0, i3)
'''
preamble = '''
[p0, i0]
- escape(i0)
- i3 = call(123456, p0, descr=elidable2calldescr)
+ escape_n(i0)
+ i3 = call_i(123456, p0, descr=elidable2calldescr)
guard_no_exception() []
- i4 = same_as(i3)
+ # i4 = same_as(i3)
jump(p0, i3, i4)
'''
expected = '''
[p0, i3, i4]
- escape(i3)
+ escape_n(i3)
jump(p0, i4, i4)
'''
self.optimize_loop(ops, expected, preamble)
@@ -8333,18 +8335,18 @@
def test_cache_setarrayitem_across_loop_boundaries(self):
ops = """
[p1]
- p2 = getarrayitem_gc_r(p1, 3, descr=arraydescr)
+ p2 = getarrayitem_gc_r(p1, 3, descr=gcarraydescr)
guard_nonnull_class(p2, ConstClass(node_vtable)) []
call_n(p2, descr=nonwritedescr)
p3 = new_with_vtable(descr=nodesize)
- setarrayitem_gc(p1, 3, p3, descr=arraydescr)
+ setarrayitem_gc(p1, 3, p3, descr=gcarraydescr)
jump(p1)
"""
expected = """
[p1, p2]
call_n(p2, descr=nonwritedescr)
p3 = new_with_vtable(descr=nodesize)
- setarrayitem_gc(p1, 3, p3, descr=arraydescr)
+ setarrayitem_gc(p1, 3, p3, descr=gcarraydescr)
jump(p1, p3)
"""
self.optimize_loop(ops, expected)
@@ -8392,8 +8394,8 @@
[i0, i1]
p0 = escape_r()
p1 = escape_r()
+ setfield_gc(p1, p0, descr=bdescr)
setfield_gc(p0, p1, descr=adescr)
- setfield_gc(p1, p0, descr=bdescr)
jump(i0, i1)
"""
self.optimize_loop(ops, expected)
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_util.py
b/rpython/jit/metainterp/optimizeopt/test/test_util.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_util.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_util.py
@@ -20,6 +20,7 @@
from rpython.jit.metainterp.counter import DeterministicJitCounter
from rpython.config.translationoption import get_combined_translation_config
from rpython.jit.metainterp.resoperation import rop, ResOperation, InputArgRef
+from rpython.jit.metainterp.optimizeopt.util import args_dict
def test_sort_descrs():
@@ -438,6 +439,12 @@
metainterp_sd.callinfocollection = self.callinfocollection
#
compile_data.enable_opts = self.enable_opts
+ new_call_pure_results = args_dict()
+ if call_pure_results is not None:
+ for k, v in call_pure_results.items():
+ new_call_pure_results[list(k)] = v
+
+ compile_data.call_pure_results = new_call_pure_results
state = optimize_trace(metainterp_sd, None, compile_data)
return state
diff --git a/rpython/jit/metainterp/optimizeopt/unroll.py
b/rpython/jit/metainterp/optimizeopt/unroll.py
--- a/rpython/jit/metainterp/optimizeopt/unroll.py
+++ b/rpython/jit/metainterp/optimizeopt/unroll.py
@@ -37,6 +37,8 @@
def setinfo_from_preamble(self, op, preamble_info, exported_infos):
op = self.get_box_replacement(op)
+ if op.get_forwarded() is not None:
+ return # XXX?
if isinstance(preamble_info, info.PtrInfo):
if preamble_info.is_virtual():
# XXX do we want to sanitize this?
@@ -88,10 +90,10 @@
assert op.get_forwarded() is None
assert not self.optimizer._newoperations
- def optimize_preamble(self, start_label, end_label, ops):
+ def optimize_preamble(self, start_label, end_label, ops,
call_pure_results):
self._check_no_forwarding([[start_label, end_label], ops])
info, newops = self.optimizer.propagate_all_forward(
- start_label.getarglist()[:], ops)
+ start_label.getarglist()[:], ops, call_pure_results)
exported_state = self.export_state(start_label, end_label,
info.inputargs)
# we need to absolutely make sure that we've cleaned up all
@@ -99,12 +101,13 @@
self.optimizer._clean_optimization_info(self.optimizer._newoperations)
return exported_state, self.optimizer._newoperations
- def optimize_peeled_loop(self, start_label, end_jump, ops, state):
+ def optimize_peeled_loop(self, start_label, end_jump, ops, state,
+ call_pure_results):
self._check_no_forwarding([[start_label, end_jump], ops])
self.import_state(start_label, state)
self.potential_extra_ops = {}
self.optimizer.propagate_all_forward(start_label.getarglist()[:], ops,
- rename_inputargs=False)
+ call_pure_results, False)
orig_jump_args = [self.get_box_replacement(op)
for op in end_jump.getarglist()]
jump_args = state.virtual_state.make_inputargs(orig_jump_args,
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit