Skip to content

Commit

Permalink
[DataLayout] Split StructAlignment into two fields (NFC) (#103700)
Browse files Browse the repository at this point in the history
Aggregate type specification doesn't have the size component.
Don't abuse LayoutAlignElem to avoid confusion.
  • Loading branch information
s-barannikov authored Aug 14, 2024
1 parent fa658ac commit 8eadf21
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 4 additions & 1 deletion llvm/include/llvm/IR/DataLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
15 changes: 8 additions & 7 deletions llvm/lib/IR/DataLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 8eadf21

Please sign in to comment.