[llvm] r243843 - Merge the const and non-const Type::getScalarType to a const version that returns a non-const pointer. Since we don't put const on Types all places were already calling the non-const version.

David Blaikie dblaikie at gmail.com
Sat Aug 1 15:43:02 PDT 2015


On Sat, Aug 1, 2015 at 3:20 PM, Craig Topper <craig.topper at gmail.com> wrote:

> Author: ctopper
> Date: Sat Aug  1 17:20:27 2015
> New Revision: 243843
>
> URL: http://llvm.org/viewvc/llvm-project?rev=243843&view=rev
> Log:
> Merge the const and non-const Type::getScalarType to a const version that
> returns a non-const pointer. Since we don't put const on Types all places
> were already calling the non-const version.
>

Any particular reason to keep the const version, if everyone should be
calling it from a non-const pointer? (by making it non-const it'll catch
some cases where people add unnecessary const) But I'm not too fussed.


>
> Modified:
>     llvm/trunk/include/llvm/IR/Type.h
>     llvm/trunk/lib/IR/Type.cpp
>
> Modified: llvm/trunk/include/llvm/IR/Type.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Type.h?rev=243843&r1=243842&r2=243843&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/IR/Type.h (original)
> +++ llvm/trunk/include/llvm/IR/Type.h Sat Aug  1 17:20:27 2015
> @@ -304,8 +304,7 @@ public:
>
>    /// getScalarType - If this is a vector type, return the element type,
>    /// otherwise return 'this'.
> -  const Type *getScalarType() const LLVM_READONLY;
> -  Type *getScalarType() LLVM_READONLY;
> +  Type *getScalarType() const LLVM_READONLY;
>
>
>  //===--------------------------------------------------------------------===//
>    // Type Iteration support.
>
> Modified: llvm/trunk/lib/IR/Type.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Type.cpp?rev=243843&r1=243842&r2=243843&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/IR/Type.cpp (original)
> +++ llvm/trunk/lib/IR/Type.cpp Sat Aug  1 17:20:27 2015
> @@ -42,16 +42,10 @@ Type *Type::getPrimitiveType(LLVMContext
>
>  /// getScalarType - If this is a vector type, return the element type,
>  /// otherwise return this.
> -Type *Type::getScalarType() {
> -  if (VectorType *VTy = dyn_cast<VectorType>(this))
> +Type *Type::getScalarType() const {
> +  if (auto *VTy = dyn_cast<VectorType>(this))
>      return VTy->getElementType();
> -  return this;
> -}
> -
> -const Type *Type::getScalarType() const {
> -  if (const VectorType *VTy = dyn_cast<VectorType>(this))
> -    return VTy->getElementType();
> -  return this;
> +  return const_cast<Type*>(this);
>  }
>
>  /// isIntegerTy - Return true if this is an IntegerType of the specified
> width.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150801/33fac770/attachment.html>


More information about the llvm-commits mailing list