Skip to content

Commit 7452422

Browse files
committed
Update for PointerType::getElementType deprecation
Update for LLVM commit 184591aeeb5a ("[OpaquePtrs] Deprecate PointerType::getElementType()", 2022-01-25). This commit changes all affected calls to getPointerElementType, which is a temporary solution. Followup work around the getPointerElementType calls will be required to align with LLVM's opaque pointer changes.
1 parent 7854a91 commit 7452422

10 files changed

+30
-33
lines changed

lib/SPIRV/OCLToSPIRV.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ void OCLToSPIRVBase::visitCallEnqueueKernel(CallInst *CI,
15631563
// TODO: these numbers should be obtained from block literal structure
15641564
Type *ParamType = getUnderlyingObject(BlockLiteral)->getType();
15651565
if (PointerType *PT = dyn_cast<PointerType>(ParamType))
1566-
ParamType = PT->getElementType();
1566+
ParamType = PT->getPointerElementType();
15671567
Args.push_back(getInt32(M, DL.getTypeStoreSize(ParamType)));
15681568
Args.push_back(getInt32(M, DL.getPrefTypeAlignment(ParamType)));
15691569

@@ -1615,7 +1615,7 @@ void OCLToSPIRVBase::visitCallKernelQuery(CallInst *CI,
16151615
Value *Param = *Args.rbegin();
16161616
Type *ParamType = getUnderlyingObject(Param)->getType();
16171617
if (PointerType *PT = dyn_cast<PointerType>(ParamType)) {
1618-
ParamType = PT->getElementType();
1618+
ParamType = PT->getPointerElementType();
16191619
}
16201620
// Last arg corresponds to SPIRV Param operand.
16211621
// Insert Invoke in front of Param.
@@ -1711,7 +1711,7 @@ static const char *getSubgroupAVCIntelOpKind(StringRef Name) {
17111711
}
17121712

17131713
static const char *getSubgroupAVCIntelTyKind(Type *Ty) {
1714-
auto STy = cast<StructType>(cast<PointerType>(Ty)->getElementType());
1714+
auto *STy = cast<StructType>(cast<PointerType>(Ty)->getPointerElementType());
17151715
auto TName = STy->getName();
17161716
return TName.endswith("_payload_t") ? "payload" : "result";
17171717
}
@@ -1746,7 +1746,7 @@ void OCLToSPIRVBase::visitSubgroupAVCBuiltinCall(CallInst *CI,
17461746
// Update names for built-ins mapped on two or more SPIRV instructions
17471747
if (FName.find(Prefix + "ime_get_streamout_major_shape_") == 0) {
17481748
auto PTy = cast<PointerType>(CI->getArgOperand(0)->getType());
1749-
auto STy = cast<StructType>(PTy->getElementType());
1749+
auto *STy = cast<StructType>(PTy->getPointerElementType());
17501750
assert(STy->hasName() && "Invalid Subgroup AVC Intel built-in call");
17511751
FName += (STy->getName().contains("single")) ? "_single_reference"
17521752
: "_dual_reference";

lib/SPIRV/OCLUtil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ getOCLOpaqueTypeAddrSpace(SPIR::TypePrimitiveEnum Prim) {
967967
static FunctionType *getBlockInvokeTy(Function *F, unsigned BlockIdx) {
968968
auto Params = F->getFunctionType()->params();
969969
PointerType *FuncPtr = cast<PointerType>(Params[BlockIdx]);
970-
return cast<FunctionType>(FuncPtr->getElementType());
970+
return cast<FunctionType>(FuncPtr->getPointerElementType());
971971
}
972972

973973
class OCLBuiltinFuncMangleInfo : public SPIRV::BuiltinFuncMangleInfo {
@@ -1370,7 +1370,7 @@ bool isSamplerTy(Type *Ty) {
13701370
if (!PTy)
13711371
return false;
13721372

1373-
auto STy = dyn_cast<StructType>(PTy->getElementType());
1373+
auto *STy = dyn_cast<StructType>(PTy->getPointerElementType());
13741374
return STy && STy->hasName() && STy->getName() == kSPR2TypeName::Sampler;
13751375
}
13761376

lib/SPIRV/SPIRVLowerBitCastToNonStandardType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace SPIRV {
5656
static VectorType *getVectorType(Type *Ty) {
5757
assert(Ty != nullptr && "Expected non-null type");
5858
if (auto *ElemTy = dyn_cast<PointerType>(Ty))
59-
Ty = ElemTy->getElementType();
59+
Ty = ElemTy->getPointerElementType();
6060
return dyn_cast<VectorType>(Ty);
6161
}
6262

lib/SPIRV/SPIRVLowerSPIRBlocks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class SPIRVLowerSPIRBlocksBase {
362362
Type *T = G.getInitializer()->getType();
363363
if (!T->isPointerTy())
364364
continue;
365-
T = cast<PointerType>(T)->getElementType();
365+
T = cast<PointerType>(T)->getPointerElementType();
366366
if (!T->isStructTy())
367367
continue;
368368
StringRef STName = cast<StructType>(T)->getName();
@@ -585,7 +585,7 @@ class SPIRVLowerSPIRBlocksBase {
585585

586586
bool isOCLClkEventPtrType(Type *T) {
587587
if (auto PT = dyn_cast<PointerType>(T))
588-
return isPointerToOpaqueStructType(PT->getElementType(),
588+
return isPointerToOpaqueStructType(PT->getPointerElementType(),
589589
SPIR_TYPE_NAME_CLK_EVENT_T);
590590
return false;
591591
}

lib/SPIRV/SPIRVReader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ void transFunctionPointerCallArgumentAttributes(SPIRVValue *BV, CallInst *CI) {
12881288
Attribute::isTypeAttrKind(LlvmAttrKind)
12891289
? Attribute::get(CI->getContext(), LlvmAttrKind,
12901290
cast<PointerType>(CI->getOperand(ArgNo)->getType())
1291-
->getElementType())
1291+
->getPointerElementType())
12921292
: Attribute::get(CI->getContext(), LlvmAttrKind);
12931293
CI->addParamAttr(ArgNo, LlvmAttr);
12941294
}
@@ -2410,7 +2410,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
24102410
else {
24112411
IID = Intrinsic::ptr_annotation;
24122412
auto *PtrTy = dyn_cast<PointerType>(Ty);
2413-
if (PtrTy && isa<IntegerType>(PtrTy->getElementType()))
2413+
if (PtrTy && isa<IntegerType>(PtrTy->getPointerElementType()))
24142414
RetTy = PtrTy;
24152415
// Whether a struct or a pointer to some other type,
24162416
// bitcast to i8*
@@ -2825,7 +2825,7 @@ Function *SPIRVToLLVM::transFunction(SPIRVFunction *BF) {
28252825
Type *AttrTy = nullptr;
28262826
switch (LLVMKind) {
28272827
case Attribute::AttrKind::ByVal:
2828-
AttrTy = cast<PointerType>(I->getType())->getElementType();
2828+
AttrTy = cast<PointerType>(I->getType())->getPointerElementType();
28292829
break;
28302830
case Attribute::AttrKind::StructRet:
28312831
AttrTy = I->getType();

lib/SPIRV/SPIRVRegularizeLLVM.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,12 @@ void SPIRVRegularizeLLVMBase::adaptStructTypes(StructType *ST) {
355355
assert(PtrTy &&
356356
"Expected a pointer to an array to represent joint matrix type");
357357
size_t TypeLayout[4] = {0, 0, 0, 0};
358-
ArrayType *ArrayTy;
359-
auto GetTypeLayout = [&](auto *Ty) -> size_t {
360-
ArrayTy = dyn_cast<ArrayType>(Ty->getElementType());
361-
assert(ArrayTy &&
362-
"Expected a pointer to an array to represent joint matrix type");
363-
return ArrayTy->getNumElements();
364-
};
365-
TypeLayout[0] = GetTypeLayout(PtrTy);
366-
for (size_t I = 1; I != 4; ++I)
367-
TypeLayout[I] = GetTypeLayout(ArrayTy);
358+
ArrayType *ArrayTy = dyn_cast<ArrayType>(PtrTy->getPointerElementType());
359+
TypeLayout[0] = ArrayTy->getNumElements();
360+
for (size_t I = 1; I != 4; ++I) {
361+
ArrayTy = dyn_cast<ArrayType>(ArrayTy->getElementType());
362+
TypeLayout[I] = ArrayTy->getNumElements();
363+
}
368364

369365
auto *ElemTy = ArrayTy->getElementType();
370366
std::string ElemTyStr;

lib/SPIRV/SPIRVToOCL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ void SPIRVToOCLBase::visitCallSPIRVAvcINTELEvaluateBuiltIn(CallInst *CI,
912912
// reference image
913913
int NumImages = std::count_if(Args.begin(), Args.end(), [](Value *Arg) {
914914
if (auto *PT = dyn_cast<PointerType>(Arg->getType())) {
915-
if (auto *ST = dyn_cast<StructType>(PT->getElementType())) {
915+
if (auto *ST = dyn_cast<StructType>(PT->getPointerElementType())) {
916916
if (ST->getName().startswith("spirv.VmeImageINTEL"))
917917
return true;
918918
}

lib/SPIRV/SPIRVToOCL20.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Instruction *SPIRVToOCL20Base::visitCallSPIRVAtomicIncDec(CallInst *CI, Op OC) {
181181
OC == OpAtomicIIncrement ? OpAtomicIAdd : OpAtomicISub);
182182
auto Ptr = findFirstPtr(Args);
183183
Type *ValueTy =
184-
cast<PointerType>(Args[Ptr]->getType())->getElementType();
184+
cast<PointerType>(Args[Ptr]->getType())->getPointerElementType();
185185
assert(ValueTy->isIntegerTy());
186186
Args.insert(Args.begin() + 1, llvm::ConstantInt::get(ValueTy, 1));
187187
return Name;
@@ -256,7 +256,8 @@ Instruction *SPIRVToOCL20Base::visitCallSPIRVAtomicCmpExchg(CallInst *CI) {
256256
new StoreInst(Args[1], PExpected, PInsertBefore);
257257
unsigned AddrSpc = SPIRAS_Generic;
258258
Type *PtrTyAS =
259-
PExpected->getType()->getElementType()->getPointerTo(AddrSpc);
259+
PExpected->getType()->getPointerElementType()->getPointerTo(
260+
AddrSpc);
260261
Args[1] = CastInst::CreatePointerBitCastOrAddrSpaceCast(
261262
PExpected, PtrTyAS, PExpected->getName() + ".as", PInsertBefore);
262263
std::swap(Args[3], Args[4]);

lib/SPIRV/SPIRVUtil.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,23 +248,23 @@ bool isVoidFuncTy(FunctionType *FT) { return FT->getReturnType()->isVoidTy(); }
248248

249249
bool isPointerToOpaqueStructType(llvm::Type *Ty) {
250250
if (auto PT = dyn_cast<PointerType>(Ty))
251-
if (auto ST = dyn_cast<StructType>(PT->getElementType()))
251+
if (auto *ST = dyn_cast<StructType>(PT->getPointerElementType()))
252252
if (ST->isOpaque())
253253
return true;
254254
return false;
255255
}
256256

257257
bool isPointerToOpaqueStructType(llvm::Type *Ty, const std::string &Name) {
258258
if (auto PT = dyn_cast<PointerType>(Ty))
259-
if (auto ST = dyn_cast<StructType>(PT->getElementType()))
259+
if (auto *ST = dyn_cast<StructType>(PT->getPointerElementType()))
260260
if (ST->isOpaque() && ST->getName() == Name)
261261
return true;
262262
return false;
263263
}
264264

265265
bool isSPIRVSamplerType(llvm::Type *Ty) {
266266
if (auto *PT = dyn_cast<PointerType>(Ty))
267-
if (auto *ST = dyn_cast<StructType>(PT->getElementType()))
267+
if (auto *ST = dyn_cast<StructType>(PT->getPointerElementType()))
268268
if (ST->isOpaque()) {
269269
auto Name = ST->getName();
270270
if (Name.startswith(std::string(kSPIRVTypeName::PrefixAndDelim) +
@@ -277,7 +277,7 @@ bool isSPIRVSamplerType(llvm::Type *Ty) {
277277

278278
bool isOCLImageType(llvm::Type *Ty, StringRef *Name) {
279279
if (auto PT = dyn_cast<PointerType>(Ty))
280-
if (auto ST = dyn_cast<StructType>(PT->getElementType()))
280+
if (auto *ST = dyn_cast<StructType>(PT->getPointerElementType()))
281281
if (ST->isOpaque()) {
282282
auto FullName = ST->getName();
283283
if (FullName.find(kSPR2TypeName::ImagePrefix) == 0) {
@@ -294,7 +294,7 @@ bool isOCLImageType(llvm::Type *Ty, StringRef *Name) {
294294
/// type Name as spirv.BaseTyName.Postfixes.
295295
bool isSPIRVType(llvm::Type *Ty, StringRef BaseTyName, StringRef *Postfix) {
296296
if (auto PT = dyn_cast<PointerType>(Ty))
297-
if (auto ST = dyn_cast<StructType>(PT->getElementType()))
297+
if (auto *ST = dyn_cast<StructType>(PT->getPointerElementType()))
298298
if (ST->isOpaque()) {
299299
auto FullName = ST->getName();
300300
std::string N =

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4232,7 +4232,7 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
42324232
// the original return type.
42334233
if (CI->hasStructRetAttr()) {
42344234
assert(ResTy->isVoidTy() && "Return type is not void");
4235-
ResTy = cast<PointerType>(OpItr->getType())->getElementType();
4235+
ResTy = cast<PointerType>(OpItr->getType())->getPointerElementType();
42364236
OpItr++;
42374237
}
42384238

@@ -4323,7 +4323,7 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
43234323
// the original return type.
43244324
if (CI->hasStructRetAttr()) {
43254325
assert(ResTy->isVoidTy() && "Return type is not void");
4326-
ResTy = cast<PointerType>(OpItr->getType())->getElementType();
4326+
ResTy = cast<PointerType>(OpItr->getType())->getPointerElementType();
43274327
OpItr++;
43284328
}
43294329

@@ -4400,7 +4400,7 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
44004400
// the original return type.
44014401
if (CI->hasStructRetAttr()) {
44024402
assert(ResTy->isVoidTy() && "Return type is not void");
4403-
ResTy = cast<PointerType>(OpItr->getType())->getElementType();
4403+
ResTy = cast<PointerType>(OpItr->getType())->getPointerElementType();
44044404
OpItr++;
44054405
}
44064406

0 commit comments

Comments
 (0)