[pypy-svn] r74617 - in pypy/branch/blackhole-improvement/pypy/jit/codewriter: . test
arigo at codespeak.net
arigo at codespeak.net
Fri May 21 11:42:30 CEST 2010
Author: arigo
Date: Fri May 21 11:42:28 2010
New Revision: 74617
Modified:
pypy/branch/blackhole-improvement/pypy/jit/codewriter/format.py
pypy/branch/blackhole-improvement/pypy/jit/codewriter/liveness.py
pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_format.py
pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_liveness.py
Log:
Change again the precise meaning of -live-. Now it's hopefully
a simple and clear meaning.
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/format.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/format.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/format.py Fri May 21 11:42:28 2010
@@ -49,7 +49,10 @@
return 'L%d' % seenlabels[lbl.name]
#
output = StringIO()
- for asm in ssarepr.insns:
+ insns = ssarepr.insns
+ if insns[-1] == ('---',):
+ insns = insns[:-1]
+ for asm in insns:
if isinstance(asm[0], Label):
if asm[0].name in seenlabels:
print >> output, '%s:' % getlabelname(asm[0])
@@ -169,7 +172,7 @@
word += c
if c in '<([':
nested += 1
- if c in '])>' and line[i-2:i+2] != ' -> ':
+ if c in '])>' and (' '+line)[i:i+4] != ' -> ':
nested -= 1
assert nested >= 0
if word:
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/liveness.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/liveness.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/liveness.py Fri May 21 11:42:28 2010
@@ -5,13 +5,11 @@
# Some instructions require liveness information (the ones that can end up
# in generate_guard() in pyjitpl.py). This is done by putting special
# space operations called '-live-' in the graph. They turn into '-live-'
-# operation in the ssarepr. Then this module expands the arguments of
-# the '-live-' operations to also include all values that are alive at
-# this point: more precisely, all values that are created before the
-# '-live-' operation and that are needed afterwards, with the exception
-# of the values that are needed only in the very next instruction. These
-# are not considered alive any more. You can force them to be alive by
-# putting them as args of the '-live-' operation in the first place.
+# operation in the ssarepr. Then the present module expands the arguments
+# of the '-live-' operations to also include all values that are alive at
+# this point (written to before, and read afterwards). You can also force
+# extra variables to be alive by putting them as args of the '-live-'
+# operation in the first place.
# For this to work properly, a special operation called '---' must be
# used to mark unreachable places (e.g. just after a 'goto').
@@ -25,7 +23,6 @@
def _compute_liveness_must_continue(ssarepr, label2alive):
alive = set()
- prevalive = None
must_continue = False
for i in range(len(ssarepr.insns)-1, -1, -1):
@@ -37,21 +34,17 @@
alive_at_point.update(alive)
if prevlength != len(alive_at_point):
must_continue = True
- prevalive = None
continue
if insn[0] == '-live-':
- assert prevalive is not None
for x in insn[1:]:
if isinstance(x, Register):
- prevalive.add(x)
- ssarepr.insns[i] = insn[:1] + tuple(prevalive)
- prevalive = None
+ alive.add(x)
+ ssarepr.insns[i] = insn[:1] + tuple(alive)
continue
if insn[0] == '---':
alive = set()
- prevalive = None
continue
args = insn[1:]
@@ -62,13 +55,13 @@
alive.discard(reg)
args = args[:-2]
#
- prevalive = alive.copy()
- #
for x in args:
if isinstance(x, Register):
alive.add(x)
elif isinstance(x, ListOfKind):
- alive.update(x)
+ for y in x:
+ if isinstance(y, Register):
+ alive.add(y)
elif isinstance(x, TLabel):
alive_at_point = label2alive.get(x.name, ())
alive.update(alive_at_point)
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_format.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_format.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_format.py Fri May 21 11:42:28 2010
@@ -121,6 +121,16 @@
('foo', Constant(123, lltype.Signed)),
]
+def test_unformat_assembler_single_return():
+ input = """
+ foo -> %i0
+ """
+ regs = {}
+ ssarepr = unformat_assembler(input, regs)
+ assert ssarepr.insns == [
+ ('foo', '->', regs['%i0']),
+ ]
+
def test_unformat_assembler_label():
input = """
L1:
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_liveness.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_liveness.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_liveness.py Fri May 21 11:42:28 2010
@@ -13,9 +13,11 @@
self.liveness_test("""
-live-
int_add %i0, $10 -> %i1
- """, """
-live-
+ """, """
+ -live- %i0
int_add %i0, $10 -> %i1
+ -live-
""")
def test_simple(self):
@@ -30,138 +32,137 @@
int_add %i0, $6 -> %i4
-live-
int_mul %i3, %i4 -> %i5
+ -live-
int_return %i5
""", """
-live- %i0
int_add %i0, $10 -> %i1
-live- %i0, %i1
int_add %i0, $3 -> %i2
- -live- %i0
+ -live- %i0, %i1, %i2
int_mul %i1, %i2 -> %i3
- -live- %i3
+ -live- %i0, %i3
int_add %i0, $6 -> %i4
- -live-
+ -live- %i3, %i4
int_mul %i3, %i4 -> %i5
+ -live- %i5
int_return %i5
""")
def test_one_path(self):
self.liveness_test("""
- -live-
int_add %i0, $5 -> %i2
+ -live-
int_is_true %i2 -> %i3
goto_if_not %i3, L1
int_copy %i0 -> %i4
- -live-
int_add %i4, $1 -> %i5
+ -live-
int_return %i5
---
L1:
int_copy %i1 -> %i6
- -live-
int_add %i6, $2 -> %i7
+ -live-
int_return %i7
""", """
- -live- %i0, %i1
int_add %i0, $5 -> %i2
+ -live- %i0, %i1, %i2
int_is_true %i2 -> %i3
goto_if_not %i3, L1
int_copy %i0 -> %i4
- -live-
int_add %i4, $1 -> %i5
+ -live- %i5
int_return %i5
---
L1:
int_copy %i1 -> %i6
- -live-
int_add %i6, $2 -> %i7
+ -live- %i7
int_return %i7
""")
def test_other_path(self):
self.liveness_test("""
- -live-
int_add %i0, $5 -> %i2
+ -live- %i2
int_is_true %i2 -> %i3
goto_if_not %i3, L1
int_copy %i0 -> %i4
int_copy %i1 -> %i5
- -live-
int_add %i4, %i5 -> %i6
+ -live- %i6
int_return %i6
---
L1:
int_copy %i0 -> %i7
- -live-
int_add %i7, $2 -> %i8
+ -live- %i8
int_return %i8
""", """
- -live- %i0, %i1
int_add %i0, $5 -> %i2
+ -live- %i0, %i1, %i2
int_is_true %i2 -> %i3
goto_if_not %i3, L1
int_copy %i0 -> %i4
int_copy %i1 -> %i5
- -live-
int_add %i4, %i5 -> %i6
+ -live- %i6
int_return %i6
---
L1:
int_copy %i0 -> %i7
- -live-
int_add %i7, $2 -> %i8
+ -live- %i8
int_return %i8
""")
def test_no_path(self):
self.liveness_test("""
- -live-
int_add %i0, %i1 -> %i2
+ -live- %i2
int_is_true %i2 -> %i3
goto_if_not %i3, L1
int_copy %i0 -> %i4
- -live-
int_add %i4, $5 -> %i5
+ -live- %i5
int_return %i5
---
L1:
int_copy %i0 -> %i6
- -live-
int_add %i6, $2 -> %i7
+ -live- %i7
int_return %i7
""", """
- -live- %i0
int_add %i0, %i1 -> %i2
+ -live- %i0, %i2
int_is_true %i2 -> %i3
goto_if_not %i3, L1
int_copy %i0 -> %i4
- -live-
int_add %i4, $5 -> %i5
+ -live- %i5
int_return %i5
---
L1:
int_copy %i0 -> %i6
- -live-
int_add %i6, $2 -> %i7
+ -live- %i7
int_return %i7
""")
def test_list_of_kind(self):
self.liveness_test("""
-live-
- stub
- foobar F[%f0]
+ foobar I[$25, %i0]
""", """
- -live- %f0
- stub
- foobar F[%f0]
+ -live- %i0
+ foobar I[$25, %i0]
""")
def test_switch(self):
self.liveness_test("""
goto_maybe L1
-live-
- stub
fooswitch <SwitchDictDescr 4:L2, 5:L3>
---
L3:
@@ -175,7 +176,6 @@
""", """
goto_maybe L1
-live- %i3, %i7
- stub
fooswitch <SwitchDictDescr 4:L2, 5:L3>
---
L3:
@@ -190,11 +190,30 @@
def test_already_some(self):
self.liveness_test("""
- -live- %i0, $52, %i2, %i0
foo %i0, %i1, %i2
+ -live- %i0, $52, %i2, %i0
bar %i3, %i4, %i5
""", """
- -live- %i0, %i2, %i3, %i4, %i5
foo %i0, %i1, %i2
+ -live- %i0, %i2, %i3, %i4, %i5
bar %i3, %i4, %i5
""")
+
+ def test_keepalive(self):
+ self.liveness_test("""
+ -live-
+ build $1 -> %i6
+ -live-
+ foo %i0, %i1 -> %i2
+ -live-
+ bar %i3, %i2 -> %i5
+ -live- %i6
+ """, """
+ -live- %i0, %i1, %i3
+ build $1 -> %i6
+ -live- %i0, %i1, %i3, %i6
+ foo %i0, %i1 -> %i2
+ -live- %i2, %i3, %i6
+ bar %i3, %i2 -> %i5
+ -live- %i6
+ """)
More information about the Pypy-commit
mailing list