[LLVMdev] recursive nested functions

John McCall rjmccall at apple.com
Fri Jun 25 11:29:29 PDT 2010


On Jun 25, 2010, at 10:46 AM, Nicolas Ojeda Bar wrote:

> Hello,
> 
> This is a little off-topic. But I am writing a compiler to llvm ir
> for a language that admits recursive nested functions and am stuck
> as to how to translate them. Concretely, I'm trying to lift them all
> to the topmost level and pass all their free variables explicitly as
> arguments. To do this, I have to determine all their free variables
> in their bodies. In particular when I come across a function call,
> I have to add _its_ free variables to the list of free variables of
> the enclosing function. You can see how this will not work if we
> allow recursive functions.

Topologically sort the functions defined in a single scope.  The free
variables of a cluster of mutually-recursive functions is the union
of their "direct" free variables, plus the free variables of any functions
they call.

John.



More information about the llvm-dev mailing list