Skip to content

Commit 046a16b

Browse files
committedSep 23, 2019
[Alignment][NFC] Switch DataLayout private members to llvm::Align
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67836 llvm-svn: 372558
1 parent 566127e commit 046a16b

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed
 

‎llvm/include/llvm/IR/DataLayout.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ class DataLayout {
175175

176176
void setAlignment(AlignTypeEnum align_type, llvm::Align abi_align,
177177
llvm::Align pref_align, uint32_t bit_width);
178-
unsigned getAlignmentInfo(AlignTypeEnum align_type, uint32_t bit_width,
179-
bool ABIAlign, Type *Ty) const;
178+
llvm::Align getAlignmentInfo(AlignTypeEnum align_type, uint32_t bit_width,
179+
bool ABIAlign, Type *Ty) const;
180180
void setPointerAlignment(uint32_t AddrSpace, llvm::Align ABIAlign,
181181
llvm::Align PrefAlign, uint32_t TypeByteWidth,
182182
uint32_t IndexWidth);
183183

184184
/// Internal helper method that returns requested alignment for type.
185-
unsigned getAlignment(Type *Ty, bool abi_or_pref) const;
185+
llvm::Align getAlignment(Type *Ty, bool abi_or_pref) const;
186186

187187
/// Parses a target data specification string. Assert if the string is
188188
/// malformed.
@@ -568,7 +568,7 @@ class StructLayout {
568568

569569
uint64_t getSizeInBits() const { return 8 * StructSize; }
570570

571-
unsigned getAlignment() const { return StructAlignment.value(); }
571+
llvm::Align getAlignment() const { return StructAlignment; }
572572

573573
/// Returns whether the struct has padding or not between its fields.
574574
/// NB: Padding in nested element is not taken into account.

‎llvm/lib/IR/DataLayout.cpp

+18-19
Original file line numberDiff line numberDiff line change
@@ -542,31 +542,31 @@ void DataLayout::setPointerAlignment(uint32_t AddrSpace, llvm::Align ABIAlign,
542542

543543
/// getAlignmentInfo - Return the alignment (either ABI if ABIInfo = true or
544544
/// preferred if ABIInfo = false) the layout wants for the specified datatype.
545-
unsigned DataLayout::getAlignmentInfo(AlignTypeEnum AlignType,
546-
uint32_t BitWidth, bool ABIInfo,
547-
Type *Ty) const {
545+
llvm::Align DataLayout::getAlignmentInfo(AlignTypeEnum AlignType,
546+
uint32_t BitWidth, bool ABIInfo,
547+
Type *Ty) const {
548548
AlignmentsTy::const_iterator I = findAlignmentLowerBound(AlignType, BitWidth);
549549
// See if we found an exact match. Of if we are looking for an integer type,
550550
// but don't have an exact match take the next largest integer. This is where
551551
// the lower_bound will point to when it fails an exact match.
552552
if (I != Alignments.end() && I->AlignType == (unsigned)AlignType &&
553553
(I->TypeBitWidth == BitWidth || AlignType == INTEGER_ALIGN))
554-
return (ABIInfo ? I->ABIAlign : I->PrefAlign).value();
554+
return ABIInfo ? I->ABIAlign : I->PrefAlign;
555555

556556
if (AlignType == INTEGER_ALIGN) {
557557
// If we didn't have a larger value try the largest value we have.
558558
if (I != Alignments.begin()) {
559559
--I; // Go to the previous entry and see if its an integer.
560560
if (I->AlignType == INTEGER_ALIGN)
561-
return (ABIInfo ? I->ABIAlign : I->PrefAlign).value();
561+
return ABIInfo ? I->ABIAlign : I->PrefAlign;
562562
}
563563
} else if (AlignType == VECTOR_ALIGN) {
564564
// By default, use natural alignment for vector types. This is consistent
565565
// with what clang and llvm-gcc do.
566566
unsigned Align = getTypeAllocSize(cast<VectorType>(Ty)->getElementType());
567567
Align *= cast<VectorType>(Ty)->getNumElements();
568568
Align = PowerOf2Ceil(Align);
569-
return Align;
569+
return llvm::Align(Align);
570570
}
571571

572572
// If we still couldn't find a reasonable default alignment, fall back
@@ -577,7 +577,7 @@ unsigned DataLayout::getAlignmentInfo(AlignTypeEnum AlignType,
577577
// layout.
578578
unsigned Align = getTypeStoreSize(Ty);
579579
Align = PowerOf2Ceil(Align);
580-
return Align;
580+
return llvm::Align(Align);
581581
}
582582

583583
namespace {
@@ -704,33 +704,32 @@ unsigned DataLayout::getIndexTypeSizeInBits(Type *Ty) const {
704704
Get the ABI (\a abi_or_pref == true) or preferred alignment (\a abi_or_pref
705705
== false) for the requested type \a Ty.
706706
*/
707-
unsigned DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
707+
llvm::Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
708708
AlignTypeEnum AlignType;
709709

710710
assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
711711
switch (Ty->getTypeID()) {
712712
// Early escape for the non-numeric types.
713713
case Type::LabelTyID:
714-
return (abi_or_pref
715-
? getPointerABIAlignment(0)
716-
: getPointerPrefAlignment(0));
714+
return llvm::Align(abi_or_pref ? getPointerABIAlignment(0)
715+
: getPointerPrefAlignment(0));
717716
case Type::PointerTyID: {
718717
unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
719-
return (abi_or_pref
720-
? getPointerABIAlignment(AS)
721-
: getPointerPrefAlignment(AS));
718+
return llvm::Align(abi_or_pref ? getPointerABIAlignment(AS)
719+
: getPointerPrefAlignment(AS));
722720
}
723721
case Type::ArrayTyID:
724722
return getAlignment(cast<ArrayType>(Ty)->getElementType(), abi_or_pref);
725723

726724
case Type::StructTyID: {
727725
// Packed structure types always have an ABI alignment of one.
728726
if (cast<StructType>(Ty)->isPacked() && abi_or_pref)
729-
return 1;
727+
return llvm::Align::None();
730728

731729
// Get the layout annotation... which is lazily created on demand.
732730
const StructLayout *Layout = getStructLayout(cast<StructType>(Ty));
733-
unsigned Align = getAlignmentInfo(AGGREGATE_ALIGN, 0, abi_or_pref, Ty);
731+
const llvm::Align Align =
732+
getAlignmentInfo(AGGREGATE_ALIGN, 0, abi_or_pref, Ty);
734733
return std::max(Align, Layout->getAlignment());
735734
}
736735
case Type::IntegerTyID:
@@ -758,17 +757,17 @@ unsigned DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
758757
}
759758

760759
unsigned DataLayout::getABITypeAlignment(Type *Ty) const {
761-
return getAlignment(Ty, true);
760+
return getAlignment(Ty, true).value();
762761
}
763762

764763
/// getABIIntegerTypeAlignment - Return the minimum ABI-required alignment for
765764
/// an integer type of the specified bitwidth.
766765
unsigned DataLayout::getABIIntegerTypeAlignment(unsigned BitWidth) const {
767-
return getAlignmentInfo(INTEGER_ALIGN, BitWidth, true, nullptr);
766+
return getAlignmentInfo(INTEGER_ALIGN, BitWidth, true, nullptr).value();
768767
}
769768

770769
unsigned DataLayout::getPrefTypeAlignment(Type *Ty) const {
771-
return getAlignment(Ty, false);
770+
return getAlignment(Ty, false).value();
772771
}
773772

774773
IntegerType *DataLayout::getIntPtrType(LLVMContext &C,

0 commit comments

Comments
 (0)
Please sign in to comment.