Skip to content

Commit c7a0b9b

Browse files
authored
[OpaquePointers][NFC] 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
1 parent 93b6d57 commit c7a0b9b

File tree

4 files changed

+7
-59
lines changed

4 files changed

+7
-59
lines changed

lib/SPIRV/OCLUtil.cpp

-26
Original file line numberDiff line numberDiff line change
@@ -1329,32 +1329,6 @@ std::unique_ptr<SPIRV::BuiltinFuncMangleInfo> makeMangler(Function &F) {
13291329
return std::make_unique<OCLBuiltinFuncMangleInfo>(&F);
13301330
}
13311331

1332-
static StringRef getStructName(Type *Ty) {
1333-
if (auto *STy = dyn_cast<StructType>(Ty))
1334-
return STy->isLiteral() ? "" : Ty->getStructName();
1335-
return "";
1336-
}
1337-
1338-
Value *unwrapSpecialTypeInitializer(Value *V) {
1339-
if (auto *BC = dyn_cast<BitCastOperator>(V)) {
1340-
Type *DestTy = BC->getDestTy();
1341-
Type *SrcTy = BC->getSrcTy();
1342-
if (SrcTy->isPointerTy() && !SrcTy->isOpaquePointerTy()) {
1343-
StringRef SrcName =
1344-
getStructName(SrcTy->getNonOpaquePointerElementType());
1345-
StringRef DestName =
1346-
getStructName(DestTy->getNonOpaquePointerElementType());
1347-
if (DestName == getSPIRVTypeName(kSPIRVTypeName::PipeStorage) &&
1348-
SrcName == getSPIRVTypeName(kSPIRVTypeName::ConstantPipeStorage))
1349-
return BC->getOperand(0);
1350-
if (DestName == getSPIRVTypeName(kSPIRVTypeName::Sampler) &&
1351-
SrcName == getSPIRVTypeName(kSPIRVTypeName::ConstantSampler))
1352-
return BC->getOperand(0);
1353-
}
1354-
}
1355-
return nullptr;
1356-
}
1357-
13581332
bool isSamplerTy(Type *Ty) {
13591333
if (auto *TPT = dyn_cast_or_null<TypedPointerType>(Ty)) {
13601334
auto *STy = dyn_cast_or_null<StructType>(TPT->getElementType());

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);

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());

lib/SPIRV/SPIRVWriter.cpp

+7-23
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
325325
// A pointer to image or pipe type in LLVM is translated to a SPIRV
326326
// (non-pointer) image or pipe type.
327327
if (T->isPointerTy()) {
328-
auto *ET = T->isOpaquePointerTy() ? Type::getInt8Ty(T->getContext())
329-
: T->getNonOpaquePointerElementType();
328+
auto *ET = Type::getInt8Ty(T->getContext());
330329
auto AddrSpc = T->getPointerAddressSpace();
331330
return transPointerType(ET, AddrSpc);
332331
}
@@ -375,7 +374,7 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
375374
ConstantInt::get(getSizetType(), T->getArrayNumElements(), false),
376375
nullptr)));
377376
mapType(T, TransType);
378-
if (ElTy->isOpaquePointerTy()) {
377+
if (ElTy->isPointerTy()) {
379378
mapType(
380379
ArrayType::get(TypedPointerType::get(Type::getInt8Ty(*Ctx),
381380
ElTy->getPointerAddressSpace()),
@@ -713,9 +712,7 @@ SPIRVType *LLVMToSPIRVBase::transSPIRVOpaqueType(StringRef STName,
713712

714713
SPIRVType *LLVMToSPIRVBase::transScavengedType(Value *V) {
715714
if (auto *F = dyn_cast<Function>(V)) {
716-
FunctionType *FnTy = F->getType()->isOpaquePointerTy()
717-
? Scavenger->getFunctionType(F)
718-
: F->getFunctionType();
715+
FunctionType *FnTy = Scavenger->getFunctionType(F);
719716
SPIRVType *RT = transType(FnTy->getReturnType());
720717
std::vector<SPIRVType *> PT;
721718
for (Argument &Arg : F->args()) {
@@ -1808,11 +1805,6 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
18081805
assert(BV);
18091806
return mapValue(V, BV);
18101807
} else if (ConstantExpr *ConstUE = dyn_cast_or_null<ConstantExpr>(Init)) {
1811-
Value *SpecialInit = unwrapSpecialTypeInitializer(ConstUE);
1812-
if (auto *SpecialGV = dyn_cast_or_null<GlobalValue>(SpecialInit)) {
1813-
Init = SpecialGV;
1814-
Ty = Scavenger->getScavengedType(SpecialGV);
1815-
}
18161808
BVarInit = transValue(Init, nullptr);
18171809
} else if (ST && isa<UndefValue>(Init)) {
18181810
// Undef initializer for LLVM structure be can translated to
@@ -1918,9 +1910,9 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
19181910
if (isa<Constant>(V)) {
19191911
auto BV = transConstant(V);
19201912
assert(BV);
1921-
// Don't store opaque pointer constants in the map--we might reuse the wrong
1922-
// type for (e.g.) a null value if we do so.
1923-
if (V->getType()->isOpaquePointerTy())
1913+
// Don't store pointer constants in the map -- they are opaque and thus we
1914+
// might reuse the wrong type (Example: a null value) if we do so.
1915+
if (V->getType()->isPointerTy())
19241916
return BV;
19251917
return mapValue(V, BV);
19261918
}
@@ -2166,8 +2158,6 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
21662158
}
21672159

21682160
if (UnaryInstruction *U = dyn_cast<UnaryInstruction>(V)) {
2169-
if (auto *Init = unwrapSpecialTypeInitializer(U))
2170-
return mapValue(V, transValue(Init, BB));
21712161
auto UI = transUnaryInst(U, BB);
21722162
return mapValue(V, UI ? UI : transValue(U->getOperand(0), BB));
21732163
}
@@ -2779,12 +2769,6 @@ SPIRVValue *LLVMToSPIRVBase::oclTransSpvcCastSampler(CallInst *CI,
27792769
auto FT = F->getFunctionType();
27802770
auto RT = FT->getReturnType();
27812771
assert(FT->getNumParams() == 1);
2782-
if (RT->isPointerTy() && !RT->isOpaquePointerTy()) {
2783-
StructType *ST = dyn_cast<StructType>(RT->getNonOpaquePointerElementType());
2784-
(void)ST;
2785-
assert(isSPIRVStructType(ST, kSPIRVTypeName::Sampler) ||
2786-
(ST->isOpaque() && ST->getName() == kSPR2TypeName::Sampler));
2787-
}
27882772
assert(FT->getParamType(0)->isIntegerTy() && "Invalid sampler type");
27892773
auto Arg = CI->getArgOperand(0);
27902774

@@ -2923,7 +2907,7 @@ void processOptionalAnnotationInfo(Constant *Const,
29232907
void processAnnotationString(IntrinsicInst *II, std::string &AnnotationString) {
29242908
auto *StrVal = II->getArgOperand(1);
29252909
auto *StrValTy = StrVal->getType();
2926-
if (StrValTy->isOpaquePointerTy()) {
2910+
if (StrValTy->isPointerTy()) {
29272911
StringRef StrRef;
29282912
if (getConstantStringInfo(dyn_cast<Constant>(StrVal), StrRef))
29292913
AnnotationString += StrRef.str();

0 commit comments

Comments
 (0)