[LLVMdev] Nested functions

Vikram S. Adve vadve at cs.uiuc.edu
Mon Nov 22 10:03:55 PST 2004

On Nov 22, 2004, at 12:05 PM, Chris Lattner wrote:

> On Sun, 21 Nov 2004, Dirk Muysers wrote:
>> Was there already some reflection about how to lower the concept of 
>> nested
>> functions (and the corresponding static links) into llvm?
> This was discussed back in August, which discusses it, provides a 
> solution
> and an example:
> http://mail.cs.uiuc.edu/pipermail/llvmdev/2004-August/001828.html
> http://mail.cs.uiuc.edu/pipermail/llvmdev/2004-August/001829.html
> http://mail.cs.uiuc.edu/pipermail/llvmdev/2004-August/001834.html
> http://mail.cs.uiuc.edu/pipermail/llvmdev/2004-August/001836.html

That's a rather simplistic example.  I wouldn't recommend doing it this 
way -- I see at least 2 problems with it:

(1) With recursion, the inlining being  assumed here would not happen.  
This means the struct initialization won't be optimized away so nicely 
and it can get really expensive.  Even without recursion, inlining 
would be impractical if you have many nested procedures and deep 

(2) If you don't rely on inlining, initializing the structs you have to 
pass around will get horrendously expensive with large numbers of local 
variables.  (Note that without inlining, the structs will *not* be 
scalar-replaced because they have to passed as arguments.)

There's a reason why code generators use static links.


More information about the llvm-dev mailing list