Skip to content

Commit 1341e54

Browse files
jcranmer-intelsvenvh
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).
1 parent d06c923 commit 1341e54

File tree

3 files changed

+0
-71
lines changed

3 files changed

+0
-71
lines changed

lib/SPIRV/SPIRVInternal.h

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

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

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

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

lib/SPIRV/SPIRVRegularizeLLVM.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ class SPIRVRegularizeLLVMBase {
7878
// that later SPIR-V writer renames.
7979
void addKernelEntryPoint(Module *M);
8080

81-
/// Erase cast inst of function and replace with the function.
82-
/// Assuming F is a SPIR-V builtin function with op code \param OC.
83-
void lowerFuncPtr(Function *F, Op OC);
84-
void lowerFuncPtr(Module *M);
85-
8681
/// Some LLVM intrinsics that have no SPIR-V counterpart may be wrapped in
8782
/// @spirv.llvm_intrinsic_* function. During reverse translation from SPIR-V
8883
/// to LLVM IR we can detect this @spirv.llvm_intrinsic_* function and
@@ -573,7 +568,6 @@ bool SPIRVRegularizeLLVMBase::runRegularizeLLVM(Module &Module) {
573568
/// Remove entities not representable by SPIR-V
574569
bool SPIRVRegularizeLLVMBase::regularize() {
575570
eraseUselessFunctions(M);
576-
lowerFuncPtr(M);
577571
addKernelEntryPoint(M);
578572
expandSYCLTypeUsing(M);
579573

@@ -721,43 +715,6 @@ bool SPIRVRegularizeLLVMBase::regularize() {
721715
return true;
722716
}
723717

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

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);
@@ -650,17 +640,6 @@ bool isFunctionPointerType(Type *T) {
650640
return false;
651641
}
652642

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

0 commit comments

Comments
 (0)