[LLVMdev] Explicitly Managed Stack Frames

Ben Chambers gtg983q at mail.gatech.edu
Sat Jan 14 12:56:39 PST 2006

Chris Lattner wrote:

> On Wed, 11 Jan 2006, Ben Chambers wrote:
>> I was wondering what the current state of this (explicitly managed 
>> stack frames)
>> is.  Is it being worked on?  If not, how hard do you think it would 
>> be for me to
>> add it?
> I'm not sure what you mean.  It depends on correct tail calls, but no 
> other LLVM-level support.

Really?  But if there are explicitly managed stack frames, it would be 
best for LLVM to spill registers into that location.  Otherwise, the 
front-end will be generating code to store the variable into the 
explicit stack frame before performing a call, and LLVM may emit some 
spill code to load that variable off the real stack frame (the one that 
LLVM uses).  So it seems like it is pretty easy to make code that will 
work, but at the same time I think it will either prevent or make less 
useful a good portion of the optimization work that has gone into LLVM.  
I guess the only way to know for sure is to implement it... so I'll get 
started on that :P

>> I am more than willing to work on it, but don't have any experience
>> with LLVM, so it might take a while.  The reason I ask is because I 
>> am starting
>> work on a project to make a language similar to ML with which to 
>> experiment, and
>> hope to build it upon LLVM.  Unfortunately, in order to implement 
>> things like
>> lexical scoping and closures, I need to be able to not only access 
>> variables on
>> the frame but also pass in a static link.
> Ok.  Are you planning on garbage collecting your stack frames, or do 
> you just need a static link?  If you just need a static link (because 
> of nested functions like pascal) but don't need GC'd stack frames, 
> there is no need even for tail call support and CPS and other 
> craziness, just pass your static link or display as an argument: lower 
> to LLVM just like you would lower to machine code. 

In order to return closures (which are functions, but may have some 
dependence on the environment in which they are created), you need to 
keep all the preceeding stack frames alive until after the closure goes 
dead.  The easiest way to implement this, by far, is through the use of 
garbage collected stack frames.  It also results in the highest efficiency.

-- Ben Chambers

More information about the llvm-dev mailing list