[llvm] r372558 - [Alignment][NFC] Switch DataLayout private members to llvm::Align

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 23 01:38:36 PDT 2019


Author: gchatelet
Date: Mon Sep 23 01:38:36 2019
New Revision: 372558

URL: http://llvm.org/viewvc/llvm-project?rev=372558&view=rev
Log:
[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

Modified:
    llvm/trunk/include/llvm/IR/DataLayout.h
    llvm/trunk/lib/IR/DataLayout.cpp

Modified: llvm/trunk/include/llvm/IR/DataLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DataLayout.h?rev=372558&r1=372557&r2=372558&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DataLayout.h (original)
+++ llvm/trunk/include/llvm/IR/DataLayout.h Mon Sep 23 01:38:36 2019
@@ -175,14 +175,14 @@ private:
 
   void setAlignment(AlignTypeEnum align_type, llvm::Align abi_align,
                     llvm::Align pref_align, uint32_t bit_width);
-  unsigned getAlignmentInfo(AlignTypeEnum align_type, uint32_t bit_width,
-                            bool ABIAlign, Type *Ty) const;
+  llvm::Align getAlignmentInfo(AlignTypeEnum align_type, uint32_t bit_width,
+                               bool ABIAlign, Type *Ty) const;
   void setPointerAlignment(uint32_t AddrSpace, llvm::Align ABIAlign,
                            llvm::Align PrefAlign, uint32_t TypeByteWidth,
                            uint32_t IndexWidth);
 
   /// Internal helper method that returns requested alignment for type.
-  unsigned getAlignment(Type *Ty, bool abi_or_pref) const;
+  llvm::Align getAlignment(Type *Ty, bool abi_or_pref) const;
 
   /// Parses a target data specification string. Assert if the string is
   /// malformed.
@@ -568,7 +568,7 @@ public:
 
   uint64_t getSizeInBits() const { return 8 * StructSize; }
 
-  unsigned getAlignment() const { return StructAlignment.value(); }
+  llvm::Align getAlignment() const { return StructAlignment; }
 
   /// Returns whether the struct has padding or not between its fields.
   /// NB: Padding in nested element is not taken into account.

Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=372558&r1=372557&r2=372558&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Mon Sep 23 01:38:36 2019
@@ -542,23 +542,23 @@ void DataLayout::setPointerAlignment(uin
 
 /// getAlignmentInfo - Return the alignment (either ABI if ABIInfo = true or
 /// preferred if ABIInfo = false) the layout wants for the specified datatype.
-unsigned DataLayout::getAlignmentInfo(AlignTypeEnum AlignType,
-                                      uint32_t BitWidth, bool ABIInfo,
-                                      Type *Ty) const {
+llvm::Align DataLayout::getAlignmentInfo(AlignTypeEnum AlignType,
+                                         uint32_t BitWidth, bool ABIInfo,
+                                         Type *Ty) const {
   AlignmentsTy::const_iterator I = findAlignmentLowerBound(AlignType, BitWidth);
   // See if we found an exact match. Of if we are looking for an integer type,
   // but don't have an exact match take the next largest integer. This is where
   // the lower_bound will point to when it fails an exact match.
   if (I != Alignments.end() && I->AlignType == (unsigned)AlignType &&
       (I->TypeBitWidth == BitWidth || AlignType == INTEGER_ALIGN))
-    return (ABIInfo ? I->ABIAlign : I->PrefAlign).value();
+    return ABIInfo ? I->ABIAlign : I->PrefAlign;
 
   if (AlignType == INTEGER_ALIGN) {
     // If we didn't have a larger value try the largest value we have.
     if (I != Alignments.begin()) {
       --I; // Go to the previous entry and see if its an integer.
       if (I->AlignType == INTEGER_ALIGN)
-        return (ABIInfo ? I->ABIAlign : I->PrefAlign).value();
+        return ABIInfo ? I->ABIAlign : I->PrefAlign;
     }
   } else if (AlignType == VECTOR_ALIGN) {
     // By default, use natural alignment for vector types. This is consistent
@@ -566,7 +566,7 @@ unsigned DataLayout::getAlignmentInfo(Al
     unsigned Align = getTypeAllocSize(cast<VectorType>(Ty)->getElementType());
     Align *= cast<VectorType>(Ty)->getNumElements();
     Align = PowerOf2Ceil(Align);
-    return Align;
+    return llvm::Align(Align);
    }
 
   // If we still couldn't find a reasonable default alignment, fall back
@@ -577,7 +577,7 @@ unsigned DataLayout::getAlignmentInfo(Al
   // layout.
   unsigned Align = getTypeStoreSize(Ty);
   Align = PowerOf2Ceil(Align);
-  return Align;
+  return llvm::Align(Align);
 }
 
 namespace {
@@ -704,21 +704,19 @@ unsigned DataLayout::getIndexTypeSizeInB
   Get the ABI (\a abi_or_pref == true) or preferred alignment (\a abi_or_pref
   == false) for the requested type \a Ty.
  */
-unsigned DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
+llvm::Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
   AlignTypeEnum AlignType;
 
   assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
   switch (Ty->getTypeID()) {
   // Early escape for the non-numeric types.
   case Type::LabelTyID:
-    return (abi_or_pref
-            ? getPointerABIAlignment(0)
-            : getPointerPrefAlignment(0));
+    return llvm::Align(abi_or_pref ? getPointerABIAlignment(0)
+                                   : getPointerPrefAlignment(0));
   case Type::PointerTyID: {
     unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
-    return (abi_or_pref
-            ? getPointerABIAlignment(AS)
-            : getPointerPrefAlignment(AS));
+    return llvm::Align(abi_or_pref ? getPointerABIAlignment(AS)
+                                   : getPointerPrefAlignment(AS));
     }
   case Type::ArrayTyID:
     return getAlignment(cast<ArrayType>(Ty)->getElementType(), abi_or_pref);
@@ -726,11 +724,12 @@ unsigned DataLayout::getAlignment(Type *
   case Type::StructTyID: {
     // Packed structure types always have an ABI alignment of one.
     if (cast<StructType>(Ty)->isPacked() && abi_or_pref)
-      return 1;
+      return llvm::Align::None();
 
     // Get the layout annotation... which is lazily created on demand.
     const StructLayout *Layout = getStructLayout(cast<StructType>(Ty));
-    unsigned Align = getAlignmentInfo(AGGREGATE_ALIGN, 0, abi_or_pref, Ty);
+    const llvm::Align Align =
+        getAlignmentInfo(AGGREGATE_ALIGN, 0, abi_or_pref, Ty);
     return std::max(Align, Layout->getAlignment());
   }
   case Type::IntegerTyID:
@@ -758,17 +757,17 @@ unsigned DataLayout::getAlignment(Type *
 }
 
 unsigned DataLayout::getABITypeAlignment(Type *Ty) const {
-  return getAlignment(Ty, true);
+  return getAlignment(Ty, true).value();
 }
 
 /// getABIIntegerTypeAlignment - Return the minimum ABI-required alignment for
 /// an integer type of the specified bitwidth.
 unsigned DataLayout::getABIIntegerTypeAlignment(unsigned BitWidth) const {
-  return getAlignmentInfo(INTEGER_ALIGN, BitWidth, true, nullptr);
+  return getAlignmentInfo(INTEGER_ALIGN, BitWidth, true, nullptr).value();
 }
 
 unsigned DataLayout::getPrefTypeAlignment(Type *Ty) const {
-  return getAlignment(Ty, false);
+  return getAlignment(Ty, false).value();
 }
 
 IntegerType *DataLayout::getIntPtrType(LLVMContext &C,




More information about the llvm-commits mailing list