Debian Codegraph @

doc/guide/src/Shrink.adoc

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