[PATCH] Re-add DataLayout convenience functions for getting pointer size

Matt Arsenault Matthew.Arsenault at amd.com
Thu Jul 25 15:42:50 PDT 2013


  Remove version that takes a Value*

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1197?vs=2964&id=3010#toc

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

Index: include/llvm/IR/DataLayout.h
===================================================================
--- include/llvm/IR/DataLayout.h
+++ include/llvm/IR/DataLayout.h
@@ -271,6 +271,18 @@
   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: lib/IR/DataLayout.cpp
===================================================================
--- lib/IR/DataLayout.cpp
+++ lib/IR/DataLayout.cpp
@@ -507,6 +507,16 @@
   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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1197.3.patch
Type: text/x-patch
Size: 1513 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130725/0bd097b4/attachment.bin>


More information about the llvm-commits mailing list