Backport from sid to buster
[hcoop/debian/mlton.git] / doc / guide / src / Shrink.adoc
CommitLineData
7f918cf1
CE
1Shrink
2======
3
4<:Shrink:> is a rewrite pass for the <:SSA:> and <:SSA2:>
5<:IntermediateLanguage:>s, invoked from every optimization pass (see
6<:SSASimplify:> and <:SSA2Simplify:>).
7
8== Description ==
9
10This pass implements a whole family of compile-time reductions, like:
11
12* `#1(a, b)` => `a`
13* `case C x of C y => e` => `let y = x in e`
14* constant folding, copy propagation
15* eta blocks
16* tuple reconstruction elimination
17
18== Implementation ==
19
20* <!ViewGitFile(mlton,master,mlton/ssa/shrink.sig)>
21* <!ViewGitFile(mlton,master,mlton/ssa/shrink.fun)>
22* <!ViewGitFile(mlton,master,mlton/ssa/shrink2.sig)>
23* <!ViewGitFile(mlton,master,mlton/ssa/shrink2.fun)>
24
25== Details and Notes ==
26
27The <:Shrink:> pass is run after every <:SSA:> and <:SSA2:>
28optimization pass.
29
30The <:Shrink:> implementation also includes functions to eliminate
31unreachable blocks from a <:SSA:> or <:SSA2:> program or function.
32The <:Shrink:> pass does not guarantee to eliminate all unreachable
33blocks. Doing so would unduly complicate the implementation, and it
34is almost always the case that all unreachable blocks are eliminated.
35However, a small number of optimization passes require that the input
36have no unreachable blocks (essentially, when the analysis works on
37the control flow graph and the rewrite iterates on the vector of
38blocks). These passes explicitly call `eliminateDeadBlocks`.
39
40The <:Shrink:> pass has a special case to turn a non-tail call where
41the continuation and handler only do `Profile` statements into a tail
42call where the `Profile` statements precede the tail call.