diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -6149,25 +6149,25 @@ case NEON::BI__builtin_neon_vbfdot_v: case NEON::BI__builtin_neon_vbfdotq_v: { llvm::Type *InputTy = - llvm::VectorType::get(Int8Ty, Ty->getPrimitiveSizeInBits() / 8); + llvm::FixedVectorType::get(Int8Ty, Ty->getPrimitiveSizeInBits() / 8); llvm::Type *Tys[2] = { Ty, InputTy }; return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vbfdot"); } case NEON::BI__builtin_neon_vbfmmlaq_v: { llvm::Type *InputTy = - llvm::VectorType::get(Int8Ty, Ty->getPrimitiveSizeInBits() / 8); + llvm::FixedVectorType::get(Int8Ty, Ty->getPrimitiveSizeInBits() / 8); llvm::Type *Tys[2] = { Ty, InputTy }; return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vbfmmla"); } case NEON::BI__builtin_neon_vbfmlalbq_v: { llvm::Type *InputTy = - llvm::VectorType::get(Int8Ty, Ty->getPrimitiveSizeInBits() / 8); + llvm::FixedVectorType::get(Int8Ty, Ty->getPrimitiveSizeInBits() / 8); llvm::Type *Tys[2] = { Ty, InputTy }; return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vbfmlalb"); } case NEON::BI__builtin_neon_vbfmlaltq_v: { llvm::Type *InputTy = - llvm::VectorType::get(Int8Ty, Ty->getPrimitiveSizeInBits() / 8); + llvm::FixedVectorType::get(Int8Ty, Ty->getPrimitiveSizeInBits() / 8); llvm::Type *Tys[2] = { Ty, InputTy }; return EmitNeonCall(CGM.getIntrinsic(Int, Tys), Ops, "vbfmlalt"); } 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 @@ -443,8 +443,20 @@ /// This static method is the primary way to construct an VectorType. static VectorType *get(Type *ElementType, ElementCount EC); + + /// Base class getter that specifically constructs a FixedVectorType. This + /// function is deprecated, and will be removed after LLVM 11 ships. Since + /// this always returns a FixedVectorType via a base VectorType pointer, + /// FixedVectorType::get(Type *, unsigned) is strictly better since no cast is + /// required to call getNumElements() on the result. + LLVM_ATTRIBUTE_DEPRECATED( + inline static VectorType *get(Type *ElementType, unsigned NumElements), + "The base class version of get with the scalable argument defaulted to " + "false is deprecated. Either call VectorType::get(Type *, unsigned, " + "bool) and pass false, or call FixedVectorType::get(Type *, unsigned)."); + static VectorType *get(Type *ElementType, unsigned NumElements, - bool Scalable = false) { + bool Scalable) { return VectorType::get(ElementType, {NumElements, Scalable}); } @@ -537,6 +549,10 @@ } }; +inline VectorType *VectorType::get(Type *ElementType, unsigned NumElements) { + return VectorType::get(ElementType, NumElements, false); +} + /// Class to represent fixed width SIMD vectors class FixedVectorType : public VectorType { protected: diff --git a/llvm/unittests/Analysis/VectorUtilsTest.cpp b/llvm/unittests/Analysis/VectorUtilsTest.cpp --- a/llvm/unittests/Analysis/VectorUtilsTest.cpp +++ b/llvm/unittests/Analysis/VectorUtilsTest.cpp @@ -77,7 +77,7 @@ } // namespace TEST_F(BasicTest, isSplat) { - Value *UndefVec = UndefValue::get(VectorType::get(IRB.getInt8Ty(), 4)); + Value *UndefVec = UndefValue::get(FixedVectorType::get(IRB.getInt8Ty(), 4)); EXPECT_TRUE(isSplatValue(UndefVec)); Constant *UndefScalar = UndefValue::get(IRB.getInt8Ty()); diff --git a/llvm/unittests/CodeGen/LowLevelTypeTest.cpp b/llvm/unittests/CodeGen/LowLevelTypeTest.cpp --- a/llvm/unittests/CodeGen/LowLevelTypeTest.cpp +++ b/llvm/unittests/CodeGen/LowLevelTypeTest.cpp @@ -85,7 +85,7 @@ // Test Type->LLT conversion. Type *IRSTy = IntegerType::get(C, S); - Type *IRTy = VectorType::get(IRSTy, Elts); + Type *IRTy = FixedVectorType::get(IRSTy, Elts); EXPECT_EQ(VTy, getLLTForType(*IRTy, DL)); } } @@ -222,8 +222,8 @@ // Test Type->LLT conversion. Type *IRTy = PointerType::get(IntegerType::get(C, 8), AS); EXPECT_EQ(Ty, getLLTForType(*IRTy, DL)); - Type *IRVTy = - VectorType::get(PointerType::get(IntegerType::get(C, 8), AS), NumElts); + Type *IRVTy = FixedVectorType::get( + PointerType::get(IntegerType::get(C, 8), AS), NumElts); EXPECT_EQ(VTy, getLLTForType(*IRVTy, DL)); } } diff --git a/llvm/unittests/FuzzMutate/OperationsTest.cpp b/llvm/unittests/FuzzMutate/OperationsTest.cpp --- a/llvm/unittests/FuzzMutate/OperationsTest.cpp +++ b/llvm/unittests/FuzzMutate/OperationsTest.cpp @@ -337,7 +337,7 @@ Type *OpaqueTy = StructType::create(Ctx, "OpaqueStruct"); Type *ZeroSizedArrayTy = ArrayType::get(Int64Ty, 0); Type *ArrayTy = ArrayType::get(Int64Ty, 4); - Type *VectorTy = VectorType::get(Int32Ty, 2); + Type *VectorTy = FixedVectorType::get(Int32Ty, 2); auto EVOp = fuzzerop::extractValueDescriptor(1); auto IVOp = fuzzerop::insertValueDescriptor(1); diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp --- a/llvm/unittests/IR/ConstantsTest.cpp +++ b/llvm/unittests/IR/ConstantsTest.cpp @@ -131,9 +131,9 @@ Type *Int8PtrTy = Type::getInt8PtrTy(C); Type *Int32PtrTy = Type::getInt32PtrTy(C); Type *Int64Ty = Type::getInt64Ty(C); - VectorType *Int8PtrVecTy = VectorType::get(Int8PtrTy, 4); - VectorType *Int32PtrVecTy = VectorType::get(Int32PtrTy, 4); - VectorType *Int64VecTy = VectorType::get(Int64Ty, 4); + VectorType *Int8PtrVecTy = FixedVectorType::get(Int8PtrTy, 4); + VectorType *Int32PtrVecTy = FixedVectorType::get(Int32PtrTy, 4); + VectorType *Int64VecTy = FixedVectorType::get(Int64Ty, 4); // ptrtoint i8* to i64 EXPECT_EQ(Constant::getNullValue(Int64Ty), @@ -210,7 +210,7 @@ Constant *P3 = ConstantExpr::getTrunc(P0, Int1Ty); Constant *P4 = ConstantExpr::getPtrToInt(Global2, Int32Ty); Constant *P5 = ConstantExpr::getUIToFP(P4, FloatTy); - Constant *P6 = ConstantExpr::getBitCast(P4, VectorType::get(Int16Ty, 2)); + Constant *P6 = ConstantExpr::getBitCast(P4, FixedVectorType::get(Int16Ty, 2)); Constant *One = ConstantInt::get(Int32Ty, 1); Constant *Two = ConstantInt::get(Int64Ty, 2); diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp --- a/llvm/unittests/IR/IRBuilderTest.cpp +++ b/llvm/unittests/IR/IRBuilderTest.cpp @@ -807,7 +807,7 @@ TEST_F(IRBuilderTest, InsertExtractElement) { IRBuilder<> Builder(BB); - auto VecTy = VectorType::get(Builder.getInt64Ty(), 4); + auto VecTy = FixedVectorType::get(Builder.getInt64Ty(), 4); auto Elt1 = Builder.getInt64(-1); auto Elt2 = Builder.getInt64(-2); Value *Vec = UndefValue::get(VecTy); diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp --- a/llvm/unittests/IR/InstructionsTest.cpp +++ b/llvm/unittests/IR/InstructionsTest.cpp @@ -186,18 +186,18 @@ Type *Int16Ty = Type::getInt16Ty(C); Type *Int32Ty = Type::getInt32Ty(C); Type *Int64Ty = Type::getInt64Ty(C); - Type *V8x8Ty = VectorType::get(Int8Ty, 8); - Type *V8x64Ty = VectorType::get(Int64Ty, 8); + Type *V8x8Ty = FixedVectorType::get(Int8Ty, 8); + Type *V8x64Ty = FixedVectorType::get(Int64Ty, 8); Type *X86MMXTy = Type::getX86_MMXTy(C); Type *HalfTy = Type::getHalfTy(C); Type *FloatTy = Type::getFloatTy(C); Type *DoubleTy = Type::getDoubleTy(C); - Type *V2Int32Ty = VectorType::get(Int32Ty, 2); - Type *V2Int64Ty = VectorType::get(Int64Ty, 2); - Type *V4Int16Ty = VectorType::get(Int16Ty, 4); - Type *V1Int16Ty = VectorType::get(Int16Ty, 1); + Type *V2Int32Ty = FixedVectorType::get(Int32Ty, 2); + Type *V2Int64Ty = FixedVectorType::get(Int64Ty, 2); + Type *V4Int16Ty = FixedVectorType::get(Int16Ty, 4); + Type *V1Int16Ty = FixedVectorType::get(Int16Ty, 1); Type *VScaleV2Int32Ty = VectorType::get(Int32Ty, 2, true); Type *VScaleV2Int64Ty = VectorType::get(Int64Ty, 2, true); @@ -210,16 +210,16 @@ Type *Int32PtrAS1Ty = PointerType::get(Int32Ty, 1); Type *Int64PtrAS1Ty = PointerType::get(Int64Ty, 1); - Type *V2Int32PtrAS1Ty = VectorType::get(Int32PtrAS1Ty, 2); - Type *V2Int64PtrAS1Ty = VectorType::get(Int64PtrAS1Ty, 2); - Type *V4Int32PtrAS1Ty = VectorType::get(Int32PtrAS1Ty, 4); + Type *V2Int32PtrAS1Ty = FixedVectorType::get(Int32PtrAS1Ty, 2); + Type *V2Int64PtrAS1Ty = FixedVectorType::get(Int64PtrAS1Ty, 2); + Type *V4Int32PtrAS1Ty = FixedVectorType::get(Int32PtrAS1Ty, 4); Type *VScaleV4Int32PtrAS1Ty = VectorType::get(Int32PtrAS1Ty, 4, true); - Type *V4Int64PtrAS1Ty = VectorType::get(Int64PtrAS1Ty, 4); + Type *V4Int64PtrAS1Ty = FixedVectorType::get(Int64PtrAS1Ty, 4); - Type *V2Int64PtrTy = VectorType::get(Int64PtrTy, 2); - Type *V2Int32PtrTy = VectorType::get(Int32PtrTy, 2); + Type *V2Int64PtrTy = FixedVectorType::get(Int64PtrTy, 2); + Type *V2Int32PtrTy = FixedVectorType::get(Int32PtrTy, 2); Type *VScaleV2Int32PtrTy = VectorType::get(Int32PtrTy, 2, true); - Type *V4Int32PtrTy = VectorType::get(Int32PtrTy, 4); + Type *V4Int32PtrTy = FixedVectorType::get(Int32PtrTy, 4); Type *VScaleV4Int32PtrTy = VectorType::get(Int32PtrTy, 4, true); Type *VScaleV4Int64PtrTy = VectorType::get(Int64PtrTy, 4, true); @@ -390,8 +390,8 @@ PointerType *Ptri8Ty = PointerType::get(I8Ty, 0); PointerType *Ptri32Ty = PointerType::get(I32Ty, 0); - VectorType *V2xi8PTy = VectorType::get(Ptri8Ty, 2); - VectorType *V2xi32PTy = VectorType::get(Ptri32Ty, 2); + VectorType *V2xi8PTy = FixedVectorType::get(Ptri8Ty, 2); + VectorType *V2xi32PTy = FixedVectorType::get(Ptri32Ty, 2); // Test different aspects of the vector-of-pointers type // and GEPs which use this type. @@ -1174,7 +1174,7 @@ std::unique_ptr ICall(CallInst::Create(IFnTy, ICallee, {}, "")); EXPECT_FALSE(isa(ICall)); - Type *VITy = VectorType::get(ITy, 2); + Type *VITy = FixedVectorType::get(ITy, 2); FunctionType *VIFnTy = FunctionType::get(VITy, {}); Value *VICallee = Constant::getNullValue(VIFnTy->getPointerTo()); std::unique_ptr VICall(CallInst::Create(VIFnTy, VICallee, {}, "")); @@ -1192,7 +1192,7 @@ std::unique_ptr FCall(CallInst::Create(FFnTy, FCallee, {}, "")); EXPECT_TRUE(isa(FCall)); - Type *VFTy = VectorType::get(FTy, 2); + Type *VFTy = FixedVectorType::get(FTy, 2); FunctionType *VFFnTy = FunctionType::get(VFTy, {}); Value *VFCallee = Constant::getNullValue(VFFnTy->getPointerTo()); std::unique_ptr VFCall(CallInst::Create(VFFnTy, VFCallee, {}, "")); diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp --- a/llvm/unittests/IR/PatternMatch.cpp +++ b/llvm/unittests/IR/PatternMatch.cpp @@ -928,9 +928,9 @@ // // SP1 = VectorSplat(2, i8 2) // SP2 = VectorSplat(2, i8 %Val) - Type *VecTy = VectorType::get(IRB.getInt8Ty(), 2); + Type *VecTy = FixedVectorType::get(IRB.getInt8Ty(), 2); Type *i32 = IRB.getInt32Ty(); - Type *i32VecTy = VectorType::get(i32, 2); + Type *i32VecTy = FixedVectorType::get(i32, 2); Value *Val = IRB.CreateAdd(IRB.getInt8(0), IRB.getInt8(1)); Value *Val2 = IRB.CreateAdd(Val, IRB.getInt8(3)); @@ -1021,7 +1021,7 @@ TEST_F(PatternMatchTest, VectorUndefInt) { Type *ScalarTy = IRB.getInt8Ty(); - Type *VectorTy = VectorType::get(ScalarTy, 4); + Type *VectorTy = FixedVectorType::get(ScalarTy, 4); Constant *ScalarUndef = UndefValue::get(ScalarTy); Constant *VectorUndef = UndefValue::get(VectorTy); Constant *ScalarZero = Constant::getNullValue(ScalarTy); @@ -1086,7 +1086,7 @@ TEST_F(PatternMatchTest, VectorUndefFloat) { Type *ScalarTy = IRB.getFloatTy(); - Type *VectorTy = VectorType::get(ScalarTy, 4); + Type *VectorTy = FixedVectorType::get(ScalarTy, 4); Constant *ScalarUndef = UndefValue::get(ScalarTy); Constant *VectorUndef = UndefValue::get(VectorTy); Constant *ScalarZero = Constant::getNullValue(ScalarTy); diff --git a/llvm/unittests/IR/VectorTypesTest.cpp b/llvm/unittests/IR/VectorTypesTest.cpp --- a/llvm/unittests/IR/VectorTypesTest.cpp +++ b/llvm/unittests/IR/VectorTypesTest.cpp @@ -43,15 +43,12 @@ EXPECT_EQ(V16Int8Ty->getNumElements(), 16U); EXPECT_EQ(V16Int8Ty->getElementType()->getScalarSizeInBits(), 8U); - auto *V8Int32Ty = dyn_cast(VectorType::get(Int32Ty, 8)); + auto *V8Int32Ty = + dyn_cast(VectorType::get(Int32Ty, 8, false)); ASSERT_NE(nullptr, V8Int32Ty); EXPECT_EQ(V8Int32Ty->getNumElements(), 8U); EXPECT_EQ(V8Int32Ty->getElementType()->getScalarSizeInBits(), 32U); - auto *V8Int32TyExplicitFalse = - dyn_cast(VectorType::get(Int32Ty, 8, false)); - EXPECT_VTY_EQ(V8Int32Ty, V8Int32TyExplicitFalse); - auto *V8Int8Ty = dyn_cast(VectorType::get(Int8Ty, V8Int32Ty)); EXPECT_VTY_NE(V8Int32Ty, V8Int8Ty);