[llvm] [DataLayout] Use member initialization (NFC) (PR #103712)

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 02:23:37 PDT 2024


================
@@ -198,37 +198,38 @@ const char *DataLayout::getManglingComponent(const Triple &T) {
   return "-m:e";
 }
 
-static const std::pair<AlignTypeEnum, LayoutAlignElem> DefaultAlignments[] = {
-    {INTEGER_ALIGN, {1, Align(1), Align(1)}},    // i1
-    {INTEGER_ALIGN, {8, Align(1), Align(1)}},    // i8
-    {INTEGER_ALIGN, {16, Align(2), Align(2)}},   // i16
-    {INTEGER_ALIGN, {32, Align(4), Align(4)}},   // i32
-    {INTEGER_ALIGN, {64, Align(4), Align(8)}},   // i64
-    {FLOAT_ALIGN, {16, Align(2), Align(2)}},     // half, bfloat
-    {FLOAT_ALIGN, {32, Align(4), Align(4)}},     // float
-    {FLOAT_ALIGN, {64, Align(8), Align(8)}},     // double
-    {FLOAT_ALIGN, {128, Align(16), Align(16)}},  // ppcf128, quad, ...
-    {VECTOR_ALIGN, {64, Align(8), Align(8)}},    // v2i32, v1i64, ...
-    {VECTOR_ALIGN, {128, Align(16), Align(16)}}, // v16i8, v8i16, v4i32, ...
+// Default primitive type specifications.
+// NOTE: These arrays must be sorted by type bit width.
+constexpr LayoutAlignElem DataLayout::DefaultIntSpecs[] = {
+    {1, Align::Constant<1>(), Align::Constant<1>()},  // i1:8:8
+    {8, Align::Constant<1>(), Align::Constant<1>()},  // i8:8:8
+    {16, Align::Constant<2>(), Align::Constant<2>()}, // i16:16:16
+    {32, Align::Constant<4>(), Align::Constant<4>()}, // i32:32:32
+    {64, Align::Constant<4>(), Align::Constant<8>()}, // i64:32:64
+};
+constexpr LayoutAlignElem DataLayout::DefaultFloatSpecs[] = {
+    {16, Align::Constant<2>(), Align::Constant<2>()},    // f16:16:16
----------------
bjope wrote:

These changes actually hard codes how many bytes that correspond to 16 bits. If the goal with this patch was to simplify life for non-8-bit-byte targets (as you wrote that you planned to do in https://discourse.llvm.org/t/rfc-on-non-8-bit-bytes-and-the-target-for-it/53455/46) then I'm confused. This currently causes some head-ache for use downstream as our old solution for converting the bit-sized alignments into bytes no longer works.

Should there perhaps be a comment somewhere saying that the alignments are specified in "number of octests"? And why is that better than specifying them in bits?


(Btw, as I mentioned in the discourse thread I wouldn't mind being added as reviewer to the patches related to non-8-bit-byte-support-improvements. This to avoid surprises like this when merging the patches that already has landed on main.)

https://github.com/llvm/llvm-project/pull/103712


More information about the llvm-commits mailing list