Skip to content

Commit bd0ce29

Browse files
asudarsajsji
authored andcommitted
Replace use of isOpaquePointerTy with isPointerTy (#2091)
'bool llvm::Type::isOpaquePointerTy() const' has been removed. We need to use isPointerTy() instead. This PR handles all uses except one (lib/SPIRV/SPIRVWriter.cpp:279) which is handled in a different PR (#2089) Thanks Original commit: KhronosGroup/SPIRV-LLVM-Translator@c7a0b9b
1 parent 68bb243 commit bd0ce29

File tree

4 files changed

+7
-59
lines changed

4 files changed

+7
-59
lines changed

llvm-spirv/lib/SPIRV/OCLUtil.cpp

-26
Original file line numberDiff line numberDiff line change
@@ -1321,32 +1321,6 @@ std::unique_ptr<SPIRV::BuiltinFuncMangleInfo> makeMangler(Function &F) {
13211321
return std::make_unique<OCLBuiltinFuncMangleInfo>(&F);
13221322
}
13231323

1324-
static StringRef getStructName(Type *Ty) {
1325-
if (auto *STy = dyn_cast<StructType>(Ty))
1326-
return STy->isLiteral() ? "" : Ty->getStructName();
1327-
return "";
1328-
}
1329-
1330-
Value *unwrapSpecialTypeInitializer(Value *V) {
1331-
if (auto *BC = dyn_cast<BitCastOperator>(V)) {
1332-
Type *DestTy = BC->getDestTy();
1333-
Type *SrcTy = BC->getSrcTy();
1334-
if (SrcTy->isPointerTy() && !SrcTy->isOpaquePointerTy()) {
1335-
StringRef SrcName =
1336-
getStructName(SrcTy->getNonOpaquePointerElementType());
1337-
StringRef DestName =
1338-
getStructName(DestTy->getNonOpaquePointerElementType());
1339-
if (DestName == getSPIRVTypeName(kSPIRVTypeName::PipeStorage) &&
1340-
SrcName == getSPIRVTypeName(kSPIRVTypeName::ConstantPipeStorage))
1341-
return BC->getOperand(0);
1342-
if (DestName == getSPIRVTypeName(kSPIRVTypeName::Sampler) &&
1343-
SrcName == getSPIRVTypeName(kSPIRVTypeName::ConstantSampler))
1344-
return BC->getOperand(0);
1345-
}
1346-
}
1347-
return nullptr;
1348-
}
1349-
13501324
bool isSamplerTy(Type *Ty) {
13511325
if (auto *TPT = dyn_cast_or_null<TypedPointerType>(Ty)) {
13521326
auto *STy = dyn_cast_or_null<StructType>(TPT->getElementType());

llvm-spirv/lib/SPIRV/OCLUtil.h

-5
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,6 @@ inline OCLMemOrderKind mapSPIRVMemOrderToOCL(unsigned Sema) {
489489
return OCLMemOrderMap::rmap(extractSPIRVMemOrderSemantic(Sema));
490490
}
491491

492-
/// If the value is a special type initializer (something that bitcasts from
493-
/// spirv.ConstantSampler to spirv.Sampler or likewise for PipeStorage), get the
494-
/// original type initializer, unwrap the bitcast. Otherwise, return nullptr.
495-
Value *unwrapSpecialTypeInitializer(Value *V);
496-
497492
bool isPipeOrAddressSpaceCastBI(const StringRef MangledName);
498493
bool isEnqueueKernelBI(const StringRef MangledName);
499494
bool isKernelQueryBI(const StringRef MangledName);

llvm-spirv/lib/SPIRV/SPIRVLowerBitCastToNonStandardType.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ static Value *removeBitCasts(Value *OldValue, Type *NewTy, NFIRBuilder &Builder,
7777
if (auto *LI = dyn_cast<LoadInst>(OldValue)) {
7878
Builder.SetInsertPoint(LI);
7979
Value *Pointer = LI->getPointerOperand();
80-
if (!Pointer->getType()->isOpaquePointerTy()) {
81-
Type *NewPointerTy =
82-
PointerType::get(NewTy, LI->getPointerAddressSpace());
83-
Pointer = removeBitCasts(Pointer, NewPointerTy, Builder, InstsToErase);
84-
}
8580
LoadInst *NewLI = Builder.CreateAlignedLoad(NewTy, Pointer, LI->getAlign(),
8681
LI->isVolatile());
8782
NewLI->setOrdering(LI->getOrdering());

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

+7-23
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
329329
// A pointer to image or pipe type in LLVM is translated to a SPIRV
330330
// (non-pointer) image or pipe type.
331331
if (T->isPointerTy()) {
332-
auto *ET = T->isOpaquePointerTy() ? Type::getInt8Ty(T->getContext())
333-
: T->getNonOpaquePointerElementType();
332+
auto *ET = Type::getInt8Ty(T->getContext());
334333
auto AddrSpc = T->getPointerAddressSpace();
335334
return transPointerType(ET, AddrSpc);
336335
}
@@ -379,7 +378,7 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
379378
ConstantInt::get(getSizetType(), T->getArrayNumElements(), false),
380379
nullptr)));
381380
mapType(T, TransType);
382-
if (ElTy->isOpaquePointerTy()) {
381+
if (ElTy->isPointerTy()) {
383382
mapType(
384383
ArrayType::get(TypedPointerType::get(Type::getInt8Ty(*Ctx),
385384
ElTy->getPointerAddressSpace()),
@@ -717,9 +716,7 @@ SPIRVType *LLVMToSPIRVBase::transSPIRVOpaqueType(StringRef STName,
717716

718717
SPIRVType *LLVMToSPIRVBase::transScavengedType(Value *V) {
719718
if (auto *F = dyn_cast<Function>(V)) {
720-
FunctionType *FnTy = F->getType()->isOpaquePointerTy()
721-
? Scavenger->getFunctionType(F)
722-
: F->getFunctionType();
719+
FunctionType *FnTy = Scavenger->getFunctionType(F);
723720
SPIRVType *RT = transType(FnTy->getReturnType());
724721
std::vector<SPIRVType *> PT;
725722
for (Argument &Arg : F->args()) {
@@ -1824,11 +1821,6 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
18241821
assert(BV);
18251822
return mapValue(V, BV);
18261823
} else if (ConstantExpr *ConstUE = dyn_cast_or_null<ConstantExpr>(Init)) {
1827-
Value *SpecialInit = unwrapSpecialTypeInitializer(ConstUE);
1828-
if (auto *SpecialGV = dyn_cast_or_null<GlobalValue>(SpecialInit)) {
1829-
Init = SpecialGV;
1830-
Ty = Scavenger->getScavengedType(SpecialGV);
1831-
}
18321824
BVarInit = transValue(Init, nullptr);
18331825
} else if (ST && isa<UndefValue>(Init)) {
18341826
// Undef initializer for LLVM structure be can translated to
@@ -1983,9 +1975,9 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
19831975
if (isa<Constant>(V)) {
19841976
auto BV = transConstant(V);
19851977
assert(BV);
1986-
// Don't store opaque pointer constants in the map--we might reuse the wrong
1987-
// type for (e.g.) a null value if we do so.
1988-
if (V->getType()->isOpaquePointerTy())
1978+
// Don't store pointer constants in the map -- they are opaque and thus we
1979+
// might reuse the wrong type (Example: a null value) if we do so.
1980+
if (V->getType()->isPointerTy())
19891981
return BV;
19901982
return mapValue(V, BV);
19911983
}
@@ -2231,8 +2223,6 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
22312223
}
22322224

22332225
if (UnaryInstruction *U = dyn_cast<UnaryInstruction>(V)) {
2234-
if (auto *Init = unwrapSpecialTypeInitializer(U))
2235-
return mapValue(V, transValue(Init, BB));
22362226
auto UI = transUnaryInst(U, BB);
22372227
return mapValue(V, UI ? UI : transValue(U->getOperand(0), BB));
22382228
}
@@ -2844,12 +2834,6 @@ SPIRVValue *LLVMToSPIRVBase::oclTransSpvcCastSampler(CallInst *CI,
28442834
auto FT = F->getFunctionType();
28452835
auto RT = FT->getReturnType();
28462836
assert(FT->getNumParams() == 1);
2847-
if (RT->isPointerTy() && !RT->isOpaquePointerTy()) {
2848-
StructType *ST = dyn_cast<StructType>(RT->getNonOpaquePointerElementType());
2849-
(void)ST;
2850-
assert(isSPIRVStructType(ST, kSPIRVTypeName::Sampler) ||
2851-
(ST->isOpaque() && ST->getName() == kSPR2TypeName::Sampler));
2852-
}
28532837
assert(FT->getParamType(0)->isIntegerTy() && "Invalid sampler type");
28542838
auto Arg = CI->getArgOperand(0);
28552839

@@ -2988,7 +2972,7 @@ void processOptionalAnnotationInfo(Constant *Const,
29882972
void processAnnotationString(IntrinsicInst *II, std::string &AnnotationString) {
29892973
auto *StrVal = II->getArgOperand(1);
29902974
auto *StrValTy = StrVal->getType();
2991-
if (StrValTy->isOpaquePointerTy()) {
2975+
if (StrValTy->isPointerTy()) {
29922976
StringRef StrRef;
29932977
if (getConstantStringInfo(dyn_cast<Constant>(StrVal), StrRef))
29942978
AnnotationString += StrRef.str();

0 commit comments

Comments
 (0)