Re-add DataLayout pointer size convenience functions.
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Fri, 26 Jul 2013 17:37:20 +0000 (17:37 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Fri, 26 Jul 2013 17:37:20 +0000 (17:37 +0000)
These were reverted in r167222 along with the rest
of the last different address space pointer size attempt.
These will be used in later commits.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187223 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/DataLayout.h
lib/IR/DataLayout.cpp

index c15591b6d25f0e3531ed09dfe001820fc11f4c41..269edeb9f36c6ee37ca3d28701a1f0e4a92e9b43 100644 (file)
@@ -271,6 +271,18 @@ public:
   unsigned getPointerSizeInBits(unsigned AS = 0) const {
     return getPointerSize(AS) * 8;
   }
+
+  /// 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.  This should only be called with a pointer or
+  /// vector of pointers.
+  unsigned getPointerTypeSizeInBits(Type *) const;
+
+  unsigned getPointerTypeSize(Type *Ty) const {
+    return getPointerTypeSizeInBits(Ty) / 8;
+  }
+
   /// Size examples:
   ///
   /// Type        SizeInBits  StoreSizeInBits  AllocSizeInBits[*]
index adb2d7a62ac4d43ccb610e84de1d1cd6075256b1..d1096d74242b31b115eb9ae8eccca566a5dd413d 100644 (file)
@@ -507,6 +507,16 @@ std::string DataLayout::getStringRepresentation() const {
   return OS.str();
 }
 
+unsigned DataLayout::getPointerTypeSizeInBits(Type *Ty) const {
+  assert(Ty->isPtrOrPtrVectorTy() &&
+         "This should only be called with a pointer or pointer vector type");
+
+  if (Ty->isPointerTy())
+    return getTypeSizeInBits(Ty);
+
+  Type *EleTy = cast<VectorType>(Ty)->getElementType();
+  return getTypeSizeInBits(EleTy);
+}
 
 /*!
   \param abi_or_pref Flag that determines which alignment is returned. true