Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / CommonBlock.adoc
CommitLineData
7f918cf1
CE
1CommonBlock
2===========
3
4<:CommonBlock:> is an optimization pass for the <:SSA:>
5<:IntermediateLanguage:>, invoked from <:SSASimplify:>.
6
7== Description ==
8
9It eliminates equivalent blocks in a <:SSA:> function. The
10equivalence criteria requires blocks to have no arguments or
11statements and transfer via `Raise`, `Return`, or `Goto` of a single
12global variable.
13
14== Implementation ==
15
16* <!ViewGitFile(mlton,master,mlton/ssa/common-block.fun)>
17
18== Details and Notes ==
19
20* Rewrites
21+
22----
23L_X ()
24 raise (global_Y)
25----
26+
27to
28+
29----
30L_X ()
31 L_Y' ()
32----
33+
34and adds
35+
36----
37L_Y' ()
38 raise (global_Y)
39----
40+
41to the <:SSA:> function.
42
43* Rewrites
44+
45----
46L_X ()
47 return (global_Y)
48----
49+
50to
51+
52----
53L_X ()
54 L_Y' ()
55----
56+
57and adds
58+
59----
60L_Y' ()
61 return (global_Y)
62----
63+
64to the <:SSA:> function.
65
66* Rewrites
67+
68----
69L_X ()
70 L_Z (global_Y)
71----
72+
73to
74+
75----
76L_X ()
77 L_Y' ()
78----
79+
80and adds
81+
82----
83L_Y' ()
84 L_Z (global_Y)
85----
86+
87to the <:SSA:> function.
88
89The <:Shrink:> pass rewrites all uses of `L_X` to `L_Y'` and drops `L_X`.
90
91For example, all uncaught `Overflow` exceptions in a <:SSA:> function
92share the same raising block.