Implement a getTypeSizeInBits method. This helps in transforms that want
authorReid Spencer <rspencer@reidspencer.com>
Sat, 20 Jan 2007 23:32:04 +0000 (23:32 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Sat, 20 Jan 2007 23:32:04 +0000 (23:32 +0000)
to ensure the bit size of a type is identical before proceeding.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33413 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetData.h
lib/Target/TargetData.cpp

index b045bef616f71250fd443c228e044685d855478d..71db27ca73a0b336a918edc4743f3cd3d59ebbce 100644 (file)
@@ -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;
index 3cfdd40ddd407c42515f9479d29bd8161e0f8448..f50e6c3bd398e44de99399b41feb90b3b8aee15f 100644 (file)
@@ -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;