diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -1032,13 +1032,13 @@ Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)), Ptr->getType()->getPointerAddressSpace()); // Vector GEP - if (Ptr->getType()->isVectorTy()) { - ElementCount EltCount = Ptr->getType()->getVectorElementCount(); + if (auto *PtrVTy = dyn_cast(Ptr->getType())) { + ElementCount EltCount = PtrVTy->getElementCount(); return VectorType::get(PtrTy, EltCount); } for (Value *Index : IdxList) - if (Index->getType()->isVectorTy()) { - ElementCount EltCount = Index->getType()->getVectorElementCount(); + if (auto *IndexVTy = dyn_cast(Index->getType())) { + ElementCount EltCount = IndexVTy->getElementCount(); return VectorType::get(PtrTy, EltCount); } // Scalar GEP @@ -1991,7 +1991,8 @@ /// Examples: shufflevector <4 x n> A, <4 x n> B, <1,2,3> /// shufflevector <4 x n> A, <4 x n> B, <1,2,3,4,5> bool changesLength() const { - unsigned NumSourceElts = Op<0>()->getType()->getVectorNumElements(); + unsigned NumSourceElts = + cast(Op<0>()->getType())->getNumElements(); unsigned NumMaskElts = ShuffleMask.size(); return NumSourceElts != NumMaskElts; } @@ -2000,7 +2001,8 @@ /// elements than its source vectors. /// Example: shufflevector <2 x n> A, <2 x n> B, <1,2,3> bool increasesLength() const { - unsigned NumSourceElts = Op<0>()->getType()->getVectorNumElements(); + unsigned NumSourceElts = + cast(Op<0>()->getType())->getNumElements(); unsigned NumMaskElts = ShuffleMask.size(); return NumSourceElts < NumMaskElts; } @@ -2193,7 +2195,7 @@ /// Return true if this shuffle mask is an extract subvector mask. bool isExtractSubvectorMask(int &Index) const { - int NumSrcElts = Op<0>()->getType()->getVectorNumElements(); + int NumSrcElts = cast(Op<0>()->getType())->getNumElements(); return isExtractSubvectorMask(ShuffleMask, NumSrcElts, Index); } diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -275,7 +275,7 @@ return this->isValue(CI->getValue()); // Non-splat vector constant: check each element for a match. - unsigned NumElts = V->getType()->getVectorNumElements(); + unsigned NumElts = cast(V->getType())->getNumElements(); assert(NumElts != 0 && "Constant vector with no elements?"); bool HasNonUndefElements = false; for (unsigned i = 0; i != NumElts; ++i) { @@ -334,7 +334,7 @@ return this->isValue(CF->getValueAPF()); // Non-splat vector constant: check each element for a match. - unsigned NumElts = V->getType()->getVectorNumElements(); + unsigned NumElts = cast(V->getType())->getNumElements(); assert(NumElts != 0 && "Constant vector with no elements?"); bool HasNonUndefElements = false; for (unsigned i = 0; i != NumElts; ++i) { @@ -2173,8 +2173,8 @@ if (m_PtrToInt(m_OffsetGep(m_Zero(), m_SpecificInt(1))).match(V)) { Type *PtrTy = cast(V)->getOperand(0)->getType(); - Type *DerefTy = PtrTy->getPointerElementType(); - if (DerefTy->isVectorTy() && DerefTy->getVectorIsScalable() && + auto *DerefTy = dyn_cast(PtrTy->getPointerElementType()); + if (DerefTy && DerefTy->isScalable() && DL.getTypeAllocSizeInBits(DerefTy).getKnownMinSize() == 8) return true; } diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -464,7 +464,7 @@ static void PrintShuffleMask(raw_ostream &Out, Type *Ty, ArrayRef Mask) { Out << ", <"; - if (Ty->getVectorIsScalable()) + if (cast(Ty)->isScalable()) Out << "vscale x "; Out << Mask.size() << " x i32> "; bool FirstElt = true; @@ -1504,13 +1504,14 @@ } if (isa(CV) || isa(CV)) { - Type *ETy = CV->getType()->getVectorElementType(); + auto *CVVTy = cast(CV->getType()); + Type *ETy = CVVTy->getElementType(); Out << '<'; TypePrinter.print(ETy, Out); Out << ' '; WriteAsOperandInternal(Out, CV->getAggregateElement(0U), &TypePrinter, Machine, Context); - for (unsigned i = 1, e = CV->getType()->getVectorNumElements(); i != e;++i){ + for (unsigned i = 1, e = CVVTy->getNumElements(); i != e; ++i) { Out << ", "; TypePrinter.print(ETy, Out); Out << ' '; diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -899,8 +899,8 @@ // to byte shuffles. static Value *UpgradeX86PSLLDQIntrinsics(IRBuilder<> &Builder, Value *Op, unsigned Shift) { - Type *ResultTy = Op->getType(); - unsigned NumElts = ResultTy->getVectorNumElements() * 8; + auto *ResultTy = cast(Op->getType()); + unsigned NumElts = ResultTy->getNumElements() * 8; // Bitcast from a 64-bit element type to a byte element type. Type *VecTy = VectorType::get(Builder.getInt8Ty(), NumElts); @@ -933,8 +933,8 @@ // to byte shuffles. static Value *UpgradeX86PSRLDQIntrinsics(IRBuilder<> &Builder, Value *Op, unsigned Shift) { - Type *ResultTy = Op->getType(); - unsigned NumElts = ResultTy->getVectorNumElements() * 8; + auto *ResultTy = cast(Op->getType()); + unsigned NumElts = ResultTy->getNumElements() * 8; // Bitcast from a 64-bit element type to a byte element type. Type *VecTy = VectorType::get(Builder.getInt8Ty(), NumElts); @@ -990,7 +990,8 @@ if (C->isAllOnesValue()) return Op0; - Mask = getX86MaskVec(Builder, Mask, Op0->getType()->getVectorNumElements()); + Mask = getX86MaskVec(Builder, Mask, + cast(Op0->getType())->getNumElements()); return Builder.CreateSelect(Mask, Op0, Op1); } @@ -1018,7 +1019,7 @@ bool IsVALIGN) { unsigned ShiftVal = cast(Shift)->getZExtValue(); - unsigned NumElts = Op0->getType()->getVectorNumElements(); + unsigned NumElts = cast(Op0->getType())->getNumElements(); assert((IsVALIGN || NumElts % 16 == 0) && "Illegal NumElts for PALIGNR!"); assert((!IsVALIGN || NumElts <= 16) && "NumElts too large for VALIGN!"); assert(isPowerOf2_32(NumElts) && "NumElts not a power of 2!"); @@ -1149,7 +1150,7 @@ // Funnel shifts amounts are treated as modulo and types are all power-of-2 so // we only care about the lowest log2 bits anyway. if (Amt->getType() != Ty) { - unsigned NumElts = Ty->getVectorNumElements(); + unsigned NumElts = cast(Ty)->getNumElements(); Amt = Builder.CreateIntCast(Amt, Ty->getScalarType(), false); Amt = Builder.CreateVectorSplat(NumElts, Amt); } @@ -1219,7 +1220,7 @@ // Funnel shifts amounts are treated as modulo and types are all power-of-2 so // we only care about the lowest log2 bits anyway. if (Amt->getType() != Ty) { - unsigned NumElts = Ty->getVectorNumElements(); + unsigned NumElts = cast(Ty)->getNumElements(); Amt = Builder.CreateIntCast(Amt, Ty->getScalarType(), false); Amt = Builder.CreateVectorSplat(NumElts, Amt); } @@ -1255,7 +1256,7 @@ return Builder.CreateAlignedStore(Data, Ptr, Alignment); // Convert the mask from an integer type to a vector of i1. - unsigned NumElts = Data->getType()->getVectorNumElements(); + unsigned NumElts = cast(Data->getType())->getNumElements(); Mask = getX86MaskVec(Builder, Mask, NumElts); return Builder.CreateMaskedStore(Data, Ptr, Alignment, Mask); } @@ -1276,7 +1277,7 @@ return Builder.CreateAlignedLoad(ValTy, Ptr, Alignment); // Convert the mask from an integer type to a vector of i1. - unsigned NumElts = Passthru->getType()->getVectorNumElements(); + unsigned NumElts = cast(Passthru->getType())->getNumElements(); Mask = getX86MaskVec(Builder, Mask, NumElts); return Builder.CreateMaskedLoad(Ptr, Alignment, Mask, Passthru); } @@ -1340,7 +1341,7 @@ // Applying mask on vector of i1's and make sure result is at least 8 bits wide. static Value *ApplyX86MaskOn1BitsVec(IRBuilder<> &Builder, Value *Vec, Value *Mask) { - unsigned NumElts = Vec->getType()->getVectorNumElements(); + unsigned NumElts = cast(Vec->getType())->getNumElements(); if (Mask) { const auto *C = dyn_cast(Mask); if (!C || !C->isAllOnesValue()) @@ -1363,7 +1364,7 @@ static Value *upgradeMaskedCompare(IRBuilder<> &Builder, CallInst &CI, unsigned CC, bool Signed) { Value *Op0 = CI.getArgOperand(0); - unsigned NumElts = Op0->getType()->getVectorNumElements(); + unsigned NumElts = cast(Op0->getType())->getNumElements(); Value *Cmp; if (CC == 3) { @@ -1416,7 +1417,7 @@ static Value* UpgradeMaskToInt(IRBuilder<> &Builder, CallInst &CI) { Value* Op = CI.getArgOperand(0); Type* ReturnOp = CI.getType(); - unsigned NumElts = CI.getType()->getVectorNumElements(); + unsigned NumElts = cast(CI.getType())->getNumElements(); Value *Mask = getX86MaskVec(Builder, Op, NumElts); return Builder.CreateSExt(Mask, ReturnOp, "vpmovm2"); } @@ -1866,7 +1867,7 @@ Rep = ApplyX86MaskOn1BitsVec(Builder, Rep, Mask); } else if (IsX86 && (Name.startswith("avx512.mask.pbroadcast"))){ unsigned NumElts = - CI->getArgOperand(1)->getType()->getVectorNumElements(); + cast(CI->getArgOperand(1)->getType())->getNumElements(); Rep = Builder.CreateVectorSplat(NumElts, CI->getArgOperand(0)); Rep = EmitX86Select(Builder, CI->getArgOperand(2), Rep, CI->getArgOperand(1)); @@ -2084,16 +2085,19 @@ Name == "sse2.cvtsi2sd" || Name == "sse.cvtsi642ss" || Name == "sse2.cvtsi642sd")) { - Rep = Builder.CreateSIToFP(CI->getArgOperand(1), - CI->getType()->getVectorElementType()); + Rep = Builder.CreateSIToFP( + CI->getArgOperand(1), + cast(CI->getType())->getElementType()); Rep = Builder.CreateInsertElement(CI->getArgOperand(0), Rep, (uint64_t)0); } else if (IsX86 && Name == "avx512.cvtusi2sd") { - Rep = Builder.CreateUIToFP(CI->getArgOperand(1), - CI->getType()->getVectorElementType()); + Rep = Builder.CreateUIToFP( + CI->getArgOperand(1), + cast(CI->getType())->getElementType()); Rep = Builder.CreateInsertElement(CI->getArgOperand(0), Rep, (uint64_t)0); } else if (IsX86 && Name == "sse2.cvtss2sd") { Rep = Builder.CreateExtractElement(CI->getArgOperand(1), (uint64_t)0); - Rep = Builder.CreateFPExt(Rep, CI->getType()->getVectorElementType()); + Rep = Builder.CreateFPExt( + Rep, cast(CI->getType())->getElementType()); Rep = Builder.CreateInsertElement(CI->getArgOperand(0), Rep, (uint64_t)0); } else if (IsX86 && (Name == "sse2.cvtdq2pd" || Name == "sse2.cvtdq2ps" || @@ -2113,18 +2117,18 @@ Name == "avx.cvt.ps2.pd.256" || Name == "avx512.mask.cvtps2pd.128" || Name == "avx512.mask.cvtps2pd.256")) { - Type *DstTy = CI->getType(); + auto *DstTy = cast(CI->getType()); Rep = CI->getArgOperand(0); - Type *SrcTy = Rep->getType(); + auto *SrcTy = cast(Rep->getType()); - unsigned NumDstElts = DstTy->getVectorNumElements(); - if (NumDstElts < SrcTy->getVectorNumElements()) { + unsigned NumDstElts = DstTy->getNumElements(); + if (NumDstElts < SrcTy->getNumElements()) { assert(NumDstElts == 2 && "Unexpected vector size"); uint32_t ShuffleMask[2] = { 0, 1 }; Rep = Builder.CreateShuffleVector(Rep, Rep, ShuffleMask); } - bool IsPS2PD = SrcTy->getVectorElementType()->isFloatTy(); + bool IsPS2PD = SrcTy->getElementType()->isFloatTy(); bool IsUnsigned = (StringRef::npos != Name.find("cvtu")); if (IsPS2PD) Rep = Builder.CreateFPExt(Rep, DstTy, "cvtps2pd"); @@ -2146,11 +2150,11 @@ CI->getArgOperand(1)); } else if (IsX86 && (Name.startswith("avx512.mask.vcvtph2ps.") || Name.startswith("vcvtph2ps."))) { - Type *DstTy = CI->getType(); + auto *DstTy = cast(CI->getType()); Rep = CI->getArgOperand(0); - Type *SrcTy = Rep->getType(); - unsigned NumDstElts = DstTy->getVectorNumElements(); - if (NumDstElts != SrcTy->getVectorNumElements()) { + auto *SrcTy = cast(Rep->getType()); + unsigned NumDstElts = DstTy->getNumElements(); + if (NumDstElts != SrcTy->getNumElements()) { assert(NumDstElts == 4 && "Unexpected vector size"); uint32_t ShuffleMask[4] = {0, 1, 2, 3}; Rep = Builder.CreateShuffleVector(Rep, Rep, ShuffleMask); @@ -2170,30 +2174,30 @@ CI->getArgOperand(1),CI->getArgOperand(2), /*Aligned*/true); } else if (IsX86 && Name.startswith("avx512.mask.expand.load.")) { - Type *ResultTy = CI->getType(); - Type *PtrTy = ResultTy->getVectorElementType(); + auto *ResultTy = cast(CI->getType()); + Type *PtrTy = ResultTy->getElementType(); // Cast the pointer to element type. Value *Ptr = Builder.CreateBitCast(CI->getOperand(0), llvm::PointerType::getUnqual(PtrTy)); Value *MaskVec = getX86MaskVec(Builder, CI->getArgOperand(2), - ResultTy->getVectorNumElements()); + ResultTy->getNumElements()); Function *ELd = Intrinsic::getDeclaration(F->getParent(), Intrinsic::masked_expandload, ResultTy); Rep = Builder.CreateCall(ELd, { Ptr, MaskVec, CI->getOperand(1) }); } else if (IsX86 && Name.startswith("avx512.mask.compress.store.")) { - Type *ResultTy = CI->getArgOperand(1)->getType(); - Type *PtrTy = ResultTy->getVectorElementType(); + auto *ResultTy = cast(CI->getArgOperand(1)->getType()); + Type *PtrTy = ResultTy->getElementType(); // Cast the pointer to element type. Value *Ptr = Builder.CreateBitCast(CI->getOperand(0), llvm::PointerType::getUnqual(PtrTy)); Value *MaskVec = getX86MaskVec(Builder, CI->getArgOperand(2), - ResultTy->getVectorNumElements()); + ResultTy->getNumElements()); Function *CSt = Intrinsic::getDeclaration(F->getParent(), Intrinsic::masked_compressstore, @@ -2201,10 +2205,10 @@ Rep = Builder.CreateCall(CSt, { CI->getArgOperand(1), Ptr, MaskVec }); } else if (IsX86 && (Name.startswith("avx512.mask.compress.") || Name.startswith("avx512.mask.expand."))) { - Type *ResultTy = CI->getType(); + auto *ResultTy = cast(CI->getType()); Value *MaskVec = getX86MaskVec(Builder, CI->getArgOperand(2), - ResultTy->getVectorNumElements()); + ResultTy->getNumElements()); bool IsCompress = Name[12] == 'c'; Intrinsic::ID IID = IsCompress ? Intrinsic::x86_avx512_mask_compress @@ -2281,9 +2285,9 @@ } else if (IsX86 && (Name.startswith("avx.vbroadcast.s") || Name.startswith("avx512.vbroadcast.s"))) { // Replace broadcasts with a series of insertelements. - Type *VecTy = CI->getType(); - Type *EltTy = VecTy->getVectorElementType(); - unsigned EltNum = VecTy->getVectorNumElements(); + auto *VecTy = cast(CI->getType()); + Type *EltTy = VecTy->getElementType(); + unsigned EltNum = VecTy->getNumElements(); Value *Cast = Builder.CreateBitCast(CI->getArgOperand(0), EltTy->getPointerTo()); Value *Load = Builder.CreateLoad(EltTy, Cast); @@ -2328,7 +2332,7 @@ } else if (IsX86 && (Name.startswith("avx.vbroadcastf128") || Name == "avx2.vbroadcasti128")) { // Replace vbroadcastf128/vbroadcasti128 with a vector load+shuffle. - Type *EltTy = CI->getType()->getVectorElementType(); + Type *EltTy = cast(CI->getType())->getElementType(); unsigned NumSrcElts = 128 / EltTy->getPrimitiveSizeInBits(); Type *VT = VectorType::get(EltTy, NumSrcElts); Value *Op = Builder.CreatePointerCast(CI->getArgOperand(0), @@ -2366,8 +2370,8 @@ }else if (IsX86 && (Name.startswith("avx512.mask.broadcastf") || Name.startswith("avx512.mask.broadcasti"))) { unsigned NumSrcElts = - CI->getArgOperand(0)->getType()->getVectorNumElements(); - unsigned NumDstElts = CI->getType()->getVectorNumElements(); + cast(CI->getArgOperand(0)->getType())->getNumElements(); + unsigned NumDstElts = cast(CI->getType())->getNumElements(); SmallVector ShuffleMask(NumDstElts); for (unsigned i = 0; i != NumDstElts; ++i) @@ -2384,8 +2388,8 @@ Name.startswith("avx512.mask.broadcast.s"))) { // Replace vp?broadcasts with a vector shuffle. Value *Op = CI->getArgOperand(0); - unsigned NumElts = CI->getType()->getVectorNumElements(); - Type *MaskTy = VectorType::get(Type::getInt32Ty(C), NumElts); + ElementCount EC = cast(CI->getType())->getElementCount(); + Type *MaskTy = VectorType::get(Type::getInt32Ty(C), EC); Rep = Builder.CreateShuffleVector(Op, UndefValue::get(Op->getType()), Constant::getNullValue(MaskTy)); @@ -2470,8 +2474,8 @@ Value *Op0 = CI->getArgOperand(0); Value *Op1 = CI->getArgOperand(1); unsigned Imm = cast(CI->getArgOperand(2))->getZExtValue(); - unsigned DstNumElts = CI->getType()->getVectorNumElements(); - unsigned SrcNumElts = Op1->getType()->getVectorNumElements(); + unsigned DstNumElts = cast(CI->getType())->getNumElements(); + unsigned SrcNumElts = cast(Op1->getType())->getNumElements(); unsigned Scale = DstNumElts / SrcNumElts; // Mask off the high bits of the immediate value; hardware ignores those. @@ -2514,8 +2518,8 @@ Name.startswith("avx512.mask.vextract"))) { Value *Op0 = CI->getArgOperand(0); unsigned Imm = cast(CI->getArgOperand(1))->getZExtValue(); - unsigned DstNumElts = CI->getType()->getVectorNumElements(); - unsigned SrcNumElts = Op0->getType()->getVectorNumElements(); + unsigned DstNumElts = cast(CI->getType())->getNumElements(); + unsigned SrcNumElts = cast(Op0->getType())->getNumElements(); unsigned Scale = SrcNumElts / DstNumElts; // Mask off the high bits of the immediate value; hardware ignores those. @@ -2562,7 +2566,7 @@ uint8_t Imm = cast(CI->getArgOperand(2))->getZExtValue(); - unsigned NumElts = CI->getType()->getVectorNumElements(); + unsigned NumElts = cast(CI->getType())->getNumElements(); unsigned HalfSize = NumElts / 2; SmallVector ShuffleMask(NumElts); @@ -2614,7 +2618,7 @@ Name.startswith("avx512.mask.pshufl.w."))) { Value *Op0 = CI->getArgOperand(0); unsigned Imm = cast(CI->getArgOperand(1))->getZExtValue(); - unsigned NumElts = CI->getType()->getVectorNumElements(); + unsigned NumElts = cast(CI->getType())->getNumElements(); SmallVector Idxs(NumElts); for (unsigned l = 0; l != NumElts; l += 8) { @@ -2633,7 +2637,7 @@ Name.startswith("avx512.mask.pshufh.w."))) { Value *Op0 = CI->getArgOperand(0); unsigned Imm = cast(CI->getArgOperand(1))->getZExtValue(); - unsigned NumElts = CI->getType()->getVectorNumElements(); + unsigned NumElts = cast(CI->getType())->getNumElements(); SmallVector Idxs(NumElts); for (unsigned l = 0; l != NumElts; l += 8) { @@ -2652,7 +2656,7 @@ Value *Op0 = CI->getArgOperand(0); Value *Op1 = CI->getArgOperand(1); unsigned Imm = cast(CI->getArgOperand(2))->getZExtValue(); - unsigned NumElts = CI->getType()->getVectorNumElements(); + unsigned NumElts = cast(CI->getType())->getNumElements(); unsigned NumLaneElts = 128/CI->getType()->getScalarSizeInBits(); unsigned HalfLaneElts = NumLaneElts / 2; @@ -2677,7 +2681,7 @@ Name.startswith("avx512.mask.movshdup") || Name.startswith("avx512.mask.movsldup"))) { Value *Op0 = CI->getArgOperand(0); - unsigned NumElts = CI->getType()->getVectorNumElements(); + unsigned NumElts = cast(CI->getType())->getNumElements(); unsigned NumLaneElts = 128/CI->getType()->getScalarSizeInBits(); unsigned Offset = 0; @@ -2699,7 +2703,7 @@ Name.startswith("avx512.mask.unpckl."))) { Value *Op0 = CI->getArgOperand(0); Value *Op1 = CI->getArgOperand(1); - int NumElts = CI->getType()->getVectorNumElements(); + int NumElts = cast(CI->getType())->getNumElements(); int NumLaneElts = 128/CI->getType()->getScalarSizeInBits(); SmallVector Idxs(NumElts); @@ -2715,7 +2719,7 @@ Name.startswith("avx512.mask.unpckh."))) { Value *Op0 = CI->getArgOperand(0); Value *Op1 = CI->getArgOperand(1); - int NumElts = CI->getType()->getVectorNumElements(); + int NumElts = cast(CI->getType())->getNumElements(); int NumLaneElts = 128/CI->getType()->getScalarSizeInBits(); SmallVector Idxs(NumElts); @@ -3283,7 +3287,7 @@ Rep = Builder.CreateCall(Intrinsic::getDeclaration(F->getParent(), IID), Ops); } else { - int NumElts = CI->getType()->getVectorNumElements(); + int NumElts = cast(CI->getType())->getNumElements(); Value *Ops[] = { CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2) }; diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -56,13 +56,13 @@ // doing so requires endianness information. This should be handled by // Analysis/ConstantFolding.cpp unsigned NumElts = DstTy->getNumElements(); - if (NumElts != CV->getType()->getVectorNumElements()) + if (NumElts != cast(CV->getType())->getNumElements()) return nullptr; Type *DstEltTy = DstTy->getElementType(); // Fast path for splatted constants. if (Constant *Splat = CV->getSplatValue()) { - return ConstantVector::getSplat(DstTy->getVectorElementCount(), + return ConstantVector::getSplat(DstTy->getElementCount(), ConstantExpr::getBitCast(Splat, DstEltTy)); } @@ -572,18 +572,20 @@ // count may be mismatched; don't attempt to handle that here. if ((isa(V) || isa(V)) && DestTy->isVectorTy() && - DestTy->getVectorNumElements() == V->getType()->getVectorNumElements()) { + cast(DestTy)->getNumElements() == + cast(V->getType())->getNumElements()) { VectorType *DestVecTy = cast(DestTy); Type *DstEltTy = DestVecTy->getElementType(); // Fast path for splatted constants. if (Constant *Splat = V->getSplatValue()) { return ConstantVector::getSplat( - DestTy->getVectorElementCount(), + cast(DestTy)->getElementCount(), ConstantExpr::getCast(opc, Splat, DstEltTy)); } SmallVector res; Type *Ty = IntegerType::get(V->getContext(), 32); - for (unsigned i = 0, e = V->getType()->getVectorNumElements(); i != e; ++i) { + for (unsigned i = 0, e = cast(V->getType())->getNumElements(); + i != e; ++i) { Constant *C = ConstantExpr::getExtractElement(V, ConstantInt::get(Ty, i)); res.push_back(ConstantExpr::getCast(opc, C, DstEltTy)); @@ -745,9 +747,10 @@ // If the condition is a vector constant, fold the result elementwise. if (ConstantVector *CondV = dyn_cast(Cond)) { + auto *V1VTy = CondV->getType(); SmallVector Result; Type *Ty = IntegerType::get(CondV->getContext(), 32); - for (unsigned i = 0, e = V1->getType()->getVectorNumElements(); i != e;++i){ + for (unsigned i = 0, e = V1VTy->getNumElements(); i != e; ++i) { Constant *V; Constant *V1Element = ConstantExpr::getExtractElement(V1, ConstantInt::get(Ty, i)); @@ -766,7 +769,7 @@ } // If we were able to build the vector, return it. - if (Result.size() == V1->getType()->getVectorNumElements()) + if (Result.size() == V1VTy->getNumElements()) return ConstantVector::get(Result); } @@ -794,18 +797,20 @@ Constant *llvm::ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx) { + auto *ValVTy = cast(Val->getType()); + // extractelt undef, C -> undef // extractelt C, undef -> undef if (isa(Val) || isa(Idx)) - return UndefValue::get(Val->getType()->getVectorElementType()); + return UndefValue::get(ValVTy->getElementType()); auto *CIdx = dyn_cast(Idx); if (!CIdx) return nullptr; // ee({w,x,y,z}, wrong_value) -> undef - if (CIdx->uge(Val->getType()->getVectorNumElements())) - return UndefValue::get(Val->getType()->getVectorElementType()); + if (CIdx->uge(ValVTy->getNumElements())) + return UndefValue::get(ValVTy->getElementType()); // ee (gep (ptr, idx0, ...), idx) -> gep (ee (ptr, idx), ee (idx0, idx), ...) if (auto *CE = dyn_cast(Val)) { @@ -822,8 +827,7 @@ } else Ops.push_back(Op); } - return CE->getWithOperands(Ops, CE->getType()->getVectorElementType(), - false, + return CE->getWithOperands(Ops, ValVTy->getElementType(), false, Ops[0]->getType()->getPointerElementType()); } } @@ -846,7 +850,7 @@ if (ValTy->isScalable()) return nullptr; - unsigned NumElts = Val->getType()->getVectorNumElements(); + unsigned NumElts = cast(Val->getType())->getNumElements(); if (CIdx->uge(NumElts)) return UndefValue::get(Val->getType()); @@ -869,10 +873,10 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, ArrayRef Mask) { + auto *V1VTy = cast(V1->getType()); unsigned MaskNumElts = Mask.size(); - ElementCount MaskEltCount = {MaskNumElts, - V1->getType()->getVectorIsScalable()}; - Type *EltTy = V1->getType()->getVectorElementType(); + ElementCount MaskEltCount = {MaskNumElts, V1VTy->isScalable()}; + Type *EltTy = V1VTy->getElementType(); // Undefined shuffle mask -> undefined value. if (all_of(Mask, [](int Elt) { return Elt == UndefMaskElem; })) { @@ -890,11 +894,10 @@ } // Do not iterate on scalable vector. The num of elements is unknown at // compile-time. - VectorType *ValTy = cast(V1->getType()); - if (ValTy->isScalable()) + if (V1VTy->isScalable()) return nullptr; - unsigned SrcNumElts = V1->getType()->getVectorNumElements(); + unsigned SrcNumElts = V1VTy->getNumElements(); // Loop over the shuffle mask, evaluating each element. SmallVector Result; @@ -968,8 +971,8 @@ // Handle scalar UndefValue and scalable vector UndefValue. Fixed-length // vectors are always evaluated per element. - bool IsScalableVector = - C->getType()->isVectorTy() && C->getType()->getVectorIsScalable(); + bool IsScalableVector = isa(C->getType()) && + cast(C->getType())->isScalable(); bool HasScalarUndefOrScalableVectorUndef = (!C->getType()->isVectorTy() || IsScalableVector) && isa(C); @@ -1042,8 +1045,8 @@ // Handle scalar UndefValue and scalable vector UndefValue. Fixed-length // vectors are always evaluated per element. - bool IsScalableVector = - C1->getType()->isVectorTy() && C1->getType()->getVectorIsScalable(); + bool IsScalableVector = isa(C1->getType()) && + cast(C1->getType())->isScalable(); bool HasScalarUndefOrScalableVectorUndef = (!C1->getType()->isVectorTy() || IsScalableVector) && (isa(C1) || isa(C2)); @@ -1375,7 +1378,7 @@ return UndefValue::get(VTy); if (Constant *C1Splat = C1->getSplatValue()) { return ConstantVector::getSplat( - VTy->getVectorElementCount(), + VTy->getElementCount(), ConstantExpr::get(Opcode, C1Splat, C2Splat)); } } @@ -1992,16 +1995,18 @@ return ConstantInt::get(ResultTy, R==APFloat::cmpGreaterThan || R==APFloat::cmpEqual); } - } else if (C1->getType()->isVectorTy()) { + } else if (auto *C1VTy = dyn_cast(C1->getType())) { + // Do not iterate on scalable vector. The number of elements is unknown at // compile-time. - if (C1->getType()->getVectorIsScalable()) + if (C1VTy->isScalable()) return nullptr; + // Fast path for splatted constants. if (Constant *C1Splat = C1->getSplatValue()) if (Constant *C2Splat = C2->getSplatValue()) return ConstantVector::getSplat( - C1->getType()->getVectorElementCount(), + C1VTy->getElementCount(), ConstantExpr::getCompare(pred, C1Splat, C2Splat)); // If we can constant fold the comparison of each element, constant fold @@ -2009,7 +2014,7 @@ SmallVector ResElts; Type *Ty = IntegerType::get(C1->getContext(), 32); // Compare the elements, producing an i1 result or constant expr. - for (unsigned i = 0, e = C1->getType()->getVectorNumElements(); i != e;++i){ + for (unsigned i = 0, e = C1VTy->getNumElements(); i != e; ++i) { Constant *C1E = ConstantExpr::getExtractElement(C1, ConstantInt::get(Ty, i)); Constant *C2E = @@ -2262,7 +2267,8 @@ Constant *Idx0 = cast(Idxs[0]); if (Idxs.size() == 1 && (Idx0->isNullValue() || isa(Idx0))) return GEPTy->isVectorTy() && !C->getType()->isVectorTy() - ? ConstantVector::getSplat(GEPTy->getVectorElementCount(), C) + ? ConstantVector::getSplat( + cast(GEPTy)->getElementCount(), C) : C; if (C->isNullValue()) { @@ -2494,18 +2500,19 @@ if (!IsCurrIdxVector && IsPrevIdxVector) CurrIdx = ConstantDataVector::getSplat( - PrevIdx->getType()->getVectorNumElements(), CurrIdx); + cast(PrevIdx->getType())->getNumElements(), CurrIdx); if (!IsPrevIdxVector && IsCurrIdxVector) PrevIdx = ConstantDataVector::getSplat( - CurrIdx->getType()->getVectorNumElements(), PrevIdx); + cast(CurrIdx->getType())->getNumElements(), PrevIdx); Constant *Factor = ConstantInt::get(CurrIdx->getType()->getScalarType(), NumElements); if (UseVector) Factor = ConstantDataVector::getSplat( - IsPrevIdxVector ? PrevIdx->getType()->getVectorNumElements() - : CurrIdx->getType()->getVectorNumElements(), + IsPrevIdxVector + ? cast(PrevIdx->getType())->getNumElements() + : cast(CurrIdx->getType())->getNumElements(), Factor); NewIdxs[i] = ConstantExpr::getSRem(CurrIdx, Factor); @@ -2522,9 +2529,10 @@ Type *ExtendedTy = Type::getIntNTy(Div->getContext(), CommonExtendedWidth); if (UseVector) ExtendedTy = VectorType::get( - ExtendedTy, IsPrevIdxVector - ? PrevIdx->getType()->getVectorNumElements() - : CurrIdx->getType()->getVectorNumElements()); + ExtendedTy, + IsPrevIdxVector + ? cast(PrevIdx->getType())->getNumElements() + : cast(CurrIdx->getType())->getNumElements()); if (!PrevIdx->getType()->isIntOrIntVectorTy(CommonExtendedWidth)) PrevIdx = ConstantExpr::getSExt(PrevIdx, ExtendedTy); diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -160,8 +160,8 @@ return !CFP->getValueAPF().bitcastToAPInt().isOneValue(); // Check that vectors don't contain 1 - if (this->getType()->isVectorTy()) { - unsigned NumElts = this->getType()->getVectorNumElements(); + if (auto *VTy = dyn_cast(this->getType())) { + unsigned NumElts = VTy->getNumElements(); for (unsigned i = 0; i != NumElts; ++i) { Constant *Elt = this->getAggregateElement(i); if (!Elt || !Elt->isNotOneValue()) @@ -210,8 +210,8 @@ return !CFP->getValueAPF().bitcastToAPInt().isMinSignedValue(); // Check that vectors don't contain INT_MIN - if (this->getType()->isVectorTy()) { - unsigned NumElts = this->getType()->getVectorNumElements(); + if (auto *VTy = dyn_cast(this->getType())) { + unsigned NumElts = VTy->getNumElements(); for (unsigned i = 0; i != NumElts; ++i) { Constant *Elt = this->getAggregateElement(i); if (!Elt || !Elt->isNotMinSignedValue()) @@ -227,9 +227,10 @@ bool Constant::isFiniteNonZeroFP() const { if (auto *CFP = dyn_cast(this)) return CFP->getValueAPF().isFiniteNonZero(); - if (!getType()->isVectorTy()) + auto *VTy = dyn_cast(getType()); + if (!VTy) return false; - for (unsigned i = 0, e = getType()->getVectorNumElements(); i != e; ++i) { + for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { auto *CFP = dyn_cast_or_null(this->getAggregateElement(i)); if (!CFP || !CFP->getValueAPF().isFiniteNonZero()) return false; @@ -240,9 +241,10 @@ bool Constant::isNormalFP() const { if (auto *CFP = dyn_cast(this)) return CFP->getValueAPF().isNormal(); - if (!getType()->isVectorTy()) + auto *VTy = dyn_cast(getType()); + if (!VTy) return false; - for (unsigned i = 0, e = getType()->getVectorNumElements(); i != e; ++i) { + for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { auto *CFP = dyn_cast_or_null(this->getAggregateElement(i)); if (!CFP || !CFP->getValueAPF().isNormal()) return false; @@ -253,9 +255,10 @@ bool Constant::hasExactInverseFP() const { if (auto *CFP = dyn_cast(this)) return CFP->getValueAPF().getExactInverse(nullptr); - if (!getType()->isVectorTy()) + auto *VTy = dyn_cast(getType()); + if (!VTy) return false; - for (unsigned i = 0, e = getType()->getVectorNumElements(); i != e; ++i) { + for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { auto *CFP = dyn_cast_or_null(this->getAggregateElement(i)); if (!CFP || !CFP->getValueAPF().getExactInverse(nullptr)) return false; @@ -266,9 +269,10 @@ bool Constant::isNaN() const { if (auto *CFP = dyn_cast(this)) return CFP->isNaN(); - if (!getType()->isVectorTy()) + auto *VTy = dyn_cast(getType()); + if (!VTy) return false; - for (unsigned i = 0, e = getType()->getVectorNumElements(); i != e; ++i) { + for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { auto *CFP = dyn_cast_or_null(this->getAggregateElement(i)); if (!CFP || !CFP->isNaN()) return false; @@ -282,18 +286,18 @@ return true; // The input value must be a vector constant with the same type. - Type *Ty = getType(); - if (!isa(Y) || !Ty->isVectorTy() || Ty != Y->getType()) + auto *VTy = dyn_cast(getType()); + if (!isa(Y) || !VTy || VTy != Y->getType()) return false; // TODO: Compare pointer constants? - if (!(Ty->getVectorElementType()->isIntegerTy() || - Ty->getVectorElementType()->isFloatingPointTy())) + if (!(VTy->getElementType()->isIntegerTy() || + VTy->getElementType()->isFloatingPointTy())) return false; // They may still be identical element-wise (if they have `undef`s). // Bitcast to integer to allow exact bitwise comparison for all types. - Type *IntTy = VectorType::getInteger(cast(Ty)); + Type *IntTy = VectorType::getInteger(VTy); Constant *C0 = ConstantExpr::getBitCast(const_cast(this), IntTy); Constant *C1 = ConstantExpr::getBitCast(cast(Y), IntTy); Constant *CmpEq = ConstantExpr::getICmp(ICmpInst::ICMP_EQ, C0, C1); @@ -301,21 +305,21 @@ } bool Constant::containsUndefElement() const { - if (!getType()->isVectorTy()) - return false; - for (unsigned i = 0, e = getType()->getVectorNumElements(); i != e; ++i) - if (isa(getAggregateElement(i))) - return true; + if (auto *VTy = dyn_cast(getType())) { + for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) + if (isa(getAggregateElement(i))) + return true; + } return false; } bool Constant::containsConstantExpression() const { - if (!getType()->isVectorTy()) - return false; - for (unsigned i = 0, e = getType()->getVectorNumElements(); i != e; ++i) - if (isa(getAggregateElement(i))) - return true; + if (auto *VTy = dyn_cast(getType())) { + for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) + if (isa(getAggregateElement(i))) + return true; + } return false; } @@ -639,10 +643,11 @@ } // Don't know how to deal with this constant. - if (!Ty->isVectorTy()) + auto *VTy = dyn_cast(Ty); + if (!VTy) return C; - unsigned NumElts = Ty->getVectorNumElements(); + unsigned NumElts = VTy->getNumElements(); SmallVector NewC(NumElts); for (unsigned i = 0; i != NumElts; ++i) { Constant *EltC = C->getAggregateElement(i); @@ -1490,7 +1495,7 @@ Constant *Constant::getSplatValue(bool AllowUndefs) const { assert(this->getType()->isVectorTy() && "Only valid for vectors!"); if (isa(this)) - return getNullValue(this->getType()->getVectorElementType()); + return getNullValue(cast(getType())->getElementType()); if (const ConstantDataVector *CV = dyn_cast(this)) return CV->getSplatValue(); if (const ConstantVector *CV = dyn_cast(this)) @@ -1890,8 +1895,9 @@ assert(DstTy->isIntOrIntVectorTy() && "PtrToInt destination must be integer or integer vector"); assert(isa(C->getType()) == isa(DstTy)); - if (isa(C->getType())) - assert(C->getType()->getVectorNumElements()==DstTy->getVectorNumElements()&& + if (auto *CVTy = dyn_cast(C->getType())) + assert(CVTy->getNumElements() == + cast(DstTy)->getNumElements() && "Invalid cast between a different number of vector elements"); return getFoldedCast(Instruction::PtrToInt, C, DstTy, OnlyIfReduced); } @@ -1903,8 +1909,9 @@ assert(DstTy->isPtrOrPtrVectorTy() && "IntToPtr destination must be a pointer or pointer vector"); assert(isa(C->getType()) == isa(DstTy)); - if (isa(C->getType())) - assert(C->getType()->getVectorNumElements()==DstTy->getVectorNumElements()&& + if (auto *CVTy = dyn_cast(C->getType())) + assert(CVTy->getNumElements() == + cast(DstTy)->getNumElements() && "Invalid cast between a different number of vector elements"); return getFoldedCast(Instruction::IntToPtr, C, DstTy, OnlyIfReduced); } @@ -2151,9 +2158,10 @@ ArgVec.reserve(1 + Idxs.size()); ArgVec.push_back(C); for (unsigned i = 0, e = Idxs.size(); i != e; ++i) { - assert((!Idxs[i]->getType()->isVectorTy() || - Idxs[i]->getType()->getVectorElementCount() == EltCount) && - "getelementptr index type missmatch"); + assert( + (!isa(Idxs[i]->getType()) || + cast(Idxs[i]->getType())->getElementCount() == EltCount) && + "getelementptr index type missmatch"); Constant *Idx = cast(Idxs[i]); if (EltCount.Min != 0 && !Idxs[i]->getType()->isVectorTy()) @@ -2231,7 +2239,7 @@ if (Constant *FC = ConstantFoldExtractElementInstruction(Val, Idx)) return FC; // Fold a few common cases. - Type *ReqTy = Val->getType()->getVectorElementType(); + Type *ReqTy = cast(Val->getType())->getElementType(); if (OnlyIfReducedTy == ReqTy) return nullptr; @@ -2247,7 +2255,7 @@ Constant *Idx, Type *OnlyIfReducedTy) { assert(Val->getType()->isVectorTy() && "Tried to create insertelement operation on non-vector type!"); - assert(Elt->getType() == Val->getType()->getVectorElementType() && + assert(Elt->getType() == cast(Val->getType())->getElementType() && "Insertelement types must match!"); assert(Idx->getType()->isIntegerTy() && "Insertelement index must be i32 type!"); @@ -2276,8 +2284,9 @@ return FC; // Fold a few common cases. unsigned NElts = Mask.size(); - Type *EltTy = V1->getType()->getVectorElementType(); - bool TypeIsScalable = V1->getType()->getVectorIsScalable(); + auto V1VTy = cast(V1->getType()); + Type *EltTy = V1VTy->getElementType(); + bool TypeIsScalable = V1VTy->isScalable(); Type *ShufTy = VectorType::get(EltTy, NElts, TypeIsScalable); if (OnlyIfReducedTy == ShufTy) @@ -2569,7 +2578,7 @@ unsigned ConstantDataSequential::getNumElements() const { if (ArrayType *AT = dyn_cast(getType())) return AT->getNumElements(); - return getType()->getVectorNumElements(); + return cast(getType())->getNumElements(); } diff --git a/llvm/lib/IR/ConstantsContext.h b/llvm/lib/IR/ConstantsContext.h --- a/llvm/lib/IR/ConstantsContext.h +++ b/llvm/lib/IR/ConstantsContext.h @@ -150,7 +150,8 @@ ShuffleVectorConstantExpr(Constant *C1, Constant *C2, ArrayRef Mask) : ConstantExpr( VectorType::get(cast(C1->getType())->getElementType(), - Mask.size(), C1->getType()->getVectorIsScalable()), + Mask.size(), + cast(C1->getType())->isScalable()), Instruction::ShuffleVector, &Op<0>(), 2) { assert(ShuffleVectorInst::isValidOperands(C1, C2, Mask) && "Invalid shuffle vector instruction operands!"); diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -646,8 +646,8 @@ } else if (VectorType* VTy = dyn_cast(Ty)) { if (VTy->isScalable()) Result += "nx"; - Result += "v" + utostr(VTy->getVectorNumElements()) + - getMangledTypeStr(VTy->getVectorElementType()); + Result += "v" + utostr(VTy->getNumElements()) + + getMangledTypeStr(VTy->getElementType()); } else if (Ty) { switch (Ty->getTypeID()) { default: llvm_unreachable("Unhandled type"); @@ -1055,7 +1055,7 @@ VectorType *VTy = dyn_cast(Ty); if (!VTy) llvm_unreachable("Expected an argument of Vector Type"); - Type *EltTy = VTy->getVectorElementType(); + Type *EltTy = VTy->getElementType(); return PointerType::getUnqual(EltTy); } case IITDescriptor::VecElementArgument: { @@ -1074,9 +1074,9 @@ // Return the overloaded type (which determines the pointers address space) return Tys[D.getOverloadArgNumber()]; case IITDescriptor::ScalableVecArgument: { - Type *Ty = DecodeFixedType(Infos, Tys, Context); - return VectorType::get(Ty->getVectorElementType(), - { Ty->getVectorNumElements(), true }); + auto *Ty = cast(DecodeFixedType(Infos, Tys, Context)); + return VectorType::get(Ty->getElementType(), + {(unsigned)Ty->getNumElements(), true}); } } llvm_unreachable("unhandled"); @@ -1281,7 +1281,7 @@ if (ReferenceType->getElementCount() != ThisArgType->getElementCount()) return true; - EltTy = ThisArgType->getVectorElementType(); + EltTy = ThisArgType->getElementType(); } return matchIntrinsicType(EltTy, Infos, ArgTys, DeferredChecks, IsDeferredCheck); @@ -1326,15 +1326,13 @@ VectorType *ReferenceType = dyn_cast(ArgTys[RefArgNumber]); VectorType *ThisArgVecTy = dyn_cast(Ty); if (!ThisArgVecTy || !ReferenceType || - (ReferenceType->getVectorNumElements() != - ThisArgVecTy->getVectorNumElements())) + (ReferenceType->getNumElements() != ThisArgVecTy->getNumElements())) return true; PointerType *ThisArgEltTy = - dyn_cast(ThisArgVecTy->getVectorElementType()); + dyn_cast(ThisArgVecTy->getElementType()); if (!ThisArgEltTy) return true; - return ThisArgEltTy->getElementType() != - ReferenceType->getVectorElementType(); + return ThisArgEltTy->getElementType() != ReferenceType->getElementType(); } case IITDescriptor::VecElementArgument: { if (D.getArgumentNumber() >= ArgTys.size()) diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp --- a/llvm/lib/IR/IRBuilder.cpp +++ b/llvm/lib/IR/IRBuilder.cpp @@ -524,7 +524,7 @@ const Twine &Name) { auto PtrsTy = cast(Ptrs->getType()); auto PtrTy = cast(PtrsTy->getElementType()); - unsigned NumElts = PtrsTy->getVectorNumElements(); + unsigned NumElts = PtrsTy->getNumElements(); Type *DataTy = VectorType::get(PtrTy->getElementType(), NumElts); if (!Mask) @@ -554,11 +554,11 @@ Align Alignment, Value *Mask) { auto PtrsTy = cast(Ptrs->getType()); auto DataTy = cast(Data->getType()); - unsigned NumElts = PtrsTy->getVectorNumElements(); + unsigned NumElts = PtrsTy->getNumElements(); #ifndef NDEBUG auto PtrTy = cast(PtrsTy->getElementType()); - assert(NumElts == DataTy->getVectorNumElements() && + assert(NumElts == DataTy->getNumElements() && PtrTy->getElementType() == DataTy->getElementType() && "Incompatible pointer and data types"); #endif diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -1879,7 +1879,8 @@ Instruction *InsertBefore) : Instruction( VectorType::get(cast(V1->getType())->getElementType(), - Mask.size(), V1->getType()->getVectorIsScalable()), + Mask.size(), + cast(V1->getType())->isScalable()), ShuffleVector, OperandTraits::op_begin(this), OperandTraits::operands(this), InsertBefore) { assert(isValidOperands(V1, V2, Mask) && @@ -1894,7 +1895,8 @@ const Twine &Name, BasicBlock *InsertAtEnd) : Instruction( VectorType::get(cast(V1->getType())->getElementType(), - Mask.size(), V1->getType()->getVectorIsScalable()), + Mask.size(), + cast(V1->getType())->isScalable()), ShuffleVector, OperandTraits::op_begin(this), OperandTraits::operands(this), InsertAtEnd) { assert(isValidOperands(V1, V2, Mask) && @@ -1907,7 +1909,7 @@ } void ShuffleVectorInst::commute() { - int NumOpElts = Op<0>()->getType()->getVectorNumElements(); + int NumOpElts = cast(Op<0>()->getType())->getNumElements(); int NumMaskElts = ShuffleMask.size(); SmallVector NewMask(NumMaskElts); for (int i = 0; i != NumMaskElts; ++i) { @@ -1936,7 +1938,7 @@ if (Elem != UndefMaskElem && Elem >= V1Size * 2) return false; - if (V1->getType()->getVectorIsScalable()) + if (cast(V1->getType())->isScalable()) if ((Mask[0] != 0 && Mask[0] != UndefMaskElem) || !is_splat(Mask)) return false; @@ -1952,7 +1954,7 @@ // Mask must be vector of i32. auto *MaskTy = dyn_cast(Mask->getType()); if (!MaskTy || !MaskTy->getElementType()->isIntegerTy(32) || - MaskTy->isScalable() != V1->getType()->getVectorIsScalable()) + MaskTy->isScalable() != cast(V1->getType())->isScalable()) return false; // Check to see if Mask is valid. @@ -1985,7 +1987,7 @@ void ShuffleVectorInst::getShuffleMask(const Constant *Mask, SmallVectorImpl &Result) { - unsigned NumElts = Mask->getType()->getVectorElementCount().Min; + unsigned NumElts = cast(Mask->getType())->getElementCount().Min; if (isa(Mask)) { Result.resize(NumElts, 0); return; @@ -2010,7 +2012,7 @@ Constant *ShuffleVectorInst::convertShuffleMaskForBitcode(ArrayRef Mask, Type *ResultTy) { Type *Int32Ty = Type::getInt32Ty(ResultTy->getContext()); - if (ResultTy->getVectorIsScalable()) { + if (cast(ResultTy)->isScalable()) { assert(is_splat(Mask) && "Unexpected shuffle"); Type *VecTy = VectorType::get(Int32Ty, Mask.size(), true); if (Mask[0] == 0) @@ -2170,8 +2172,8 @@ } bool ShuffleVectorInst::isIdentityWithPadding() const { - int NumOpElts = Op<0>()->getType()->getVectorNumElements(); - int NumMaskElts = getType()->getVectorNumElements(); + int NumOpElts = cast(Op<0>()->getType())->getNumElements(); + int NumMaskElts = cast(getType())->getNumElements(); if (NumMaskElts <= NumOpElts) return false; @@ -2189,8 +2191,8 @@ } bool ShuffleVectorInst::isIdentityWithExtract() const { - int NumOpElts = Op<0>()->getType()->getVectorNumElements(); - int NumMaskElts = getType()->getVectorNumElements(); + int NumOpElts = cast(Op<0>()->getType())->getNumElements(); + int NumMaskElts = getType()->getNumElements(); if (NumMaskElts >= NumOpElts) return false; @@ -2202,8 +2204,8 @@ if (isa(Op<0>()) || isa(Op<1>())) return false; - int NumOpElts = Op<0>()->getType()->getVectorNumElements(); - int NumMaskElts = getType()->getVectorNumElements(); + int NumOpElts = cast(Op<0>()->getType())->getNumElements(); + int NumMaskElts = getType()->getNumElements(); if (NumMaskElts != NumOpElts * 2) return false; @@ -2944,7 +2946,8 @@ "Invalid cast"); assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast"); assert((!Ty->isVectorTy() || - Ty->getVectorNumElements() == S->getType()->getVectorNumElements()) && + cast(Ty)->getNumElements() == + cast(S->getType())->getNumElements()) && "Invalid cast"); if (Ty->isIntOrIntVectorTy()) @@ -2962,7 +2965,8 @@ "Invalid cast"); assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast"); assert((!Ty->isVectorTy() || - Ty->getVectorNumElements() == S->getType()->getVectorNumElements()) && + cast(Ty)->getNumElements() == + cast(S->getType())->getNumElements()) && "Invalid cast"); if (Ty->isIntOrIntVectorTy()) diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2825,8 +2825,9 @@ &I); Assert(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(), "AddrSpaceCast must be between different address spaces", &I); - if (SrcTy->isVectorTy()) - Assert(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements(), + if (auto *SrcVTy = dyn_cast(SrcTy)) + Assert(SrcVTy->getNumElements() == + cast(DestTy)->getNumElements(), "AddrSpaceCast vector pointer number of elements mismatch", &I); visitInstruction(I); } @@ -3333,16 +3334,18 @@ GEP.getResultElementType() == ElTy, "GEP is not of right type for indices!", &GEP, ElTy); - if (GEP.getType()->isVectorTy()) { + if (auto *GEPVTy = dyn_cast(GEP.getType())) { // Additional checks for vector GEPs. - unsigned GEPWidth = GEP.getType()->getVectorNumElements(); + unsigned GEPWidth = GEPVTy->getNumElements(); if (GEP.getPointerOperandType()->isVectorTy()) - Assert(GEPWidth == GEP.getPointerOperandType()->getVectorNumElements(), - "Vector GEP result width doesn't match operand's", &GEP); + Assert( + GEPWidth == + cast(GEP.getPointerOperandType())->getNumElements(), + "Vector GEP result width doesn't match operand's", &GEP); for (Value *Idx : Idxs) { Type *IndexTy = Idx->getType(); - if (IndexTy->isVectorTy()) { - unsigned IndexWidth = IndexTy->getVectorNumElements(); + if (auto *IndexVTy = dyn_cast(IndexTy)) { + unsigned IndexWidth = IndexVTy->getNumElements(); Assert(IndexWidth == GEPWidth, "Invalid GEP index vector width", &GEP); } Assert(IndexTy->isIntOrIntVectorTy(), @@ -4656,8 +4659,8 @@ "masked_load: return must match pointer type", Call); Assert(PassThru->getType() == DataTy, "masked_load: pass through and data type must match", Call); - Assert(Mask->getType()->getVectorNumElements() == - DataTy->getVectorNumElements(), + Assert(cast(Mask->getType())->getNumElements() == + cast(DataTy)->getNumElements(), "masked_load: vector mask must be same length as data", Call); break; } @@ -4675,8 +4678,8 @@ Type *DataTy = cast(Ptr->getType())->getElementType(); Assert(DataTy == Val->getType(), "masked_store: storee must match pointer type", Call); - Assert(Mask->getType()->getVectorNumElements() == - DataTy->getVectorNumElements(), + Assert(cast(Mask->getType())->getNumElements() == + cast(DataTy)->getNumElements(), "masked_store: vector mask must be same length as data", Call); break; }