[LLVMdev] variable sized structs in LLVM

Carl Friedrich Bolz cfbolz at gmx.de
Mon Jun 20 17:36:03 PDT 2005


Hi Reid!

Reid Spencer wrote:
> Its certainly possible to generate .ll files but its probably about the
> same amount of work to use the LLVM API and there are significant speed
> and validity benefits to doing so.

I can't really judge that because I've not used the API yet. For now 
creating .ll files seem like a good solution since string handling is so 
easy in Python. I guess we will have to use the API at a later point 
when we start to work on implementing jit compilation/dynamic 
specialization and want to directly use emitted functions.

> 
> Here's some ideas on how to handle this situation for the variable sized
> structs you need for PyPy:
> 
> 1. Don't support the feature in your first release (not sure if this is
>    viable or not).

A lot of things are implemented as var-sized struct, e.g. strings are a 
struct with a hash and the chars, so we can't just leave 'em out.

> 
> 2. Make some worst case assumptions about size and alignment (8 bytes)
>    and allocate that size, possibly over-allocating memory.

yes, this might a quick solution for the next weeks since we don't 
deallocate _any_ memory at the moment because the garbage collector is 
not implemented yet :-). The GC is what I'll be working on during the 
summer.

> 
> 3. Figure out the exact maximum size of the struct so you can declare
>    the type correctly.
> 4. Implement variable sized fields as separately allocated arrays so
>    that your example becomes:
>     %struct.array = type { int, int, int* }
>    The third field is allocated according to the actual size needed.
>    This is a bit more code generation but should be fairly efficient.

I guess we will probably do that.

Thanks for your suggestions,

Carl Friedrich




More information about the llvm-dev mailing list