Skip to content

Commit 81e8abb

Browse files
Reorder the liveness computation and test livein instead of liveout to determine fixed point as liveness is a backward DF problem.
1 parent de34763 commit 81e8abb

File tree

1 file changed

+9
-7
lines changed
  • optvm/src/main/java/com/compilerprogramming/ezlang/compiler

1 file changed

+9
-7
lines changed

optvm/src/main/java/com/compilerprogramming/ezlang/compiler/Liveness.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ public Liveness(CompiledFunction function) {
3434
// The problem is that if there are infinite loops, we will not visit all basic blocks
3535
// if we started at the exit block (this could be solved by adding artificial edges from infinite loop
3636
// to exit block, but we do not do that yet).
37-
// For a forward CFG traversal, we cannot do RPO as this is a backward dataflow
38-
// problem, i.e. successors must be processed first.
3937
List<BasicBlock> blocks = BBHelper.findAllBlocksPostOrderForwardCFG(function);
4038
RegisterPool regPool = function.registerPool;
4139
initBlocks(regPool, blocks);
@@ -136,15 +134,19 @@ private void computeLiveness(List<BasicBlock> blocks) {
136134
// This corresponds to placing a copy of a_i to a_0 on each edge from B_i to B_0.
137135
//
138136
private boolean recomputeLiveOut(BasicBlock block) {
139-
LiveSet oldLiveOut = block.liveOut.dup();
140-
LiveSet t = block.liveOut.dup().subtract(block.varKill);
141-
block.liveIn.union(block.phiDefs).union(block.UEVar).union(t);
137+
LiveSet oldLiveIn = block.liveIn.dup();
138+
// LiveOut(B) = U all S (LiveIn(S) \ PhiDefs(S)) U PhiUses
142139
block.liveOut.clear();
143140
for (BasicBlock s: block.successors) {
144-
t = s.liveIn.dup().subtract(s.phiDefs);
141+
LiveSet t = s.liveIn.dup().subtract(s.phiDefs);
145142
block.liveOut.union(t);
146143
}
147144
block.liveOut.union(block.phiUses);
148-
return !oldLiveOut.equals(block.liveOut);
145+
// LiveIn(B) = PhiDefs(B) U UpwardExposed(B) U (LiveOut(B) \ Defs(B))
146+
LiveSet t = block.liveOut.dup().subtract(block.varKill);
147+
block.liveIn = t.union(block.phiDefs).union(block.UEVar);
148+
// we check changes to both live in and out sets to
149+
// make the code robust against order of traversal
150+
return !oldLiveIn.equals(block.liveIn);
149151
}
150152
}

0 commit comments

Comments
 (0)