Skip to content

Commit a54f245

Browse files
SPIRV and SYCL builtin functions are not considered as module entry points
1 parent 1eec0c4 commit a54f245

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; RUN: sycl-post-link -ir-output-only -split=auto -S %s -o %t.ll
2+
; RUN: FileCheck %s -input-file=%t.ll
3+
4+
; This test checks that known SPIRV and SYCL builtin functions
5+
; (that are also marked with SYCL_EXTRENAL) are not considered
6+
; as module entry points and thus are not added as entry to the
7+
; device binary symbol table. So, they can be dropped if
8+
; unreferenced.
9+
10+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
11+
target triple = "spir64-unknown-linux-sycldevice"
12+
13+
define dso_local spir_func void @_Z28__spirv_GlobalInvocationId_xv() #0 {
14+
ret void
15+
}
16+
define dso_local spir_func void @_Z28__spXrv_GlobalInvocationId_xv() #0 {
17+
ret void
18+
}
19+
20+
define dso_local spir_func void @_Z33__sycl_getScalarSpecConstantValue() #0 {
21+
ret void
22+
}
23+
define dso_local spir_func void @_Z33__sXcl_getScalarSpecConstantValue() #0 {
24+
ret void
25+
}
26+
27+
attributes #0 = { "sycl-module-id"="a.cpp" }
28+
29+
; CHECK-NOT: define dso_local spir_func void @_Z28__spirv_GlobalInvocationId_xv()
30+
; CHECK-NOT: define dso_local spir_func void @_Z33__sycl_getScalarSpecConstantValue()
31+
32+
; CHECK-DAG: define dso_local spir_func void @_Z28__spXrv_GlobalInvocationId_xv()
33+
; CHECK-DAG: define dso_local spir_func void @_Z33__sXcl_getScalarSpecConstantValue()

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,17 @@ static KernelMapEntryScope selectDeviceCodeSplitScopeAutomatically(Module &M) {
232232
return Scope_PerModule;
233233
}
234234

235+
// Return true if the function is a SPIRV or SYCL builtin, e.g.
236+
// _Z28__spirv_GlobalInvocationId_xv
237+
static bool funcIsSpirvSyclBuiltin(StringRef FName) {
238+
if (!FName.consume_front("_Z"))
239+
return false;
240+
// now skip the digits
241+
FName = FName.drop_while([](char C) { return std::isdigit(C); });
242+
243+
return FName.startswith("__spirv_") || FName.startswith("__sycl_");
244+
}
245+
235246
// This function decides how kernels of the input module M will be distributed
236247
// ("split") into multiple modules based on the command options and IR
237248
// attributes. The decision is recorded in the output map parameter
@@ -244,9 +255,11 @@ static void collectKernelModuleMap(
244255

245256
// Process module entry points: kernels and SYCL_EXTERNAL functions.
246257
// Only they have sycl-module-id attribute, so any other unrefenced
247-
// functions are dropped.
258+
// functions are dropped. SPIRV and SYCL builtin functions are not
259+
// considered as module entry points.
248260
for (auto &F : M.functions()) {
249-
if (F.hasFnAttribute(ATTR_SYCL_MODULE_ID)) {
261+
if (F.hasFnAttribute(ATTR_SYCL_MODULE_ID) &&
262+
!funcIsSpirvSyclBuiltin(F.getName())) {
250263
switch (EntryScope) {
251264
case Scope_PerKernel:
252265
ResKernelModuleMap[F.getName()].push_back(&F);
@@ -644,9 +657,11 @@ static ModulePair splitSyclEsimd(std::unique_ptr<Module> M) {
644657
// Collect information about the SYCL and ESIMD functions in the module.
645658
// Process module entry points: kernels and SYCL_EXTERNAL functions.
646659
// Only they have sycl-module-id attribute, so any other unrefenced
647-
// functions are dropped.
660+
// functions are dropped. SPIRV and SYCL builtin functions are not
661+
// considered as module entry points.
648662
for (auto &F : M->functions()) {
649-
if (F.hasFnAttribute(ATTR_SYCL_MODULE_ID)) {
663+
if (F.hasFnAttribute(ATTR_SYCL_MODULE_ID) &&
664+
!funcIsSpirvSyclBuiltin(F.getName())) {
650665
if (F.getMetadata("sycl_explicit_simd"))
651666
EsimdFunctions.push_back(&F);
652667
else

0 commit comments

Comments
 (0)