Author: Carl Friedrich Bolz <[email protected]>
Branch: regalloc-playground
Changeset: r92189:c5b3232137fe
Date: 2017-08-20 16:27 +0200
http://bitbucket.org/pypy/pypy/changeset/c5b3232137fe/
Log: spill variables that are no longer "really" used (ie appear only in
failargs or jumps)
diff --git a/rpython/jit/backend/llsupport/regalloc.py
b/rpython/jit/backend/llsupport/regalloc.py
--- a/rpython/jit/backend/llsupport/regalloc.py
+++ b/rpython/jit/backend/llsupport/regalloc.py
@@ -433,7 +433,13 @@
continue
if need_lower_byte and reg in self.no_lower_byte_regs:
continue
- max_age = self.longevity[next].last_usage
+ lifetime = self.longevity[next]
+ if lifetime.is_last_real_use_before(self.position):
+ # this variable has no "real" use as an argument to an op left
+ # it is only used in failargs, and maybe in a jump. spilling is
+ # fine
+ return next
+ max_age = lifetime.last_usage
if cur_max_age < max_age:
cur_max_age = max_age
candidate = next
@@ -814,6 +820,9 @@
def is_last_real_use_before(self, position):
return self.last_real_usage <= position
+ def __repr__(self):
+ return "%s:%s(%s)" % (self.definition_pos, self.last_real_usage,
self.last_usage)
+
def compute_vars_longevity(inputargs, operations):
# compute a dictionary that maps variables to Lifetime information
# if a variable is not in the dictionary, it's operation is dead because
diff --git a/rpython/jit/backend/llsupport/test/test_regalloc.py
b/rpython/jit/backend/llsupport/test/test_regalloc.py
--- a/rpython/jit/backend/llsupport/test/test_regalloc.py
+++ b/rpython/jit/backend/llsupport/test/test_regalloc.py
@@ -395,6 +395,28 @@
assert spilled2 is loc
rm._check_invariants()
+ def test_spill_useless_vars_first(self):
+ b0, b1, b2, b3, b4, b5 = newboxes(0, 1, 2, 3, 4, 5)
+ longevity = {b0: Lifetime(0, 5), b1: Lifetime(0, 5),
+ # b3 becomes useless but b2 lives longer
+ b3: Lifetime(0, 5, 3), b2: Lifetime(0, 6),
+ b4: Lifetime(4, 5), b5: Lifetime(4, 7)}
+ fm = TFrameManager()
+ asm = MockAsm()
+ rm = RegisterManager(longevity, frame_manager=fm, assembler=asm)
+ rm.next_instruction()
+ for b in b0, b1, b2, b3:
+ rm.force_allocate_reg(b)
+ rm.position = 4
+ assert len(rm.free_regs) == 0
+ loc = rm.loc(b3)
+ spilled = rm.force_allocate_reg(b4)
+ assert spilled is loc
+ loc = rm.loc(b2)
+ spilled2 = rm.force_allocate_reg(b5)
+ assert spilled2 is loc
+ rm._check_invariants()
+
def test_hint_frame_locations_1(self):
for hint_value in range(11):
b0, = newboxes(0)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit