Skip to content

Commit 6f4be90

Browse files
committed
Re-add DataLayout pointer size convenience functions.
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. llvm-svn: 187223
1 parent 8ea2e40 commit 6f4be90

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

llvm/include/llvm/IR/DataLayout.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ class DataLayout : public ImmutablePass {
271271
unsigned getPointerSizeInBits(unsigned AS = 0) const {
272272
return getPointerSize(AS) * 8;
273273
}
274+
275+
/// Layout pointer size, in bits, based on the type. If this function is
276+
/// called with a pointer type, then the type size of the pointer is returned.
277+
/// If this function is called with a vector of pointers, then the type size
278+
/// of the pointer is returned. This should only be called with a pointer or
279+
/// vector of pointers.
280+
unsigned getPointerTypeSizeInBits(Type *) const;
281+
282+
unsigned getPointerTypeSize(Type *Ty) const {
283+
return getPointerTypeSizeInBits(Ty) / 8;
284+
}
285+
274286
/// Size examples:
275287
///
276288
/// Type SizeInBits StoreSizeInBits AllocSizeInBits[*]

llvm/lib/IR/DataLayout.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,16 @@ std::string DataLayout::getStringRepresentation() const {
507507
return OS.str();
508508
}
509509

510+
unsigned DataLayout::getPointerTypeSizeInBits(Type *Ty) const {
511+
assert(Ty->isPtrOrPtrVectorTy() &&
512+
"This should only be called with a pointer or pointer vector type");
513+
514+
if (Ty->isPointerTy())
515+
return getTypeSizeInBits(Ty);
516+
517+
Type *EleTy = cast<VectorType>(Ty)->getElementType();
518+
return getTypeSizeInBits(EleTy);
519+
}
510520

511521
/*!
512522
\param abi_or_pref Flag that determines which alignment is returned. true

0 commit comments

Comments
 (0)