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

Reid Spencer reid at x10sys.com
Wed Jun 22 10:55:24 PDT 2005


On Wed, 2005-06-22 at 17:52 +0200, 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.
> 
> 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.

I don't know if LLVM currently will do this or not, but it is unlikely.
I'll defer to someone who knows the optimizations better. However, what
I do know is that such an optimization could quite easily be written.
The situation is quite identifiable in just a few lines of LLVM C++ IR
code and the transformation is similarly simple. So, one approach would
be to use the IR as is (as you quoted above) and write an optimization
to do what you want (turn two allocations into one).
> 
> 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. Chances are the optimization I suggested above could be written
fairly easily. The change to the assembly language to provide the "hint"
or alternatively directly support variable sized structures is a much
larger task.

I think we should wait until Chris and others can weigh in on this,
however. Chris will be off-line until 6/26 or thereabouts. If you can
defer your implementation for a few more days, perhaps we can work out a
solution that works for everyone.

Reid.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20050622/dd6c565e/attachment.sig>


More information about the llvm-dev mailing list