[LLVMdev] Structure memory layout

Duncan Sands baldrick at free.fr
Tue Oct 19 01:09:55 PDT 2010


Hi Jin Gu Kang,

> I have been working to make target independent memory layout for struct
> type(Aggregate type) in my team.
> I think that struct type has different memory layouts according to each target
> system in current LLVM.

yes this is true, because alignment depends on the target.  You may want to look
at packed structs where no alignment padding is added between elements.  This
does not completely fix the problem, because non-aggregate types can have a size
that depends on their alignment, for example x86 long double occupies 12 bytes
in a packed struct on x86-32 linux but 16 bytes on x86-32 darwin.  It used to be
that in packed structs the amount of space was the minimum possible (10 bytes
for an x86 long double), but this was removed because it was considered too
confusing.  However it could probably be restored if really needed.

> To implement target dependent concept for struct type,
> Frist, I have been implementing common type for struct type on bitcode at
> compilation time using llvm-gcc and then changing common type to target specific
> types at code generation time using llc (reconstruct StructLayout).
> Second, I have been adding two new intrinsic functions as following.
> 1. "getelement" intrinsic function to load from bitfield of struct type.
> 2. "setelement" intrinsic function to store to bitfied of struct type.
> I would like to how do LLVM developers think about above concept.
> (advices, problems, other solutions etc...)

I didn't understand this paragraph.  Perhaps you could explain with a simple
example?

Best wishes,

Duncan.



More information about the llvm-dev mailing list