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

Chris Lattner sabre at nondot.org
Fri Jun 24 11:19:51 PDT 2005


On Tue, 21 Jun 2005, Reid Spencer wrote:
> On Wed, 2005-06-22 at 01:17 -0400, Ed Cogburn wrote:
>> One of LLVM's powerful (IMHO) selling points was the
>> concept of a *complete*, abstract IR language which any independent
>> frontend could write to (sending llvm-as unoptimized, even ugly, but
>> correct, IR assembly that gets converted to optimized native code), without
>> being dependent on LLVM's own code, i.e. just write to the IR spec, and be
>> able to do anything that any frontend linked to LLVM itself, like Reid's
>> Stacker, could do.
>
> You can still do that. You just can't make assumptions about sizes and
> alignments in a platform-neutral way. FWIW, you couldn't do it in Java
> either for much the same reason: the details differ from platform to
> platform.

Yup.

> If your language depends on knowing the sizes/alignment/offset of actual
> machines then the language is not, itself, machine neutral.

This is true.

> However, there are various techniques youc an use to do what you want. 
> I've already suggested how you can make variable sized structures by 
> using a pointer for one of the structure members.

This is one way to do it, but it is not the only way.  This is also less 
efficient for obvious reasons.  It's better to just use variable sized 
arrays.

> As for Stacker, it doesn't generate LLVM assembly. At least not
> directly. Its compiler directly manipulates the C++ IR from which either
> bytecode or assembly can be generated.

I really don't see what this has to do with anything.  You're confusing 
what the LLVM API's provide and what the LLVM language/IR provides. 
Nothing in stacker depends on the LLVM API's: it could be written as a 
perl script that outputs .ll files.

>> and with variable structs handled perhaps like GCC & C99
>> eventually did to support variable sized structs in C.
>
> LLVM is not GCC nor C99, its LLVM.

This is true, but obviously LLVM wants to support C99 and other things 
that GCC does! :)

> The notion doesn't exist in LLVM

This is not true.

> but there are alternatives, several 
> already suggested, that you can use instead. It is likely that "under 
> the covers" GCC and C99 are using similar techniques.

Not true, but for a different reason.  C/C++ are already not 
target-independent (e.g. you can write code that detects endianness, 
header files are system specific, etc).  Because of this, the llvm-gcc 
front-end doesn't really even try to emit super portable llvm code.  As 
such, when using C VLA's, they just get lowered to allocations of exactly 
the right number of bytes, without the LLVM portable 'sizeof' construct 
being used.

> 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.

Fortunately, nothing in LLVM has to be there explicitly to support the 
feature.  It's one of those high-level things that can be expressed with 
the low-level things we already have.  :)

-Chris

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




More information about the llvm-dev mailing list