[PATCH] Re-add DataLayout convenience functions for getting pointer size

Eli Friedman eli.friedman at gmail.com
Mon Jul 22 18:48:03 PDT 2013


Also, I'm not sure I really like the general design of these APIs;
what is the benefit of using them over getTypeSizeInBits()?

-Eli

On Mon, Jul 22, 2013 at 6:00 PM, Matt Arsenault
<Matthew.Arsenault at amd.com> wrote:
> These were reverted in r167222 along with the rest of the last different address space pointer size attempt. These will be used in later commits.
>
> http://llvm-reviews.chandlerc.com/D1197
>
> Files:
>   include/llvm/IR/DataLayout.h
>   lib/IR/DataLayout.cpp
>
> Index: include/llvm/IR/DataLayout.h
> ===================================================================
> --- include/llvm/IR/DataLayout.h
> +++ include/llvm/IR/DataLayout.h
> @@ -271,6 +271,27 @@
>    unsigned getPointerSizeInBits(unsigned AS = 0) const {
>      return getPointerSize(AS) * 8;
>    }
> +
> +  /// 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 sizeof a default pointer is returned.
> +  unsigned getPointerTypeSizeInBits(Type *) const;
> +
> +  unsigned getPointerTypeSizeInBits(Value *V) const {
> +    return getPointerTypeSizeInBits(V->getType());
> +  }
> +
> +  unsigned getPointerTypeSize(Type *Ty) const {
> +    return getPointerTypeSizeInBits(Ty) / 8;
> +  }
> +
> +  unsigned getPointerTypeSize(Value *V) const {
> +    return getPointerTypeSizeInBits(V) / 8;
> +  }
> +
>    /// Size examples:
>    ///
>    /// Type        SizeInBits  StoreSizeInBits  AllocSizeInBits[*]
> Index: lib/IR/DataLayout.cpp
> ===================================================================
> --- lib/IR/DataLayout.cpp
> +++ lib/IR/DataLayout.cpp
> @@ -507,6 +507,18 @@
>    return OS.str();
>  }
>
> +unsigned DataLayout::getPointerTypeSizeInBits(Type *Ty) const {
> +  if (Ty->isPointerTy())
> +    return getTypeSizeInBits(Ty);
> +
> +  if (VectorType *VT = dyn_cast<VectorType>(Ty)) {
> +    Type *EleTy = VT->getElementType();
> +    if (EleTy->isPointerTy())
> +      return getTypeSizeInBits(EleTy);
> +  }
> +
> +  return getPointerSizeInBits(0);
> +}
>
>  /*!
>    \param abi_or_pref Flag that determines which alignment is returned. true
>
> _______________________________________________
> 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