Skip to content

[clang][SYCL] Add sycl_external attribute and restrict emitting device code #140282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
abdbf89
Add sycl_external attribute
schittir May 16, 2025
f631d7a
Fix test and remove space
schittir May 16, 2025
128ab1b
Address review comments #1
schittir May 23, 2025
118656c
Fix conditional and failing tests
schittir May 28, 2025
7c592a4
Fix the remaining six failing tests
schittir Jun 4, 2025
90ead01
Fix formatting
schittir Jun 4, 2025
195a3cc
Merge branch 'main' into sycl_external
schittir Jun 5, 2025
a0071d1
Remove sycl_external attribute support to variables.
schittir Jun 9, 2025
d20382c
Rename test file
schittir Jun 9, 2025
65262ba
Add tests for sycl_external attribute
schittir Jun 9, 2025
770c65e
Add code examples to sycl_external documentation
schittir Jun 10, 2025
328d242
Merge branch 'main' into sycl_external
schittir Jun 10, 2025
aab6f7d
Update clang/lib/Sema/SemaDeclAttr.cpp
schittir Jun 10, 2025
385ea37
Address review comments -2
schittir Jun 10, 2025
be80436
Address review comments -3
schittir Jun 17, 2025
060b24f
Rename test file
schittir Jun 17, 2025
625cff2
Address review comments -4
schittir Jun 17, 2025
a9fe3fb
Merge branch 'main' into sycl_external
schittir Jun 17, 2025
4eb05b8
Fix failing tests and address review comments
schittir Jun 18, 2025
ab845a2
Address review comments -3
schittir Jun 24, 2025
3ff689e
Merge branch 'main' into sycl_external
schittir Jun 24, 2025
a177b9b
Merge branch 'main' into sycl_external
schittir Jun 24, 2025
58ffb64
Merge branch 'main' into sycl_external
schittir Jul 1, 2025
7893e90
Merge branch 'main' into sycl_external
schittir Jul 1, 2025
7e76afd
Change the second RUN line to use -sycl-is-host
schittir Jul 3, 2025
e8d26a2
Switch to using sycl_external attr to pass the failing test
schittir Jul 3, 2025
82fa98a
Change diagnostic messages
schittir Jun 25, 2025
e4d15eb
Revert RUN line to -fsycl-is-device
schittir Jul 3, 2025
b38e578
Revert test change
schittir Jul 3, 2025
1d82fc1
Merge branch 'main' into sycl_external
schittir Jul 8, 2025
d751b43
Fix conflict resolution errors.
schittir Jul 8, 2025
2b22ed2
Remove changes introduced from downstream.
schittir Jul 8, 2025
1b3a198
Update diagnostic messages in tests
schittir Jul 8, 2025
568b569
Undo more downstream changes
schittir Jul 8, 2025
0ab9ac5
Ungroup diagnostics and add test cases
schittir Jul 9, 2025
19d1660
Merge branch 'main' into sycl_external
schittir Jul 10, 2025
a70e2df
Fix newly failing tests by adding sycl_external attribute
schittir Jul 10, 2025
45f7b09
Add constexpr and consteval test cases
schittir Jul 10, 2025
4db4101
Use existing diagnostic and address other minor comments
schittir Jul 11, 2025
931fd76
Add additional test cases and address review comments
schittir Jul 14, 2025
e34f2a6
Add test cases
schittir Jul 16, 2025
13a68d5
Add FIXME comments, enable diagnostics for host, remove a needless decl
schittir Jul 18, 2025
2c6cf7f
Merge branch 'main' into sycl_external
schittir Jul 18, 2025
394fc32
Add test cases and address comments
schittir Jul 25, 2025
96fcd60
Add test case where device code is not emitted without the attribute
schittir Jul 26, 2025
8e42487
Merge branch 'main' into sycl_external
schittir Jul 26, 2025
1981b57
Addressing further comments
schittir Jul 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,13 @@ def DeviceKernel : DeclOrTypeAttr {
}];
}

def SYCLExternal : InheritableAttr {
let Spellings = [CXX11<"clang", "sycl_external">];
let Subjects = SubjectList<[Function], ErrorDiag>;
let LangOpts = [SYCLHost, SYCLDevice];
let Documentation = [SYCLExternalDocs];
}

def SYCLKernelEntryPoint : InheritableAttr {
let Spellings = [Clang<"sycl_kernel_entry_point">];
let Args = [
Expand Down
41 changes: 41 additions & 0 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,47 @@ The SYCL kernel in the previous code sample meets these expectations.
}];
}

def SYCLExternalDocs : Documentation {
let Category = DocCatFunction;
let Heading = "sycl_external";
let Content = [{
The ``sycl_external`` attribute indicates that a function defined in another
translation unit may be called by a device function defined in the current
translation unit or, if defined in the current translation unit, the function
may be called by device functions defined in other translation units.
The attribute is intended for use in the implementation of the ``SYCL_EXTERNAL``
macro as specified in section 5.10.1, "SYCL functions and member functions
linkage", of the SYCL 2020 specification.

The attribute only appertains to functions and only those that meet the
following requirements:

* Has external linkage
* Is not explicitly defined as deleted (the function may be an explicitly
defaulted function that is defined as deleted)

The attribute shall be present on the first declaration of a function and
may optionally be present on subsequent declarations.

When compiling for a SYCL device target that does not support the generic
address space, the function shall not specify a raw pointer or reference type
as the return type or as a parameter type.
See section 5.10, "SYCL offline linking", of the SYCL 2020 specification.
The following examples demonstrate the use of this attribute:

.. code-block:: c++

[[clang::sycl_external]] void Foo(); // Ok.

[[clang::sycl_external]] void Bar() { /* ... */ } // Ok.

[[clang::sycl_external]] extern void Baz(); // Ok.

[[clang::sycl_external]] static void Quux() { /* ... */ } // error: Quux() has internal linkage.

}];
}

def SYCLKernelEntryPointDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
Expand Down
9 changes: 9 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -12910,6 +12910,15 @@ def err_sycl_special_type_num_init_method : Error<
"types with 'sycl_special_class' attribute must have one and only one '__init' "
"method defined">;

// SYCL external attribute diagnostics
def err_sycl_attribute_invalid_linkage : Error<
"'clang::sycl_external' can only be applied to functions with external"
" linkage">;
def err_sycl_attribute_invalid_main : Error<
"'clang::sycl_external' cannot be applied to the 'main' function">;
def err_sycl_attribute_invalid_deleted_function : Error<
"'clang::sycl_external' cannot be applied to an explicitly deleted function">;

// SYCL kernel entry point diagnostics
def err_sycl_entry_point_invalid : Error<
"'sycl_kernel_entry_point' attribute cannot be applied to a"
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Sema/SemaSYCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class SemaSYCL : public SemaBase {
void handleKernelAttr(Decl *D, const ParsedAttr &AL);
void handleKernelEntryPointAttr(Decl *D, const ParsedAttr &AL);

void CheckSYCLExternalFunctionDecl(FunctionDecl *FD);
void CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD);
StmtResult BuildSYCLKernelCallStmt(FunctionDecl *FD, CompoundStmt *Body);
};
Expand Down
17 changes: 8 additions & 9 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12975,6 +12975,14 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
if (D->hasAttr<WeakRefAttr>())
return false;

// SYCL device compilation requires that functions defined with the
// sycl_kernel_entry_point or sycl_external attributes be emitted. All
// other entities are emitted only if they are used by a function
// defined with one of those attributes.
if (LangOpts.SYCLIsDevice)
return isa<FunctionDecl>(D) && (D->hasAttr<SYCLKernelEntryPointAttr>() ||
D->hasAttr<SYCLExternalAttr>());

// Aliases and used decls are required.
if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>())
return true;
Expand All @@ -12984,15 +12992,6 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
if (!FD->doesThisDeclarationHaveABody())
return FD->doesDeclarationForceExternallyVisibleDefinition();

// Function definitions with the sycl_kernel_entry_point attribute are
// required during device compilation so that SYCL kernel caller offload
// entry points are emitted.
if (LangOpts.SYCLIsDevice && FD->hasAttr<SYCLKernelEntryPointAttr>())
return true;

// FIXME: Functions declared with SYCL_EXTERNAL are required during
// device compilation.

// Constructors and destructors are required.
if (FD->hasAttr<ConstructorAttr>() || FD->hasAttr<DestructorAttr>())
return true;
Expand Down
29 changes: 29 additions & 0 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4092,6 +4092,19 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
diag::note_carries_dependency_missing_first_decl) << 0/*Function*/;
}

// SYCL 2020 section 5.10.1, "SYCL functions and member functions linkage":
// When a function is declared with SYCL_EXTERNAL, that macro must be
// used on the first declaration of that function in the translation unit.
// Redeclarations of the function in the same translation unit may
// optionally use SYCL_EXTERNAL, but this is not required.
const SYCLExternalAttr *SEA = New->getAttr<SYCLExternalAttr>();
if (SEA && !Old->hasAttr<SYCLExternalAttr>()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with the rest of our attributes, I'd probably suggest we support adding it up until definition. We can then do a conformance warning instead of error, but still let it work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be reasonable. I think we might still have to make it an error if there was an ODR-use before the definition though. I'd have to think about that more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tahonermann - do you have any additional thoughts here?
Thank you!

Diag(SEA->getLocation(), diag::err_attribute_missing_on_first_decl)
<< SEA;
Diag(Old->getLocation(), diag::note_previous_declaration);
New->dropAttr<SYCLExternalAttr>();
}

// (C++98 8.3.5p3):
// All declarations for a function shall agree exactly in both the
// return type and the parameter-type-list.
Expand Down Expand Up @@ -12259,6 +12272,9 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
if (NewFD->hasAttr<SYCLKernelEntryPointAttr>())
SYCL().CheckSYCLEntryPointFunctionDecl(NewFD);

if (NewFD->hasAttr<SYCLExternalAttr>())
SYCL().CheckSYCLExternalFunctionDecl(NewFD);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... this seems like it should be handled when doing the attribute 'visiting', why is it here instead of there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checks include checking for linkage which I don't think is necessarily computed at the time the attribute is visited.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm that linkage isn't computed at that point? I would expect us to (since the entire declaration is read before we handle attributes) have it there, so it is a little surprising.

Also, I didn't see instantiation of this attribute, do we prevent it on function templates?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linkage, or rather, external visibility, which is what we actually check, can depend on other attributes like VisibilityAttr. Checking here ensures that all attributes have been processed and therefore avoids visitation ordering issues.

The attribute is allowed on function templates and is automatically inherited by (implicit and explicit) instantiations (and explicit specializations which is incorrect according to the C++ standard). I don't think there is anything to do to handle instantiation.

We do have a testing gap to address yet though. We have good tests for diagnostics, but are missing a test to validate which symbols are actually emitted. We'll ensure that test exercises function templates.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linkage, or rather, external visibility, which is what we actually check, can depend on other attributes like VisibilityAttr. Checking here ensures that all attributes have been processed and therefore avoids visitation ordering issues.

The attribute is allowed on function templates and is automatically inherited by (implicit and explicit) instantiations (and explicit specializations which is incorrect according to the C++ standard). I don't think there is anything to do to handle instantiation.

We do have a testing gap to address yet though. We have good tests for diagnostics, but are missing a test to validate which symbols are actually emitted. We'll ensure that test exercises function templates.

Ah, I see, the visibility attribute makes sense here, thank you for looking into that.

I don't think there is anything to do to handle instantiation.

We've had to do some work in the past for attribute instantiation, though simple ones might be automatic. Can you make sure that specializations/partial specializations are properly tested? And diagnose if linkage isn't right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll add tests to make sure the attribute has the proper affect with regard to actually emitting symbols. Tests for diagnostics are already in place in clang/test/SemaSYCL/sycl-external-attr.cpp.

Though, hmm, I think we're missing a test for implicit instantiation; I don't think we should diagnose cases like this:

namespace { struct S9 {}; }
struct T9 {
  using type = S9;
};
template<typename>
[[clang::sycl_external]] void func9() {}
template<typename T>
[[clang::sycl_external]] void test_func9() {
  func9<typename T::type>();
}
template void test_func9<T9>(); // Ok; don't diagnose implicit instantiation of func9<S9>().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace { struct S9 {}; }
struct T9 {
  using type = S9;
};
template<typename>
[[clang::sycl_external]] void func9() {} // error here : {{'sycl_external' can only be applied to functions with external linkage}}
template<typename T>
[[clang::sycl_external]] void test_func9() {
  func9<typename T::type>(); // note here: {{in instantiation of function template specialization 'func9<(anonymous namespace)::S9>' requested here}}
}
template void test_func9<T9>(); // note here: {{in instantiation of function template specialization 'test_func9<T9>' requested here}}

This case is being diagnosed at present. Will fix it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test for implicit instantiation, call FunctionDecl::getTemplateSpecializationInfo(). If it returns non-null, call getSpecializationKind() via the returned pointer. If that returns TSK_ImplicitInstantiation, then skip the diagnostic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested change to avoid diagnosing the abovementioned case affects cases even with explicit template specializations, such as the two preceding it in the test file. Using the canonical decls doesn't solve the problem. Further investigation is needed. I will leave the FIXME as it is for this case for follow up in a subsequent PR.


// Semantic checking for this function declaration (in isolation).

if (getLangOpts().CPlusPlus) {
Expand Down Expand Up @@ -12447,6 +12463,12 @@ void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) {
return;
}

if (FD->hasAttr<SYCLExternalAttr>()) {
Diag(FD->getLocation(), diag::err_sycl_attribute_invalid_main);
FD->setInvalidDecl();
return;
}

// Functions named main in hlsl are default entries, but don't have specific
// signatures they are required to conform to.
if (getLangOpts().HLSL)
Expand Down Expand Up @@ -16283,6 +16305,13 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
}
}

if (FD && !FD->isInvalidDecl() && FD->hasAttr<SYCLExternalAttr>()) {
SYCLExternalAttr *SEAttr = FD->getAttr<SYCLExternalAttr>();
if (FD->isDeletedAsWritten())
Diag(SEAttr->getLocation(),
diag::err_sycl_attribute_invalid_deleted_function);
}

{
// Do not call PopExpressionEvaluationContext() if it is a lambda because
// one is already popped when finishing the lambda in BuildLambdaExpr().
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7054,6 +7054,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
case ParsedAttr::AT_EnumExtensibility:
handleEnumExtensibilityAttr(S, D, AL);
break;
case ParsedAttr::AT_SYCLExternal:
handleSimpleAttribute<SYCLExternalAttr>(S, D, AL);
break;
case ParsedAttr::AT_SYCLKernelEntryPoint:
S.SYCL().handleKernelEntryPointAttr(D, AL);
break;
Expand Down
14 changes: 14 additions & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,20 @@ static bool CheckSYCLKernelName(Sema &S, SourceLocation Loc,
return false;
}

void SemaSYCL::CheckSYCLExternalFunctionDecl(FunctionDecl *FD) {
const auto *SEAttr = FD->getAttr<SYCLExternalAttr>();
assert(SEAttr && "Missing sycl_external attribute");
if (!FD->isExternallyVisible()) {
Diag(SEAttr->getLocation(), diag::err_sycl_attribute_invalid_linkage);
return;
}
if (FD->isDeletedAsWritten()) {
Diag(SEAttr->getLocation(),
diag::err_sycl_attribute_invalid_deleted_function);
return;
}
}

void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
// Ensure that all attributes present on the declaration are consistent
// and warn about any redundant ones.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// CHECK-NEXT: [[SPV_CAST:%.*]] = tail call noundef ptr @llvm.spv.generic.cast.to.ptr.explicit.p0(ptr addrspace(4) %p)
// CHECK-NEXT: ret ptr [[SPV_CAST]]
//
__attribute__((opencl_private)) int* test_cast_to_private(int* p) {
[[clang::sycl_external]] __attribute__((opencl_private)) int* test_cast_to_private(int* p) {
return __builtin_spirv_generic_cast_to_ptr_explicit(p, 7);
}

Expand All @@ -18,7 +18,7 @@ __attribute__((opencl_private)) int* test_cast_to_private(int* p) {
// CHECK-NEXT: [[SPV_CAST:%.*]] = tail call noundef ptr addrspace(1) @llvm.spv.generic.cast.to.ptr.explicit.p1(ptr addrspace(4) %p)
// CHECK-NEXT: ret ptr addrspace(1) [[SPV_CAST]]
//
__attribute__((opencl_global)) int* test_cast_to_global(int* p) {
[[clang::sycl_external]] __attribute__((opencl_global)) int* test_cast_to_global(int* p) {
return __builtin_spirv_generic_cast_to_ptr_explicit(p, 5);
}

Expand All @@ -28,6 +28,6 @@ __attribute__((opencl_global)) int* test_cast_to_global(int* p) {
// CHECK-NEXT: [[SPV_CAST:%.*]] = tail call noundef ptr addrspace(3) @llvm.spv.generic.cast.to.ptr.explicit.p3(ptr addrspace(4) %p)
// CHECK-NEXT: ret ptr addrspace(3) [[SPV_CAST]]
//
__attribute__((opencl_local)) int* test_cast_to_local(int* p) {
[[clang::sycl_external]] __attribute__((opencl_local)) int* test_cast_to_local(int* p) {
return __builtin_spirv_generic_cast_to_ptr_explicit(p, 4);
}
24 changes: 12 additions & 12 deletions clang/test/CodeGenSPIRV/Builtins/ids_and_ranges.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// CHECK64-NEXT: tail call i64 @llvm.spv.num.workgroups.i64(i32 0)
// CHECK32-NEXT: tail call i32 @llvm.spv.num.workgroups.i32(i32 0)
//
unsigned int test_num_workgroups() {
[[clang::sycl_external]] unsigned int test_num_workgroups() {
return __builtin_spirv_num_workgroups(0);
}

Expand All @@ -16,7 +16,7 @@ unsigned int test_num_workgroups() {
// CHECK64-NEXT: tail call i64 @llvm.spv.workgroup.size.i64(i32 0)
// CHECK32-NEXT: tail call i32 @llvm.spv.workgroup.size.i32(i32 0)
//
unsigned int test_workgroup_size() {
[[clang::sycl_external]] unsigned int test_workgroup_size() {
return __builtin_spirv_workgroup_size(0);
}

Expand All @@ -25,7 +25,7 @@ unsigned int test_workgroup_size() {
// CHECK64-NEXT: tail call i64 @llvm.spv.group.id.i64(i32 0)
// CHECK32-NEXT: tail call i32 @llvm.spv.group.id.i32(i32 0)
//
unsigned int test_workgroup_id() {
[[clang::sycl_external]] unsigned int test_workgroup_id() {
return __builtin_spirv_workgroup_id(0);
}

Expand All @@ -34,7 +34,7 @@ unsigned int test_workgroup_id() {
// CHECK64-NEXT: tail call i64 @llvm.spv.thread.id.in.group.i64(i32 0)
// CHECK32-NEXT: tail call i32 @llvm.spv.thread.id.in.group.i32(i32 0)
//
unsigned int test_local_invocation_id() {
[[clang::sycl_external]] unsigned int test_local_invocation_id() {
return __builtin_spirv_local_invocation_id(0);
}

Expand All @@ -43,7 +43,7 @@ unsigned int test_local_invocation_id() {
// CHECK64-NEXT: tail call i64 @llvm.spv.thread.id.i64(i32 0)
// CHECK32-NEXT: tail call i32 @llvm.spv.thread.id.i32(i32 0)
//
unsigned int test_global_invocation_id() {
[[clang::sycl_external]] unsigned int test_global_invocation_id() {
return __builtin_spirv_global_invocation_id(0);
}

Expand All @@ -52,7 +52,7 @@ unsigned int test_global_invocation_id() {
// CHECK64-NEXT: tail call i64 @llvm.spv.global.size.i64(i32 0)
// CHECK32-NEXT: tail call i32 @llvm.spv.global.size.i32(i32 0)
//
unsigned int test_global_size() {
[[clang::sycl_external]] unsigned int test_global_size() {
return __builtin_spirv_global_size(0);
}

Expand All @@ -61,46 +61,46 @@ unsigned int test_global_size() {
// CHECK64-NEXT: tail call i64 @llvm.spv.global.offset.i64(i32 0)
// CHECK32-NEXT: tail call i32 @llvm.spv.global.offset.i32(i32 0)
//
unsigned int test_global_offset() {
[[clang::sycl_external]] unsigned int test_global_offset() {
return __builtin_spirv_global_offset(0);
}

// CHECK: @test_subgroup_size(
// CHECK-NEXT: [[ENTRY:.*:]]
// CHECK-NEXT: tail call i32 @llvm.spv.subgroup.size()
//
unsigned int test_subgroup_size() {
[[clang::sycl_external]] unsigned int test_subgroup_size() {
return __builtin_spirv_subgroup_size();
}

// CHECK: @test_subgroup_max_size(
// CHECK-NEXT: [[ENTRY:.*:]]
// CHECK-NEXT: tail call i32 @llvm.spv.subgroup.max.size()
//
unsigned int test_subgroup_max_size() {
[[clang::sycl_external]] unsigned int test_subgroup_max_size() {
return __builtin_spirv_subgroup_max_size();
}

// CHECK: @test_num_subgroups(
// CHECK-NEXT: [[ENTRY:.*:]]
// CHECK-NEXT: tail call i32 @llvm.spv.num.subgroups()
//
unsigned int test_num_subgroups() {
[[clang::sycl_external]] unsigned int test_num_subgroups() {
return __builtin_spirv_num_subgroups();
}

// CHECK: @test_subgroup_id(
// CHECK-NEXT: [[ENTRY:.*:]]
// CHECK-NEXT: tail call i32 @llvm.spv.subgroup.id()
//
unsigned int test_subgroup_id() {
[[clang::sycl_external]] unsigned int test_subgroup_id() {
return __builtin_spirv_subgroup_id();
}

// CHECK: @test_subgroup_local_invocation_id(
// CHECK-NEXT: [[ENTRY:.*:]]
// CHECK-NEXT: tail call i32 @llvm.spv.subgroup.local.invocation.id()
//
unsigned int test_subgroup_local_invocation_id() {
[[clang::sycl_external]] unsigned int test_subgroup_local_invocation_id() {
return __builtin_spirv_subgroup_local_invocation_id();
}
Loading
Loading