Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / Shrink
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="generator" content="AsciiDoc 8.6.9">
6 <title>Shrink</title>
7 <link rel="stylesheet" href="./asciidoc.css" type="text/css">
8 <link rel="stylesheet" href="./pygments.css" type="text/css">
9
10
11 <script type="text/javascript" src="./asciidoc.js"></script>
12 <script type="text/javascript">
13 /*<![CDATA[*/
14 asciidoc.install();
15 /*]]>*/
16 </script>
17 <link rel="stylesheet" href="./mlton.css" type="text/css">
18 </head>
19 <body class="article">
20 <div id="banner">
21 <div id="banner-home">
22 <a href="./Home">MLton 20180207</a>
23 </div>
24 </div>
25 <div id="header">
26 <h1>Shrink</h1>
27 </div>
28 <div id="content">
29 <div id="preamble">
30 <div class="sectionbody">
31 <div class="paragraph"><p><a href="Shrink">Shrink</a> is a rewrite pass for the <a href="SSA">SSA</a> and <a href="SSA2">SSA2</a>
32 <a href="IntermediateLanguage">IntermediateLanguage</a>s, invoked from every optimization pass (see
33 <a href="SSASimplify">SSASimplify</a> and <a href="SSA2Simplify">SSA2Simplify</a>).</p></div>
34 </div>
35 </div>
36 <div class="sect1">
37 <h2 id="_description">Description</h2>
38 <div class="sectionbody">
39 <div class="paragraph"><p>This pass implements a whole family of compile-time reductions, like:</p></div>
40 <div class="ulist"><ul>
41 <li>
42 <p>
43 <span class="monospaced">#1(a, b)</span> &#8658; <span class="monospaced">a</span>
44 </p>
45 </li>
46 <li>
47 <p>
48 <span class="monospaced">case C x of C y =&gt; e</span> &#8658; <span class="monospaced">let y = x in e</span>
49 </p>
50 </li>
51 <li>
52 <p>
53 constant folding, copy propagation
54 </p>
55 </li>
56 <li>
57 <p>
58 eta blocks
59 </p>
60 </li>
61 <li>
62 <p>
63 tuple reconstruction elimination
64 </p>
65 </li>
66 </ul></div>
67 </div>
68 </div>
69 <div class="sect1">
70 <h2 id="_implementation">Implementation</h2>
71 <div class="sectionbody">
72 <div class="ulist"><ul>
73 <li>
74 <p>
75 <a href="https://github.com/MLton/mlton/blob/master/mlton/ssa/shrink.sig"><span class="monospaced">shrink.sig</span></a>
76 </p>
77 </li>
78 <li>
79 <p>
80 <a href="https://github.com/MLton/mlton/blob/master/mlton/ssa/shrink.fun"><span class="monospaced">shrink.fun</span></a>
81 </p>
82 </li>
83 <li>
84 <p>
85 <a href="https://github.com/MLton/mlton/blob/master/mlton/ssa/shrink2.sig"><span class="monospaced">shrink2.sig</span></a>
86 </p>
87 </li>
88 <li>
89 <p>
90 <a href="https://github.com/MLton/mlton/blob/master/mlton/ssa/shrink2.fun"><span class="monospaced">shrink2.fun</span></a>
91 </p>
92 </li>
93 </ul></div>
94 </div>
95 </div>
96 <div class="sect1">
97 <h2 id="_details_and_notes">Details and Notes</h2>
98 <div class="sectionbody">
99 <div class="paragraph"><p>The <a href="Shrink">Shrink</a> pass is run after every <a href="SSA">SSA</a> and <a href="SSA2">SSA2</a>
100 optimization pass.</p></div>
101 <div class="paragraph"><p>The <a href="Shrink">Shrink</a> implementation also includes functions to eliminate
102 unreachable blocks from a <a href="SSA">SSA</a> or <a href="SSA2">SSA2</a> program or function.
103 The <a href="Shrink">Shrink</a> pass does not guarantee to eliminate all unreachable
104 blocks. Doing so would unduly complicate the implementation, and it
105 is almost always the case that all unreachable blocks are eliminated.
106 However, a small number of optimization passes require that the input
107 have no unreachable blocks (essentially, when the analysis works on
108 the control flow graph and the rewrite iterates on the vector of
109 blocks). These passes explicitly call <span class="monospaced">eliminateDeadBlocks</span>.</p></div>
110 <div class="paragraph"><p>The <a href="Shrink">Shrink</a> pass has a special case to turn a non-tail call where
111 the continuation and handler only do <span class="monospaced">Profile</span> statements into a tail
112 call where the <span class="monospaced">Profile</span> statements precede the tail call.</p></div>
113 </div>
114 </div>
115 </div>
116 <div id="footnotes"><hr></div>
117 <div id="footer">
118 <div id="footer-text">
119 </div>
120 <div id="footer-badges">
121 </div>
122 </div>
123 </body>
124 </html>