Skip to content

Commit 8eadf21

Browse files
authored
[DataLayout] Split StructAlignment into two fields (NFC) (#103700)
Aggregate type specification doesn't have the size component. Don't abuse LayoutAlignElem to avoid confusion.
1 parent fa658ac commit 8eadf21

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ class DataLayout {
147147
AlignmentsTy IntAlignments;
148148
AlignmentsTy FloatAlignments;
149149
AlignmentsTy VectorAlignments;
150-
LayoutAlignElem StructAlignment;
151150

152151
/// The string representation used to create this DataLayout
153152
std::string StringRepresentation;
@@ -157,6 +156,10 @@ class DataLayout {
157156

158157
const PointerAlignElem &getPointerAlignElem(uint32_t AddressSpace) const;
159158

159+
// Struct type ABI and preferred alignments. The default spec is "a:8:64".
160+
Align StructABIAlignment = Align::Constant<1>();
161+
Align StructPrefAlignment = Align::Constant<8>();
162+
160163
// The StructType -> StructLayout map.
161164
mutable void *LayoutMap = nullptr;
162165

llvm/lib/IR/DataLayout.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ DataLayout::DataLayout(StringRef LayoutString) {
219219
DefaultGlobalsAddrSpace = 0;
220220
TheFunctionPtrAlignType = FunctionPtrAlignType::Independent;
221221
ManglingMode = MM_None;
222-
StructAlignment = LayoutAlignElem::get(Align(1), Align(8), 0);
223222

224223
// Default alignments
225224
for (const auto &[Kind, Layout] : DefaultAlignments) {
@@ -250,8 +249,9 @@ DataLayout &DataLayout::operator=(const DataLayout &Other) {
250249
IntAlignments = Other.IntAlignments;
251250
FloatAlignments = Other.FloatAlignments;
252251
VectorAlignments = Other.VectorAlignments;
253-
StructAlignment = Other.StructAlignment;
254252
Pointers = Other.Pointers;
253+
StructABIAlignment = Other.StructABIAlignment;
254+
StructPrefAlignment = Other.StructPrefAlignment;
255255
NonIntegralAddressSpaces = Other.NonIntegralAddressSpaces;
256256
return *this;
257257
}
@@ -271,7 +271,9 @@ bool DataLayout::operator==(const DataLayout &Other) const {
271271
IntAlignments == Other.IntAlignments &&
272272
FloatAlignments == Other.FloatAlignments &&
273273
VectorAlignments == Other.VectorAlignments &&
274-
StructAlignment == Other.StructAlignment && Pointers == Other.Pointers;
274+
Pointers == Other.Pointers &&
275+
StructABIAlignment == Other.StructABIAlignment &&
276+
StructPrefAlignment == Other.StructPrefAlignment;
275277
}
276278

277279
Expected<DataLayout> DataLayout::parse(StringRef LayoutDescription) {
@@ -628,8 +630,8 @@ Error DataLayout::setAlignment(AlignTypeEnum AlignType, Align ABIAlign,
628630
SmallVectorImpl<LayoutAlignElem> *Alignments;
629631
switch (AlignType) {
630632
case AGGREGATE_ALIGN:
631-
StructAlignment.ABIAlign = ABIAlign;
632-
StructAlignment.PrefAlign = PrefAlign;
633+
StructABIAlignment = ABIAlign;
634+
StructPrefAlignment = PrefAlign;
633635
return Error::success();
634636
case INTEGER_ALIGN:
635637
Alignments = &IntAlignments;
@@ -801,8 +803,7 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
801803

802804
// Get the layout annotation... which is lazily created on demand.
803805
const StructLayout *Layout = getStructLayout(cast<StructType>(Ty));
804-
const Align Align =
805-
abi_or_pref ? StructAlignment.ABIAlign : StructAlignment.PrefAlign;
806+
const Align Align = abi_or_pref ? StructABIAlignment : StructPrefAlignment;
806807
return std::max(Align, Layout->getAlignment());
807808
}
808809
case Type::IntegerTyID:

0 commit comments

Comments
 (0)