Ouriel, Boaz
2011-Dec-14 20:44 UTC
[LLVMdev] A Question about LLVM structures - alignment of data members
Hi All, Today, LLVM IR doesn't include a description for alignment for specific data members inside structures. The implies that LLVM IR Generators need to do the padding themselves in order to achieve the requested alignment. Since the information is not represented explicitly by the LLVM IR, optimization passes might unintentionally break the required alignment and lead to unexpected results when executing the generated program. Here is an example "C" code (and OpenCL as well) struct st1_t { int i; float __attribute__((align(64))) f; }; struct st1_t ist1; Generated IR by CLANG: %struct.st1_t = type { i32, [60 x i8], float, [60 x i8] } @ist1 = common global %struct.st1_t zeroinitializer, align 64 What is the reason for disallowing alignment of data members inside structs in LLVM IR? What were the design considerations? Thanks, Boaz --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111214/6a0bc7a3/attachment.html>
Eli Friedman
2011-Dec-14 21:06 UTC
[LLVMdev] A Question about LLVM structures - alignment of data members
On Wed, Dec 14, 2011 at 12:44 PM, Ouriel, Boaz <boaz.ouriel at intel.com> wrote:> Hi All, > > > > Today, LLVM IR doesn’t include a description for alignment for specific data > members inside structures. > > The implies that LLVM IR Generators need to do the padding themselves in > order to achieve the requested alignment.If the alignment required is higher than native alignment, yes.> Since the information is not represented explicitly by the LLVM IR, > optimization passes might unintentionally break the required alignment and > lead to unexpected results when executing the generated program.I don't see how this follows: you can explicitly specify alignment for every operation where it matters. If some operation requires a specific alignment specified in the IR, the optimizers won't break it.> What is the reason for disallowing alignment of data members inside structs > in LLVM IR? What were the design considerations?We have a perfectly usable design for handling explicitly specifying alignment. Allowing explicit alignment on struct types would make the IR more complicated, and making the IR more complicated requires a strong justification. -Eli
Maybe Matching Threads
- [LLVMdev] SPIR Portability Discussion
- [LLVMdev] SPIR Portability Discussion
- [LLVMdev] [cfe-dev] SPIR provisional specification is now available in the Khronos website
- [LLVMdev] [cfe-dev] SPIR provisional specification is now available in the Khronos website
- [LLVMdev] SPIR Portability Discussion