[llvm-commits] [PATCH] Cleanup DataLayout
Duncan Sands
baldrick at free.fr
Fri Oct 26 10:10:22 PDT 2012
Hi Micah, I just did something similar in my own tree but masses of tests
fail because I put an assertion that the type actually is a pointer type
(or vector of pointer type), and unfortunately random non pointer types are
being passed in all over the place. So I don't think you addressed a core
issue: that only pointer types have address spaces, and trying to use any of
these routines on a non pointer type should assert, and not do something
meaningless (like use address space 0).
Ciao, Duncan.
On 26/10/12 18:56, Micah Villmow wrote:
> Hi chandlerc,
>
> This is a patch to cleanup the getPointerTypeSizeInBits API.
>
> http://llvm-reviews.chandlerc.com/D84
>
> Files:
> include/llvm/DataLayout.h
> lib/VMCore/DataLayout.cpp
>
> Index: include/llvm/DataLayout.h
> ===================================================================
> --- include/llvm/DataLayout.h
> +++ include/llvm/DataLayout.h
> @@ -238,6 +238,7 @@
> }
> return val->second.ABIAlign;
> }
> +
> /// Return target's alignment for stack-based pointers
> unsigned getPointerPrefAlignment(unsigned AS) const {
> DenseMap<unsigned, PointerAlignElem>::const_iterator val = Pointers.find(AS);
> @@ -246,6 +247,7 @@
> }
> return val->second.PrefAlign;
> }
> +
> /// Layout pointer size
> unsigned getPointerSize(unsigned AS) const {
> DenseMap<unsigned, PointerAlignElem>::const_iterator val = Pointers.find(AS);
> @@ -254,6 +256,7 @@
> }
> return val->second.TypeBitWidth;
> }
> +
> /// Layout pointer size, in bits
> unsigned getPointerSizeInBits(unsigned AS) const {
> DenseMap<unsigned, PointerAlignElem>::const_iterator val = Pointers.find(AS);
> @@ -262,12 +265,15 @@
> }
> return 8*val->second.TypeBitWidth;
> }
> - /// Layout pointer size, in bits, based on the type.
> +
> + /// \brief Layout pointer size, in bits, based on the type.
> + ///
> /// If this function is called with a pointer type, then
> /// the type size of the pointer is returned.
> /// If this function is called with a vector of pointers,
> /// then the type size of the pointer is returned.
> - /// Otherwise the type sizeo f a default pointer is returned.
> + ///
> + /// \returns Returns the size in bits of the pointer type.
> unsigned getPointerTypeSizeInBits(Type* Ty) const;
>
> /// Size examples:
> Index: lib/VMCore/DataLayout.cpp
> ===================================================================
> --- lib/VMCore/DataLayout.cpp
> +++ lib/VMCore/DataLayout.cpp
> @@ -524,13 +524,13 @@
> return OS.str();
> }
>
> -unsigned DataLayout::getPointerTypeSizeInBits(Type *Ty) const
> -{
> - if (Ty->isPointerTy()) return getTypeSizeInBits(Ty);
> - if (Ty->isVectorTy()
> - && cast<VectorType>(Ty)->getElementType()->isPointerTy())
> - return getTypeSizeInBits(cast<VectorType>(Ty)->getElementType());
> - return getPointerSizeInBits(0);
> +unsigned DataLayout::getPointerTypeSizeInBits(Type *Ty) const {
> + // If the type is a vector, then use the address
> + // space of the element pointer type.
> + if (Ty->isVectorTy()) Ty = Ty->getVectorElementType();
> +
> + // Return the size of the pointer type.
> + return getPointerSizeInBits(Ty->getPointerAddressSpace());
> }
>
> uint64_t DataLayout::getTypeSizeInBits(Type *Ty) const {
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list