<div dir="ltr">Woah this is a good idea.<br><br>I'd ask that alignment come in different bit sizes and endienesses so that we can add an alignment type to ELF types. I would love to review this and add it to llvm-objcopy. We have special functions to handle all of these 'zero' cases. Several other bits of code I've seen/written have to find maximum alignment and I'd imagine the mistake of not accounting for zero is common.<br><br>Where's the patch? Add me as a reviewer and I'll look at it today or Monday.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 12, 2019 at 9:07 AM JF Bastien via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;">Without looking at the patch, I like this idea. Numeric quantities in general (alignment, bits, bytes, etc) are often confusing in the codebase IMO, and what you propose would help alleviate this problem.<div><br></div><div>Can you fix this incrementally? i.e. add an alignment class which has implicit conversions to the current unsigned convention, and incrementally replace it throughout the codebase. Once everything is fixed, remove the implicit conversions.</div><div><br><div><br><blockquote type="cite"><div>On Jul 12, 2019, at 2:20 AM, Guillaume Chatelet via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="gmail-m_-4118310109383713936Apple-interchange-newline"><div><div dir="ltr">Alignment in LLVM is currently represented with an `unsigned`, sometimes an `uint32_t`, `uint64_t` or `uint16_t`.<br>FWIU the value has the following possible semantics:<br> - 0 means alignment is unknown,<br> - 1 means no alignment requirement,<br> - a power of two means a required alignment in bytes.<br><br>Using `unsigned` throughout the codebase has several disadvantages:<br> - comparing alignments may compare different things, what does `A < B` or `std::min(A, B)` mean when A or B are allowed to be 0?<br> - integer promotion can kick in and turn a `bool` in an alignment when calling a function (1)<br> - masking may lead to incorrect result when value is 0 (2)<br> - integer promotion leads to not obviously correct code in the presence of signed and unsigned values (3)<br> - dividing an alignment by 2 can change the associated semantic from `unaligned` to `unknown alignment` (4)<br> - developers have to be defensive to make sure assumptions hold (5)<br> - checking that an offset is aligned is sometimes done backward `Alignment % Offset == 0` instead of `Offset % Alignment == 0` (6) (7)<br> - MachineConstantPoolEntry::Alignment encodes special information in its topmost bit (8) but `AsmPrinter::GetCPISymbol` seems to use it directly (9) instead of calling `getAlignment()` (10)<br><br>I have a patch to introduce alignment object in LLVM.<br>This patch does not fix the code but replaces the unsigned value by a type so it's easier to introduce proper semantic later on.<br><br>The patch (11) is too big to be sent to Phabricator, arc diff complains about server's `post_max_size` being too small.<br><br>I would like to seek guidance from the community:<br> - Is this patch worthwhile?<br> - If so, how should it be reviewed? Should it be split?<br><br>-- Guillaume<br>PS: If you intend to have a look at it you should start with `llvm/include/llvm/Support/Alignment.h`<br><br>1 - <a href="https://github.com/llvm/llvm-project/blob/b725d27350ffdda9e8e9144668ad54c922297f59/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp#L2593" target="_blank">https://github.com/llvm/llvm-project/blob/b725d27350ffdda9e8e9144668ad54c922297f59/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp#L2593</a><br>2 - <a href="https://github.com/llvm/llvm-project/blob/b725d27350ffdda9e8e9144668ad54c922297f59/llvm/lib/CodeGen/SafeStack.cpp#L545" target="_blank">https://github.com/llvm/llvm-project/blob/b725d27350ffdda9e8e9144668ad54c922297f59/llvm/lib/CodeGen/SafeStack.cpp#L545</a><br>3 - <a href="https://github.com/llvm/llvm-project/blob/b725d27350ffdda9e8e9144668ad54c922297f59/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp#L1533" target="_blank">https://github.com/llvm/llvm-project/blob/b725d27350ffdda9e8e9144668ad54c922297f59/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp#L1533</a><br>4 - <a href="https://github.com/llvm/llvm-project/blob/b725d27350ffdda9e8e9144668ad54c922297f59/llvm/lib/CodeGen/CodeGenPrepare.cpp#L6751" target="_blank">https://github.com/llvm/llvm-project/blob/b725d27350ffdda9e8e9144668ad54c922297f59/llvm/lib/CodeGen/CodeGenPrepare.cpp#L6751</a><br>5 - <a href="https://github.com/llvm/llvm-project/blob/d0307f93a7658e6d0eef1ffd0b0ed4f1506bfc13/llvm/include/llvm/Analysis/VectorUtils.h#L278" target="_blank">https://github.com/llvm/llvm-project/blob/d0307f93a7658e6d0eef1ffd0b0ed4f1506bfc13/llvm/include/llvm/Analysis/VectorUtils.h#L278</a><br>6 - <a href="https://github.com/llvm/llvm-project/blob/fafec5155e39f5dad098376c1beb4a56604aa655/llvm/lib/Target/ARM/ARMCallingConv.cpp#L207" target="_blank">https://github.com/llvm/llvm-project/blob/fafec5155e39f5dad098376c1beb4a56604aa655/llvm/lib/Target/ARM/ARMCallingConv.cpp#L207</a><br>7 - <a href="https://github.com/llvm/llvm-project/blob/d0307f93a7658e6d0eef1ffd0b0ed4f1506bfc13/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp#L563" target="_blank">https://github.com/llvm/llvm-project/blob/d0307f93a7658e6d0eef1ffd0b0ed4f1506bfc13/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp#L563</a><br>8 - <a href="https://github.com/llvm/llvm-project/blob/7eeb82b58554163962d2696ce9be7d021d5b25d4/llvm/include/llvm/CodeGen/MachineConstantPool.h#L76" target="_blank">https://github.com/llvm/llvm-project/blob/7eeb82b58554163962d2696ce9be7d021d5b25d4/llvm/include/llvm/CodeGen/MachineConstantPool.h#L76</a><br>9 - <a href="https://github.com/llvm/llvm-project/blob/7eeb82b58554163962d2696ce9be7d021d5b25d4/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp#L2809" target="_blank">https://github.com/llvm/llvm-project/blob/7eeb82b58554163962d2696ce9be7d021d5b25d4/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp#L2809</a><br>10 - <a href="https://github.com/llvm/llvm-project/blob/7eeb82b58554163962d2696ce9be7d021d5b25d4/llvm/include/llvm/CodeGen/MachineConstantPool.h#L96" target="_blank">https://github.com/llvm/llvm-project/blob/7eeb82b58554163962d2696ce9be7d021d5b25d4/llvm/include/llvm/CodeGen/MachineConstantPool.h#L96</a><br><div>11 - <a href="https://drive.google.com/file/d/1PgrEuNjIcSH9hOs6REe9FedCH5mf43Q9/view?usp=sharing" target="_blank">https://drive.google.com/file/d/1PgrEuNjIcSH9hOs6REe9FedCH5mf43Q9/view?usp=sharing</a></div></div>
_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br></div></blockquote></div><br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>