[llvm] r177632 - Hoist the definition of getTypeSizeInBits to be inlinable and in the
Duncan Sands
baldrick at free.fr
Thu Mar 21 06:14:29 PDT 2013
Hi Chandler,
On 21/03/13 10:52, Chandler Carruth wrote:
> Author: chandlerc
> Date: Thu Mar 21 04:52:22 2013
> New Revision: 177632
>
> URL: http://llvm.org/viewvc/llvm-project?rev=177632&view=rev
> Log:
> Hoist the definition of getTypeSizeInBits to be inlinable and in the
> header.
> --- llvm/trunk/include/llvm/IR/DataLayout.h (original)
> +++ llvm/trunk/include/llvm/IR/DataLayout.h Thu Mar 21 04:52:22 2013
> @@ -423,6 +425,49 @@ private:
> StructLayout(StructType *ST, const DataLayout &TD);
> };
>
> +
> +// The implementation of this method is provided inline as it is particularly
> +// well suited to constant folding when called on a specific Type subclass.
> +inline uint64_t DataLayout::getTypeSizeInBits(Type *Ty) const {
> + assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");
> + switch (Ty->getTypeID()) {
> + case Type::LabelTyID:
> + return getPointerSizeInBits(0);
> + case Type::PointerTyID:
> + return getPointerSizeInBits(cast<PointerType>(Ty)->getAddressSpace());
> + case Type::ArrayTyID: {
> + ArrayType *ATy = cast<ArrayType>(Ty);
> + return ATy->getNumElements() *
> + getTypeAllocSizeInBits(ATy->getElementType());
> + }
> + case Type::StructTyID:
> + // Get the layout annotation... which is lazily created on demand.
> + return getStructLayout(cast<StructType>(Ty))->getSizeInBits();
> + case Type::IntegerTyID:
> + return cast<IntegerType>(Ty)->getBitWidth();
> + case Type::HalfTyID:
> + return 16;
> + case Type::FloatTyID:
> + return 32;
> + case Type::DoubleTyID:
> + case Type::X86_MMXTyID:
> + return 64;
> + case Type::PPC_FP128TyID:
> + case Type::FP128TyID:
> + return 128;
> + // In memory objects this is always aligned to a higher boundary, but
> + // only 80 bits contain information.
something funny happened to the comment indentation here.
Ciao, Duncan.
More information about the llvm-commits
mailing list