Skip to content

Commit 42e6626

Browse files
#57 Use better naming of temps created as a result of SSA destruction - using original names as prefix if possible. Update tests.
1 parent 3b12690 commit 42e6626

File tree

2 files changed

+989
-985
lines changed

2 files changed

+989
-985
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
/**
66
* Implement method to exit SSA by converting to conventional SSA,
7-
* without coalescing. This is the basic form.
7+
* without coalescing. This is the basic form - it creates extra copies but
8+
* the transformation is simple and correct, and does not suffer from the lost copy or
9+
* swap problem.
810
*
9-
* This is essentially Method 1 described by
11+
* The simple conversion is essentially Method 1 described by
1012
* Translating Out of Static Single Assignment Form
1113
* Vugranam C. Sreedhar, Roy Dz-Ching Ju, David M. Gillies, and Vatsa Santhanam
1214
*
@@ -17,11 +19,11 @@
1719
* Benoit Boissinot, Alain Darte, Fabrice Rastello, Benoît Dupont de Dinechin, Christophe Guillon
1820
*
1921
* The Boissinot paper gives a more correct description, discussing the need for parallel copy
20-
* and sequencing the parallel copy, but the paper describes a
21-
* more complex approach that performs coalescing.
22+
* and sequencing the parallel copy. Much of the Boissinot paper is about optimizing away any extra copies, but
23+
* it seems to me that the Briggs algorithm achieves that anyway while being simpler
24+
* to implement.
2225
*
2326
* Engineering a Compiler, 3rd edition, describes the simpler form - omitting the coalescing part.
24-
*
2527
* Our implementation is similar to EaC.
2628
*
2729
* We do not use the sequencing algo described in Boissinot paper. Instead, we use:
@@ -115,12 +117,14 @@ private void makeConventionalSSA() {
115117
BasicBlock pred = block.predecessor(j);
116118
var pCopyBEnd = getParallelCopyAtEnd(pred);
117119
var oldInput = phi.input(j);
118-
var newInput = function.registerPool.newTempReg(oldInput.type);
120+
var newInput = oldInput instanceof Operand.RegisterOperand regInput ?
121+
function.registerPool.newTempReg(regInput.reg.name(), oldInput.type) :
122+
function.registerPool.newTempReg(oldInput.type);
119123
pCopyBEnd.addCopy(oldInput,new Operand.RegisterOperand(newInput));
120124
phi.replaceInput(j,newInput);
121125
}
122126
var oldPhiVar = phi.value();
123-
var newPhiVar = function.registerPool.newTempReg(oldPhiVar.type);
127+
var newPhiVar = function.registerPool.newTempReg(oldPhiVar.name(), oldPhiVar.type);
124128
phi.replaceValue(newPhiVar);
125129
var pCopyBBegin = getParallelCopyAtBegin(block);
126130
pCopyBBegin.addCopy(new Operand.RegisterOperand(newPhiVar),new Operand.RegisterOperand(oldPhiVar));

0 commit comments

Comments
 (0)