[LLVMdev] Re: Re: variable sized structs in LLVM

Chris Lattner sabre at nondot.org
Fri Jun 24 11:21:35 PDT 2005


On Wed, 22 Jun 2005, Armin Rigo wrote:
> Hi Reid,
> On Tue, Jun 21, 2005 at 11:15:22PM -0700, Reid Spencer wrote:
>> If you believe that variable sized structs are a feature that is missing
>> in LLVM, then that's another discussion. However, LLVM needs to remain
>> "low level" and it is unlikely such a feature would gain much traction
>> since a combination of existing features can accomplish the same thing.
>
> The only alternative so far in our case seems to be this one (quoting
> from a previous e-mail):
>
>> 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.

ick.

> If the LLVM optimizers are clever enough to figure out that the arrays
> doesn't really have to be allocated separately, but can be inlined
> within the allocation of the parent structure, and moreover no pointer
> indirection is needed, then it is indeed all that we need.

In simple cases, yes we could do something like this.  In general though, 
this is a very hard problem and not something your front-end wants to 
depend on for something as core as arrays and strings.

> In this sense, the feature Carl asked for is quite low level; we are
> looking for an effect that can be acheived either by optimizers working
> on a higher-level description in which the optimization hint cannot be
> expressed, or by giving the hint explicitely -- which so far doesn't
> seem possible portably in an assembler source.

Agreed.  If my previous emails don't clarify the issue, please let me 
know.

Thanks!

-Chris

-- 
http://nondot.org/sabre/
http://llvm.cs.uiuc.edu/




More information about the llvm-dev mailing list