[PATCH] Re-add DataLayout convenience functions for getting pointer size
Matt Arsenault
Matthew.Arsenault at amd.com
Mon Jul 22 21:40:14 PDT 2013
Fix stupid behavior of returning address space 0 pointer size for non-pointer types. Instead, assert that it's a pointer or vector or pointers.
http://llvm-reviews.chandlerc.com/D1197
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1197?vs=2958&id=2964#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,24 @@
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 getPointerTypeSizeInBits(Value *V) const;
+
+ unsigned getPointerTypeSize(Type *Ty) const {
+ return getPointerTypeSizeInBits(Ty) / 8;
+ }
+
+ unsigned getPointerTypeSize(Value *V) const {
+ return getPointerTypeSizeInBits(V) / 8;
+ }
+
/// Size examples:
///
/// Type SizeInBits StoreSizeInBits AllocSizeInBits[*]
Index: lib/IR/DataLayout.cpp
===================================================================
--- lib/IR/DataLayout.cpp
+++ lib/IR/DataLayout.cpp
@@ -507,6 +507,20 @@
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);
+}
+
+unsigned DataLayout::getPointerTypeSizeInBits(Value *V) const {
+ return getPointerTypeSizeInBits(V->getType());
+}
/*!
\param abi_or_pref Flag that determines which alignment is returned. true
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1197.2.patch
Type: text/x-patch
Size: 1790 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130722/5d5f9b0d/attachment.bin>
More information about the llvm-commits
mailing list