| 1 |
= Restore |
| 2 |
|
| 3 |
<<Restore#>> is a rewrite pass for the <<SSA#>> and <<SSA2#>> |
| 4 |
<<IntermediateLanguage#>>s, invoked from <<KnownCase#>> and |
| 5 |
<<LocalRef#>>. |
| 6 |
|
| 7 |
== Description |
| 8 |
|
| 9 |
This pass restores the SSA condition for a violating <<SSA#>> or |
| 10 |
<<SSA2#>> program; the program must satisfy: |
| 11 |
____ |
| 12 |
Every path from the root to a use of a variable (excluding globals) |
| 13 |
passes through a def of that variable. |
| 14 |
____ |
| 15 |
|
| 16 |
== Implementation |
| 17 |
|
| 18 |
* https://github.com/MLton/mlton/blob/master/mlton/ssa/restore.sig[`restore.sig`] |
| 19 |
* https://github.com/MLton/mlton/blob/master/mlton/ssa/restore.fun[`restore.fun`] |
| 20 |
* https://github.com/MLton/mlton/blob/master/mlton/ssa/restore2.sig[`restore2.sig`] |
| 21 |
* https://github.com/MLton/mlton/blob/master/mlton/ssa/restore2.fun[`restore2.fun`] |
| 22 |
|
| 23 |
== Details and Notes |
| 24 |
|
| 25 |
Based primarily on Section 19.1 of <<References#Appel98,Modern Compiler |
| 26 |
Implementation in ML>>. |
| 27 |
|
| 28 |
The main deviation is the calculation of liveness of the violating |
| 29 |
variables, which is used to predicate the insertion of phi arguments. |
| 30 |
This is due to the algorithm's bias towards imperative languages, for |
| 31 |
which it makes the assumption that all variables are defined in the |
| 32 |
start block and all variables are "used" at exit. |
| 33 |
|
| 34 |
This is "optimized" for restoration of functions with small numbers of |
| 35 |
violating variables -- use bool vectors to represent sets of violating |
| 36 |
variables. |
| 37 |
|
| 38 |
Also, we use a `Promise.t` to suspend part of the dominance frontier |
| 39 |
computation. |