From: Dale Johannesen Date: Mon, 1 Oct 2007 16:03:14 +0000 (+0000) Subject: Add getABITypeSize, getABITypeSizeInBits X-Git-Tag: android-x86-6.0-r1~1003^2~32574 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=3b5b4cd1a50e3fe8748a8626cca3c643f5681f5a;p=android-x86%2Fexternal-llvm.git Add getABITypeSize, getABITypeSizeInBits git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42488 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Target/TargetData.h b/include/llvm/Target/TargetData.h index f2e55f10e11..026749f3e09 100644 --- a/include/llvm/Target/TargetData.h +++ b/include/llvm/Target/TargetData.h @@ -159,10 +159,23 @@ public: /// type. uint64_t getTypeSize(const Type *Ty) const; + /// getABITypeSize - Return the number of bytes allocated for the specified + /// type when used as an element in a larger object, including alignment + /// padding. + uint64_t getABITypeSize(const Type *Ty) const { + unsigned char Align = getABITypeAlignment(Ty); + return (getTypeSize(Ty) + Align - 1)/Align*Align; + } + /// getTypeSizeInBits - Return the number of bits necessary to hold the /// specified type. uint64_t getTypeSizeInBits(const Type* Ty) const; + /// getABITypeSizeInBits - Return the number of bytes allocated for the + /// specified type when used as an element in a larger object, including + /// alignment padding. + uint64_t getABITypeSizeInBits(const Type* Ty) const; + /// getABITypeAlignment - Return the minimum ABI-required alignment for the /// specified type. unsigned char getABITypeAlignment(const Type *Ty) const; diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index 30284263aec..0bdb23b5b74 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -471,7 +471,12 @@ uint64_t TargetData::getTypeSizeInBits(const Type *Ty) const { return getTypeSize(Ty) * 8; } - +uint64_t TargetData::getABITypeSizeInBits(const Type *Ty) const { + if (Ty->isInteger()) + return cast(Ty)->getBitWidth(); + else + return getABITypeSize(Ty) * 8; +} /*! \param abi_or_pref Flag that determines which alignment is returned. true returns the ABI alignment, false returns the preferred alignment.