[LLVMdev] Controlling the stack layout

Basile STARYNKEVITCH basile at starynkevitch.net
Sun Dec 28 08:59:32 PST 2008


Nick Johnson wrote (citing somebody else):
>> I'd like to generate this layout:
>>
>> 12(%ebp)    - second function parameter
>> 8(%ebp)      - first function parameter
>> 4(%ebp)      - old %EIP (the function's "return address")
>> 0(%ebp)      - old %EBP (previous function's base pointer)
>> -4(%ebp)     - My language specific information
>> -8(%ebp)     - first local variable
>> -12(%ebp)   - second local variable
>>
>>     
>
> Take a look at the register allocators, each of which is implemented
> as a MachineFunctionPass.  These are responsible for assigning stack
> slots, and it shouldn't be too hard to modify them to reserve some
> stack slots.
>
> Also, I'd recommend that you consider the prevalence of this language
> specific information, and re-evaluate whether you want to modify the
> stack frame at all.  Do you expect *every* function will need it, or
> *at most* every function will need it? 

I don't know the motivation of the initial poster, but I do understand 
the wish to put some language specific information on the call stack. I 
even can think of several reasons to do that:

1. easy support of a precise garbage collector: you want each call frame 
to have, at some fixed offset, a pointer to some frame layout descriptor 
(used by your copying garbage collector) which tells what are the 
pointers in the call frame. Another way to do that is to have your GC 
use the return address to find out the routine and hence its frame 
layout (IIRC, the ocaml native compiler does that), but this is much 
harder to implement.

2. introspective/reflective facilities: your language is compiled but 
yet has the ability to inspect each of its call stack frame. There are 
many reasons to want that.

3. reification of continuations : your language implement continuations, 
and perhaps facilities to inspect them, or dump or serialize them, ...

Happy New Year 2009 to everyone!

Regards.

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***
membre de l'APRIL "promouvoir et défendre le logiciel libre"
Rejoignez maitenant pplus de 3700 adhérents http://www.april.org




More information about the llvm-dev mailing list