diff --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h --- a/llvm/include/llvm/IR/DerivedTypes.h +++ b/llvm/include/llvm/IR/DerivedTypes.h @@ -546,18 +546,6 @@ } }; -unsigned Type::getVectorNumElements() const { - return cast(this)->getNumElements(); -} - -bool Type::getVectorIsScalable() const { - return cast(this)->isScalable(); -} - -ElementCount Type::getVectorElementCount() const { - return cast(this)->getElementCount(); -} - /// Class to represent pointers. class PointerType : public Type { explicit PointerType(Type *ElType, unsigned AddrSpace); @@ -610,8 +598,8 @@ isIntOrIntVectorTy() && "Original type expected to be a vector of integers or a scalar integer."); Type *NewType = getIntNTy(getContext(), NewBitWidth); - if (isVectorTy()) - NewType = VectorType::get(NewType, getVectorElementCount()); + if (auto *VTy = dyn_cast(this)) + NewType = VectorType::get(NewType, VTy->getElementCount()); return NewType; } diff --git a/llvm/include/llvm/IR/Type.h b/llvm/include/llvm/IR/Type.h --- a/llvm/include/llvm/IR/Type.h +++ b/llvm/include/llvm/IR/Type.h @@ -304,11 +304,7 @@ /// If this is a vector type, return the element type, otherwise return /// 'this'. - Type *getScalarType() const { - if (isVectorTy()) - return getVectorElementType(); - return const_cast(this); - } + Type *getScalarType() const; //===--------------------------------------------------------------------===// // Type Iteration support. @@ -343,8 +339,8 @@ //===--------------------------------------------------------------------===// // Helper methods corresponding to subclass methods. This forces a cast to - // the specified subclass and calls its accessor. "getVectorNumElements" (for - // example) is shorthand for cast(Ty)->getNumElements(). This is + // the specified subclass and calls its accessor. "getArrayNumElements" (for + // example) is shorthand for cast(Ty)->getNumElements(). This is // only intended to cover the core methods that are frequently used, helper // methods should not be added here. @@ -370,14 +366,6 @@ return ContainedTys[0]; } - inline bool getVectorIsScalable() const; - inline unsigned getVectorNumElements() const; - inline ElementCount getVectorElementCount() const; - Type *getVectorElementType() const { - assert(getTypeID() == VectorTyID); - return ContainedTys[0]; - } - Type *getPointerElementType() const { assert(getTypeID() == PointerTyID); return ContainedTys[0]; diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp --- a/llvm/lib/IR/Type.cpp +++ b/llvm/lib/IR/Type.cpp @@ -149,6 +149,12 @@ return -1; } +Type *Type::getScalarType() const { + if (isVectorTy()) + return cast(this)->getElementType(); + return const_cast(this); +} + bool Type::isSizedDerivedType(SmallPtrSetImpl *Visited) const { if (auto *ATy = dyn_cast(this)) return ATy->getElementType()->isSized(Visited);