summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/DataLayout.cpp
diff options
context:
space:
mode:
authorMicah Villmow <villmow@gmail.com>2012-10-24 15:52:52 +0000
committerMicah Villmow <villmow@gmail.com>2012-10-24 15:52:52 +0000
commit12d9127833b08733090eabb2b55d1184db8da395 (patch)
tree7cd4873f9416a670b3bc2b3e92e02da1d67d1854 /llvm/lib/VMCore/DataLayout.cpp
parentc6317dbf5ed134f3dc54a92848707831f8787fb2 (diff)
downloadbcm5719-llvm-12d9127833b08733090eabb2b55d1184db8da395.tar.gz
bcm5719-llvm-12d9127833b08733090eabb2b55d1184db8da395.zip
Add in support for getIntPtrType to get the pointer type based on the address space.
This checkin also adds in some tests that utilize these paths and updates some of the clients. llvm-svn: 166578
Diffstat (limited to 'llvm/lib/VMCore/DataLayout.cpp')
-rw-r--r--llvm/lib/VMCore/DataLayout.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/llvm/lib/VMCore/DataLayout.cpp b/llvm/lib/VMCore/DataLayout.cpp
index e6994be257c..8d7a8e267cc 100644
--- a/llvm/lib/VMCore/DataLayout.cpp
+++ b/llvm/lib/VMCore/DataLayout.cpp
@@ -660,13 +660,32 @@ unsigned DataLayout::getPreferredTypeAlignmentShift(Type *Ty) const {
return Log2_32(Align);
}
-/// getIntPtrType - Return an unsigned integer type that is the same size or
-/// greater to the host pointer size.
+/// getIntPtrType - Return an integer type that is the same size or
+/// greater to the pointer size for the address space.
IntegerType *DataLayout::getIntPtrType(LLVMContext &C,
unsigned AddressSpace) const {
return IntegerType::get(C, getPointerSizeInBits(AddressSpace));
}
+/// getIntPtrType - Return an integer type that is the same size or
+/// greater to the pointer size of the specific PointerType.
+IntegerType *DataLayout::getIntPtrType(Type *Ty) const {
+ LLVMContext &C = Ty->getContext();
+ // For pointers, we return the size for the specific address space.
+ if (Ty->isPointerTy()) return IntegerType::get(C, getTypeSizeInBits(Ty));
+ // For vector of pointers, we return the size of the address space
+ // of the pointer type.
+ if (Ty->isVectorTy() && cast<VectorType>(Ty)->getElementType()->isPointerTy())
+ return IntegerType::get(C,
+ getTypeSizeInBits(cast<VectorType>(Ty)->getElementType()));
+ // Otherwise return the address space for the default address space.
+ // An example of this occuring is that you want to get the IntPtr
+ // for all of the arguments in a function. However, the IntPtr
+ // for a non-pointer type cannot be determined by the type, so
+ // the default value is used.
+ return getIntPtrType(C, 0);
+}
+
uint64_t DataLayout::getIndexedOffset(Type *ptrTy,
ArrayRef<Value *> Indices) const {
OpenPOWER on IntegriCloud