[llvm] [DataLayout] Split StructAlignment into two fields (NFC) (PR #103700)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 13 23:34:40 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Sergei Barannikov (s-barannikov)

<details>
<summary>Changes</summary>

Aggregate type specification doesn't have the size component. Don't abuse LayoutAlignElem to avoid confusion.

---
Full diff: https://github.com/llvm/llvm-project/pull/103700.diff


2 Files Affected:

- (modified) llvm/include/llvm/IR/DataLayout.h (+4-1) 
- (modified) llvm/lib/IR/DataLayout.cpp (+8-7) 


``````````diff
diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h
index f4b4b730bee2ae..2b79facf1d8988 100644
--- a/llvm/include/llvm/IR/DataLayout.h
+++ b/llvm/include/llvm/IR/DataLayout.h
@@ -147,7 +147,6 @@ class DataLayout {
   AlignmentsTy IntAlignments;
   AlignmentsTy FloatAlignments;
   AlignmentsTy VectorAlignments;
-  LayoutAlignElem StructAlignment;
 
   /// The string representation used to create this DataLayout
   std::string StringRepresentation;
@@ -157,6 +156,10 @@ class DataLayout {
 
   const PointerAlignElem &getPointerAlignElem(uint32_t AddressSpace) const;
 
+  // Struct type ABI and preferred alignments. The default spec is "a:8:64".
+  Align StructABIAlignment = Align::Constant<1>();
+  Align StructPrefAlignment = Align::Constant<8>();
+
   // The StructType -> StructLayout map.
   mutable void *LayoutMap = nullptr;
 
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index ae0ff9c5ffe914..c10b302870edbe 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -219,7 +219,6 @@ DataLayout::DataLayout(StringRef LayoutString) {
   DefaultGlobalsAddrSpace = 0;
   TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
   ManglingMode = MM_None;
-  StructAlignment = LayoutAlignElem::get(Align(1), Align(8), 0);
 
   // Default alignments
   for (const auto &[Kind, Layout] : DefaultAlignments) {
@@ -250,8 +249,9 @@ DataLayout &DataLayout::operator=(const DataLayout &Other) {
   IntAlignments = Other.IntAlignments;
   FloatAlignments = Other.FloatAlignments;
   VectorAlignments = Other.VectorAlignments;
-  StructAlignment = Other.StructAlignment;
   Pointers = Other.Pointers;
+  StructABIAlignment = Other.StructABIAlignment;
+  StructPrefAlignment = Other.StructPrefAlignment;
   NonIntegralAddressSpaces = Other.NonIntegralAddressSpaces;
   return *this;
 }
@@ -271,7 +271,9 @@ bool DataLayout::operator==(const DataLayout &Other) const {
          IntAlignments == Other.IntAlignments &&
          FloatAlignments == Other.FloatAlignments &&
          VectorAlignments == Other.VectorAlignments &&
-         StructAlignment == Other.StructAlignment && Pointers == Other.Pointers;
+         Pointers == Other.Pointers &&
+         StructABIAlignment == Other.StructABIAlignment &&
+         StructPrefAlignment == Other.StructPrefAlignment;
 }
 
 Expected<DataLayout> DataLayout::parse(StringRef LayoutDescription) {
@@ -628,8 +630,8 @@ Error DataLayout::setAlignment(AlignTypeEnum AlignType, Align ABIAlign,
   SmallVectorImpl<LayoutAlignElem> *Alignments;
   switch (AlignType) {
   case AGGREGATE_ALIGN:
-    StructAlignment.ABIAlign = ABIAlign;
-    StructAlignment.PrefAlign = PrefAlign;
+    StructABIAlignment = ABIAlign;
+    StructPrefAlignment = PrefAlign;
     return Error::success();
   case INTEGER_ALIGN:
     Alignments = &IntAlignments;
@@ -801,8 +803,7 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
 
     // Get the layout annotation... which is lazily created on demand.
     const StructLayout *Layout = getStructLayout(cast<StructType>(Ty));
-    const Align Align =
-        abi_or_pref ? StructAlignment.ABIAlign : StructAlignment.PrefAlign;
+    const Align Align = abi_or_pref ? StructABIAlignment : StructPrefAlignment;
     return std::max(Align, Layout->getAlignment());
   }
   case Type::IntegerTyID:

``````````

</details>


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


More information about the llvm-commits mailing list