[llvm-commits] [PATCH] Cleanup DataLayout

Micah Villmow villmow at gmail.com
Fri Oct 26 09:56:31 PDT 2012


Hi chandlerc,

This is a patch to cleanup the getPointerTypeSizeInBits API.

http://llvm-reviews.chandlerc.com/D84

Files:
  include/llvm/DataLayout.h
  lib/VMCore/DataLayout.cpp

Index: include/llvm/DataLayout.h
===================================================================
--- include/llvm/DataLayout.h
+++ include/llvm/DataLayout.h
@@ -238,6 +238,7 @@
     }
     return val->second.ABIAlign;
   }
+
   /// Return target's alignment for stack-based pointers
   unsigned getPointerPrefAlignment(unsigned AS) const {
     DenseMap<unsigned, PointerAlignElem>::const_iterator val = Pointers.find(AS);
@@ -246,6 +247,7 @@
     }
     return val->second.PrefAlign;
   }
+
   /// Layout pointer size
   unsigned getPointerSize(unsigned AS)          const {
     DenseMap<unsigned, PointerAlignElem>::const_iterator val = Pointers.find(AS);
@@ -254,6 +256,7 @@
     }
     return val->second.TypeBitWidth;
   }
+
   /// Layout pointer size, in bits
   unsigned getPointerSizeInBits(unsigned AS)    const {
     DenseMap<unsigned, PointerAlignElem>::const_iterator val = Pointers.find(AS);
@@ -262,12 +265,15 @@
     }
     return 8*val->second.TypeBitWidth;
   }
-  /// Layout pointer size, in bits, based on the type.
+
+  /// \brief Layout pointer size, in bits, based on the type.
+  ///
   /// If this function is called with a pointer type, then
   /// the type size of the pointer is returned.
   /// If this function is called with a vector of pointers,
   /// then the type size of the pointer is returned.
-  /// Otherwise the type sizeo f a default pointer is returned.
+  ///
+  /// \returns Returns the size in bits of the pointer type.
   unsigned getPointerTypeSizeInBits(Type* Ty)    const;
 
   /// Size examples:
Index: lib/VMCore/DataLayout.cpp
===================================================================
--- lib/VMCore/DataLayout.cpp
+++ lib/VMCore/DataLayout.cpp
@@ -524,13 +524,13 @@
   return OS.str();
 }
 
-unsigned DataLayout::getPointerTypeSizeInBits(Type *Ty) const
-{
-    if (Ty->isPointerTy()) return getTypeSizeInBits(Ty);
-    if (Ty->isVectorTy()
-        && cast<VectorType>(Ty)->getElementType()->isPointerTy())
-      return getTypeSizeInBits(cast<VectorType>(Ty)->getElementType());
-    return getPointerSizeInBits(0);
+unsigned DataLayout::getPointerTypeSizeInBits(Type *Ty) const {
+  // If the type is a vector, then use the address
+  // space of the element pointer type.
+  if (Ty->isVectorTy()) Ty = Ty->getVectorElementType();
+
+  // Return the size of the pointer type.
+  return getPointerSizeInBits(Ty->getPointerAddressSpace());
 }
 
 uint64_t DataLayout::getTypeSizeInBits(Type *Ty) const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84.1.patch
Type: text/x-patch
Size: 2473 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121026/1993cc9f/attachment.bin>


More information about the llvm-commits mailing list