@@ -232,6 +232,17 @@ static KernelMapEntryScope selectDeviceCodeSplitScopeAutomatically(Module &M) {
232
232
return Scope_PerModule;
233
233
}
234
234
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
+
235
246
// This function decides how kernels of the input module M will be distributed
236
247
// ("split") into multiple modules based on the command options and IR
237
248
// attributes. The decision is recorded in the output map parameter
@@ -244,9 +255,11 @@ static void collectKernelModuleMap(
244
255
245
256
// Process module entry points: kernels and SYCL_EXTERNAL functions.
246
257
// 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.
248
260
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 ())) {
250
263
switch (EntryScope) {
251
264
case Scope_PerKernel:
252
265
ResKernelModuleMap[F.getName ()].push_back (&F);
@@ -644,9 +657,11 @@ static ModulePair splitSyclEsimd(std::unique_ptr<Module> M) {
644
657
// Collect information about the SYCL and ESIMD functions in the module.
645
658
// Process module entry points: kernels and SYCL_EXTERNAL functions.
646
659
// 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.
648
662
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 ())) {
650
665
if (F.getMetadata (" sycl_explicit_simd" ))
651
666
EsimdFunctions.push_back (&F);
652
667
else
0 commit comments