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

Andrew Lenharth andrewl at lenharth.org
Mon Jul 16 07:08:43 PDT 2007


On 7/16/07, Kean Lau <kean.lau at gmail.com> wrote:
> 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.

Unless the alignment or packing is overwritten at the llvm level,
structures are aligned at the natural alignment of the target machine.
 If you have exacting layout requirements, you can use a packed
structure with alignment attributes.

It would be possible to rearrange llvm structs as an optimization, but
there are many considerations to do that safely (e.g. checking that
the rearranged memory is never used by external code).  I have done
some struct reordering passes before, and the field fiddling is easy
enough to do, the hard part is making sure it is safe.

Andrew



More information about the llvm-dev mailing list