[PATCH] Re-add DataLayout convenience functions for getting pointer size
Matt Arsenault
Matthew.Arsenault at amd.com
Mon Jul 22 18:00:14 PDT 2013
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.
http://llvm-reviews.chandlerc.com/D1197
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,27 @@
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.
+ /// Otherwise the type sizeof a default pointer is returned.
+ unsigned getPointerTypeSizeInBits(Type *) const;
+
+ unsigned getPointerTypeSizeInBits(Value *V) const {
+ return getPointerTypeSizeInBits(V->getType());
+ }
+
+ 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,18 @@
return OS.str();
}
+unsigned DataLayout::getPointerTypeSizeInBits(Type *Ty) const {
+ if (Ty->isPointerTy())
+ return getTypeSizeInBits(Ty);
+
+ if (VectorType *VT = dyn_cast<VectorType>(Ty)) {
+ Type *EleTy = VT->getElementType();
+ if (EleTy->isPointerTy())
+ return getTypeSizeInBits(EleTy);
+ }
+
+ return getPointerSizeInBits(0);
+}
/*!
\param abi_or_pref Flag that determines which alignment is returned. true
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1197.1.patch
Type: text/x-patch
Size: 1719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130722/5d8f202f/attachment.bin>
More information about the llvm-commits
mailing list