Skip to content

Commit 48c6ff6

Browse files
authored
Avoid usage of deprecated "VectorType::getNumElements" (#737)
Replaced usages of "VectorType::getNumElements" with "FixedVectorType::getNumElements" Signed-off-by: amochalo <[email protected]>
1 parent 246ba20 commit 48c6ff6

File tree

6 files changed

+37
-35
lines changed

6 files changed

+37
-35
lines changed

lib/SPIRV/OCL20ToSPIRV.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,23 +1335,24 @@ void OCL20ToSPIRV::visitCallRelational(CallInst *CI, StringRef DemangledName) {
13351335
if (CI->getOperand(0)->getType()->isVectorTy())
13361336
Ret = FixedVectorType::get(
13371337
Type::getInt1Ty(*Ctx),
1338-
cast<VectorType>(CI->getOperand(0)->getType())->getNumElements());
1338+
cast<FixedVectorType>(CI->getOperand(0)->getType())
1339+
->getNumElements());
13391340
return SPIRVName;
13401341
},
13411342
[=](CallInst *NewCI) -> Instruction * {
13421343
Value *False = nullptr, *True = nullptr;
13431344
if (NewCI->getType()->isVectorTy()) {
13441345
Type *IntTy = Type::getInt32Ty(*Ctx);
1345-
if (cast<VectorType>(NewCI->getOperand(0)->getType())
1346+
if (cast<FixedVectorType>(NewCI->getOperand(0)->getType())
13461347
->getElementType()
13471348
->isDoubleTy())
13481349
IntTy = Type::getInt64Ty(*Ctx);
1349-
if (cast<VectorType>(NewCI->getOperand(0)->getType())
1350+
if (cast<FixedVectorType>(NewCI->getOperand(0)->getType())
13501351
->getElementType()
13511352
->isHalfTy())
13521353
IntTy = Type::getInt16Ty(*Ctx);
13531354
Type *VTy = FixedVectorType::get(
1354-
IntTy, cast<VectorType>(NewCI->getType())->getNumElements());
1355+
IntTy, cast<FixedVectorType>(NewCI->getType())->getNumElements());
13551356
False = Constant::getNullValue(VTy);
13561357
True = Constant::getAllOnesValue(VTy);
13571358
} else {
@@ -1618,7 +1619,7 @@ static void processSubgroupBlockReadWriteINTEL(CallInst *CI,
16181619
OCLBuiltinTransInfo &Info,
16191620
const Type *DataTy, Module *M) {
16201621
unsigned VectorNumElements = 1;
1621-
if (auto *VecTy = dyn_cast<VectorType>(DataTy))
1622+
if (auto *VecTy = dyn_cast<FixedVectorType>(DataTy))
16221623
VectorNumElements = VecTy->getNumElements();
16231624
unsigned ElementBitSize = DataTy->getScalarSizeInBits();
16241625
Info.Postfix = "_";

lib/SPIRV/OCLUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ unsigned encodeVecTypeHint(Type *Ty) {
805805
llvm_unreachable("invalid integer type");
806806
}
807807
}
808-
if (VectorType *VecTy = dyn_cast<VectorType>(Ty)) {
808+
if (FixedVectorType *VecTy = dyn_cast<FixedVectorType>(Ty)) {
809809
Type *EleTy = VecTy->getElementType();
810810
unsigned Size = VecTy->getNumElements();
811811
return Size << 16 | encodeVecTypeHint(EleTy);

lib/SPIRV/SPIRVReader.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ bool SPIRVToLLVM::transOCLBuiltinFromVariable(GlobalVariable *GV,
336336
std::vector<Value *> Vectors;
337337
Loads.push_back(LD);
338338
if (HasIndexArg) {
339-
auto *VecTy = cast<VectorType>(
339+
auto *VecTy = cast<FixedVectorType>(
340340
LD->getPointerOperandType()->getPointerElementType());
341341
Value *EmptyVec = UndefValue::get(VecTy);
342342
Vectors.push_back(EmptyVec);
@@ -1937,7 +1937,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
19371937
IRBuilder<> Builder(BB);
19381938
auto Scalar = transValue(VTS->getScalar(), F, BB);
19391939
auto Vector = transValue(VTS->getVector(), F, BB);
1940-
auto *VecTy = cast<VectorType>(Vector->getType());
1940+
auto *VecTy = cast<FixedVectorType>(Vector->getType());
19411941
unsigned VecSize = VecTy->getNumElements();
19421942
auto NewVec = Builder.CreateVectorSplat(VecSize, Scalar, Scalar->getName());
19431943
NewVec->takeName(Scalar);
@@ -1965,8 +1965,8 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
19651965

19661966
unsigned M = Mat->getType()->getArrayNumElements();
19671967

1968-
auto *VecTy = cast<VectorType>(Vec->getType());
1969-
VectorType *VTy = FixedVectorType::get(VecTy->getElementType(), M);
1968+
auto *VecTy = cast<FixedVectorType>(Vec->getType());
1969+
FixedVectorType *VTy = FixedVectorType::get(VecTy->getElementType(), M);
19701970
auto ETy = VTy->getElementType();
19711971
unsigned N = VecTy->getNumElements();
19721972
Value *V = Builder.CreateVectorSplat(M, ConstantFP::get(ETy, 0.0));
@@ -1994,7 +1994,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
19941994
auto Matrix = transValue(MTS->getMatrix(), F, BB);
19951995
uint64_t ColNum = Matrix->getType()->getArrayNumElements();
19961996
auto ColType = cast<ArrayType>(Matrix->getType())->getElementType();
1997-
auto VecSize = cast<VectorType>(ColType)->getNumElements();
1997+
auto VecSize = cast<FixedVectorType>(ColType)->getNumElements();
19981998
auto NewVec = Builder.CreateVectorSplat(VecSize, Scalar, Scalar->getName());
19991999
NewVec->takeName(Scalar);
20002000

@@ -2031,8 +2031,8 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
20312031
// where sum is defined as vector sum.
20322032

20332033
unsigned M = Mat->getType()->getArrayNumElements();
2034-
VectorType *VTy =
2035-
cast<VectorType>(cast<ArrayType>(Mat->getType())->getElementType());
2034+
FixedVectorType *VTy = cast<FixedVectorType>(
2035+
cast<ArrayType>(Mat->getType())->getElementType());
20362036
unsigned N = VTy->getNumElements();
20372037
auto ETy = VTy->getElementType();
20382038
Value *V = Builder.CreateVectorSplat(N, ConstantFP::get(ETy, 0.0));
@@ -2086,10 +2086,10 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
20862086

20872087
unsigned C1 = M1->getType()->getArrayNumElements();
20882088
unsigned C2 = M2->getType()->getArrayNumElements();
2089-
VectorType *V1Ty =
2090-
cast<VectorType>(cast<ArrayType>(M1->getType())->getElementType());
2091-
VectorType *V2Ty =
2092-
cast<VectorType>(cast<ArrayType>(M2->getType())->getElementType());
2089+
FixedVectorType *V1Ty =
2090+
cast<FixedVectorType>(cast<ArrayType>(M1->getType())->getElementType());
2091+
FixedVectorType *V2Ty =
2092+
cast<FixedVectorType>(cast<ArrayType>(M2->getType())->getElementType());
20932093
unsigned R1 = V1Ty->getNumElements();
20942094
unsigned R2 = V2Ty->getNumElements();
20952095
auto ETy = V1Ty->getElementType();
@@ -2127,8 +2127,8 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
21272127
IRBuilder<> Builder(BB);
21282128
auto Matrix = transValue(TR->getMatrix(), F, BB);
21292129
unsigned ColNum = Matrix->getType()->getArrayNumElements();
2130-
VectorType *ColTy =
2131-
cast<VectorType>(cast<ArrayType>(Matrix->getType())->getElementType());
2130+
FixedVectorType *ColTy = cast<FixedVectorType>(
2131+
cast<ArrayType>(Matrix->getType())->getElementType());
21322132
unsigned RowNum = ColTy->getNumElements();
21332133

21342134
auto VTy = FixedVectorType::get(ColTy->getElementType(), ColNum);
@@ -4255,7 +4255,7 @@ Instruction *SPIRVToLLVM::transOCLAllAny(SPIRVInstruction *I, BasicBlock *BB) {
42554255
auto OldArg = CI->getOperand(0);
42564256
auto NewArgTy = FixedVectorType::get(
42574257
Int32Ty,
4258-
cast<VectorType>(OldArg->getType())->getNumElements());
4258+
cast<FixedVectorType>(OldArg->getType())->getNumElements());
42594259
auto NewArg =
42604260
CastInst::CreateSExtOrBitCast(OldArg, NewArgTy, "", CI);
42614261
Args[0] = NewArg;
@@ -4281,16 +4281,17 @@ Instruction *SPIRVToLLVM::transOCLRelational(SPIRVInstruction *I,
42814281
Type *IntTy = Type::getInt32Ty(*Context);
42824282
RetTy = IntTy;
42834283
if (CI->getType()->isVectorTy()) {
4284-
if (cast<VectorType>(CI->getOperand(0)->getType())
4284+
if (cast<FixedVectorType>(CI->getOperand(0)->getType())
42854285
->getElementType()
42864286
->isDoubleTy())
42874287
IntTy = Type::getInt64Ty(*Context);
4288-
if (cast<VectorType>(CI->getOperand(0)->getType())
4288+
if (cast<FixedVectorType>(CI->getOperand(0)->getType())
42894289
->getElementType()
42904290
->isHalfTy())
42914291
IntTy = Type::getInt16Ty(*Context);
42924292
RetTy = FixedVectorType::get(
4293-
IntTy, cast<VectorType>(CI->getType())->getNumElements());
4293+
IntTy,
4294+
cast<FixedVectorType>(CI->getType())->getNumElements());
42944295
}
42954296
return CI->getCalledFunction()->getName().str();
42964297
},
@@ -4299,7 +4300,7 @@ Instruction *SPIRVToLLVM::transOCLRelational(SPIRVInstruction *I,
42994300
if (NewCI->getType()->isVectorTy())
43004301
RetTy = FixedVectorType::get(
43014302
Type::getInt1Ty(*Context),
4302-
cast<VectorType>(NewCI->getType())->getNumElements());
4303+
cast<FixedVectorType>(NewCI->getType())->getNumElements());
43034304
return CastInst::CreateTruncOrBitCast(NewCI, RetTy, "",
43044305
NewCI->getNextNode());
43054306
},

lib/SPIRV/SPIRVToOCL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ void SPIRVToOCL::visitCallSPRIVImageQuerySize(CallInst *CI) {
190190
GetImageSize,
191191
FixedVectorType::get(
192192
CI->getType()->getScalarType(),
193-
cast<VectorType>(GetImageSize->getType())->getNumElements()),
193+
cast<FixedVectorType>(GetImageSize->getType())->getNumElements()),
194194
false, CI->getName(), CI);
195195
}
196196
}
197197

198198
if (ImgArray || ImgDim == 3) {
199-
auto *VecTy = cast<VectorType>(CI->getType());
199+
auto *VecTy = cast<FixedVectorType>(CI->getType());
200200
const unsigned ImgQuerySizeRetEls = VecTy->getNumElements();
201201

202202
if (ImgDim == 1) {
@@ -224,7 +224,7 @@ void SPIRVToOCL::visitCallSPRIVImageQuerySize(CallInst *CI) {
224224
if (ImgArray) {
225225
assert((ImgDim == 1 || ImgDim == 2) && "invalid image array type");
226226
// Insert get_image_array_size to the last position of the resulting vector.
227-
auto *VecTy = cast<VectorType>(CI->getType());
227+
auto *VecTy = cast<FixedVectorType>(CI->getType());
228228
Type *SizeTy =
229229
Type::getIntNTy(*Ctx, M->getDataLayout().getPointerSizeInBits(0));
230230
Instruction *GetImageArraySize = addCallInst(
@@ -482,7 +482,7 @@ void SPIRVToOCL::visitCallSPIRVImageMediaBlockBuiltin(CallInst *CI, Op OC) {
482482
else
483483
assert(0 && "Unsupported texel type!");
484484

485-
if (auto *VecTy = dyn_cast<VectorType>(RetType)) {
485+
if (auto *VecTy = dyn_cast<FixedVectorType>(RetType)) {
486486
unsigned int NumEl = VecTy->getNumElements();
487487
assert((NumEl == 2 || NumEl == 4 || NumEl == 8 || NumEl == 16) &&
488488
"Wrong function type!");

lib/SPIRV/SPIRVUtil.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ std::string mapLLVMTypeToOCLType(const Type *Ty, bool Signed) {
141141
}
142142
return SignPrefix + Stem;
143143
}
144-
if (auto VecTy = dyn_cast<VectorType>(Ty)) {
144+
if (auto VecTy = dyn_cast<FixedVectorType>(Ty)) {
145145
Type *EleTy = VecTy->getElementType();
146146
unsigned Size = VecTy->getNumElements();
147147
std::stringstream Ss;
@@ -738,7 +738,7 @@ void makeVector(Instruction *InsPos, std::vector<Value *> &Ops,
738738
void expandVector(Instruction *InsPos, std::vector<Value *> &Ops,
739739
size_t VecPos) {
740740
auto Vec = Ops[VecPos];
741-
auto *VT = dyn_cast<VectorType>(Vec->getType());
741+
auto *VT = dyn_cast<FixedVectorType>(Vec->getType());
742742
if (!VT)
743743
return;
744744
size_t N = VT->getNumElements();
@@ -1045,7 +1045,7 @@ static SPIR::RefParamType transTypeDesc(Type *Ty,
10451045
return SPIR::RefParamType(new SPIR::PrimitiveType(SPIR::PRIMITIVE_FLOAT));
10461046
if (Ty->isDoubleTy())
10471047
return SPIR::RefParamType(new SPIR::PrimitiveType(SPIR::PRIMITIVE_DOUBLE));
1048-
if (auto *VecTy = dyn_cast<VectorType>(Ty)) {
1048+
if (auto *VecTy = dyn_cast<FixedVectorType>(Ty)) {
10491049
return SPIR::RefParamType(new SPIR::VectorType(
10501050
transTypeDesc(VecTy->getElementType(), Info), VecTy->getNumElements()));
10511051
}
@@ -1159,7 +1159,7 @@ Value *getScalarOrArray(Value *V, unsigned Size, Instruction *Pos) {
11591159
Constant *getScalarOrVectorConstantInt(Type *T, uint64_t V, bool IsSigned) {
11601160
if (auto IT = dyn_cast<IntegerType>(T))
11611161
return ConstantInt::get(IT, V);
1162-
if (auto VT = dyn_cast<VectorType>(T)) {
1162+
if (auto VT = dyn_cast<FixedVectorType>(T)) {
11631163
std::vector<Constant *> EV(
11641164
VT->getNumElements(),
11651165
getScalarOrVectorConstantInt(VT->getElementType(), V, IsSigned));
@@ -1536,7 +1536,7 @@ bool checkTypeForSPIRVExtendedInstLowering(IntrinsicInst *II, SPIRVModule *BM) {
15361536
if (II->getArgOperand(0)->getType() != Ty)
15371537
return false;
15381538
int NumElems = 1;
1539-
if (auto *VecTy = dyn_cast<VectorType>(Ty)) {
1539+
if (auto *VecTy = dyn_cast<FixedVectorType>(Ty)) {
15401540
NumElems = VecTy->getNumElements();
15411541
Ty = VecTy->getElementType();
15421542
}

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ SPIRVType *LLVMToSPIRV::transType(Type *T) {
372372
}
373373
}
374374

375-
if (auto *VecTy = dyn_cast<VectorType>(T))
375+
if (auto *VecTy = dyn_cast<FixedVectorType>(T))
376376
return mapType(T, BM->addVectorType(transType(VecTy->getElementType()),
377377
VecTy->getNumElements()));
378378

@@ -3446,7 +3446,7 @@ LLVMToSPIRV::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
34463446
auto IsVector = ResultTy->isVectorTy();
34473447
if (IsVector)
34483448
BoolTy = FixedVectorType::get(
3449-
BoolTy, cast<VectorType>(ResultTy)->getNumElements());
3449+
BoolTy, cast<FixedVectorType>(ResultTy)->getNumElements());
34503450
auto BBT = transType(BoolTy);
34513451
SPIRVInstruction *Res;
34523452
if (isCmpOpCode(OC)) {

0 commit comments

Comments
 (0)