Skip to content

Commit 8885175

Browse files
jcranmer-intelPavel V Chupin
authored andcommitted
Remove function pointer cast deletion in SPIRVRegularizeLLVM.
It seems to be another remnant of earlier versions of dealing with block types, as it is looking for SPIR-V builtins that have function pointer arguments. With blocks now represented as structs, it seems that nothing will trigger this code any more. In any case, with opaque pointers, this code becomes unnecessary (as the bitcasts that would be deleted won't exist anymore). Original commit: KhronosGroup/SPIRV-LLVM-Translator@1341e54
1 parent 201b40f commit 8885175

File tree

3 files changed

+0
-71
lines changed

3 files changed

+0
-71
lines changed

llvm-spirv/lib/SPIRV/SPIRVInternal.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,6 @@ bool isVoidFuncTy(FunctionType *FT);
716716
/// \returns true if \p T is a function pointer type.
717717
bool isFunctionPointerType(Type *T);
718718

719-
/// \returns true if function \p F has function pointer type argument.
720-
/// \param AI points to the function pointer type argument if returns true.
721-
bool hasFunctionPointerArg(Function *F, Function::arg_iterator &AI);
722-
723719
/// \returns true if function \p F has array type argument.
724720
bool hasArrayArg(Function *F);
725721

@@ -1018,9 +1014,6 @@ std::string getSPIRVFriendlyIRFunctionName(OCLExtOpKind ExtOpId,
10181014
std::string getSPIRVFriendlyIRFunctionName(const std::string &UniqName,
10191015
spv::Op OC, ArrayRef<Type *> ArgTys);
10201016

1021-
/// Remove cast from a value.
1022-
Value *removeCast(Value *V);
1023-
10241017
/// Cast a function to a void(void) funtion pointer.
10251018
Constant *castToVoidFuncPtr(Function *F);
10261019

llvm-spirv/lib/SPIRV/SPIRVRegularizeLLVM.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ class SPIRVRegularizeLLVMBase {
7272
// Lower functions
7373
bool regularize();
7474

75-
/// Erase cast inst of function and replace with the function.
76-
/// Assuming F is a SPIR-V builtin function with op code \param OC.
77-
void lowerFuncPtr(Function *F, Op OC);
78-
void lowerFuncPtr(Module *M);
79-
8075
/// Some LLVM intrinsics that have no SPIR-V counterpart may be wrapped in
8176
/// @spirv.llvm_intrinsic_* function. During reverse translation from SPIR-V
8277
/// to LLVM IR we can detect this @spirv.llvm_intrinsic_* function and
@@ -567,7 +562,6 @@ bool SPIRVRegularizeLLVMBase::runRegularizeLLVM(Module &Module) {
567562
/// Remove entities not representable by SPIR-V
568563
bool SPIRVRegularizeLLVMBase::regularize() {
569564
eraseUselessFunctions(M);
570-
lowerFuncPtr(M);
571565
expandSYCLTypeUsing(M);
572566

573567
for (auto I = M->begin(), E = M->end(); I != E;) {
@@ -722,43 +716,6 @@ bool SPIRVRegularizeLLVMBase::regularize() {
722716
return true;
723717
}
724718

725-
// Assume F is a SPIR-V builtin function with a function pointer argument which
726-
// is a bitcast instruction casting a function to a void(void) function pointer.
727-
void SPIRVRegularizeLLVMBase::lowerFuncPtr(Function *F, Op OC) {
728-
LLVM_DEBUG(dbgs() << "[lowerFuncPtr] " << *F << '\n');
729-
auto Name = decorateSPIRVFunction(getName(OC));
730-
std::set<Value *> InvokeFuncPtrs;
731-
auto Attrs = F->getAttributes();
732-
mutateFunction(
733-
F,
734-
[=, &InvokeFuncPtrs](CallInst *CI, std::vector<Value *> &Args) {
735-
for (auto &I : Args) {
736-
if (isFunctionPointerType(I->getType())) {
737-
InvokeFuncPtrs.insert(I);
738-
I = removeCast(I);
739-
}
740-
}
741-
return Name;
742-
},
743-
nullptr, &Attrs, false);
744-
for (auto &I : InvokeFuncPtrs)
745-
eraseIfNoUse(I);
746-
}
747-
748-
void SPIRVRegularizeLLVMBase::lowerFuncPtr(Module *M) {
749-
std::vector<std::pair<Function *, Op>> Work;
750-
for (auto &F : *M) {
751-
auto AI = F.arg_begin();
752-
if (hasFunctionPointerArg(&F, AI)) {
753-
auto OC = getSPIRVFuncOC(F.getName());
754-
if (OC != OpNop) // builtin with a function pointer argument
755-
Work.push_back(std::make_pair(&F, OC));
756-
}
757-
}
758-
for (auto &I : Work)
759-
lowerFuncPtr(I.first, I.second);
760-
}
761-
762719
} // namespace SPIRV
763720

764721
INITIALIZE_PASS(SPIRVRegularizeLLVMLegacy, "spvregular",

llvm-spirv/lib/SPIRV/SPIRVUtil.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,6 @@ void removeFnAttr(CallInst *Call, Attribute::AttrKind Attr) {
8989
Call->removeFnAttr(Attr);
9090
}
9191

92-
Value *removeCast(Value *V) {
93-
auto Cast = dyn_cast<ConstantExpr>(V);
94-
if (Cast && Cast->isCast()) {
95-
return removeCast(Cast->getOperand(0));
96-
}
97-
if (auto Cast = dyn_cast<CastInst>(V))
98-
return removeCast(Cast->getOperand(0));
99-
return V;
100-
}
101-
10292
void saveLLVMModule(Module *M, const std::string &OutputFile) {
10393
std::error_code EC;
10494
ToolOutputFile Out(OutputFile.c_str(), EC, sys::fs::OF_None);
@@ -652,17 +642,6 @@ bool isFunctionPointerType(Type *T) {
652642
return false;
653643
}
654644

655-
bool hasFunctionPointerArg(Function *F, Function::arg_iterator &AI) {
656-
AI = F->arg_begin();
657-
for (auto AE = F->arg_end(); AI != AE; ++AI) {
658-
LLVM_DEBUG(dbgs() << "[hasFuncPointerArg] " << *AI << '\n');
659-
if (isFunctionPointerType(AI->getType())) {
660-
return true;
661-
}
662-
}
663-
return false;
664-
}
665-
666645
Constant *castToVoidFuncPtr(Function *F) {
667646
auto T = getVoidFuncPtrType(F->getParent());
668647
return ConstantExpr::getBitCast(F, T);

0 commit comments

Comments
 (0)