Author: Antonio Cuni <[email protected]>
Branch: autoreds
Changeset: r58839:6475dd9c47d1
Date: 2012-11-12 16:07 +0100
http://bitbucket.org/pypy/pypy/changeset/6475dd9c47d1/
Log: add support for FLOAT and REF automatic reds
diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py
--- a/pypy/jit/codewriter/support.py
+++ b/pypy/jit/codewriter/support.py
@@ -78,6 +78,11 @@
link = split_block(None, portalblock, 0, greens_v + reds_v)
return link.target
+def sort_vars(args_v):
+ from pypy.jit.metainterp.history import getkind
+ _kind2count = {'int': 1, 'ref': 2, 'float': 3}
+ return sorted(args_v, key=lambda v: _kind2count[getkind(v.concretetype)])
+
def decode_hp_hint_args(op):
# Returns (list-of-green-vars, list-of-red-vars) without Voids.
# Both lists must be sorted: first INT, then REF, then FLOAT.
@@ -91,16 +96,14 @@
assert len(reds_v) == numreds
#
def _sort(args_v, is_green):
- from pypy.jit.metainterp.history import getkind
lst = [v for v in args_v if v.concretetype is not lltype.Void]
if is_green:
assert len(lst) == len(args_v), (
"not supported so far: 'greens' variables contain Void")
- _kind2count = {'int': 1, 'ref': 2, 'float': 3}
- lst2 = sorted(lst, key=lambda v: _kind2count[getkind(v.concretetype)])
# a crash here means that you have to reorder the variable named in
# the JitDriver. Indeed, greens and reds must both be sorted: first
# all INTs, followed by all REFs, followed by all FLOATs.
+ lst2 = sort_vars(args_v)
assert lst == lst2
return lst
#
diff --git a/pypy/jit/metainterp/test/test_ajit.py
b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -118,6 +118,42 @@
assert res == expected
self.check_resops(int_sub=2, int_mul=0, int_add=10)
+ def test_loop_automatic_reds_with_floats_and_refs(self):
+ myjitdriver = JitDriver(greens = ['m'], reds = 'auto')
+ class MyObj(object):
+ def __init__(self, val):
+ self.val = val
+ def f(n, m):
+ res = 0
+ # try to have lots of red vars, so that if there is an error in
+ # the ordering of reds, there are low chances that the test passes
+ # by chance
+ i1 = i2 = i3 = i4 = n
+ f1 = f2 = f3 = f4 = float(n)
+ r1 = r2 = r3 = r4 = MyObj(n)
+ while n > 0:
+ myjitdriver.can_enter_jit(m=m)
+ myjitdriver.jit_merge_point(m=m)
+ n -= 1
+ i1 += 1 # dummy unused red
+ i2 += 2 # dummy unused red
+ i3 += 3 # dummy unused red
+ i4 += 4 # dummy unused red
+ f1 += 1 # dummy unused red
+ f2 += 2 # dummy unused red
+ f3 += 3 # dummy unused red
+ f4 += 4 # dummy unused red
+ r1.val += 1 # dummy unused red
+ r2.val += 2 # dummy unused red
+ r3.val += 3 # dummy unused red
+ r4.val += 4 # dummy unused red
+ res += m*2
+ return res
+ expected = f(21, 5)
+ res = self.meta_interp(f, [21, 5])
+ assert res == expected
+ self.check_resops(int_sub=2, int_mul=0, int_add=18, float_add=8)
+
def test_loop_variant_mul1(self):
myjitdriver = JitDriver(greens = [], reds = ['y', 'res', 'x'])
diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py
--- a/pypy/jit/metainterp/warmspot.py
+++ b/pypy/jit/metainterp/warmspot.py
@@ -261,7 +261,7 @@
alive_v = set(block.inputargs) # XXX: there might be more
# alive vars?
reds_v = alive_v - set(greens_v)
- reds_v = list(reds_v) # XXX: order the reds by type (INT, REF,
FLOAT)
+ reds_v = support.sort_vars(reds_v)
op.args.extend(reds_v)
assert jitdriver.autoreds
#assert jitdriver.numreds is None,
'autodetect_jit_markers_redvars called twice?!?'
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit