Skip to content

Commit ea50ba9

Browse files
vmaksimojsji
authored andcommitted
Remove entry point wrapper (#3418)
After LLVM community changes we don't need to do it ourselves. Original commit: KhronosGroup/SPIRV-LLVM-Translator@5458eb2511d6184
1 parent ed1becb commit ea50ba9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+98
-222
lines changed

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,17 +1276,8 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgFunction(const DISubprogram *Func) {
12761276
Ops[FunctionIdIdx] = getDebugInfoNoneId();
12771277
for (const llvm::Function &F : M->functions()) {
12781278
if (Func->describes(&F)) {
1279-
// Function definition of spir_kernel can have no "spir_kernel" calling
1280-
// convention because SPIRVRegularizeLLVMBase::addKernelEntryPoint pass
1281-
// could have turned it to spir_func. The "true" entry point is a
1282-
// wrapper kernel function, which can be found further in the module.
1283-
if (FuncDef) {
1284-
if (F.getCallingConv() == CallingConv::SPIR_KERNEL) {
1285-
IsEntryPointKernel = true;
1286-
break;
1287-
}
1279+
if (FuncDef)
12881280
continue;
1289-
}
12901281

12911282
SPIRVValue *SPIRVFunc = SPIRVWriter->getTranslatedValue(&F);
12921283
assert(SPIRVFunc && "All function must be already translated");
@@ -1295,7 +1286,6 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgFunction(const DISubprogram *Func) {
12951286
if (!isNonSemanticDebugInfo())
12961287
break;
12971288

1298-
// Most likely unreachable because of Regularise LLVM pass
12991289
if (F.getCallingConv() == CallingConv::SPIR_KERNEL) {
13001290
IsEntryPointKernel = true;
13011291
break;

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,25 +3474,6 @@ Function *SPIRVToLLVM::transFunction(SPIRVFunction *BF, unsigned AS) {
34743474
return Loc->second;
34753475

34763476
auto IsKernel = isKernel(BF);
3477-
3478-
if (IsKernel) {
3479-
// search for a previous function with the same name
3480-
// upgrade it to a kernel and drop this if it's found
3481-
for (auto &I : FuncMap) {
3482-
auto BFName = I.getFirst()->getName();
3483-
if (BF->getName() == BFName) {
3484-
auto *F = I.getSecond();
3485-
F->setCallingConv(CallingConv::SPIR_KERNEL);
3486-
F->setLinkage(GlobalValue::ExternalLinkage);
3487-
F->setDSOLocal(false);
3488-
F = cast<Function>(mapValue(BF, F));
3489-
mapFunction(BF, F);
3490-
transFunctionAttrs(BF, F);
3491-
return F;
3492-
}
3493-
}
3494-
}
3495-
34963477
auto Linkage = IsKernel ? GlobalValue::ExternalLinkage : transLinkageType(BF);
34973478
FunctionType *FT = cast<FunctionType>(transType(BF->getFunctionType()));
34983479
std::string FuncName = BF->getName();

llvm-spirv/lib/SPIRV/SPIRVRegularizeLLVM.cpp

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,6 @@ void prepareCacheControlsTranslation(Metadata *MD, Instruction *Inst) {
615615
/// Remove entities not representable by SPIR-V
616616
bool SPIRVRegularizeLLVMBase::regularize() {
617617
eraseUselessFunctions(M);
618-
addKernelEntryPoint(M);
619618
expandSYCLTypeUsing(M);
620619
cleanupConversionToNonStdIntegers(M);
621620
replacePrivateConstGlobalsWithAllocas(M);
@@ -808,69 +807,6 @@ bool SPIRVRegularizeLLVMBase::regularize() {
808807
return true;
809808
}
810809

811-
void SPIRVRegularizeLLVMBase::addKernelEntryPoint(Module *M) {
812-
std::vector<Function *> Work;
813-
814-
// Get a list of all functions that have SPIR kernel calling conv
815-
for (auto &F : *M) {
816-
if (F.getCallingConv() == CallingConv::SPIR_KERNEL)
817-
Work.push_back(&F);
818-
}
819-
for (auto &F : Work) {
820-
// for declarations just make them into SPIR functions.
821-
F->setCallingConv(CallingConv::SPIR_FUNC);
822-
if (F->isDeclaration())
823-
continue;
824-
825-
// Otherwise add a wrapper around the function to act as an entry point.
826-
FunctionType *FType = F->getFunctionType();
827-
std::string WrapName =
828-
kSPIRVName::EntrypointPrefix + static_cast<std::string>(F->getName());
829-
Function *WrapFn =
830-
getOrCreateFunction(M, F->getReturnType(), FType->params(), WrapName);
831-
832-
auto *CallBB = BasicBlock::Create(M->getContext(), "", WrapFn);
833-
IRBuilder<> Builder(CallBB);
834-
835-
Function::arg_iterator DestI = WrapFn->arg_begin();
836-
for (const Argument &I : F->args()) {
837-
DestI->setName(I.getName());
838-
DestI++;
839-
}
840-
SmallVector<Value *, 1> Args;
841-
for (Argument &I : WrapFn->args()) {
842-
Args.emplace_back(&I);
843-
}
844-
auto *CI = CallInst::Create(F, ArrayRef<Value *>(Args), "", CallBB);
845-
CI->setCallingConv(F->getCallingConv());
846-
CI->setAttributes(F->getAttributes());
847-
848-
// copy over all the metadata (should it be removed from F?)
849-
SmallVector<std::pair<unsigned, MDNode *>> MDs;
850-
F->getAllMetadata(MDs);
851-
WrapFn->setAttributes(F->getAttributes());
852-
for (auto MD = MDs.begin(), End = MDs.end(); MD != End; ++MD) {
853-
WrapFn->addMetadata(MD->first, *MD->second);
854-
}
855-
WrapFn->setCallingConv(CallingConv::SPIR_KERNEL);
856-
WrapFn->setLinkage(llvm::GlobalValue::InternalLinkage);
857-
858-
Builder.CreateRet(F->getReturnType()->isVoidTy() ? nullptr : CI);
859-
860-
// Have to find the spir-v metadata for execution mode and transfer it to
861-
// the wrapper.
862-
if (auto NMD = SPIRVMDWalker(*M).getNamedMD(kSPIRVMD::ExecutionMode)) {
863-
while (!NMD.atEnd()) {
864-
Function *MDF = nullptr;
865-
auto N = NMD.nextOp(); /* execution mode MDNode */
866-
N.get(MDF);
867-
if (MDF == F)
868-
N.M->replaceOperandWith(0, ValueAsMetadata::get(WrapFn));
869-
}
870-
}
871-
}
872-
}
873-
874810
} // namespace SPIRV
875811

876812
INITIALIZE_PASS(SPIRVRegularizeLLVMLegacy, "spvregular",

llvm-spirv/lib/SPIRV/SPIRVRegularizeLLVM.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ class SPIRVRegularizeLLVMBase {
5151
// Lower functions
5252
bool regularize();
5353

54-
// SPIR-V disallows functions being entrypoints and called
55-
// LLVM doesn't. This adds a wrapper around the entry point
56-
// that later SPIR-V writer renames.
57-
void addKernelEntryPoint(Module *M);
58-
5954
/// Some LLVM intrinsics that have no SPIR-V counterpart may be wrapped in
6055
/// @spirv.llvm_intrinsic_* function. During reverse translation from SPIR-V
6156
/// to LLVM IR we can detect this @spirv.llvm_intrinsic_* function and

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -954,19 +954,12 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) {
954954
static_cast<SPIRVFunction *>(mapValue(F, BM->addFunction(BFT)));
955955
BF->setFunctionControlMask(transFunctionControlMask(F));
956956
if (F->hasName()) {
957-
if (isKernel(F)) {
958-
/* strip the prefix as the runtime will be looking for this name */
959-
std::string Prefix = kSPIRVName::EntrypointPrefix;
960-
std::string Name = F->getName().str();
961-
BM->setName(BF, Name.substr(Prefix.size()));
962-
} else {
963-
if (isUniformGroupOperation(F))
964-
BM->getErrorLog().checkError(
965-
BM->isAllowedToUseExtension(
966-
ExtensionID::SPV_KHR_uniform_group_instructions),
967-
SPIRVEC_RequiresExtension, "SPV_KHR_uniform_group_instructions\n");
968-
BM->setName(BF, F->getName().str());
969-
}
957+
if (isUniformGroupOperation(F))
958+
BM->getErrorLog().checkError(
959+
BM->isAllowedToUseExtension(
960+
ExtensionID::SPV_KHR_uniform_group_instructions),
961+
SPIRVEC_RequiresExtension, "SPV_KHR_uniform_group_instructions\n");
962+
BM->setName(BF, F->getName().str());
970963
}
971964
if (!isKernel(F) && F->getLinkage() != GlobalValue::InternalLinkage)
972965
BF->setLinkageType(transLinkageType(F));
@@ -6268,7 +6261,7 @@ void LLVMToSPIRVBase::transFunction(Function *I) {
62686261

62696262
if (isKernel(I)) {
62706263
auto Interface = collectEntryPointInterfaces(BF, I);
6271-
BM->addEntryPoint(ExecutionModelKernel, BF->getId(), BF->getName(),
6264+
BM->addEntryPoint(ExecutionModelKernel, BF->getId(), I->getName().str(),
62726265
Interface);
62736266
}
62746267
}
@@ -6630,9 +6623,8 @@ bool LLVMToSPIRVBase::transMetadata() {
66306623
// Work around to translate kernel_arg_type and kernel_arg_type_qual metadata
66316624
static void transKernelArgTypeMD(SPIRVModule *BM, Function *F, MDNode *MD,
66326625
std::string MDName) {
6633-
std::string Prefix = kSPIRVName::EntrypointPrefix;
6634-
std::string Name = F->getName().str().substr(Prefix.size());
6635-
std::string KernelArgTypesMDStr = std::string(MDName) + "." + Name + ".";
6626+
std::string KernelArgTypesMDStr =
6627+
std::string(MDName) + "." + F->getName().str() + ".";
66366628
for (const auto &TyOp : MD->operands())
66376629
KernelArgTypesMDStr += cast<MDString>(TyOp)->getString().str() + ",";
66386630
BM->getString(KernelArgTypesMDStr);

llvm-spirv/test/AtomicCompareExchangeWeak.spvasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
OpCapability Int8
1212
%1 = OpExtInstImport "OpenCL.std"
1313
OpMemoryModel Physical64 OpenCL
14-
OpEntryPoint Kernel %19 "test_atomic_global"
14+
OpEntryPoint Kernel %19 "entry_test_atomic_global"
1515
OpSource OpenCL_C 200000
1616
OpName %test_atomic_global "test_atomic_global"
1717
OpName %dst "dst"

llvm-spirv/test/DebugInfo/DebugInfoTypeVector.spvasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
%1 = OpExtInstImport "OpenCL.std"
2323
%2 = OpExtInstImport "OpenCL.DebugInfo.100"
2424
OpMemoryModel Physical32 OpenCL
25-
OpEntryPoint Kernel %23 "do_add_sub" %__spirv_BuiltInGlobalInvocationId
25+
OpEntryPoint Kernel %23 "kernel" %__spirv_BuiltInGlobalInvocationId
2626
%27 = OpString "/app/<stdin>"
2727
%28 = OpString "//__CSK_MD5:df3c6ff4eef4b9de43419af39216b003"
2828
%31 = OpString "short4"

llvm-spirv/test/extensions/INTEL/SPV_INTEL_cache_controls/multiple-decoration-single-arg.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
; RUN: llvm-spirv --spirv-ext=+SPV_INTEL_cache_controls %t.bc -o %t.spv
44
; RUN: llvm-spirv -r %t.spv --spirv-target-env=SPV-IR -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-LLVM
55

6-
; CHECK-SPIRV-DAG: Name [[#Func:]] "test"
7-
; CHECK-SPIRV-DAG: Name [[#FuncGEP:]] "test_gep"
6+
; CHECK-SPIRV-DAG: EntryPoint [[#]] [[#Func:]] "test"
7+
; CHECK-SPIRV-DAG: EntryPoint [[#]] [[#FuncGEP:]] "test_gep"
88
; CHECK-SPIRV-DAG: TypeInt [[#Int32:]] 32 0
99
; CHECK-SPIRV-DAG: Constant [[#Int32]] [[#Zero:]] 0
1010
; CHECK-SPIRV-DAG: Decorate [[#GEP1:]] CacheControlLoadINTEL 1 1

llvm-spirv/test/extensions/INTEL/SPV_INTEL_fpga_argument_interfaces/sycl-kernel-arg-annotation.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ entry:
5252
; CHECK-SPIRV: Capability FPGAArgumentInterfacesINTEL
5353
; CHECK-SPIRV: Extension "SPV_INTEL_fpga_argument_interfaces"
5454
; CHECK-SPIRV: Extension "SPV_INTEL_fpga_buffer_location"
55-
; CHECK-SPIRV-DAG: Name [[IDS:[0-9]+]] "_arg_p"
5655
; CHECK-SPIRV-DAG: Name [[ID:[0-9]+]] "_arg_p"
5756
; CHECK-SPIRV: Decorate [[ID]] Alignment 4
5857
; CHECK-SPIRV: Decorate [[ID]] MMHostInterfaceAddressWidthINTEL 32

llvm-spirv/test/extensions/INTEL/SPV_INTEL_function_pointers/CodeSectionINTEL/alias.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ target triple = "spir64-unknown-unknown"
1010
; when used since they can't be translated directly.
1111

1212
; CHECK-SPIRV-DAG: Name [[#FOO:]] "foo"
13-
; CHECK-SPIRV-DAG: Name [[#BAR:]] "bar"
13+
; CHECK-SPIRV-DAG: EntryPoint [[#]] [[#BAR:]] "bar"
1414
; CHECK-SPIRV-DAG: Name [[#Y:]] "y"
1515
; CHECK-SPIRV-DAG: Name [[#FOOPTR:]] "foo.alias"
1616
; CHECK-SPIRV-DAG: Decorate [[#FOO]] LinkageAttributes "foo" Export
17-
; CHECK-SPIRV-DAG: Decorate [[#BAR]] LinkageAttributes "bar" Export
1817
; CHECK-SPIRV-DAG: TypeInt [[#I32:]] 32 0
1918
; CHECK-SPIRV-DAG: TypeInt [[#I64:]] 64 0
2019
; CHECK-SPIRV-DAG: TypeFunction [[#FOO_TYPE:]] [[#I32]] [[#I32]]

0 commit comments

Comments
 (0)