Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / ToMachine.adoc
1 ToMachine
2 =========
3
4 <:ToMachine:> is a translation pass from the <:RSSA:>
5 <:IntermediateLanguage:> to the <:Machine:> <:IntermediateLanguage:>.
6
7 == Description ==
8
9 This pass converts from a <:RSSA:> program into a <:Machine:> program.
10
11 It uses <:AllocateRegisters:>, <:Chunkify:>, and <:ParallelMove:>.
12
13 == Implementation ==
14
15 * <!ViewGitFile(mlton,master,mlton/backend/backend.sig)>
16 * <!ViewGitFile(mlton,master,mlton/backend/backend.fun)>
17
18 == Details and Notes ==
19
20 Because the MLton runtime system is shared by all <:Codegen:codegens>, it is most
21 convenient to decide on stack layout _before_ any <:Codegen:codegen> takes over.
22 In particular, we compute all the stack frame info for each <:RSSA:>
23 function, including stack size, <:GarbageCollection:garbage collector>
24 masks for each frame, etc. To do so, the <:Machine:>
25 <:IntermediateLanguage:> imagines an abstract machine with an infinite
26 number of (pseudo-)registers of every size. A liveness analysis
27 determines, for each variable, whether or not it is live across a
28 point where the runtime system might take over (for example, any
29 garbage collection point) or a non-tail call to another <:RSSA:>
30 function. Those that are live go on the stack, while those that
31 aren't live go into psuedo-registers. From this information, we know
32 all we need to about each stack frame. On the downside, nothing
33 further on is allowed to change this stack info; it is set in stone.