[pypy-commit] pypy regalloc: storing the variable use/def information in the tuple of longevity as third parameter
plan_rich
noreply at buildbot.pypy.org
Thu Jun 18 09:58:31 CEST 2015
Author: Richard Plangger <rich at pasra.at>
Branch: regalloc
Changeset: r78164:73506cd059de
Date: 2015-06-18 09:58 +0200
http://bitbucket.org/pypy/pypy/changeset/73506cd059de/
Log: storing the variable use/def information in the tuple of longevity
as third parameter
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
@@ -673,7 +673,6 @@
else:
return [self.loc(op.getarg(0))]
-
def compute_vars_longevity(inputargs, operations):
# compute a dictionary that maps variables to index in
# operations that is a "last-time-seen"
@@ -685,6 +684,7 @@
produced = {}
last_used = {}
last_real_usage = {}
+ usage_positions = {}
for i in range(len(operations)-1, -1, -1):
op = operations[i]
if op.result:
@@ -692,11 +692,13 @@
continue
assert op.result not in produced
produced[op.result] = i
+ usage_positions.setdefault(op.result, []).insert(0, i)
opnum = op.getopnum()
for j in range(op.numargs()):
arg = op.getarg(j)
if not isinstance(arg, Box):
continue
+ usage_positions.setdefault(arg, []).insert(0, i)
if arg not in last_used:
last_used[arg] = i
if opnum != rop.JUMP and opnum != rop.LABEL:
@@ -707,6 +709,7 @@
if arg is None: # hole
continue
assert isinstance(arg, Box)
+ usage_positions.setdefault(arg, []).insert(0, i)
if arg not in last_used:
last_used[arg] = i
#
@@ -715,14 +718,20 @@
if arg in last_used:
assert isinstance(arg, Box)
assert produced[arg] < last_used[arg]
- longevity[arg] = (produced[arg], last_used[arg])
+ upos = usage_positions[arg]
+ if len(upos) == 2:
+ upos = None
+ longevity[arg] = (produced[arg], last_used[arg], upos)
del last_used[arg]
for arg in inputargs:
assert isinstance(arg, Box)
if arg not in last_used:
- longevity[arg] = (-1, -1)
+ longevity[arg] = (-1, -1, None)
else:
- longevity[arg] = (0, last_used[arg])
+ upos = usage_positions[arg]
+ if len(upos) == 2:
+ upos = None
+ longevity[arg] = (0, last_used[arg], upos)
del last_used[arg]
assert len(last_used) == 0
return longevity, last_real_usage
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
@@ -574,16 +574,27 @@
a = BoxInt()
b = BoxInt()
c = BoxInt()
- inputargs = [a, b]
+ d = BoxInt()
+ e = BoxInt()
+ f = BoxInt()
+ a0 = BoxInt()
+ a1 = BoxInt()
+ a2 = BoxInt()
+ inputargs = [a, b,e,a0]
operations = [
- ResOperation(rop.LABEL, [a,b], None),
+ ResOperation(rop.LABEL, [a,b,e,a0], None),
ResOperation(rop.INT_ADD, [a,b], c),
- ResOperation(rop.INT_ADD, [c,a], BoxInt()),
- ResOperation(rop.INT_ADD, [c,b], BoxInt()),
- ResOperation(rop.JUMP, [a,c], None),
+ ResOperation(rop.INT_ADD, [e,a], f),
+ ResOperation(rop.INT_ADD, [a0,a], a1),
+ ResOperation(rop.INT_ADD, [c,b], d),
+ ResOperation(rop.JUMP, [c,d,f,a1], None),
]
longevity, lru = compute_vars_longevity(inputargs, operations)
- assert lru[c] == 3
- assert longevity[c][0] == 0
- assert longevity[a][1] == 1
+ assert lru[c] == 4
+ assert longevity[a] == (0,3, [0,1,2,3])
+ assert longevity[b] == (0,4, [0,1,4])
+ assert longevity[c] == (1,5, [1,4,5])
+ assert longevity[d] == (4,5, None)
+ assert longevity[e] == (0,2, None)
+ assert longevity[f] == (2,5, None)
diff --git a/rpython/jit/backend/x86/regalloc.py b/rpython/jit/backend/x86/regalloc.py
--- a/rpython/jit/backend/x86/regalloc.py
+++ b/rpython/jit/backend/x86/regalloc.py
@@ -139,14 +139,15 @@
operations = cpu.gc_ll_descr.rewrite_assembler(cpu, operations,
allgcrefs)
# compute longevity of variables
- longevity, last_real_usage = compute_vars_longevity(
- inputargs, operations)
+ longevity, last_real_usage = \
+ compute_vars_longevity(inputargs, operations)
self.longevity = longevity
self.last_real_usage = last_real_usage
self.rm = gpr_reg_mgr_cls(self.longevity,
frame_manager = self.fm,
assembler = self.assembler)
- self.xrm = xmm_reg_mgr_cls(self.longevity, frame_manager = self.fm,
+ self.xrm = xmm_reg_mgr_cls(self.longevity,
+ frame_manager = self.fm,
assembler = self.assembler)
return operations
More information about the pypy-commit
mailing list