diff options
-rw-r--r-- | include/llvm/Target/TargetData.h | 4 | ||||
-rw-r--r-- | lib/Target/TargetData.cpp | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/include/llvm/Target/TargetData.h b/include/llvm/Target/TargetData.h index b045bef616..71db27ca73 100644 --- a/include/llvm/Target/TargetData.h +++ b/include/llvm/Target/TargetData.h @@ -221,6 +221,10 @@ public: /// uint64_t getTypeSize(const Type *Ty) const; + /// getTypeSizeInBits - Return the number of bytes necessary to hold the + /// specified type. + uint64_t getTypeSizeInBits(const Type* Ty) const; + /// getTypeAlignmentABI - Return the minimum ABI-required alignment for the /// specified type. unsigned char getTypeAlignmentABI(const Type *Ty) const; diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index 3cfdd40ddd..f50e6c3bd3 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -426,6 +426,16 @@ uint64_t TargetData::getTypeSize(const Type *Ty) const { return Size; } +uint64_t TargetData::getTypeSizeInBits(const Type *Ty) const { + if (Ty->isInteger()) + return cast<IntegerType>(Ty)->getBitWidth(); + + uint64_t Size; + unsigned char Align; + getTypeInfoABI(Ty, this, Size, Align); + return Size * 8; +} + unsigned char TargetData::getTypeAlignmentABI(const Type *Ty) const { uint64_t Size; unsigned char Align; |