[LLVMdev] fields in structure re-arranged for alignment?

Kean Lau kean.lau at gmail.com
Mon Jul 16 00:21:58 PDT 2007


Hi Folks,

Bear with me, I'm a newbie to LLVM.

I've read the language reference and the mailing list archive. One area of
the semantics of the Structure type that hasn't been discussed is whether
fields in the structure get re-arranged to better suit the target machine's
natural alignment, ala what happens in C.

For example would this structure on a 32-bit machine:

{ i16, i32, i16 }

get re-arranged to

{ i16, i16, i32 } or { i32, i16, i16 }

Does LLVM guarantee a consistent code generation in this case for all
platforms, or is this considered target-specific and a decision left up to
the back-end of the target platform?

Furthermore if re-arrangement does occur, how does this affect the semantics
of GetElementPtr when it is used for pointer calculation of a Structure? For
example if I had:

%BLAH = type { i16, i32, i16 }
...
%firstField = getelementptr %BLAH* %instance, i32 1, i32 0


In this example I want to access the first 16-bit integer field of Structure
BLAH, so the last argument to GetElementPtr is index 0, but if the fields
gets re-arranged, how do I know which index to use?

Thanks,
Kean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070716/d88e2cb1/attachment.html>


More information about the llvm-dev mailing list