Joan Lluch via llvm-dev
2019-May-12 20:02 UTC
[llvm-dev] How to change CLang struct alignment behaviour?
My target implementation has 2 byte (16 bit ints) For my target implementation I would want that Clang would always use 2 byte aligned padding for Structs, which would match the size of an int. The current situation is that for this struct: struct AA { char n; char m; char j; }; I get it aligned by 1: %a = alloca %struct.AA, align 1 I would want it to implicitly use 4 bytes instead of 3, (or it be aligned by 2 bytes instead of 1). If I replace the above struct by this struct AA { int n; char m; }; I correctly get it aligned by 2: %a = alloca %struct.AA, align 2 (note that my architecture is 16 bit, so ints are 16 bits) In summary, I noticed that Clang will compute struct alignments as the max of the alignment of the individual members. How do I change that behaviour to get structs always (at least) 2 byte aligned ? John Lluch -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190512/62ef28ec/attachment.html>
Tim Northover via llvm-dev
2019-May-13 06:36 UTC
[llvm-dev] How to change CLang struct alignment behaviour?
Hi Joan, On Sun, 12 May 2019 at 21:02, Joan Lluch via llvm-dev <llvm-dev at lists.llvm.org> wrote:> How do I change that behaviour to get structs always (at least) 2 byte aligned ?I don't think there's a feature you can toggle for this (except, maybe, making the alignment of every basic type 2 bytes; but that would obviously affect arrays and even normal variables too). So you probably have to modify lib/AST/RecordLayoutBuilder.cpp directly. Might be worth asking this on the cfe-dev mailing list though. That's where most of the Clang experts live. Cheers. Tim.
Joan Lluch via llvm-dev
2019-May-13 06:53 UTC
[llvm-dev] How to change CLang struct alignment behaviour?
Hi Tim, Thanks for your reply. That’s what I was afraid of. I will try on the cfe-list as you suggest though. The reason I want structs to be aligned/padded to 2 bytes is because my architecture only has 16 bit operations. I can read (sign and zero extended) and write (truncated) 8 bit data from/to memory, but all intermediate operations in registers are performed in 16 bit registers. This causes LLVM to generate odd tricks such as shifts and byte-swaps, when trying to replace struct ‘memcpy’s by word sized load/store instructions. For 16 bit aligned structs the ‘memcpy’ replacement code is much cleaner. That’s the reason I would want structs to be always 16 bit aligned/padded. Joan Lluch Puigsacalm, 7 17458 - Fornells de la Selva Girona Tel: 620 28 45 13> On 13 May 2019, at 08:36, Tim Northover <t.p.northover at gmail.com> wrote: > > Hi Joan, > > On Sun, 12 May 2019 at 21:02, Joan Lluch via llvm-dev > <llvm-dev at lists.llvm.org> wrote: >> How do I change that behaviour to get structs always (at least) 2 byte aligned ? > > I don't think there's a feature you can toggle for this (except, > maybe, making the alignment of every basic type 2 bytes; but that > would obviously affect arrays and even normal variables too). So you > probably have to modify lib/AST/RecordLayoutBuilder.cpp directly. > > Might be worth asking this on the cfe-dev mailing list though. That's > where most of the Clang experts live. > > Cheers. > > Tim.-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190513/98d04ef9/attachment.html>