On 07/09/10 14:22, Erik de Castro Lopo wrote: [...]> When generating 32 bit code the struct looks like: > > <{ i32, pointer }> > > and for 64 bit code: > > <{ union { i32, i64 }, pointer }>Surely LLVM will cause the first structure to be correctly aligned on 64-bit platforms by automatically inserting padding? Is explicit alignment by the user really necessary? -- ┌─── dg@cowlark.com ───── http://www.cowlark.com ───── │ │ life←{ ↑1 ⍵∨.^3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ } │ --- Conway's Game Of Life, in one line of APL -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 262 bytes Desc: OpenPGP digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100908/888f6977/attachment.sig>
On 08 Sep 2010, at 13:03, David Given wrote:> On 07/09/10 14:22, Erik de Castro Lopo wrote: > [...] >> When generating 32 bit code the struct looks like: >> >> <{ i32, pointer }> >> >> and for 64 bit code: >> >> <{ union { i32, i64 }, pointer }> > > Surely LLVM will cause the first structure to be correctly aligned on > 64-bit platforms by automatically inserting padding?No, because it is declared as "packed" (the angle brackets). Jonas
Erik de Castro Lopo
2010-Sep-08 11:49 UTC
[LLVMdev] Union type, is it really used or necessary?
David Given wrote:> On 07/09/10 14:22, Erik de Castro Lopo wrote: > [...] > > When generating 32 bit code the struct looks like: > > > > <{ i32, pointer }> > > > > and for 64 bit code: > > > > <{ union { i32, i64 }, pointer }> > > Surely LLVM will cause the first structure to be correctly aligned on > 64-bit platforms by automatically inserting padding? Is explicit > alignment by the user really necessary?You missed the point. a struct defined with just parentheses like { i32, pointer } may be padded. A struct defined with angle brackets and parentheses <{ i32, pointer }> is a packed struct, guaranteed not to have padding. See: http://llvm.org/docs/LangRef.html#t_pstruct Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
On 08/09/10 12:36, Jonas Maebe wrote: [...]>> Surely LLVM will cause the first structure to be correctly aligned on >> 64-bit platforms by automatically inserting padding? > > No, because it is declared as "packed" (the angle brackets).Ah, I wasn't aware of that. Ta. -- ┌─── dg@cowlark.com ───── http://www.cowlark.com ───── │ │ life←{ ↑1 ⍵∨.^3 4=+/,¯1 0 1∘.⊖¯1 0 1∘.⌽⊂⍵ } │ --- Conway's Game Of Life, in one line of APL -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 262 bytes Desc: OpenPGP digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100908/0eca1d59/attachment.sig>
On Sep 8, 2010, at 4:49 AM, Erik de Castro Lopo wrote:> David Given wrote: > >> On 07/09/10 14:22, Erik de Castro Lopo wrote: >> [...] >>> When generating 32 bit code the struct looks like: >>> >>> <{ i32, pointer }> >>> >>> and for 64 bit code: >>> >>> <{ union { i32, i64 }, pointer }> >> >> Surely LLVM will cause the first structure to be correctly aligned on >> 64-bit platforms by automatically inserting padding? Is explicit >> alignment by the user really necessary? > > You missed the point. a struct defined with just parentheses like > > { i32, pointer } > > may be padded. A struct defined with angle brackets and parentheses > > <{ i32, pointer }> > > is a packed struct, guaranteed not to have padding. > > See: > > http://llvm.org/docs/LangRef.html#t_pstruct>From what you've described so far, regular non-packed structswould be a much better approach than packed structs with unions, even in LLVM versions which support unions. The output would be more readable and you'd get better optimization. I don't know how much work it would involve for you to change whatever assumptions you have in your code about packed structs, but if you're considering doing work in LLVM to re-introduce and finish unions, it's something to consider. Dan