[MLton] Converting recursive functions to SSA

Ben Chambers gtg983q@mail.gatech.edu
Fri, 21 Jul 2006 10:53:08 -0400


So, we're almost done (hopefully) with converting the CPS code back into SSA.
We just hit what we think is our last major stumbling block.  How do you handle
recursive functions when you produce the SSA code?  We've considered multiple
approaches, such as Lets-and-Sets, and hoisting the LetRec (we introduced this
to ourn CPS, but it is similar to a PolyVal that has a function block) to the
top level.  The problem is, it seems like if we choose the wrong mechanism it
could break a lot of the intelligence that is built into later stages of the
compiler, bu producing code that is not in the style that the optimizations have
been tuned for.  That's why we decided to ask and see how you handle compilation
of recursive functions.  For example, if I had the ML code:

let fun fib (n, a, b) = if n = 0 then a else fib (n - 1, b, a + b)
 in fib (5, 0, 1)
end

How do I convert this to SSA?  It's made even more difficult if the function
being converted has free variables, and is mutually recursive with other
functions who also have free variables.

Thanks,
Ben Chambers